/* ============================================================
   Nihon Ninja — shared design system, wired to the real app.
   Applies the v2 "one focus, calm motion" system to the actual
   five-direction translator code. Chrome (top bar, reading
   surface, info card, status row, bottom bar) is design-system;
   the #output block list keeps each direction's real DOM and is
   restyled here so the legal record reads cleanly.
   ============================================================ */

:root {
  --font-ui: "Zen Kaku Gothic New", "Noto Sans JP", system-ui, sans-serif;
  --font-mono: "Space Mono", ui-monospace, monospace;

  /* sumi (dark) — default operator console */
  --bg: oklch(0.16 0.004 65);
  --bg-2: oklch(0.205 0.005 65);
  --surface: oklch(0.235 0.006 65);
  --line: oklch(0.36 0.006 65);
  --line-soft: oklch(0.28 0.005 65);

  --ink: oklch(0.99 0.004 85);
  --ink-2: oklch(0.92 0.006 82);
  --ink-3: oklch(0.82 0.008 80);
  --faint: oklch(0.68 0.008 78);

  --accent: #D6451D;
  --accent-soft: rgba(214, 69, 29, 0.16);
  --live: oklch(0.74 0.13 158);
  --warn: oklch(0.80 0.13 75);

  --radius: 12px;
  --radius-lg: 18px;
  --pad: clamp(20px, 3.2vw, 56px);
  --t-commit: 240ms;
}

[data-theme="washi"] {
  --bg: oklch(0.97 0.005 90);
  --bg-2: oklch(0.94 0.006 88);
  --surface: oklch(0.99 0.004 90);
  --line: oklch(0.80 0.009 82);
  --line-soft: oklch(0.87 0.007 84);
  --ink: oklch(0.17 0.012 60);
  --ink-2: oklch(0.29 0.012 65);
  --ink-3: oklch(0.40 0.012 70);
  --faint: oklch(0.50 0.011 74);
  --accent: #D6451D;
  --accent-soft: rgba(214, 69, 29, 0.12);
  --live: oklch(0.52 0.14 158);
  --warn: oklch(0.58 0.14 70);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font-ui);
  font-weight: 500;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: 100%;
  /* the original sheets set max-width/margin/padding on body — neutralised */
  max-width: none;
  padding: 0;
  line-height: 1.5;
}

[data-motion="calm"] * { animation: none !important; }
[data-motion="calm"] .spin,
[data-motion="calm"] .ninja-spinner,
[data-motion="calm"] .spinner { animation-duration: .7s !important; animation-name: spin !important; animation-iteration-count: infinite !important; animation-timing-function: linear !important; }
@media (prefers-reduced-motion: reduce) { *:not(.spin):not(.ninja-spinner) { animation: none !important; transition: none !important; } }

svg.ico { width: 16px; height: 16px; flex: none; }

::selection { background: var(--accent-soft); }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--line); border-radius: 99px; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   Top bar
   ============================================================ */
.topbar {
  flex: none;
  display: flex; align-items: center; gap: 14px;
  padding: 12px var(--pad);
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 12px; flex: none; }
.brand-logo { width: 36px; height: 36px; border-radius: 9px; display: block; flex: none; }
.brand-name { font-family: var(--font-ui); font-size: 17px; font-weight: 800; letter-spacing: -0.01em; line-height: 1.1; }
.brand-sub { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--faint); margin-top: 3px; }
.spacer { flex: 1; }

/* a quiet divider between status cluster items */
.bar-div { width: 1px; align-self: stretch; background: var(--line); margin: 5px 2px; flex: none; }

/* session clock */
.clock {
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.06em;
  color: var(--ink-3); display: none; align-items: baseline; gap: 7px; white-space: nowrap;
}
.clock.show { display: inline-flex; }
.clock .lbl { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); }

/* connection status — static dot */
.status {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 600; color: var(--ink-2); white-space: nowrap;
}
.status .dot { width: 8px; height: 8px; border-radius: 99px; background: var(--faint); flex: none; }
.status[data-s="connected"] .dot { background: var(--live); }
.status[data-s="connecting"] .dot { background: var(--warn); }
.status[data-s="error"] { color: var(--accent); }
.status[data-s="error"] .dot { background: var(--accent); }

/* indicator pills — TTS engine, mic/tab sources, direction lock */
.pill {
  display: none; align-items: center; gap: 7px; white-space: nowrap;
  font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  padding: 6px 11px; border-radius: 99px; border: 1px solid var(--line); color: var(--ink-3); background: transparent;
}
.pill.show { display: inline-flex; }
.pill .dot { width: 7px; height: 7px; border-radius: 99px; background: var(--faint); flex: none; }
.pill .ico { width: 13px; height: 13px; }
/* TTS engine pill states */
.pill.tts[data-s="open"] { color: var(--ink-2); border-color: var(--line); }
.pill.tts[data-s="open"] .dot { background: var(--live); }
.pill.tts[data-s="speaking"] { color: var(--ink); border-color: color-mix(in oklch, var(--accent) 50%, var(--line)); }
.pill.tts[data-s="speaking"] .dot { background: var(--accent); }
.pill.tts[data-s="muted"] { color: var(--faint); }
.pill.tts[data-s="muted"] .dot { background: var(--faint); }
/* source pills: dot-only — compact, color is the signal */
.pill.src .lbl { display: none; }
.pill.src { padding: 7px 9px; gap: 0; }
.pill.src[data-s="live"] .dot { background: var(--live); }
.pill.src[data-s="off"] { opacity: 0.45; }
/* direction lock badge */
.pill.dir { color: var(--ink-2); border-color: color-mix(in oklch, var(--accent) 30%, var(--line)); }
.pill.dir .dot { display: none; }

/* buttons (real #start/#stop/#mute/#reset live in here) */
.bar-actions { display: flex; align-items: center; gap: 10px; flex: none; }
.app .btn,
button.btn,
a.btn {
  font-family: var(--font-ui); font-size: 13.5px; font-weight: 700; letter-spacing: 0.01em;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; line-height: 1;
  text-decoration: none;
}
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: oklch(0.98 0.01 85); }
.btn-primary:not(:disabled):hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:not(:disabled):hover { border-color: var(--ink-3); color: var(--ink); }
.btn-stop { background: transparent; border-color: color-mix(in oklch, var(--accent) 45%, var(--line)); color: var(--accent); }
.btn-stop:not(:disabled):hover { background: var(--accent); border-color: var(--accent); color: oklch(0.98 0.01 85); }
.btn .ico { width: 15px; height: 15px; display: block; }
/* compact secondary actions */
.btn-sm { padding: 7px 12px; font-size: 12.5px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; justify-content: center; }

/* theme toggle */
.themebtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line);
  background: transparent; color: var(--ink-2); cursor: pointer; flex: none;
  transition: border-color .15s, color .15s;
}
.themebtn:hover { border-color: var(--ink-3); color: var(--ink); }
.themebtn .ico { width: 16px; height: 16px; }

/* ============================================================
   Stage + reading surface
   ============================================================ */
.app {
  flex: 1;
  min-height: 0;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.read-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: clamp(22px, 3.6vh, 40px) var(--pad) clamp(40px, 8vh, 96px);
  display: flex; flex-direction: column; align-items: center;
}
.read-col {
  width: 100%; max-width: 900px; margin: 0 auto;
  display: flex; flex-direction: column;
}

/* ---- error banner (real #error-banner, toggled .visible by main.js) ---- */
#error-banner {
  display: none;
  align-items: flex-start; gap: 11px;
  width: 100%; max-width: 900px; margin: 0 auto 18px;
  padding: 13px 16px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in oklch, var(--accent) 45%, transparent);
  color: var(--accent); font-size: 13.5px; font-weight: 600; line-height: 1.45;
}
#error-banner.visible { display: flex; }
#error-banner::before {
  content: ""; flex: none; width: 8px; height: 8px; border-radius: 99px;
  background: var(--accent); margin-top: 6px;
}

/* ---- info card: explains the direction, scrolls/collapses away on first turn ---- */
.info-card {
  width: 100%; max-width: 900px; margin: 0 auto 8px;
  border: 1px solid var(--line-soft); border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  padding: clamp(20px, 2.6vw, 30px);
  overflow: hidden;
  transition: max-height .5s cubic-bezier(.4,0,.1,1), opacity .4s ease, margin .5s ease, transform .5s cubic-bezier(.4,0,.1,1), padding .5s ease, border-color .4s ease;
  max-height: 600px;
}
.info-card.dismissed {
  max-height: 0; opacity: 0; margin-bottom: 0; padding-top: 0; padding-bottom: 0;
  transform: translateY(-14px); border-color: transparent; pointer-events: none;
}
.info-head { display: flex; align-items: flex-start; gap: 14px; }
.info-glyph {
  flex: none; width: 44px; height: 44px; border-radius: 11px;
  display: grid; place-items: center; color: var(--accent);
  background: var(--accent-soft); border: 1px solid color-mix(in oklch, var(--accent) 30%, transparent);
}
.info-glyph .ico { width: 22px; height: 22px; }
.info-titles { flex: 1; min-width: 0; }
.info-kicker { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); margin-bottom: 5px; }
.info-title { font-size: clamp(19px, 1.9vw, 24px); font-weight: 800; letter-spacing: -0.01em; line-height: 1.18; }
.info-dismiss {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-ui); font-size: 12px; font-weight: 700; color: var(--ink-3);
  background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px; cursor: pointer;
  transition: border-color .15s, color .15s;
}
.info-dismiss:hover { border-color: var(--ink-3); color: var(--ink); }
.info-desc { font-size: 14.5px; line-height: 1.6; color: var(--ink-2); margin: 16px 0 0; text-wrap: pretty; max-width: 64ch; }
.info-desc strong { color: var(--ink); font-weight: 700; }

/* the pipeline / sources meta row */
.info-meta { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line-soft); }
.info-fact { display: flex; flex-direction: column; gap: 5px; }
.info-fact .k { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); }
.info-fact .v { font-size: 13.5px; font-weight: 600; color: var(--ink-2); display: inline-flex; align-items: center; gap: 8px; }
/* source dots: filled = used */
.srcdots { display: inline-flex; gap: 5px; }
.srcdots i { width: 9px; height: 9px; border-radius: 99px; border: 1.5px solid var(--ink-3); display: block; }
.srcdots i.on { background: var(--accent); border-color: var(--accent); }
/* pipeline chips */
.pipe { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.pipe span { font-family: var(--font-mono); font-size: 11px; font-weight: 700; color: var(--ink-2); padding: 4px 9px; border-radius: 7px; background: var(--bg); border: 1px solid var(--line-soft); }
.pipe b { color: var(--faint); font-weight: 400; }

/* listening placeholder while connected + empty */
.listening {
  width: 100%; max-width: 900px; margin: 8px auto 0;
  display: none; align-items: center; gap: 12px;
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint);
}
.app[data-conn="connected"] .listening.armed { display: flex; }
.listening .bar { width: 2px; height: 15px; background: var(--accent); opacity: 0.85; border-radius: 1px; }

/* ============================================================
   #output — the append-only block list (legal record).
   Each direction builds slightly different DOM; all variants
   are restyled to the same calm reading model.
   ============================================================ */
#output {
  width: 100%; max-width: 900px; margin: 0 auto;
  /* the originals set max-height/border/overflow here — neutralised,
     the .read-scroll owns scrolling now */
  max-height: none; overflow: visible; border: 0; padding: 0;
  display: flex; flex-direction: column; gap: clamp(20px, 2.6vh, 32px);
}
#output:empty { display: none; }

.utterance-block {
  display: flex; flex-direction: column; gap: 9px;
  padding: 0 0 clamp(20px, 2.6vh, 30px);
  margin: 0; border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  animation: commit var(--t-commit) ease both;
}
.utterance-block:last-child { border-bottom: 0; padding-bottom: 0; }
@keyframes commit { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* the newest block reads as the hero (bottom of list) */
.utterance-block:last-child .section-text:not(.spoken-text):not(.placeholder),
.utterance-block:last-child .utterance-translation,
.utterance-block:last-child .translation-text {
  color: var(--ink);
}

/* lang / direction badges that main.js writes into */
.lang-badge, .direction-badge {
  align-self: flex-start;
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-3);
  background: transparent; border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 99px; margin: 0;
}

/* section labels (SPOKEN / JAPANESE TRANSLATION / ENGLISH TRANSLATION) */
.section-label, .utterance-label {
  display: block;
  font-family: var(--font-mono); font-size: 10px; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint);
  margin: 6px 0 1px;
}
.utterance-block > .section-label:first-of-type { margin-top: 0; }

/* the source ("SPOKEN") line — subordinate caption */
.section-text { font-size: clamp(16px, 1.35vw, 20px); line-height: 1.5; color: var(--ink-2); text-wrap: pretty; }
.spoken-section .section-text,
.spoken-text,
.utterance-spoken,
.source-text {
  font-size: clamp(14.5px, 1.15vw, 17px); line-height: 1.5; color: var(--ink-3); font-weight: 500; text-wrap: pretty;
}

/* the translations — the thing to read, largest + full contrast */
.ja-section .section-text,
.en-section .section-text,
.ja-text, .en-text,
.utterance-translation,
.translation-text {
  font-family: var(--font-ui); font-weight: 700;
  font-size: clamp(21px, 1.9vw, 27px); line-height: 1.34; letter-spacing: -0.008em;
  color: var(--ink-2); text-wrap: pretty;
}

/* placeholders / pending / "(source language)" — quiet, italic-free */
.section-text.placeholder,
.translation-text.pending,
.ja-text:empty, .en-text:empty {
  color: var(--faint); font-weight: 500; font-style: normal;
}
/* override the inline styles some directions set on "(source language)" */
.utterance-block .section-text[style] { color: var(--faint) !important; font-style: normal !important; }

/* Direction E translation line: it sets font-style italic inline via CSS class */
.translation-text { font-style: normal; }
.translation-text.pending,
.section-text.pending {
  display: inline-flex; align-items: center; min-height: 1.34em;
  opacity: 1; color: var(--faint);
}

/* Direction B pending block (spinner + "Translating…") */
.pending-block {
  flex-direction: row !important; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--faint); font-family: var(--font-mono); font-size: 12px;
  letter-spacing: 0.1em; text-transform: uppercase; font-style: normal !important;
}
.pending-block .section-label, .pending-block .lang-badge { display: none; }
.spinner, .ninja-spinner {
  width: 15px; height: 15px; flex: none; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Bottom bar — controls that don't belong up top (sliders),
   plus the build badge area. Hidden when a direction has none.
   ============================================================ */
.bottombar {
  flex: none; display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 11px var(--pad);
  border-top: 1px solid var(--line-soft); background: var(--bg);
}
.bottombar:empty { display: none; }
.bottombar .lbl { font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--faint); }
.ctrl-group { display: flex; align-items: center; gap: 11px; }
.ctrl-group label { font-size: 12.5px; font-weight: 600; color: var(--ink-3); }
.ctrl-group input[type="range"] {
  width: clamp(110px, 12vw, 170px); height: 4px; -webkit-appearance: none; appearance: none;
  background: var(--line); border-radius: 99px; cursor: pointer;
}
.ctrl-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--bg);
}
.ctrl-group input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px; border-radius: 50%; background: var(--accent); cursor: pointer; border: 2px solid var(--bg);
}
.ctrl-val { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-2); min-width: 48px; }
.bottombar .right { margin-left: auto; display: flex; align-items: center; gap: 14px; }

/* the original sliders/loader/badge markup the directions ship — re-skinned
   in-place so we don't touch their IDs. Loading indicator becomes a quiet
   mono "translating" affordance. */
#loading-indicator { display: none; align-items: center; gap: 9px; font-family: var(--font-mono); font-size: 11.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
#loading-indicator.visible { display: flex; }
/* direction-badge / pair-badge live in chrome via JS mirror; hide the originals */
#direction-badge, #pair-badge { display: none !important; }

/* build-info badge from build-info.js — calm it down + move clear of the top bar */
#build-info-badge {
  top: 64px !important; right: 14px !important; bottom: auto !important; left: auto !important;
  font-family: var(--font-mono) !important; font-size: 10px !important;
  letter-spacing: 0.06em !important; box-shadow: none !important;
  background: var(--bg-2) !important; color: var(--faint) !important;
  border: 1px solid var(--line-soft) !important; border-radius: 8px !important;
  padding: 5px 9px !important; opacity: 0.62;
}

.spin { width: 14px; height: 14px; border-radius: 99px; border: 2px solid currentColor; border-top-color: transparent; display: inline-block; animation: spin .7s linear infinite; }
