/* ==========================================================================
   Sign Reader — stylesheet

   Design notes
   ------------
   The palette is warm and paper-like rather than the usual blue-grey app
   chrome: ink on unbleached paper, with a single terracotta accent used only
   for things that are live or actionable. Structure comes from hairline rules
   and generous space, not from cards-inside-cards or drop shadows.

   Accessibility is the point of this tool, so: body text never goes below
   16px, every interactive control has a visible focus ring, contrast on text
   is at least 7:1 against its background, hit targets are 44px minimum, and
   all motion is disabled under prefers-reduced-motion.

   No web fonts are loaded — the type stacks are system faces, which keeps the
   page working offline and avoids a third-party request.
   ========================================================================== */

/* ---------- Tokens -------------------------------------------------- */

:root {
  --paper:        #f6f2ea;
  --paper-sunk:   #ece6da;
  --ink:          #191714;
  --ink-soft:     #4d463c;
  --ink-faint:    #7a7264;
  --rule:         #d8d0c1;
  --rule-strong:  #b8ae9b;

  --stage:        #141311;
  --stage-edge:   #2b2723;

  --accent:       #b4552d;
  --accent-warm:  #e8843c;
  --accent-soft:  #f6e6da;

  --good:         #2f6b46;
  --warn:         #9a6b12;
  --bad:          #a33227;

  --radius:       10px;
  --radius-sm:    6px;

  --font-ui:  system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-display: ui-serif, Georgia, "Iowan Old Style", "Palatino Linotype", Palatino, serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --shell: 1180px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:       #171613;
    --paper-sunk:  #201e1a;
    --ink:         #f2ede4;
    --ink-soft:    #c2b9aa;
    --ink-faint:   #8e8677;
    --rule:        #322e28;
    --rule-strong: #4a443c;

    --stage:       #0d0c0b;
    --stage-edge:  #2b2723;

    --accent:      #e8843c;
    --accent-warm: #f2a869;
    --accent-soft: #2c2119;

    --good:        #7fc79b;
    --warn:        #e0b354;
    --bad:         #f08b7e;
  }
}

/* ---------- Reset --------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  padding: 0 clamp(1rem, 4vw, 2.5rem) 4rem;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }

p { margin: 0 0 0.75em; }

button, input, select, textarea { font: inherit; color: inherit; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -4rem;
  z-index: 50;
  padding: 0.7rem 1.1rem;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: top 160ms var(--ease);
}
.skip-link:focus { top: 1rem; }

/* ---------- Masthead ------------------------------------------------ */

.masthead {
  max-width: var(--shell);
  margin: 0 auto;
  padding: clamp(1.75rem, 5vw, 3rem) 0 1.5rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  align-items: start;
  border-bottom: 1px solid var(--rule);
}

.masthead__mark {
  display: flex;
  gap: 5px;
  padding-top: 0.85rem;
}
.masthead__mark .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--ink);
}
.masthead__mark .dot:nth-child(2) { background: var(--accent); }
.masthead__mark .dot:nth-child(3) { background: var(--rule-strong); }

.masthead h1 {
  margin: 0;
  font-size: clamp(1.9rem, 4.2vw, 2.6rem);
  line-height: 1.1;
}

.masthead__sub {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  max-width: 48ch;
}

.masthead__privacy {
  grid-column: 2;
  margin: 0.9rem 0 0;
  font-size: 0.86rem;
  color: var(--ink-faint);
  border-left: 2px solid var(--accent);
  padding-left: 0.7rem;
}

/* ---------- Layout -------------------------------------------------- */

.layout {
  max-width: var(--shell);
  margin: 0 auto;
  display: grid;
  gap: clamp(1.5rem, 3vw, 2.5rem);
  grid-template-columns: 1fr;
  padding-top: clamp(1.5rem, 3vw, 2.5rem);
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1.35fr) minmax(340px, 1fr);
  }
  .panel--help { grid-column: 1 / -1; }
}

.panel__title {
  margin: 0 0 1rem;
  font-family: var(--font-ui);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ---------- Camera stage -------------------------------------------- */

.stage {
  position: relative;
  background: var(--stage);
  border: 1px solid var(--stage-edge);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
}

@media (min-width: 900px) {
  .stage { aspect-ratio: 16 / 10; }
}

.stage video {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  /* The mirrored canvas is what the user actually sees; the raw <video> stays
     in the layout (hidden elements stop delivering frames in some browsers)
     but is pushed out of sight. */
  opacity: 0;
  pointer-events: none;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Permission / loading gate */
.gate {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: radial-gradient(120% 100% at 50% 0%, #211e1a 0%, #0f0e0d 100%);
  text-align: center;
  z-index: 2;
}
.gate[hidden] { display: none; }

.gate__inner { max-width: 34ch; }

.gate__lead {
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2.6vw, 1.4rem);
  color: #f4efe6;
  margin-bottom: 0.4rem;
}
.gate__note {
  color: #a49b8c;
  font-size: 0.9rem;
  margin-bottom: 1.4rem;
}

/* Status readout over the video */
.readout {
  position: absolute;
  left: 0.85rem;
  bottom: 0.85rem;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.85rem 0.45rem 0.7rem;
  border-radius: 999px;
  background: rgba(12, 11, 10, 0.78);
  backdrop-filter: blur(8px);
  color: #f4efe6;
  font-size: 0.85rem;
  max-width: calc(100% - 1.7rem);
}

.readout__lamp {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #8e8677;
  flex: none;
  transition: background 220ms var(--ease), box-shadow 220ms var(--ease);
}
.readout__lamp[data-state="loading"]   { background: #e0b354; animation: pulse 1.3s infinite; }
.readout__lamp[data-state="searching"] { background: #8e8677; }
.readout__lamp[data-state="tracking"]  { background: var(--accent-warm); }
.readout__lamp[data-state="locked"]    { background: #6dc48f; box-shadow: 0 0 0 4px rgba(109, 196, 143, 0.22); }
.readout__lamp[data-state="error"]     { background: #f08b7e; }

@keyframes pulse { 50% { opacity: 0.35; } }

.readout__text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Stage footer controls */
.stage__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.75rem;
  align-items: center;
  justify-content: space-between;
  margin-top: 1rem;
}

.modes { border: 0; margin: 0; padding: 0; }
.modes legend {
  padding: 0;
  font-size: 0.76rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 0.5rem;
}
.modes__row { display: flex; gap: 0.5rem; }

.chip {
  position: relative;
  display: inline-flex;
}
.chip input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%; height: 100%;
  margin: 0;
  cursor: pointer;
}
.chip span {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 1.05rem;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 0.95rem;
  transition: background 180ms var(--ease), color 180ms var(--ease), border-color 180ms var(--ease);
}
.chip input:checked + span {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.chip input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.chip:hover input:not(:checked) + span { border-color: var(--ink-soft); }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 44px;
  color: var(--ink-soft);
  font-size: 0.95rem;
  cursor: pointer;
}
.toggle input {
  width: 20px; height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---------- Current reading ----------------------------------------- */

.current {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
  padding: 1.15rem;
  background: var(--paper-sunk);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.current__glyph {
  font-family: var(--font-display);
  font-size: 3.4rem;
  line-height: 1;
  min-width: 2.1ch;
  padding: 0.5rem 0.35rem;
  text-align: center;
  border-radius: var(--radius-sm);
  background: var(--paper);
  border: 1px solid var(--rule);
  color: var(--ink);
  transition: background 200ms var(--ease), color 200ms var(--ease);
}
.current__glyph[data-wide="true"] { font-size: 1.5rem; padding: 1.25rem 0.6rem; }

.current__glyph.is-flash {
  animation: commit 520ms var(--ease);
}
@keyframes commit {
  0%   { background: var(--accent); color: #fff; transform: scale(1.06); }
  100% { background: var(--paper); color: var(--ink); transform: scale(1); }
}

.current__name {
  margin: 0.1rem 0 0.2rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
}
.current__why {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
  color: var(--ink-soft);
  min-height: 2.6em;
}

.meter {
  height: 8px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 999px;
  overflow: hidden;
}
.meter__fill {
  height: 100%;
  width: 0;
  background: var(--rule-strong);
  transition: width 120ms linear, background 240ms var(--ease);
}
.meter__fill[data-level="mid"]  { background: var(--warn); }
.meter__fill[data-level="high"] { background: var(--good); }

.meter__label {
  margin: 0.4rem 0 0;
  font-size: 0.82rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.hold { margin-top: 0.7rem; }
.hold[hidden] { display: none; }
.hold__bar {
  height: 5px;
  background: var(--paper);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--rule);
}
.hold__fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 90ms linear;
}
.hold[data-kind="cooling"] .hold__fill { background: var(--rule-strong); }
.hold__text {
  display: inline-block;
  margin-top: 0.3rem;
  font-size: 0.78rem;
  color: var(--ink-faint);
  letter-spacing: 0.03em;
}
.hold[data-kind="cooling"] .hold__text::before { content: "Ready in a moment — "; }

/* ---------- Fields and controls -------------------------------------- */

.field { display: block; margin-bottom: 1rem; }
.field__label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.field__label em { text-transform: none; letter-spacing: 0; font-style: normal; }

.field--inline { flex: 1 1 12rem; margin-bottom: 0; }

textarea, select, input[type="range"] {
  width: 100%;
  border-radius: var(--radius-sm);
}

textarea {
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.35rem;
  line-height: 1.45;
  letter-spacing: 0.02em;
  resize: vertical;
  min-height: 6rem;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease);
}
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

select {
  padding: 0.6rem 0.7rem;
  min-height: 44px;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
}

input[type="range"] { accent-color: var(--accent); min-height: 44px; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0 1.15rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
  transition: background 160ms var(--ease), border-color 160ms var(--ease),
              transform 120ms var(--ease), color 160ms var(--ease);
}
.btn:hover { border-color: var(--ink-soft); background: var(--paper-sunk); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}
.btn--primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn--quiet { color: var(--ink-soft); }
.btn--quiet:hover { color: var(--bad); border-color: var(--bad); background: var(--paper); }

.btn--lg { min-height: 52px; padding: 0 1.6rem; font-size: 1.05rem; }

.btn.is-speaking { background: var(--accent); border-color: var(--accent); color: #fff; }

.voice {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}

/* ---------- Help panel ----------------------------------------------- */

.steps {
  margin: 0 0 1.5rem;
  padding: 0;
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: 0.9rem;
}
@media (min-width: 720px) {
  .steps { grid-template-columns: repeat(4, 1fr); gap: 1.4rem; }
}
.steps li {
  counter-increment: step;
  padding-top: 2.35rem;
  position: relative;
  color: var(--ink-soft);
  font-size: 0.95rem;
  border-top: 1px solid var(--rule);
}
.steps li::before {
  content: counter(step);
  position: absolute;
  top: 0.7rem;
  left: 0;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--accent);
}
.steps strong { color: var(--ink); font-weight: 600; }

.note {
  border-top: 1px solid var(--rule);
  padding: 0.35rem 0;
}
.note summary {
  cursor: pointer;
  padding: 0.65rem 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 500;
  list-style: none;
}
.note summary::-webkit-details-marker { display: none; }
.note summary::before {
  content: "+";
  display: inline-block;
  width: 1.4rem;
  color: var(--accent);
  font-family: var(--font-mono);
}
.note[open] summary::before { content: "–"; }
.note summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.note__body {
  padding: 0.25rem 0 1rem 1.4rem;
  max-width: 78ch;
  color: var(--ink-soft);
  font-size: 0.95rem;
}
.note__body strong { color: var(--ink); }
.note__fine { font-size: 0.85rem; color: var(--ink-faint); margin-bottom: 0; }

.keys { margin: 0 0 0.75rem; padding: 0; list-style: none; display: grid; gap: 0.4rem; }
kbd {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--rule-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--paper-sunk);
  margin-right: 0.4rem;
}
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--paper-sunk);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
}

/* ---------- Colophon -------------------------------------------------- */

.colophon {
  max-width: var(--shell);
  margin: 3.5rem auto 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
  color: var(--ink-faint);
  font-size: 0.85rem;
}
.colophon p { margin: 0; max-width: 70ch; }

/* ---------- Motion and contrast preferences --------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --ink-soft: var(--ink);
    --ink-faint: var(--ink);
    --rule: var(--ink);
    --rule-strong: var(--ink);
  }
  .btn { border-width: 2px; }
}
