/* Code Switch — web client theme.
   Design authority: .impeccable.md. Tokens mirror ios/Translator/Theme.swift
   exactly (white(x) -> hsl lightness x%; RGB -> hex). Precise, calm, tool-like.
   Azure primary accent; language hues (ES coral / EN azure / FR violet) are
   supplementary — always paired with a text label. Light + dark, both first-class.
   The caption is the product; motion lives in one place (the reading zone). */

:root {
  /* Dark is the default token set; light overrides below. Matches Theme.swift dark. */
  --bg: #0f0f0f;            /* white 0.06 */
  --surface: #1c1c1c;       /* white 0.11 */
  --text-primary: #ebebeb;  /* white 0.92 */
  --text-secondary: #8c8c8c;/* white 0.55 */
  --hairline: #2e2e2e;      /* white 0.18 */

  --accent: #4d94ff;        /* rgb(0.30,0.58,1.00) */
  --on-accent: #ffffff;

  --hue-es: #f5735c;        /* coral, dark: rgb(0.96,0.45,0.36) */
  --hue-fr: #9985fa;        /* violet, dark: rgb(0.60,0.52,0.98) */
  --hue-en: var(--accent);  /* azure */

  --radius: 14px;
  --radius-pill: 999px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "SF Pro Text",
    "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Menlo", monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f7f7;            /* white 0.97 */
    --surface: #ebebeb;       /* white 0.92 */
    --text-primary: #1a1a1a;  /* white 0.10 */
    --text-secondary: #737373;/* white 0.45 */
    --hairline: #d9d9d9;      /* white 0.85 */

    --accent: #1a73f2;        /* rgb(0.10,0.45,0.95) */

    --hue-es: #d95240;        /* coral, light: rgb(0.85,0.32,0.24) */
    --hue-fr: #7359d9;        /* violet, light: rgb(0.45,0.35,0.85) */
  }
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

main { height: 100dvh; }
[hidden] { display: none !important; }

.spacer { flex: 1 1 auto; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* Visible keyboard focus — restrained, azure, consistent across every surface. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
:focus:not(:focus-visible) { outline: none; }

/* ============================ HOME / JOIN ============================ */

.home {
  display: flex;
  justify-content: center;
  /* Scroll when the viewport is shorter than the form (extension side panel,
     landscape phones). align-items:center would clip the top when overflowing —
     .home-inner's margin:auto centers only when there's room. */
  height: 100dvh;
  overflow-y: auto;
  padding: max(24px, env(safe-area-inset-top)) 24px max(32px, env(safe-area-inset-bottom));
}

.home-inner {
  width: 100%;
  max-width: 460px;
  margin: auto;
}

.identity h1 {
  font-size: clamp(2rem, 8vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0;
}
.subtitle {
  color: var(--text-secondary);
  font-weight: 500;
  margin: 4px 0 0;
}

#setup-form {
  margin-top: 40px;
  border: 0;
}

.field { margin-bottom: 24px; border: 0; padding: 0; }
.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.field-label .hint { text-transform: none; letter-spacing: 0; font-weight: 500; opacity: 0.8; }

.text-input {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  font-family: var(--font);
  font-size: 1.05rem;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s ease;
}
.text-input::placeholder { color: var(--text-secondary); opacity: 0.7; }
.text-input:focus { border-color: var(--accent); }

.code-input {
  text-transform: uppercase;
  letter-spacing: 0.28em;
  font-weight: 700;
  font-family: var(--font-mono);
}

.pill-row { display: flex; flex-wrap: wrap; gap: 10px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 16px;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface);
  border: 1.5px solid var(--hairline);
  border-radius: var(--radius-pill);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.pill .pill-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--pill-hue, var(--accent));
}
.pill[aria-checked="true"],
.pill[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}

.actions { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }

.btn {
  height: 54px;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-secondary {
  background: var(--surface);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}
.btn-ghost { background: transparent; color: var(--text-secondary); }

.host-panel {
  margin-top: 8px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
}

.home-error {
  color: var(--hue-es);
  font-size: 0.9rem;
  font-weight: 500;
  min-height: 1.2em;
  margin: 14px 0 0;
}

/* ============================ LIVE ============================ */

.live {
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.status-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--hairline);
}

.listening { display: inline-flex; align-items: center; gap: 9px; }
.listening .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--text-secondary);
  opacity: 0.4;
  transition: opacity 0.1s linear, transform 0.1s linear, background 0.2s ease;
}
.listening-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-secondary);
}
.listening.off .dot { background: var(--text-secondary) !important; opacity: 0.4; transform: none; }

.status-error {
  color: var(--hue-es);
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40%;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-pill);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.chip.mono { cursor: default; }
.chip-icon { font-size: 0.85rem; line-height: 1; }
#code-chip-text { letter-spacing: 0.05em; }
.chip.copied { color: var(--accent); border-color: var(--accent); }

.content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.history {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0;
  /* Recede toward the top so history visually falls away from the reading zone. */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14%, #000 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 14%, #000 100%);
}

.history-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
}
.history-row .row-text {
  font-size: 1rem;
  color: var(--text-primary);
  margin: 0 0 4px;
  line-height: 1.35;
}
.history-row .row-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.history-row .row-meta .row-source {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-zone {
  flex: 0 0 auto;
  min-height: 40vh;
  padding: 18px 20px calc(18px + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--surface) 35%, transparent);
  border-top: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.reading-empty {
  margin: auto;
  text-align: center;
  color: var(--text-secondary);
  font-size: 1.05rem;
  max-width: 24ch;
}

.reading-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.reading-speaker {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-translation {
  font-size: clamp(1.6rem, 4vw, 2.6rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: 0;
}
.reading-translation.partial { color: var(--text-secondary); font-style: italic; }
.reading-translation.speculative { opacity: 0.7; }

.reading-source {
  margin: 12px 0 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

/* Language pill (text-carrying; hue supplementary) */
.lang-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  background: var(--surface);
  border-radius: var(--radius-pill);
  white-space: nowrap;
}
.lang-pill .lang-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--pill-hue, var(--accent));
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom, 0px));
}

.mic-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  background: var(--accent);
  color: var(--on-accent);
  border: 1.5px solid transparent;
  transition: background 0.2s ease, color 0.2s ease;
}
.mic-btn[aria-pressed="false"] {
  background: transparent;
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
}
.mic-glyph { line-height: 1; }
.mic-btn.muted .mic-glyph { opacity: 0.85; }

/* Speak-translations toggle — same visual grammar as the mic button.
   Off (default) = outline; on = filled accent. */
.speak-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  cursor: pointer;
  background: transparent;
  color: var(--accent);
  border: 1.5px solid color-mix(in srgb, var(--accent) 50%, transparent);
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.speak-btn.active {
  background: var(--accent);
  color: var(--on-accent);
  border-color: transparent;
}
.speak-glyph { line-height: 1; }

.leave-btn { height: 44px; padding: 0 24px; width: auto; font-size: 0.95rem; }

/* ============================ ENDED ============================ */

.ended {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  overflow-y: auto;
}
.ended-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 560px;
}
.ended-mark {
  width: 64px; height: 64px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem;
  color: var(--text-secondary);
  border: 2px solid var(--hairline);
}
.ended-inner h2 { margin: 0; font-size: 1.5rem; font-weight: 600; }
.ended-inner .btn { margin-top: 10px; padding: 0 40px; width: auto; }

/* Summary — generating state */
.summary-pending {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
}
.summary-generating {
  color: var(--text-secondary);
  font-size: 0.98rem;
  margin: 0;
}
.summary-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--hairline);
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Summary — content */
.summary-block {
  width: 100%;
  text-align: left;
  border-top: 1px solid var(--hairline);
  padding-top: 20px;
  margin-top: 4px;
}
.summary-content {
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.65;
  max-width: 60ch;
  margin: 0 auto;
}
.summary-content h3 {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-secondary);
  margin: 20px 0 6px;
}
.summary-content h3:first-child { margin-top: 0; }
.summary-content p { margin: 0 0 6px; }
.summary-content ul {
  margin: 0 0 6px;
  padding-left: 20px;
}
.summary-content li { margin-bottom: 3px; }
.summary-content strong { font-weight: 600; color: var(--text-primary); }
@media (prefers-reduced-motion: reduce) {
  .summary-spinner { animation: none; }
}

/* ============================ NARROW / SHORT (extension side panel) ======== */
/* At ~350px the one-line meta row ellipsized the source transcription into
   nothing. Give the source its own wrapped line — translation big, original
   small underneath, same grammar as the Mac app. Short viewports also give
   back some fixed reading-zone height so history stays readable. */
@media (max-width: 520px) {
  .history-row .row-meta { flex-wrap: wrap; row-gap: 2px; }
  .history-row .row-meta .row-source {
    flex-basis: 100%;
    white-space: normal;
    overflow: visible;
  }
}
@media (max-height: 700px) {
  .reading-zone { min-height: 30vh; }
}

/* ============================ WIDE / LANDSCAPE ============================ */
/* On wide screens history sits left (42%), reading zone right (58%). */
@media (min-width: 900px) and (orientation: landscape) {
  .content { flex-direction: row; }
  .history {
    flex: 0 0 42%;
    max-width: 42%;
    border-right: 1px solid var(--hairline);
  }
  .reading-zone {
    flex: 1 1 58%;
    min-height: 0;
    border-top: 0;
    justify-content: center;
  }
}

/* ============================ ACCOUNT CHIP ============================ */

.identity-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.account-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  margin-top: 4px;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.account-chip.signed-in {
  color: var(--text-primary);
  border-color: var(--hairline);
}
.account-chip.signed-in::before {
  content: "";
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
}

/* ============================ MODALS ============================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: color-mix(in srgb, #000 45%, transparent);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.modal {
  position: relative;
  width: 100%;
  max-width: 420px;
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 28px 24px 24px;
  box-shadow: 0 20px 60px -12px rgba(0, 0, 0, 0.5);
}
.modal-close {
  position: absolute;
  top: 12px; right: 14px;
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.4rem; line-height: 1;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  cursor: pointer;
  border-radius: 50%;
}
.modal-close:hover { background: var(--surface); }
.modal-title {
  margin: 0 0 10px;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.modal-body {
  margin: 0 0 20px;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.5;
}
.modal-body strong { color: var(--text-primary); font-weight: 600; }
.modal-note {
  margin: 12px 0 0;
  padding: 10px 12px;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
}
.modal .field-label { margin-top: 4px; }
.modal .actions { margin-top: 18px; }
.modal .btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }

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