:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #657089;
  --border: #d7deea;
  --primary: #1557d6;
  --accent: #6b3fd6;
  --success: #147a45;
  --danger: #a93131;
  --shadow: 0 8px 22px rgba(23, 32, 51, 0.07);
}
* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, textarea, input, select { font: inherit; }
.app-shell {
  width: min(98vw, 1760px);
  margin: 0 auto;
  padding: clamp(10px, 1.4vw, 24px);
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 10px;
}
.eyebrow { margin: 0 0 4px; font-size: .72rem; letter-spacing: .11em; font-weight: 800; color: var(--primary); }
h1 { margin: 0; font-size: clamp(1.55rem, 2.6vw, 2.7rem); line-height: 1.03; }
h2 { margin: 0; }
.subtitle { margin: 5px 0 0; color: var(--muted); font-size: clamp(.85rem, 1vw, 1rem); }
.status-pill { padding: 8px 12px; border-radius: 999px; background: #e8f5ee; color: var(--success); font-weight: 800; white-space: nowrap; font-size: .86rem; }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 10px 0; }
.metrics > div { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 9px 13px; box-shadow: var(--shadow); }
.metrics strong { display: block; font-size: clamp(1.2rem, 1.8vw, 1.55rem); line-height: 1.1; }
.metrics span { color: var(--muted); font-size: .8rem; }
.compact-card, .composer, .keyboard, .prediction-panel, .insight-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
}
.setup-grid {
  display: grid;
  grid-template-columns: minmax(260px, .82fr) minmax(430px, 1.35fr) minmax(350px, 1fr);
  gap: 10px;
  margin-bottom: 10px;
  align-items: stretch;
}
.compact-card { padding: 11px 13px; min-width: 0; }
.controls-panel { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center; }
.controls-panel > div { grid-column: 1 / -1; }
.controls-panel h2, .speech-panel h2 { font-size: 1.05rem; }
.toggle-row, .dwell-row { display: flex; align-items: center; gap: 7px; font-weight: 750; font-size: .88rem; }
.toggle-row input { width: 20px; height: 20px; }
.dwell-row { grid-column: 1 / -1; }
.dwell-row input { width: min(150px, 34vw); }
.compact-button { min-height: 42px; padding: 8px 12px; border-radius: 11px; }
.controls-panel > button { justify-self: start; }
.speech-panel { display: grid; grid-template-columns: auto 1fr; gap: 7px 12px; align-items: center; }
.speech-selects { display: grid; grid-template-columns: minmax(110px, .7fr) minmax(190px, 1.3fr); gap: 8px; }
.speech-panel label { display: flex; flex-direction: column; gap: 4px; font-weight: 750; font-size: .82rem; }
.speech-panel select { min-height: 40px; border: 2px solid var(--border); border-radius: 10px; padding: 6px 8px; background: white; color: var(--text); min-width: 0; width: 100%; }
.voice-status { grid-column: 1 / -1; margin: 0; color: var(--muted); font-weight: 650; font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-card { display: grid; gap: 9px; }
.task-label { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; font-weight: 800; letter-spacing: .07em; }
#taskGoal { display: block; font-size: .96rem; line-height: 1.25; margin-top: 3px; }
.task-buttons, .action-row { display: flex; gap: 8px; flex-wrap: wrap; }
.task-buttons .compact-button { flex: 1 1 90px; }
.composer { padding: 12px 14px; margin-bottom: 10px; }
.composer label { display: block; font-weight: 800; margin-bottom: 5px; }
#messageBox {
  width: 100%; resize: vertical; height: clamp(88px, 10vh, 108px); min-height: 82px; font-size: clamp(1.25rem, 1.75vw, 1.6rem);
  line-height: 1.38; border: 3px solid var(--border); border-radius: 13px; padding: 11px 13px; color: var(--text);
}
#messageBox:focus { outline: 4px solid rgba(21, 87, 214, .14); border-color: var(--primary); }
.action-row { margin-top: 8px; }
button { border: 0; border-radius: 12px; min-height: 50px; padding: 9px 14px; font-weight: 800; cursor: pointer; position: relative; overflow: hidden; }
button:focus-visible { outline: 4px solid #f2ad24; outline-offset: 3px; }
button:hover { transform: translateY(-1px); }
.primary { background: var(--primary); color: white; }
.accent { background: var(--accent); color: white; }
.success { background: var(--success); color: white; }
.danger { background: #fbe8e8; color: var(--danger); }
.secondary { background: #edf2f8; color: var(--text); border: 1px solid var(--border); }
.feedback { min-height: 20px; margin: 6px 0 0; font-weight: 700; font-size: .86rem; color: var(--success); }
.input-workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  align-items: start;
}
.keyboard-panel, .prediction-panel { min-width: 0; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 10px; margin: 0 2px 7px; }
.section-heading h2 { font-size: 1.12rem; }
.section-heading p:last-child { margin: 0; color: var(--muted); font-size: .78rem; }
.keyboard { padding: 10px; display: grid; grid-template-columns: repeat(10, minmax(52px, 1fr)); gap: 7px; }
.key { min-height: clamp(54px, 6.1vh, 65px); font-size: clamp(1.05rem, 1.3vw, 1.22rem); background: #f8fafc; border: 2px solid var(--border); color: var(--text); }
.key.special { background: #fff5da; border-color: #ecd18b; }
.key.wide { grid-column: span 3; }
.key.space-key { grid-column: span 4; }
.key.backspace { font-size: .95rem; background: #fff2e2; border-color: #e8bd87; }
.prediction-panel { padding: 10px; position: static; }
.prediction-heading { margin-bottom: 7px; }
/* Eight reserved physical slots: four columns by two rows.
   Empty placeholders remain invisible but occupy their cells, keeping the keyboard fixed. */
.suggestion-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(60px, auto)); gap: 8px; }
.suggestion { min-height: 60px; font-size: clamp(.86rem, 1vw, 1rem); line-height: 1.18; background: #eaf1ff; color: #123d88; border: 2px solid #c6d7fb; padding: 8px; }
.word-prediction { background: #f5f9ff; border-color: #a9c5f7; }
.phrase-prediction { background: #eaf1ff; border-color: #c6d7fb; }
.suggestion.placeholder { visibility: hidden; pointer-events: none; }
.insight-card { margin-top: 10px; padding: 10px 14px; border-left: 5px solid var(--primary); }
.insight-card summary { font-weight: 800; cursor: pointer; }
.insight-card p { margin: 8px 0 0; font-size: .9rem; }
.gaze-target.dwelling::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 7px; background: #f2ad24;
  animation: dwellProgress var(--dwell-duration, 900ms) linear forwards;
}
@keyframes dwellProgress { from { width: 0; } to { width: 100%; } }

/* Use wide desktop screens instead of leaving large empty side margins. */
@media (min-width: 1500px) {
  .app-shell { width: min(96vw, 1800px); }
}

/* Height-aware compaction: preserve target size while reducing non-interactive vertical space. */
@media (min-width: 1100px) and (max-height: 1150px) {
  .app-shell { padding-top: 8px; padding-bottom: 10px; }
  .topbar { margin-bottom: 6px; }
  .subtitle { display: none; }
  .metrics { margin: 6px 0; }
  .metrics > div { padding: 6px 11px; }
  .setup-grid { margin-bottom: 7px; }
  .compact-card { padding: 8px 10px; }
  .composer { padding: 9px 11px; margin-bottom: 7px; }
  #messageBox { height: 82px; min-height: 78px; }
  .action-row { margin-top: 6px; }
  .action-row button { min-height: 44px; }
  .feedback { margin-top: 4px; }
  .keyboard { padding: 8px; gap: 6px; }
  .key { min-height: 50px; }
  .prediction-panel { padding: 8px; }
  .suggestion-grid { grid-template-rows: repeat(2, minmax(54px, auto)); gap: 6px; }
  .suggestion { min-height: 54px; }
  .insight-card { margin-top: 7px; }
}

@media (max-width: 1250px) {
  .setup-grid { grid-template-columns: 1fr 1.4fr; }
  .task-card { grid-column: 1 / -1; grid-template-columns: minmax(300px, 1fr) auto; align-items: center; }
}
@media (max-width: 1020px) {
  .setup-grid { grid-template-columns: 1fr; }
  .task-card { grid-template-columns: 1fr; }
  .suggestion-grid { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, minmax(62px, auto)); }
  .keyboard { grid-template-columns: repeat(10, minmax(44px, 1fr)); }
}
@media (max-width: 760px) {
  .topbar { flex-direction: column; gap: 8px; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .speech-panel { grid-template-columns: 1fr; }
  .speech-selects { grid-template-columns: 1fr; }
  .suggestion-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(64px, auto)); }
  .suggestion { font-size: .8rem; padding: 6px; }
  .keyboard { grid-template-columns: repeat(5, 1fr); }
  .key.wide, .key.space-key { grid-column: span 2; }
}
@media (max-width: 500px) {
  .app-shell { width: 100%; padding: 8px; }
  .metrics { gap: 6px; }
  .suggestion-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(58px, auto)); gap: 5px; }
  .suggestion { min-height: 58px; font-size: .72rem; padding: 4px; }
}

/* Hosted SmartBox test refinements */
html, body { max-width: 100%; overflow-x: hidden; overscroll-behavior: none; }
body { touch-action: manipulation; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.utility-button { min-height: 48px; padding-inline: 14px; }
.privacy-strip {
  background: #eef7f2; border: 1px solid #bddccb; color: #245c3f;
  border-radius: 12px; padding: 8px 12px; margin: 6px 0 8px; font-size: .84rem;
}
.smartbox-note { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: .78rem; line-height: 1.3; }
.diagnostics-card {
  margin-top: 10px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); border-left: 5px solid #6b3fd6;
}
.diagnostics-card summary { font-weight: 800; cursor: pointer; }
.diagnostics-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-top: 10px; }
.diagnostic-item { background: #f7f9fc; border: 1px solid var(--border); border-radius: 10px; padding: 7px 9px; min-width: 0; }
.diagnostic-item span { display: block; color: var(--muted); font-size: .72rem; }
.diagnostic-item strong { display: block; margin-top: 2px; overflow-wrap: anywhere; font-size: .84rem; }
.diagnostics-help { color: var(--muted); font-size: .8rem; margin: 8px 0 0; }

/* A gaze target should not physically move under the pointer. */
button:hover { transform: none; }
button:hover, button:focus-visible { box-shadow: 0 0 0 3px rgba(21,87,214,.12); }

/* Keep interactive targets comfortably large even on height-compacted desktops. */
button { min-height: 54px; }
.compact-button, .utility-button { min-height: 48px; }
@media (min-width: 1100px) and (max-height: 1150px) {
  .action-row button { min-height: 50px; }
  .key { min-height: 52px; }
}
@media (max-width: 900px) {
  .diagnostics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .header-actions { justify-content: flex-start; }
}
@media (max-width: 560px) {
  .diagnostics-grid { grid-template-columns: 1fr; }
}

/* ============================================================
   SmartBox Test Build .2 — single-screen viewport fit
   Goal: keep the entire communication workspace visible without
   page scrolling, while preserving stable gaze target locations.
   ============================================================ */

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  height: 100vh;
  height: 100dvh;
}

.app-shell {
  width: 100%;
  max-width: none;
  height: 100vh;
  height: 100dvh;
  margin: 0;
  padding: clamp(6px, .7vw, 12px);
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr);
  gap: clamp(4px, .55vh, 7px);
  overflow: hidden;
}

/* Header: retain identity and safety state, but do not spend
   valuable vertical gaze space on explanatory copy. */
.topbar {
  margin: 0;
  gap: 10px;
  align-items: center;
  min-height: 46px;
}
.topbar > div:first-child { min-width: 0; }
.topbar .subtitle { display: none; }
.topbar .eyebrow { margin-bottom: 1px; font-size: .64rem; }
h1 { font-size: clamp(1.45rem, 2.05vw, 2.15rem); line-height: 1; white-space: nowrap; }
.header-actions { flex-wrap: nowrap; gap: 6px; }
.status-pill { padding: 6px 10px; font-size: .78rem; }
.utility-button { min-height: 42px; padding: 6px 11px; }

.privacy-strip {
  margin: 0;
  padding: 5px 10px;
  border-radius: 10px;
  font-size: .76rem;
  line-height: 1.2;
}

/* Metrics remain visible, but function as a compact instrument bar. */
.metrics {
  margin: 0;
  gap: 6px;
}
.metrics > div {
  border-radius: 11px;
  padding: 5px 10px;
  box-shadow: none;
}
.metrics strong { font-size: clamp(1.05rem, 1.35vw, 1.35rem); }
.metrics span { font-size: .68rem; }

/* Three setup areas stay on one row on SmartBox-sized desktop views. */
.setup-grid {
  grid-template-columns: minmax(260px, .8fr) minmax(420px, 1.35fr) minmax(340px, 1fr);
  gap: 6px;
  margin: 0;
  min-height: 0;
}
.compact-card {
  padding: 6px 9px;
  border-radius: 12px;
  box-shadow: none;
}
.compact-card .eyebrow { font-size: .61rem; margin-bottom: 1px; }
.controls-panel,
.speech-panel { gap: 4px 8px; }
.controls-panel h2,
.speech-panel h2 { font-size: .9rem; }
.toggle-row,
.dwell-row { font-size: .76rem; gap: 5px; }
.toggle-row input { width: 17px; height: 17px; }
.dwell-row input { width: min(130px, 28vw); }
.smartbox-note { font-size: .66rem; line-height: 1.15; }
.compact-button { min-height: 38px; padding: 5px 9px; border-radius: 9px; font-size: .78rem; }
.speech-panel label { font-size: .7rem; gap: 2px; }
.speech-panel select { min-height: 35px; padding: 4px 7px; border-radius: 8px; }
.voice-status { font-size: .66rem; }
.task-card { gap: 5px; }
.task-label { font-size: .62rem; }
#taskGoal { font-size: .8rem; margin-top: 1px; }
.task-buttons { gap: 5px; flex-wrap: nowrap; }
.task-buttons .compact-button { min-height: 42px; }

/* Composer: large enough for easy reading, but fixed so it cannot push
   predictions and keyboard below the viewport. */
.composer {
  margin: 0;
  padding: 7px 10px;
  border-radius: 12px;
  box-shadow: none;
  min-height: 0;
}
.composer label { margin-bottom: 3px; font-size: .82rem; }
#messageBox {
  height: clamp(58px, 7.3vh, 76px);
  min-height: 54px;
  resize: none;
  padding: 7px 10px;
  border-width: 2px;
  border-radius: 10px;
  font-size: clamp(1.02rem, 1.45vw, 1.35rem);
  line-height: 1.25;
}
.action-row { margin-top: 5px; gap: 5px; flex-wrap: nowrap; }
.action-row button {
  min-height: 41px;
  padding: 5px 10px;
  border-radius: 9px;
  font-size: .78rem;
}
.feedback {
  min-height: 13px;
  margin: 2px 0 0;
  line-height: 1.1;
  font-size: .67rem;
}

/* The remaining viewport is reserved for the two-row prediction strip
   and the keyboard. Neither panel changes its physical location. */
.input-workspace {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(94px, 12vh) minmax(0, 1fr);
  gap: 5px;
  overflow: hidden;
}
.prediction-panel,
.keyboard-panel { min-height: 0; overflow: hidden; }
.prediction-panel {
  padding: 5px 8px;
  border-radius: 12px;
  box-shadow: none;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.section-heading {
  margin: 0 1px 4px;
  min-height: 24px;
  align-items: center;
}
.section-heading .eyebrow { font-size: .58rem; margin-bottom: 0; }
.section-heading h2 { font-size: .9rem; line-height: 1.05; }
.section-heading p:last-child { font-size: .64rem; }
.prediction-heading { margin-bottom: 4px; }
.suggestion-grid {
  min-height: 0;
  height: 100%;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 5px;
}
.suggestion {
  min-height: 0;
  height: 100%;
  padding: 4px 6px;
  border-radius: 9px;
  font-size: clamp(.7rem, .9vw, .88rem);
  line-height: 1.1;
}

.keyboard-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.keyboard {
  height: 100%;
  min-height: 0;
  padding: 5px;
  gap: 4px;
  border-radius: 12px;
  box-shadow: none;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
}
.key {
  min-height: 0 !important;
  height: 100%;
  padding: 3px 5px;
  border-radius: 8px;
  font-size: clamp(.78rem, 1.05vw, 1.05rem);
}
.key.backspace { font-size: .72rem; }

/* Diagnostics are still in the source and available to developers if
   re-enabled, but they must never create a page scrollbar during a
   SmartBox communication session. */
.diagnostics-card,
.insight-card { display: none; }

/* Override older responsive rules that stacked the setup cards or changed
   the keyboard to five columns. A gaze layout must remain spatially stable. */
@media (min-width: 901px) {
  .setup-grid { grid-template-columns: minmax(250px, .8fr) minmax(400px, 1.35fr) minmax(320px, 1fr) !important; }
  .task-card { grid-column: auto !important; grid-template-columns: 1fr !important; }
  .keyboard { grid-template-columns: repeat(10, minmax(0, 1fr)) !important; }
  .key.wide { grid-column: span 3 !important; }
  .key.space-key { grid-column: span 4 !important; }
}

/* Short desktop viewports: compact passive text before shrinking the
   keyboard. This is the automatic fit path for browser chrome / scaling. */
@media (min-width: 901px) and (max-height: 820px) {
  .app-shell { padding: 4px 7px; gap: 3px; }
  .privacy-strip { padding-block: 3px; font-size: .68rem; }
  .metrics > div { padding-block: 3px; }
  .smartbox-note { display: none; }
  .voice-status { font-size: .61rem; }
  .composer { padding-block: 5px; }
  #messageBox { height: 50px; min-height: 48px; }
  .action-row button { min-height: 36px; }
  .input-workspace { grid-template-rows: 84px minmax(0, 1fr); }
  .section-heading { min-height: 19px; margin-bottom: 2px; }
  .suggestion-grid, .keyboard { gap: 3px; }
}

/* Very narrow devices keep natural page flow rather than making gaze
   targets unreasonably small. Michael's SmartBox test is desktop-class. */
@media (max-width: 900px) {
  html, body { height: auto; min-height: 100%; overflow-y: auto; }
  body { height: auto; }
  .app-shell { height: auto; min-height: 100vh; overflow: visible; display: block; }
  .topbar { flex-direction: column; align-items: stretch; }
  h1 { white-space: normal; }
  .header-actions { flex-wrap: wrap; }
  .metrics, .setup-grid, .composer, .input-workspace { margin-bottom: 7px; }
  .setup-grid { display: grid; grid-template-columns: 1fr !important; }
  .task-card { grid-template-columns: 1fr !important; }
  .input-workspace { height: auto; display: grid; grid-template-rows: auto auto; overflow: visible; }
  .prediction-panel, .keyboard-panel { overflow: visible; }
  .suggestion-grid { grid-template-rows: repeat(2, minmax(54px, auto)); }
  .keyboard { height: auto; grid-template-columns: repeat(5, 1fr) !important; grid-template-rows: none; }
  .key { min-height: 50px !important; height: auto; }
  .key.wide, .key.space-key { grid-column: span 2 !important; }
}
