:root {
  --bg: #f6f8f8;
  --surface: #ffffff;
  --ink: #16302e;
  --muted: #5d6b69;
  --brand: #0f6f6a;
  --brand-ink: #ffffff;
  --accent: #b5446e;      /* used sparingly for distress flags */
  --line: #dde5e4;
  --warn-bg: #fff4e5;
  --warn-ink: #8a5a00;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.05);
  font-size: 17px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .7rem 1rem; background: var(--brand); color: var(--brand-ink);
  position: sticky; top: 0; z-index: 10; padding-top: max(.7rem, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 600; letter-spacing: .2px; }
.brand .logo { border-radius: 6px; background: #fff; }
.pill { background: rgba(255,255,255,.18); padding: .2rem .6rem; border-radius: 999px; font-size: .8rem; }

main { max-width: 760px; margin: 0 auto; padding: 1rem; }

.screen { display: none; }
.screen.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

h1 { font-size: 1.5rem; margin: .4rem 0 1rem; }

.field { display: block; margin: 0 0 1rem; }
.field > span, legend { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .95rem; }
.field.inline { display: flex; align-items: center; gap: .5rem; margin: 0; }
.field.inline > span { margin: 0; }
.field.checkbox { display: flex; align-items: flex-start; gap: .5rem; }
select, input[type="text"] {
  width: 100%; padding: .7rem .8rem; font-size: 1rem; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface); color: var(--ink);
}
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; margin: 0 0 1rem; }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem; padding: .5rem .8rem;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer;
  user-select: none;
}
.chip input { accent-color: var(--brand); }
.chip.on { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }

.row { display: flex; gap: .6rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.controls { margin-top: 1rem; }

button {
  font: inherit; cursor: pointer; border: 1px solid transparent; border-radius: 10px;
  padding: .7rem 1rem; background: #e9eeed; color: var(--ink);
}
button.primary { background: var(--brand); color: var(--brand-ink); }
button.ghost { background: transparent; border-color: var(--line); }
button.danger { background: #fff; color: #a32020; border-color: #f1c6c6; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }
.mic { font-size: 1.1rem; padding: .9rem 1.2rem; }
.mic.live { background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(181,68,110,.5);} 50% { box-shadow: 0 0 0 .5rem rgba(181,68,110,0);} }

.consent {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brand);
  border-radius: 10px; padding: 1rem; margin: 0 0 1rem; box-shadow: var(--shadow); white-space: pre-line;
}

.banner { border-radius: 10px; padding: .7rem .9rem; font-size: .9rem; margin: 1rem 0; background: #eef5f4; border: 1px solid var(--line); }
.banner.warn, .warn { background: var(--warn-bg); color: var(--warn-ink); border-color: #ffe2b0; }

.live-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.muted { color: var(--muted); }
.tiny { font-size: .8rem; }
.speaker-bar { display: flex; gap: .6rem; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: .5rem 0; }
.text-row { display: flex; gap: .5rem; margin: .5rem 0 1rem; }
.text-row input { flex: 1; }

.transcript { display: flex; flex-direction: column; gap: .6rem; min-height: 30vh; }
.utt { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .7rem .8rem; box-shadow: var(--shadow); }
.utt .src { font-size: .78rem; color: var(--muted); margin-bottom: .25rem; }
.utt .said { font-weight: 600; margin-bottom: .35rem; }
.rec { color: #fff; background: #c0392b; padding: .1rem .45rem; border-radius: 999px; font-size: .72rem; font-weight: 700; animation: pulse 1.5s infinite; }
.record-row { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; margin: .5rem 0; }
.stream-row { background: var(--surface); border: 1px dashed var(--brand); border-radius: 10px; padding: .55rem .7rem; margin: 0 0 .5rem; font-size: .9rem; }
.interim { color: var(--muted); font-style: italic; padding: .25rem .2rem; min-height: 1.2rem; }
.slowdown { margin: .25rem 0 .5rem; font-weight: 600; text-align: center; animation: fade .2s ease; }
.delivery { margin: .25rem 0 .5rem; font-weight: 700; text-align: center; color: #a32020; background: #fff; border-color: #f1c6c6; animation: fade .2s ease; }
.utt .line { display: flex; gap: .5rem; padding: .15rem 0; }
.utt .tag { font-weight: 700; color: var(--brand); min-width: 2.4rem; text-transform: uppercase; font-size: .8rem; padding-top: .15rem; }
.utt .txt { flex: 1; }
.flag { color: var(--accent); font-weight: 600; }
.note { color: var(--muted); font-style: italic; }

/* A3: structured safety flags, visually decoupled from the translation text */
.flags { display: flex; flex-wrap: wrap; gap: .35rem; margin: .25rem 0 0 2.9rem; }
.flag-item { font-size: .78rem; padding: .12rem .45rem; border-radius: 7px; line-height: 1.3; }
.flag-item.note { color: var(--muted); background: #eef5f4; font-style: italic; }
.flag-item.verify { color: var(--warn-ink); background: var(--warn-bg); border: 1px solid #ffe2b0; font-weight: 600; }
/* A4: distress chip is calm + brand-tinted (a "check in"), never a red alarm */
.flag-item.distress { color: var(--brand); background: rgba(15,111,106,.12); border: 1px solid var(--brand); font-weight: 600; }
.checkin { margin: .25rem 0 .5rem; text-align: center; font-weight: 600; color: var(--brand); background: rgba(15,111,106,.12); border-color: var(--brand); animation: fade .2s ease; }

/* A2: persistent transparency label + lecture preset + captions-primary */
.ai-label { display: inline-block; margin: .2rem 0 .4rem; padding: .2rem .6rem; border-radius: 999px;
  background: rgba(15,111,106,.12); color: var(--brand); border: 1px solid var(--brand); font-size: .8rem; font-weight: 600; }
.preset-btn { width: 100%; margin: 0 0 1rem; border-style: dashed; border-color: var(--brand); color: var(--brand); font-weight: 600; }
.audio-row { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; margin: 0 0 .5rem; font-size: .9rem; }
/* captions-primary (lecture): make the translated captions the dominant element */
body.captions-primary .transcript .txt { font-size: 1.25rem; line-height: 1.4; }
body.captions-primary .transcript .tag { font-size: .9rem; }
body.captions-primary .transcript { min-height: 45vh; }

.tabs { display: flex; gap: .4rem; margin-bottom: 1rem; }
.tab { flex: 1; background: transparent; border: 1px solid var(--line); }
.tab.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.room-box { text-align: right; }
.room-box strong { display: block; font-size: 1.5rem; letter-spacing: .15em; color: var(--brand); }
.share-btn { margin-top: .35rem; padding: .4rem .7rem; font-size: .85rem; }
#join-code { text-transform: uppercase; letter-spacing: .2em; font-size: 1.3rem; text-align: center; }

.hidden { display: none !important; }

@media (max-width: 480px) {
  :root { font-size: 16px; }
  .speaker-bar { flex-direction: column; align-items: stretch; }
  .mic { width: 100%; }
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#0e1817; --surface:#152423; --ink:#e7efee; --muted:#9fb0ae; --line:#26403d; --warn-bg:#3a2c12; --warn-ink:#ffd591; }
}
