/* Live Interpreter — subtitle-booth styling.
   One typeface family (IBM Plex) across Latin, Japanese and Devanagari so every language shares a voice.
   Saffron is reserved for "live right now": a line being spoken, a connected call. */

:root {
  --paper: #eceff4; /* cool washi grey */
  --surface: #ffffff;
  --ink: #1c2541; /* ai-zome indigo ink */
  --muted: #5e6880; /* original-language text */
  --line: #d3d9e4;
  --action: #2b3a8c; /* indigo */
  --action-ink: #ffffff;
  --live: #e8a33d; /* saffron */
  --live-soft: rgba(232, 163, 61, 0.14);
  --danger: #b9382f;

  --font: "IBM Plex Sans", "IBM Plex Sans JP", "IBM Plex Sans Devanagari", system-ui, -apple-system,
    "Hiragino Sans", sans-serif;

  /* classic scale: 12 14 16 18 21 24 30 36 */
  --t-xs: 0.75rem;
  --t-sm: 0.875rem;
  --t-md: 1rem;
  --t-lg: 1.125rem;
  --t-xl: 1.3125rem;
  --t-2xl: 1.5rem;
  --t-3xl: 1.875rem;

  --radius-control: 10px;
  --radius-panel: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1428;
    --surface: #161c36;
    --ink: #e7eaf3;
    --muted: #9aa3bd;
    --line: #2a3253;
    --action: #8c9df2;
    --action-ink: #0f1428;
    --live-soft: rgba(232, 163, 61, 0.12);
    --danger: #e0685f;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--t-md) / 1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

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

:focus-visible {
  outline: 2px solid var(--action);
  outline-offset: 2px;
}

a {
  color: var(--action);
  text-underline-offset: 3px;
}

/* ---------- controls ---------- */

button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-weight: 500;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.primary {
  min-height: 50px;
  border-color: var(--action);
  background: var(--action);
  color: var(--action-ink);
  font-weight: 600;
}

button.danger {
  border-color: transparent;
  background: transparent;
  color: var(--danger);
}

button.active {
  border-color: var(--danger);
  background: var(--danger);
  color: #fff;
}

label {
  display: grid;
  gap: 6px;
  font-size: var(--t-sm);
  font-weight: 500;
}

/* 16px minimum keeps iPhone Safari from zooming into fields */
input,
select {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  font-size: var(--t-md);
  font-weight: 400;
}

input[type="range"],
input[type="checkbox"] {
  min-height: 0;
  padding: 0;
  accent-color: var(--action);
}

.field-note,
.hint {
  font-size: var(--t-sm);
  font-weight: 400;
  color: var(--muted);
}

/* ---------- join ---------- */

.join {
  max-width: 30rem;
  margin: 0 auto;
  padding: max(40px, 8vh) 20px 48px;
}

.brand {
  margin: 0 0 40px;
  font-weight: 600;
  color: var(--action);
}

/* The hero: a caption pair, the way the call screen shows every line. */
.specimen {
  margin: 0 0 24px;
  padding-left: 18px;
  border-left: 4px solid var(--live);
}

.specimen-source {
  margin: 0 0 6px;
  font-size: var(--t-lg);
  line-height: 1.6;
  color: var(--muted);
}

.specimen-output {
  margin: 0;
  font-size: var(--t-3xl);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.lead {
  margin: 0 0 32px;
  max-width: 34em;
  color: var(--muted);
}

form {
  display: grid;
  gap: 18px;
}

form button {
  margin-top: 6px;
}

.hint {
  margin: 20px 0 0;
}

.hint + .hint {
  margin-top: 8px;
}

/* ---------- call ---------- */

#call-screen,
#test-screen {
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  height: 100dvh;
  max-width: 46rem;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.call-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.call-title {
  min-width: 0;
}

#status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

#status::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

#status[data-kind="live"]::before {
  background: var(--live);
  box-shadow: 0 0 0 4px var(--live-soft);
}

#status[data-kind="error"]::before {
  background: var(--danger);
}

.room {
  font-size: var(--t-sm);
  color: var(--muted);
}

.room strong {
  font-weight: 600;
  color: var(--ink);
}

#copy-link {
  flex: none;
  min-height: 40px;
  padding: 0 14px;
  font-size: var(--t-sm);
}

#enable-sound {
  width: 100%;
}

.participants {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  font-size: var(--t-sm);
}

.participant {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}

.participant:last-child {
  text-align: right;
}

#me-label,
#peer-label {
  font-weight: 600;
}

.link-mark {
  padding-top: 1px;
  color: var(--muted);
}

.badge {
  color: var(--muted);
}

/* ---------- transcript ---------- */

#feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 4px 2px 8px;
  overscroll-behavior: contain;
}

#empty-feed {
  margin: auto;
  max-width: 22em;
  text-align: center;
  color: var(--muted);
}

.bubble {
  display: flex;
  flex-direction: column;
  padding-left: 14px;
  border-left: 3px solid var(--line);
  transition: border-color 0.4s;
}

.bubble.live {
  border-left-color: var(--live);
}

.bubble .who {
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--muted);
}

/* Their lines: the translation is what you need, big; the original sits under it. */
.bubble .translation {
  font-size: var(--t-xl);
  font-weight: 500;
  line-height: 1.4;
}

.bubble .source {
  margin-top: 4px;
  font-size: var(--t-md);
  line-height: 1.6;
  color: var(--muted);
}

/* Your lines: what you said, then what they heard. */
.bubble.me {
  margin-left: 12%;
}

.bubble.me .source {
  order: 1;
  margin-top: 0;
  font-size: var(--t-lg);
  color: var(--ink);
}

.bubble.me .translation {
  order: 2;
  margin-top: 4px;
  font-size: var(--t-md);
  font-weight: 400;
  color: var(--muted);
}

.bubble.me .translation::before {
  content: "They heard: ";
}

/* ---------- call controls ---------- */

.controls {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

#mute {
  min-width: 6.5rem;
}

.slider {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 400;
  color: var(--muted);
}

.slider input {
  flex: 1;
  min-width: 0;
}

.meter {
  font-size: var(--t-xs);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

#feed.hide-source .source {
  display: none;
}

/* Your own line keeps what you said even when original text is hidden. */
#feed.hide-source .bubble.me .source {
  display: block;
}

.spacer {
  flex: 1;
}

/* ---------- sound and captions panel ---------- */

.prefs summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  font-size: var(--t-sm);
  font-weight: 500;
  color: var(--action);
  cursor: pointer;
  list-style: none;
}

.prefs summary::-webkit-details-marker {
  display: none;
}

.prefs summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.2s;
}

.prefs[open] summary::after {
  transform: translateY(2px) rotate(-135deg);
}

.prefs-body {
  display: grid;
  gap: 4px;
  padding: 4px 0 8px;
}

label.toggle {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  font-weight: 500;
  cursor: pointer;
}

label.toggle span {
  display: grid;
  gap: 2px;
}

label.toggle small {
  font-size: var(--t-sm);
  font-weight: 400;
  color: var(--muted);
}

/* A switch drawn from the native checkbox, so it stays keyboard- and screen-reader-friendly. */
label.toggle input {
  order: 2;
  flex: none;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 46px;
  height: 28px;
  margin: 2px 0 0;
  border-radius: 14px;
  background: var(--line);
  cursor: pointer;
  transition: background 0.2s;
}

label.toggle input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(28, 37, 65, 0.3);
  transition: transform 0.2s;
}

label.toggle input:checked {
  background: var(--action);
}

label.toggle input:checked::after {
  transform: translateX(18px);
}

/* ---------- test bench ---------- */

#test-screen h1 {
  margin: 0;
  font-size: var(--t-xl);
  font-weight: 600;
}

#test-screen .call-header {
  align-items: flex-start;
}

.test-controls {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
}

label.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 400;
}

.row {
  display: flex;
  gap: 10px;
}

.row button {
  flex: 1;
}

#file-player {
  width: 100%;
}

#test-screen .bubble .translation {
  order: 1;
}

/* ---------- error ---------- */

#error {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: 36rem;
  margin: 0 auto;
  padding: 14px 16px;
  border-radius: var(--radius-control);
  background: var(--danger);
  color: #fff;
}

@media (max-width: 520px) {
  .specimen-output {
    font-size: var(--t-2xl);
  }

  .slider {
    font-size: var(--t-sm);
  }

  .bubble.me {
    margin-left: 8%;
  }

  /* The ⇄ row already says who is translated into what. */
  .badge {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bubble,
  .prefs summary::after,
  label.toggle input,
  label.toggle input::after {
    transition: none;
  }
}
