/* ============================================================
   SpeakEase — plain CSS, no frameworks, no external assets.
   High contrast, large type, touch-first.
   ============================================================ */

:root {
  --ink: #14306b;        /* deep navy — text / borders (≈14:1 on white) */
  --ink-soft: #1f3f85;
  --paper: #fbf7f0;      /* warm cream page background */
  --card: #ffffff;       /* card face */
  --amber: #ffd166;      /* flash / highlight (with dark text ≈8:1) */
  --amber-deep: #e8b23a;
  --white: #ffffff;
  --focus: #ff8a00;      /* visible keyboard/touch focus ring */
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.45;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;   /* no double-tap zoom delay */
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; }

:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 3px;
  border-radius: 6px;
}

/* Text only for screen readers — used for the board's page heading, since the
   visible brand there is the logo image in the header. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------
   SpeakEase logo (shared by the landing header and the board top bar)
   ------------------------------------------------------------
   Both headers sit on the navy --ink background and the logo's wordmark is
   the same deep navy, so the logo is placed on a small light chip — the brand
   stays readable on both pages without changing either page background.
   Height is capped and width stays auto, so the proportions never distort. */

.brand-logo {
  display: block;
  box-sizing: content-box;      /* the clamp() below is the logo's own height */
  height: clamp(1.6rem, 3.6vw, 2.6rem);
  width: auto;
  max-width: 100%;              /* never overflows the header on tiny screens */
  padding: 0.3rem 0.5rem;
  background: var(--white);
  border-radius: 0.6rem;
  flex: 0 0 auto;
}

/* ------------------------------------------------------------
   Landing page
   ------------------------------------------------------------ */

.site-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.1rem 1.25rem;
  background: var(--ink);
  color: var(--white);
}

.landing-main {
  max-width: 46rem;
  margin: 0 auto;
  padding: clamp(2.5rem, 8vw, 5rem) 1.25rem 3rem;
  text-align: center;
}

.landing-main h1 {
  font-size: clamp(2.1rem, 6vw, 3.4rem);
  line-height: 1.12;
  margin: 0 0 1.25rem;
  font-weight: 800;
}

.lede {
  font-size: clamp(1.2rem, 2.6vw, 1.5rem);
  margin: 0 auto 1.5rem;
  max-width: 38rem;
}

.who {
  font-size: 1.15rem;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 1rem;
  padding: 1rem 1.25rem;
  margin: 0 auto 2rem;
  max-width: 36rem;
}

.steps {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem 1.5rem;
  padding: 0;
  margin: 0 auto 2.5rem;
  font-size: 1.2rem;
  font-weight: 700;
}

.steps li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.step-icon { font-size: 1.6rem; }

/* Big call to action */
.cta {
  display: inline-block;
  background: var(--ink);
  color: var(--white);
  font-size: clamp(1.35rem, 3vw, 1.7rem);
  font-weight: 800;
  text-decoration: none;
  border: 3px solid var(--ink);
  border-radius: 1.25rem;
  padding: 1.1rem 2.4rem;
  min-height: 4.5rem;
  box-shadow: 0 6px 0 var(--amber-deep);
}

.cta:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--amber-deep); }

.note {
  margin-top: 2.5rem;
  font-size: 1rem;
  color: var(--ink-soft);
}

.site-foot {
  padding: 1rem 1.25rem 2rem;
  text-align: center;
  font-size: 0.95rem;
  color: var(--ink-soft);
}

.site-foot p { margin: 0; }

/* ------------------------------------------------------------
   Board — top bar
   ------------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--white);
}

/* The brand is now the logo lockup (see .brand-logo). min-width: 0 lets this
   flex item give way to the header controls instead of pushing them off a
   narrow screen. */
.topbar .brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  text-decoration: none;
}

.gear {
  width: 3.25rem;
  height: 3.25rem;
  font-size: 1.55rem;
  line-height: 1;
  border-radius: 50%;
  border: 3px solid var(--white);
  background: var(--ink);
  color: var(--white);
  cursor: pointer;
}

/* ------------------------------------------------------------
   Board — settings (caregiver-only, out of the way)
   ------------------------------------------------------------ */

.settings {
  background: var(--white);
  border-bottom: 3px solid var(--ink);
  padding: 1rem 1.25rem;
}

.settings[hidden] { display: none; }

.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  max-width: 60rem;
  margin: 0 auto;
}

.settings-row + .settings-row { margin-top: 1rem; }
/* A note between settings rows (e.g. the offline-voice note) keeps the row
   rhythm instead of collapsing onto the row below it. */
.settings-note + .settings-row { margin-top: 1rem; }
.settings-row + .settings-note { margin-top: 0.6rem; }

.settings-label {
  font-weight: 800;
  font-size: 1.15rem;
}

.rate-group {
  display: flex;
  gap: 0.5rem;
}

.rate-btn {
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.7rem 1.4rem;
  min-height: 3.25rem;
  cursor: pointer;
}

.rate-btn[aria-checked="true"] {
  background: var(--ink);
  color: var(--white);
}

.test-voice {
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--amber);
  color: var(--ink);
  font-weight: 800;
  font-size: 1.1rem;
  padding: 0.7rem 1.4rem;
  min-height: 3.25rem;
  cursor: pointer;
}

.settings-note {
  font-size: 0.95rem;
  color: var(--ink-soft);
}

/* ------------------------------------------------------------
   Board — message banner (always visible, tap to repeat)
   ------------------------------------------------------------ */

.banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 100%;
  min-height: clamp(6.5rem, 20vw, 10rem);
  padding: 0.9rem 1rem 0.7rem;
  background: var(--ink);
  color: var(--white);
  border: none;
  border-bottom: 6px solid var(--amber);
  cursor: pointer;
  text-align: center;
}

.banner-msg {
  font-size: clamp(2.1rem, 9vw, 4.2rem);
  font-weight: 800;
  line-height: 1.1;
  word-break: break-word;
}

.banner-hint {
  font-size: 0.95rem;
  color: #cfe0ff;
  opacity: 0.95;
}

.banner.is-flashed .banner-hint { color: var(--amber); }

.banner.is-flashed { background: var(--ink-soft); }

/* ------------------------------------------------------------
   Board — category tabs
   ------------------------------------------------------------ */

.tabs {
  display: flex;
  gap: 0.6rem;
  padding: 1rem 1rem 0.75rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.tab {
  flex: 0 0 auto;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--white);
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 800;
  padding: 0.85rem 1.5rem;
  min-height: 3.75rem;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  background: var(--ink);
  color: var(--white);
}

/* ------------------------------------------------------------
   Board — card grid
   ------------------------------------------------------------ */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.75rem, 1fr));
  gap: 1rem;
  max-width: 72rem;
  margin: 0 auto;
  padding: 0.5rem 1rem 2rem;
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-height: 7.75rem;             /* ≈124px — comfortably above 64px */
  padding: 1rem 0.75rem;
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 1.25rem;
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
  min-width: 0;
}

.card:active { transform: scale(0.97); }

/* Hover is only an enhancement — everything works by touch/tap alone. */
@media (hover: hover) {
  .card:hover { box-shadow: 0 6px 14px rgba(20, 48, 107, 0.18); }
}

.card .card-emoji {
  font-size: clamp(2.2rem, 6vw, 3rem);
  line-height: 1;
}

.card .card-label {
  font-size: clamp(1.15rem, 2.6vw, 1.45rem);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
}

/* Brief flash when tapped */
.card.is-flashed {
  background: var(--amber);
  box-shadow: inset 0 0 0 5px var(--ink);
  transform: scale(0.97);
}

.status-note {
  max-width: 46rem;
  margin: 0 auto 2rem;
  padding: 0.9rem 1.25rem;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--amber);
  border: 3px solid var(--ink);
  border-radius: 1rem;
}

.status-note[hidden] { display: none; }

/* ------------------------------------------------------------
   Narrow screens — big staggered grid, still huge targets
   ------------------------------------------------------------ */

@media (max-width: 560px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    padding: 0.5rem 0.75rem 1.5rem;
  }

  .card {
    min-height: 6.75rem;           /* ≈108px on a phone */
    gap: 0.4rem;
    padding: 0.75rem 0.4rem;
    border-radius: 1rem;
  }

  .card .card-emoji { font-size: 2.1rem; }

  .banner { min-height: 7rem; }
}

@media (max-width: 340px) {
  .card { min-height: 6rem; }
  .card .card-emoji { font-size: 1.8rem; }
}

/* Respect users who asked for less motion: flash changes colour only. */
@media (prefers-reduced-motion: reduce) {
  .card, .cta, .banner { transition: none; }
  .card.is-flashed, .card:active, .cta:active { transform: none; }
}
/* ------------------------------------------------------------
   Board — top bar actions (Customize + settings)
   ------------------------------------------------------------ */

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 3.1rem;               /* ≈50px — caregiver finger friendly */
  padding: 0 1.1rem;
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1;
  border-radius: 999px;
  border: 3px solid var(--white);
  background: var(--ink);
  color: var(--white);
  cursor: pointer;
}

.icon-btn[hidden] { display: none; }

/* ------------------------------------------------------------
   Board — editing bar (edit mode only)
   ------------------------------------------------------------ */

.editbar {
  background: var(--amber);
  border-bottom: 6px solid var(--ink);
  padding: 0.8rem 1rem 1rem;
}

.editbar[hidden] { display: none; }

.editbar-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 0.7rem;
}

.editbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.btn {
  border: 3px solid var(--ink);
  border-radius: 999px;
  font-size: 1.05rem;
  font-weight: 800;
  padding: 0.65rem 1.1rem;
  min-height: 2.9rem;               /* ≈46px */
  cursor: pointer;
  line-height: 1.15;
}

.btn-ink    { background: var(--ink);  color: var(--white); }
.btn-warn   { background: var(--amber); color: var(--ink); }
.btn-done   { background: var(--ink);  color: var(--white); border-width: 3px; }
.btn-ghost  { background: var(--paper); color: var(--ink); }
.btn-primary{ background: var(--ink);  color: var(--white); }
.btn-danger { background: #b3261e; color: var(--white); border-color: #7c150f; }

.btn:active { transform: translateY(2px); }

.btn-block { display: block; width: 100%; margin-top: 1rem; }

/* ------------------------------------------------------------
   Board — edit mode card grid (compact, with corner controls)
   ------------------------------------------------------------ */

body.is-editing .grid {
  grid-template-columns: repeat(auto-fill, minmax(8.25rem, 1fr));
  gap: 0.75rem;
}

/* Edit-mode wrapper: the card button and its corner buttons are siblings
   (never nested), so the wrapper is the positioning context for the corners
   and the grid item; the card fills it exactly as before. */
.card-cell {
  position: relative;
  display: flex;
  min-width: 0;
}

.card-cell > .card { flex: 1 1 auto; width: 100%; }

/* Corners used to be positioned inside the card's 3px border; they now sit
   in the wrapper, so add the border back to keep them exactly in place. */
.card-cell > .card-corner { top: calc(0.4rem + 3px); }
.card-cell > .card-edit-btn { left: calc(0.4rem + 3px); }
.card-cell > .card-del-btn { right: calc(0.4rem + 3px); }

body.is-editing .card.is-edit-mode {
  position: relative;
  min-height: 6.25rem;              /* compact but still touchable */
  padding: 2.1rem 0.5rem 0.6rem;
  gap: 0.3rem;
  border-radius: 1rem;
}

body.is-editing .card.is-edit-mode .card-emoji { font-size: 1.9rem; }
body.is-editing .card.is-edit-mode .card-label { font-size: 1.05rem; }

.card-corner {
  position: absolute;
  top: 0.4rem;
  width: 2.85rem;                   /* ≈46px targets */
  height: 2.85rem;
  font-size: 1.25rem;
  line-height: 1;
  border-radius: 0.7rem;
  border: 3px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 0 rgba(20, 48, 107, 0.35);
}

.card-edit-btn { left: 0.4rem; }
.card-del-btn { right: 0.4rem; }

.card-edit-btn:hover, .card-del-btn:hover { background: var(--amber); }

.empty-hint {
  grid-column: 1 / -1;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink-soft);
  background: var(--white);
  border: 3px dashed var(--ink-soft);
  border-radius: 1rem;
  padding: 1.5rem 1rem;
  margin: 0.5rem 0;
}

/* ------------------------------------------------------------
   Dialog modal (card editor, set editor, confirmations)
   ------------------------------------------------------------ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(20, 48, 107, 0.55);
}

.modal-backdrop[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 34rem;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 1.25rem;
  padding: 1.25rem;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.modal-title {
  margin: 0 0 0.75rem;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--ink);
}

.modal-text {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  color: var(--ink);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.1rem;
}

.field-label {
  display: block;
  margin: 0.9rem 0 0.4rem;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
}

.field-note { font-weight: 500; color: var(--ink-soft); }

.field-input {
  width: 100%;
  font: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  padding: 0.8rem 0.9rem;
  border: 3px solid var(--ink);
  border-radius: 0.8rem;
  min-height: 3.4rem;
  background: var(--paper);
}

.field-input:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 2px;
}

.emoji-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 5rem;
  margin-bottom: 0.25rem;
  font-size: 3.2rem;
  line-height: 1;
  background: var(--paper);
  border: 3px dashed var(--ink-soft);
  border-radius: 1rem;
  padding: 0.6rem;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(2.8rem, 1fr));
  gap: 0.45rem;
}

.emoji-btn {
  min-height: 2.8rem;               /* ≈45px */
  font-size: 1.45rem;
  line-height: 1;
  border: 3px solid var(--ink);
  border-radius: 0.7rem;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  padding: 0.2rem;
}

.emoji-btn.is-selected {
  background: var(--amber);
  box-shadow: inset 0 0 0 3px var(--ink);
}

/* ------------------------------------------------------------
   Narrow screens (mobile) — modal + edit mode tweaks
   ------------------------------------------------------------ */

@media (max-width: 560px) {
  .icon-btn-text { display: none; }        /* emoji-only Customize button */
  .icon-btn { padding: 0 0.75rem; }

  body.is-editing .grid { gap: 0.6rem; }
  body.is-editing .card.is-edit-mode { min-height: 5.75rem; }
  body.is-editing .card.is-edit-mode .card-emoji { font-size: 1.7rem; }
  body.is-editing .card.is-edit-mode .card-label { font-size: 0.98rem; }

  .modal { padding: 1rem; }
  .emoji-grid { grid-template-columns: repeat(auto-fill, minmax(2.55rem, 1fr)); gap: 0.35rem; }
  .emoji-btn { min-height: 2.55rem; font-size: 1.3rem; }
  .modal-actions .btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .btn:active, .modal { transition: none; transform: none; }
}

/* ------------------------------------------------------------
   Tagline (SpeakEase landing)
   ------------------------------------------------------------ */
.landing .tagline {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin: 0.15rem 0 0.6rem;
}

/* ============================================================
   Eye-gaze prototype (experimental) — SpeakEase
   Overlay rules enforced: gaze decoration layer is fixed,
   pointer-events:none, aria-hidden, z-index < 60 (modal).
   ============================================================ */

/* Settings: "Experimental"/"soon" badges on input-method pills. */
.rate-btn .gaze-exp-badge {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--amber);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  margin-left: 0.35rem;
  vertical-align: middle;
}

.rate-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Status chip — always visible while gaze is on; interactive (it carries
   the Exit control, so it is UI, not part of the passive overlay). */
.gaze-chip {
  position: fixed;
  top: 4.6rem;
  right: 0.6rem;
  z-index: 55;                       /* below modal (60) */
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--ink);
  color: var(--white);
  border: 3px solid var(--white);
  border-radius: 999px;
  padding: 0.4rem 0.5rem 0.4rem 0.9rem;
  font-size: 1rem;
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(20, 48, 107, 0.35);
}

.gaze-chip[hidden] { display: none; }

.gaze-chip-dot {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  background: #9aa5c0;
  flex: 0 0 auto;
}

/* Status chip dot — one distinct colour per state. The state set is exactly
   the one implemented by deriveStatus() in gaze.js; keep in sync. */
.gaze-chip-dot[data-status="permission-needed"]     { background: #ffb300; }
.gaze-chip-dot[data-status="camera-starting"]       { background: #9aa5c0; }
.gaze-chip-dot[data-status="camera-ready"]          { background: #64b5f6; }
.gaze-chip-dot[data-status="model-loading"]         { background: #ab47bc; }
.gaze-chip-dot[data-status="model-ready"]           { background: #ce93d8; }
.gaze-chip-dot[data-status="looking-for-face"]      { background: #26c6da; }
.gaze-chip-dot[data-status="face-detected"]         { background: #4fc3f7; }
.gaze-chip-dot[data-status="eyes-detected"]         { background: #1e88e5; }
.gaze-chip-dot[data-status="calibration-needed"]    { background: var(--amber); }
.gaze-chip-dot[data-status="tracking-active"]       { background: #4caf50; }
.gaze-chip-dot[data-status="tracking-lost"]         { background: #e53935; }
.gaze-chip-dot[data-status="calibrating"]           { background: #ffffff; }
.gaze-chip-dot[data-status="camera-error"]          { background: #b3261e; }
.gaze-chip-dot[data-status="model-error"]           { background: #7b1fa2; }

/* Hidden camera preview element: in the DOM (some Android browsers only
   advance readyState/frames for in-DOM media elements) but invisible and
   non-interactive. NEVER rendered or captured anywhere. */
.gaze-hidden-video {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0.01;
  pointer-events: none;
  z-index: -1;
}

/* Diag toggle inside the status chip. */
.gaze-chip-diag {
  font: inherit;
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: var(--white);
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}

/* Calibrate / Recalibrate — the always-available way back into the 9-point
   calibration (e.g. after Cancel) without exiting gaze. */
.gaze-chip-cal {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink);
  background: var(--white);
  border: none;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
}

.gaze-chip-cal[hidden] { display: none; }

/* Every chip control is a comfortable touch target. */
.gaze-chip-cal, .gaze-chip-diag, .gaze-chip-exit { min-height: 2.75rem; }

/* Permission / error screen helper text. */
.gaze-perm-note {
  font-size: 0.95rem;
  color: var(--ink-soft);
}
.gaze-error-list p {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  background: #fdecea;
  border: 1px solid #f5c6c0;
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  margin: 0.35rem 0;
  word-break: break-word;
}

/* Developer diagnostics panel — text/booleans/counters ONLY (no video data). */
.gaze-diag-panel {
  position: fixed;
  left: 50%;
  bottom: 0.75rem;
  transform: translateX(-50%);
  width: min(94vw, 660px);
  max-height: 64vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #0e1a33;
  color: #dbe4f5;
  border: 2px solid #3b5a9e;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  z-index: 56; /* below modal (60), above chip (55) */
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
}
.gaze-diag-panel[hidden] { display: none; }
.gaze-diag-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  background: #14306b;
  font-weight: 800;
  font-size: 0.8rem;
}
.gaze-diag-head span { flex: 1 1 auto; }
.gaze-diag-close {
  font: inherit;
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.14);
  color: var(--white);
  border: 1px solid rgba(255, 255, 255, 0.3);
}
.gaze-diag-body {
  overflow-y: auto;
  padding: 0.5rem 0.75rem 0.75rem;
}
.gaze-diag-row {
  display: grid;
  grid-template-columns: minmax(150px, 36%) 1fr;
  gap: 0.5rem;
  padding: 0.22rem 0;
  border-bottom: 1px solid rgba(219, 228, 245, 0.08);
}
.gaze-diag-k {
  color: #9fb4dd;
  font-weight: 700;
  word-break: break-word;
}
.gaze-diag-v {
  color: #eef3fd;
  word-break: break-word;
  white-space: normal;
}

.gaze-sim-badge {
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  background: #b3261e;
  color: var(--white);
  border-radius: 999px;
  padding: 0.12rem 0.45rem;
}

.gaze-chip-exit {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink);
  background: var(--amber);
  border: none;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
}

/* Passive decoration layer: cursor + dwell progress. Never intercepts
   clicks. z-index 40 < modal 60. */
.gaze-layer {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  overflow: hidden;
}

.gaze-cursor {
  position: absolute;
  left: 0;
  top: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 4px solid var(--ink);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 2px var(--amber), 0 2px 8px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: opacity 0.15s ease;
  will-change: transform;
}

.gaze-cursor::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber-deep);
  transform: translate(-50%, -50%);
}

.gaze-cursor.is-hidden { opacity: 0 !important; }

.gaze-progress {
  position: absolute;
  left: 0;
  top: 0;
  width: 56px;
  height: 56px;
  overflow: visible;
  will-change: transform;
}

.gaze-progress-arc {
  fill: none;
  stroke: var(--amber-deep);
  stroke-width: 7;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

/* Dwell candidate highlight on the card itself (visual only). */
.card.is-dwell-target {
  outline: 6px solid var(--amber-deep);
  outline-offset: 3px;
  box-shadow: 0 0 0 2px var(--ink), 0 8px 18px rgba(20, 48, 107, 0.3);
  transform: scale(1.02);
}

/* Calibration / validation / prompt screens.
   The dim layer is decoration (pointer-events none); the dotted targets are
   look-at markers only; the callout/box carries the (interactive) buttons.
   Whole screen sits at z 50 < modal 60. */
.gaze-panel-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.gaze-panel-screen[hidden] { display: none; }

.gaze-panel-dim {
  position: absolute;
  inset: 0;
  background: rgba(20, 48, 107, 0.45);
  pointer-events: none;
}

.gaze-box {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 34rem);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 1.25rem;
  padding: 1.5rem;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.gaze-box h2 { margin: 0 0 0.6rem; font-size: 1.5rem; font-weight: 800; color: var(--ink); }
.gaze-box p { font-size: 1.1rem; }

.gaze-verdict { font-size: 1.2rem; font-weight: 700; }

.gaze-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.8rem 0;
  font-size: 1.05rem;
}

.gaze-table th, .gaze-table td {
  border: 2px solid var(--ink);
  padding: 0.5rem 0.7rem;
  text-align: left;
}

.gaze-table th { background: var(--paper); }

.gaze-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.1rem;
}

.gaze-privacy {
  font-size: 0.95rem !important;
  color: var(--ink-soft);
  margin: 0.6rem 0 0;
}

.gaze-sim-line {
  font-weight: 800;
  color: #7c150f;
  background: #fde8e6;
  border: 2px solid #b3261e;
  border-radius: 0.6rem;
  padding: 0.45rem 0.7rem;
  font-size: 0.95rem;
}

/* A calibration/validation dot. Decoration only — pointer-events none. */
.gaze-target {
  position: absolute;
  width: 120px;
  height: 120px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 51;
}

.gaze-target-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(255, 209, 102, 0.25);
  border: 8px solid var(--amber);
  box-shadow: 0 0 0 4px var(--ink);
}

.gaze-target-ring-validate { border-color: #64b5f6; background: rgba(100, 181, 246, 0.25); }

.gaze-target-progress {
  position: absolute;
  inset: 10px;
  width: 100px;
  height: 100px;
}

.gaze-target-progress-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.75);
  stroke-width: 10;
}

.gaze-target-progress-fg {
  fill: none;
  stroke: var(--ink);
  stroke-width: 10;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

.gaze-callout {
  position: absolute;
  left: 50%;
  bottom: 2.2rem;
  transform: translateX(-50%);
  width: min(92vw, 36rem);
  text-align: center;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 1.25rem;
  padding: 1rem 1.5rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.gaze-callout h2 { margin: 0 0 0.25rem; font-size: 1.4rem; font-weight: 800; color: var(--ink); }
.gaze-callout p { margin: 0.3rem 0; font-size: 1.05rem; }

/* Camera-denied note follows the ttsNote/status-note pattern. */
.gaze-error-note { margin-top: 1rem; }

.gaze-sim-link {
  display: inline-block;
  margin-left: 0.6rem;
  padding: 0.35rem 0.8rem;
  font-size: 0.9rem;
  white-space: nowrap;
}

/* Mobile: chip must not fight the banner; shrink callout. */
@media (max-width: 560px) {
  /* With Calibrate + Diag + Exit the chip can outgrow a phone: it wraps onto
     a second line instead of pushing past the viewport edge. */
  .gaze-chip { top: 5.2rem; font-size: 0.85rem; max-width: calc(100vw - 1.2rem);
               flex-wrap: wrap; justify-content: flex-end; border-radius: 1.4rem; }
  .gaze-chip-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .gaze-chip-cal, .gaze-chip-exit { font-size: 0.85rem; padding: 0.4rem 0.7rem; }
  .gaze-callout { bottom: 1rem; padding: 0.8rem 1rem; }
  .gaze-callout h2 { font-size: 1.15rem; }
  .gaze-box { padding: 1.1rem; }
}

/* ------------------------------------------------------------
   Reduced motion — gaze overlay
   ------------------------------------------------------------
   No fades or zooms. The dwell progress ring still fills (it is feedback
   about how long until a selection, not decoration), but without easing. */
@media (prefers-reduced-motion: reduce) {
  .gaze-cursor,
  .gaze-progress-arc,
  .gaze-target-progress-fg { transition: none; }
  .card.is-dwell-target { transform: none; }
}

/* ------------------------------------------------------------
   Forced colours (Windows High Contrast and similar)
   ------------------------------------------------------------
   The browser replaces our colours with the user's system palette, which
   erases every state we show with a background (selected tab, checked
   option, tapped card, dwell target, status dot). Re-express those states
   with outlines/borders in system colours so they stay visible. */
@media (forced-colors: active) {
  .tab[aria-selected="true"],
  .rate-btn[aria-checked="true"] {
    outline: 4px solid Highlight;
    outline-offset: 2px;
  }
  .card.is-flashed,
  .card.is-dwell-target {
    outline: 6px solid Highlight;
    outline-offset: 3px;
  }
  .banner.is-flashed { outline: 4px solid Highlight; }
  .gaze-chip { border-color: CanvasText; }
  .gaze-chip-dot { border: 2px solid CanvasText; }
  .gaze-cursor {
    forced-color-adjust: none;
    background: Canvas;
    border-color: CanvasText;
    box-shadow: 0 0 0 2px Highlight;
  }
  .gaze-cursor::after { forced-color-adjust: none; background: Highlight; }
  .gaze-progress-arc { forced-color-adjust: none; stroke: Highlight; }
  .gaze-target-ring { border-color: Highlight; }
}
