:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #111318;
  --text: #17191f;
  --muted: #69717d;
  --line: #d9dee6;
  --green: #087f5b;
  --green-strong: #066649;
  --coral: #d94841;
  --amber: #b7791f;
  --focus: #2563eb;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-height: 100dvh;
}

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

a {
  color: inherit;
  text-decoration: none;
}

.home-screen,
.app-screen,
.viewer-screen {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
}

.home-screen {
  display: grid;
  align-items: center;
}

.home-panel {
  display: grid;
  gap: 28px;
}

.brand-line,
.topbar,
.control-band,
.room-band,
.join-band,
.listen-header,
.panel-heading,
.stage-meta {
  display: flex;
  align-items: center;
}

.brand-line,
.topbar,
.listen-header,
.panel-heading,
.stage-meta {
  justify-content: space-between;
  gap: 12px;
}

.brand-mark,
.brand-link {
  font-weight: 900;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  color: var(--surface-strong);
  font-size: clamp(42px, 12vw, 84px);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.home-actions,
.control-band,
.join-band {
  display: grid;
  gap: 10px;
}

.home-actions {
  grid-template-columns: 1fr 1fr;
}

.control-band {
  grid-template-columns: 1fr auto;
  margin-top: 18px;
}

.join-band {
  grid-template-columns: 1.1fr 1fr auto;
  margin-top: 18px;
}

.topbar {
  min-height: 42px;
}

.status-pill {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill[data-state="ready"],
.status-pill[data-ready="true"] {
  color: var(--green);
  border-color: rgba(8, 127, 91, 0.3);
}

.status-pill[data-state="warn"] {
  color: var(--amber);
  border-color: rgba(183, 121, 31, 0.35);
}

.status-pill[data-state="error"],
.status-pill[data-ready="false"] {
  color: var(--coral);
  border-color: rgba(217, 72, 65, 0.35);
}

.field {
  min-width: 0;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field span,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

select,
input,
.button,
.action-button,
.ghost-button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

select,
input {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

input::placeholder {
  color: #a2a9b3;
}

.button,
.action-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  font-weight: 900;
  cursor: pointer;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button.primary,
.action-button.primary {
  border-color: var(--green);
  background: var(--green);
  color: white;
}

.button.primary:hover,
.action-button.primary:hover {
  background: var(--green-strong);
}

.button.danger[data-active="true"] {
  border-color: var(--coral);
  background: var(--coral);
  color: white;
}

.action-button {
  min-height: 64px;
  font-size: 18px;
}

.ghost-button {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 2px;
}

.room-band,
.listen-panel,
.manual-row,
.caption-stage,
.history-panel {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.room-band {
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.room-band strong {
  display: block;
  margin-top: 3px;
  font-size: 32px;
  letter-spacing: 0;
}

.qr-band {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px 16px;
}

.qr-band summary {
  cursor: pointer;
  font-weight: 800;
  min-height: 28px;
}

.qr-band summary span {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
}

.qr-body {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-top: 12px;
  text-align: center;
}

.qr-box {
  width: min(72vw, 300px);
  aspect-ratio: 1 / 1;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.qr-box svg {
  display: block;
  width: 100%;
  height: 100%;
}

.qr-url {
  margin: 0;
  max-width: 100%;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.lang-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: center;
  justify-items: center;
  background: var(--bg);
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

.lang-gate[hidden] {
  display: none;
}

.lang-gate-inner {
  width: min(100%, 560px);
  display: grid;
  gap: 18px;
}

.lang-gate-kicker {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.lang-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.lang-tile {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 22px;
  font-weight: 800;
  padding: 10px 12px;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.lang-tile:hover {
  border-color: var(--green);
}

.lang-tile:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.lang-tile:active {
  transform: scale(0.985);
}

.lang-chip {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

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

.lang-chip span {
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lang-chip:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

@media (max-width: 380px) {
  .lang-grid {
    grid-template-columns: 1fr;
  }
}

.listen-panel {
  padding: 14px;
}

.current-text {
  min-height: 210px;
  display: flex;
  align-items: center;
  margin: 14px 0 0;
  color: var(--surface-strong);
  font-size: clamp(30px, 8vw, 58px);
  line-height: 1.08;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.manual-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 10px;
}

.manual-row input,
.manual-row .button {
  min-height: 44px;
}

.caption-stage {
  min-height: min(56dvh, 560px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  padding: 16px;
}

.stage-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.translated-text {
  align-self: center;
  margin: 0;
  color: var(--surface-strong);
  font-size: clamp(42px, 12vw, 86px);
  line-height: 1.05;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.source-text {
  min-height: 24px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.history-panel {
  padding: 12px;
}

.caption-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.caption-list li {
  display: grid;
  gap: 4px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.caption-list p {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.caption-list span {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 620px) {
  .home-actions,
  .control-band,
  .join-band {
    grid-template-columns: 1fr;
  }

  .join-band .button,
  .control-band .button {
    width: 100%;
  }

  .current-text {
    min-height: 180px;
  }
}

/* Tour info for AI correction (guide page) */
.prep-band {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.prep-band summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}

.prep-band[open] {
  display: grid;
  gap: 10px;
}

.prep-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

#correctionLabel[data-state="ready"] {
  color: var(--green);
}

.prep-band textarea {
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
}

/* Guide page: speech stopped and could not restart by itself (iPhone). */
.tap-resume {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(217, 72, 65, 0.94);
}

.tap-resume[hidden] {
  display: none;
}

.tap-resume button {
  display: grid;
  place-content: center;
  gap: 14px;
  border: 3px solid #fff;
  border-radius: 16px;
  background: transparent;
  color: #fff;
  font: inherit;
  cursor: pointer;
}

.tap-resume strong {
  font-size: clamp(30px, 9vw, 52px);
}

.tap-resume span {
  font-size: 18px;
  font-weight: 700;
}

/* Three items in a narrow phone heading: title, save, and the other button */
.panel-heading {
  flex-wrap: wrap;
}

.panel-heading h2 {
  margin-right: auto;
}

/* How long the sentence the guide is still speaking has run (2026-10-29).
   Korean is cut early only where a thought is complete; the colour tells the
   guide when a shorter sentence would help. */
.length-gauge {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.gauge-bar {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}

.gauge-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--green);
  transition: width 0.3s ease, background-color 0.3s ease;
}

.length-gauge b { color: var(--green); }
.length-gauge[data-level="long"] .gauge-bar i { background: var(--amber); }
.length-gauge[data-level="long"] b { color: var(--amber); }
.length-gauge[data-level="over"] .gauge-bar i { background: var(--coral); }
.length-gauge[data-level="over"] b { color: var(--coral); }

/* The guide is speaking: a caption is on its way (participants' phones). */
.speaking-dots {
  display: flex;
  gap: 6px;
  min-height: 12px;
  margin: 6px 0 0;
}

.speaking-dots[hidden] { display: none; }

.speaking-dots i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  animation: speaking-pulse 1.2s infinite ease-in-out;
}

.speaking-dots i:nth-child(2) { animation-delay: 0.2s; }
.speaking-dots i:nth-child(3) { animation-delay: 0.4s; }

@keyframes speaking-pulse {
  0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .speaking-dots i { animation: none; opacity: 0.7; }
}

/* Participants' questions (2026-10-29): a box on their phones, a list on the guide's. */
.question-panel,
.question-inbox {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.question-form label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

.question-row {
  display: flex;
  gap: 8px;
}

.question-row input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 1rem;
}

.question-status {
  min-height: 1.2em;
  margin: 6px 0 0;
  color: var(--green);
  font-size: 0.9rem;
}

.question-list {
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.question-list li {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.question-list li.fresh {
  border-color: var(--amber);
  background: #fff8e6;
}

.question-list p {
  margin: 0 0 4px;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.35;
}

.question-list span {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---- Layout polish (2026-10-29) ---- */

/* Participants: once connected, the room form folds away; the language chip
   at the top still changes the language. */
body[data-connected="true"] .join-band {
  display: none;
}

.viewer-screen .caption-stage {
  min-height: min(46dvh, 480px);
  border-top: 4px solid var(--green);
}

/* A short sentence big, a long one smaller: one caption, one screen. */
.translated-text[data-size="short"] { font-size: clamp(36px, 10vw, 72px); line-height: 1.08; }
.translated-text[data-size="medium"] { font-size: clamp(28px, 7.4vw, 50px); line-height: 1.15; }
.translated-text[data-size="long"] { font-size: clamp(22px, 5.8vw, 36px); line-height: 1.25; }

/* The newest caption is on the stage already; the list holds the earlier ones. */
.viewer-screen .caption-list li:first-child {
  display: none;
}

.viewer-screen .caption-list li:nth-child(2) {
  border-top: 0;
  padding-top: 0;
}

.viewer-screen .history-panel .panel-heading h2 {
  flex: 1 0 100%;
}

.viewer-screen .question-panel {
  margin-top: 12px;
}

/* Languages others in this tour already read. */
.lang-tile.chosen {
  border-color: var(--green);
  box-shadow: inset 0 0 0 1px var(--green);
}

.lang-tile.chosen::after {
  content: " ✓";
  color: var(--green);
}

/* Guide: a room exists, so a new one is a small, deliberate action. */
body[data-room="true"] #createRoomButton {
  min-height: 40px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.question-inbox {
  margin-top: 12px;
}
