/* Suflér – a theatre prompter: curtain, brass and one large line of text. */

@font-face {
  font-family: 'Sofia Sans Condensed';
  font-style: normal;
  font-weight: 1 1000;
  font-display: swap;
  src: url('/fonts/sofia-sans-condensed-latin-ext-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Sofia Sans Condensed';
  font-style: normal;
  font-weight: 1 1000;
  font-display: swap;
  src: url('/fonts/sofia-sans-condensed-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
    U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Sofia Sans';
  font-style: normal;
  font-weight: 1 1000;
  font-display: swap;
  src: url('/fonts/sofia-sans-latin-ext-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Sofia Sans';
  font-style: normal;
  font-weight: 1 1000;
  font-display: swap;
  src: url('/fonts/sofia-sans-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308,
    U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --curtain: #3a0d16;      /* background: curtain velvet */
  --backstage: #25070d;    /* deepest tone: viewfinder and inputs */
  --velvet: #55182a;       /* raised surfaces */
  --chalk: #fbf1de;        /* text: chalk, footlights */
  --chalk-muted: #d9bfb6;
  --brass: #e6b95c;        /* accent: brass rail */
  --line: rgb(251 241 222 / 0.16);
  --rose: #f6a6b8;         /* code keywords */
  --mint: #a9dcc4;         /* code numbers */

  --font-ui: 'Sofia Sans', system-ui, sans-serif;
  --font-code: ui-monospace, 'SF Mono', 'Cascadia Code', 'Roboto Mono', Menlo, Consolas, monospace;
  --font-answer: 'Sofia Sans Condensed', 'Arial Narrow', 'Sofia Sans', system-ui, sans-serif;
  --gutter: clamp(14px, 4vw, 22px);
  color-scheme: dark;
}

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

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--curtain);
  color: var(--chalk);
  font: 400 1.0625rem/1.45 var(--font-ui);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

p, h1, h2, ol { margin: 0; }
ol { padding: 0; list-style: none; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

:focus-visible {
  outline: 3px solid var(--brass);
  outline-offset: 3px;
}

/* ---------- buttons ---------- */

.btn {
  appearance: none;
  min-height: 48px;
  padding: 0 18px;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--chalk);
  font: 600 1rem/1 var(--font-ui);
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { background: var(--velvet); }

.btn-primary {
  min-height: 60px;
  border-color: var(--brass);
  background: var(--brass);
  color: var(--backstage);
  font-size: 1.1875rem;
  font-weight: 800;
}
.btn-primary:active { background: #f3d08a; }

.btn-quiet {
  min-height: 44px;
  padding: 0 14px;
  border-color: transparent;
  color: var(--chalk-muted);
  font-weight: 500;
}

/* ---------- intro ---------- */

.intro {
  min-height: 100dvh;
  padding: var(--gutter);
  padding-bottom: max(var(--gutter), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 18px;
}
.intro h1 {
  font: 900 clamp(5rem, 31vw, 13rem)/0.82 var(--font-answer);
  letter-spacing: -0.015em;
  margin-left: -0.04em;
}
.intro-lead {
  max-width: 24ch;
  font-size: 1.375rem;
  line-height: 1.3;
}
.intro .btn-primary { margin-top: 10px; }
.intro-note { color: var(--chalk-muted); font-size: 0.9375rem; }
.intro-note[data-error] { color: var(--brass); font-weight: 600; }

/* ---------- login ---------- */

.login {
  display: grid;
  gap: 10px;
  max-width: 420px;
}
.login label { font-weight: 700; }
.login .btn-primary { margin-top: 8px; }
.login-error { color: var(--brass); font-weight: 600; }

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

.stage {
  height: 100dvh;
  padding: max(8px, env(safe-area-inset-top)) var(--gutter) max(var(--gutter), env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas: 'topbar' 'viewfinder' 'answer' 'heard' 'controls';
  gap: 12px;
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 2px;
  margin-right: -10px;
}

.status {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--chalk-muted);
}
.status > span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status[data-state='error'] { color: var(--brass); }
.status[data-state='error'] > span:last-child { white-space: normal; }

.dot {
  flex: none;
  width: 11px; height: 11px;
  border-radius: 50%;
  background: var(--brass);
}
.status[data-state='thinking'] .dot,
.status[data-state='writing'] .dot { animation: pulse 0.9s ease-in-out infinite alternate; }
.status[data-state='error'] .dot { background: transparent; box-shadow: inset 0 0 0 2.5px var(--brass); }
@keyframes pulse { from { opacity: 1; transform: scale(1); } to { opacity: 0.35; transform: scale(0.7); } }

.viewfinder {
  grid-area: viewfinder;
  position: relative;
  height: clamp(96px, 22dvh, 220px);
  border-radius: 14px;
  overflow: hidden;
  background: var(--backstage);
}
.viewfinder video {
  display: block;
  width: 100%; height: 100%;
  object-fit: cover;
}
.viewfinder-off {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  text-align: center;
  color: var(--chalk-muted);
}

.answer {
  grid-area: answer;
  container-type: inline-size;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
}
.answer-empty {
  max-width: 22ch;
  padding-top: 6px;
  font-size: 1.375rem;
  line-height: 1.3;
  color: var(--chalk-muted);
}
.answer-main {
  /* Scales with the panel, but stops growing on a large monitor. */
  font: 800 min(calc(var(--main-size, 15) * 1cqi), 9.5rem)/0.94 var(--font-answer);
  letter-spacing: -0.012em;
  overflow-wrap: anywhere;
  text-wrap: balance;
}
.answer-main:empty, .answer-body:empty { display: none; }

/* Detail under the answer: paragraphs, lists, inline code and code blocks. */
.answer-body {
  margin-top: 0.7em;
  display: grid;
  gap: 0.6em;
  font-size: clamp(1.25rem, 5.6cqi, 1.75rem);
  line-height: 1.3;
}
.answer-body > p, .answer-body > .rich-list { max-width: 40ch; }
.rich-list { margin: 0; padding-left: 1.2em; list-style: revert; display: grid; gap: 0.25em; }
.rich-list ::marker { color: var(--brass); }

.code-inline, .code-block { font-family: var(--font-code); }
.code-inline {
  padding: 0.08em 0.32em;
  border-radius: 6px;
  background: var(--backstage);
  font-size: 0.86em;
  overflow-wrap: anywhere;
}
.code-block {
  margin: 0;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--backstage);
  /* Code keeps its own, smaller size: it has to fit lines, not be read from across the room. */
  font-size: clamp(0.8125rem, 3.4cqi, 1.0625rem);
  line-height: 1.5;
  tab-size: 2;
  overflow-x: auto;
  white-space: pre;
}
.tok-comment { color: var(--chalk-muted); font-style: italic; }
.tok-string { color: var(--brass); }
.tok-keyword { color: var(--rose); }
.tok-number { color: var(--mint); }

/* A brass caret marks the end of the answer while only its first line has arrived. */
.answer[data-writing] .answer-main:has(+ .answer-body:empty)::after {
  content: '';
  display: inline-block;
  width: 0.12em; height: 0.72em;
  margin-left: 0.08em;
  background: var(--brass);
}

.history {
  margin-top: 26px;
  border-top: 1.5px solid var(--line);
}
.history:empty { display: none; }
.history > li {
  padding: 12px 0;
  border-bottom: 1.5px solid var(--line);
  color: var(--chalk-muted);
}
.history strong {
  display: block;
  font: 700 1.5rem/1.1 var(--font-answer);
  color: var(--chalk);
}
.history .answer-body { margin-top: 0.4em; font-size: 1rem; line-height: 1.4; }

.heard-row {
  grid-area: heard;
  display: grid;
  gap: 6px;
}
/* Shows that the microphone picks something up, also before any words are recognised. */
.mic-meter {
  display: block;
  height: 4px;
  border-radius: 2px;
  background: var(--backstage);
  overflow: hidden;
}
.mic-meter > span {
  display: block;
  height: 100%;
  background: var(--brass);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.1s linear;
}

.heard {
  min-height: 2.7em;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  font-size: 1rem;
  line-height: 1.35;
  color: var(--chalk-muted);
}
.heard[data-interim] { color: var(--chalk); }

.controls {
  grid-area: controls;
  display: grid;
  gap: 10px;
}
.controls-row, .ask-row {
  display: flex;
  gap: 10px;
}
/* The main action gets its own row; the two smaller ones share the row below. */
.controls-row { flex-wrap: wrap; }
.controls-row .btn { flex: 1 1 0; white-space: nowrap; }
.controls-row .btn-primary { flex: 1 1 100%; }
.ask-row input { flex: 1; min-width: 0; }

input[type='text'], input[type='password'], textarea, select {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--backstage);
  color: var(--chalk);
  font: 400 1.0625rem/1.35 var(--font-ui);
}
input::placeholder { color: var(--chalk-muted); opacity: 0.8; }
textarea { resize: vertical; }

/* Landscape: viewfinder and controls on the left, the answer takes the full height on the right. */
@media (orientation: landscape) and (min-width: 560px) {
  .stage {
    grid-template-columns: minmax(220px, 34%) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      'topbar     answer'
      'viewfinder answer'
      'heard      answer'
      'controls   answer';
    column-gap: clamp(16px, 3vw, 32px);
  }
  /* The narrow column cannot fit the status next to the buttons, so the status gets its own row. */
  .topbar { flex-wrap: wrap; margin-left: -14px; }
  .stage .status { flex: 1 1 100%; order: 1; padding-left: 14px; }
  .viewfinder { height: auto; min-height: 0; }
  .controls-row { flex-wrap: wrap; }
  .controls-row .btn { flex: 1 1 auto; }
}

/* Desktop: everything sits in a centred column instead of hugging the bottom-left corner. */
@media (min-width: 900px) and (min-height: 600px) {
  .intro {
    justify-content: center;
    align-items: center;
    text-align: center;
  }
  .intro h1 { margin-left: 0; font-size: 11rem; }
  .intro-lead { max-width: 30ch; }
  .intro .btn-primary, .login { width: min(420px, 100%); }
  .login { text-align: left; }

  .stage {
    max-width: 1320px;
    margin-inline: auto;
    padding: 28px 40px;
    grid-template-columns: 380px minmax(0, 1fr);
    grid-template-rows: auto auto auto auto minmax(0, 1fr);
    grid-template-areas:
      'topbar     answer'
      'viewfinder answer'
      'heard      answer'
      'controls   answer'
      '.          answer';
    column-gap: 48px;
  }
  .viewfinder { aspect-ratio: 16 / 9; }
}

/* ---------- observer ---------- */

.observer {
  height: 100dvh;
  max-width: 1200px;
  margin-inline: auto;
  padding: max(16px, env(safe-area-inset-top)) clamp(16px, 4vw, 48px) 24px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(16px, 3vh, 36px);
}
.observer-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 8px 28px;
  padding-bottom: 14px;
  border-bottom: 1.5px solid var(--line);
}
/* The answer panel is placed by name in the phone layout; here it simply follows the bar. */
.observer .answer { grid-area: auto; }
.observer-bar .status { flex: none; }
.observer-bar .heard { min-height: 0; -webkit-line-clamp: 1; line-clamp: 1; text-align: right; }
.observer .answer-body { font-size: clamp(1.25rem, 2.6cqi, 2rem); }
.observer .code-block { font-size: clamp(0.875rem, 1.7cqi, 1.25rem); }
.observer .history .answer-body { font-size: 1.0625rem; }
.observer .history .code-block { font-size: 0.875rem; }
@media (max-width: 640px) {
  .observer-bar { grid-template-columns: minmax(0, 1fr); }
  .observer-bar .heard { text-align: left; }
}

/* ---------- settings ---------- */

.settings {
  width: min(560px, 100vw);
  max-width: 100vw;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 22px 18px 18px;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--velvet);
  color: var(--chalk);
}
.settings::backdrop { background: rgb(37 7 13 / 0.72); }
.settings form { display: grid; gap: 22px; padding-bottom: env(safe-area-inset-bottom); }
.settings h2 { font: 800 2.25rem/1 var(--font-answer); }

.field { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field > label, .field legend, .pair label {
  padding: 0;
  font-weight: 700;
}
.field legend { margin-bottom: 8px; }
.pair { grid-template-columns: 1fr 1fr; gap: 12px; }
.pair > div { display: grid; gap: 8px; min-width: 0; }

.choice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 44px;
  padding: 8px 0;
}
.choice input {
  flex: none;
  width: 22px; height: 22px;
  margin: 2px 0 0;
  accent-color: var(--brass);
}
.choice-select { display: grid; gap: 8px; padding-top: 6px; }

.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.presets .btn {
  min-height: 40px;
  padding: 0 14px;
  font-size: 0.9375rem;
  font-weight: 500;
}

@media (min-width: 600px) {
  .settings { margin: auto; border-radius: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .dot { animation: none !important; }
}
