:root {
  --bg: #05070a;
  --panel: #0f1319;
  --line: #222a35;
  --text: #f5f7fa;
  --muted: #8a96a8;
  --corey: #5ab8ff;
  --kana: #ff7aa8;
  --accent: #ffd84a;
  --live: #ff3b4e;
  --ok: #3ddc84;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
.ja { color: var(--muted); font-size: 0.8em; font-weight: 400; }

.screen { height: 100dvh; display: flex; flex-direction: column; }

/* --- setup --- */
#setup {
  padding: calc(var(--safe-top) + 32px) 20px calc(var(--safe-bottom) + 24px);
  gap: 14px;
  max-width: 520px;
  margin: 0 auto;
}
#setup h1 { margin: 0 0 8px; font-size: 1.7rem; display: flex; flex-direction: column; gap: 2px; }
.hint { margin: 0; color: var(--muted); }
.hint.small { font-size: 0.85rem; }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 6px 0 18px; }
.who-btn {
  min-height: 150px;
  border-radius: 22px;
  border: 2px solid var(--line);
  background: var(--panel);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  transition: transform 0.08s ease, border-color 0.2s;
}
.who-btn:active { transform: scale(0.97); }
.who-btn[data-speaker="corey"] { border-color: color-mix(in srgb, var(--corey) 55%, transparent); }
.who-btn[data-speaker="kana"] { border-color: color-mix(in srgb, var(--kana) 55%, transparent); }
.who-btn.last { box-shadow: inset 0 0 0 2px var(--accent); }
.who-name { font-size: 1.6rem; font-weight: 700; }
.who-lang { color: var(--muted); }
.room-label { font-weight: 600; }
#room {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 1.1rem;
}

/* --- HUD --- */
.bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: rgba(5, 7, 10, 0.92);
  border-bottom: 1px solid var(--line);
}
.bar.bottom {
  padding: 10px 12px calc(var(--safe-bottom) + 10px);
  border-top: 1px solid var(--line);
  border-bottom: 0;
}
.icon-btn { background: none; border: 0; font-size: 2rem; line-height: 1; padding: 0 6px; color: var(--muted); }
.room-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
#room-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { font-size: 0.72rem; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--muted); }
.pill.ok { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.pill.bad { background: color-mix(in srgb, var(--live) 20%, transparent); color: var(--live); }
.peer { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.peer .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.peer.online .dot { background: var(--ok); }
.peer.muted .dot { background: var(--accent); }

#stream {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px 24px;
  display: flex; flex-direction: column; gap: 12px;
}
.empty { margin: auto; text-align: center; color: var(--muted); line-height: 1.6; }

.line {
  max-width: 92%;
  padding: 10px 14px 12px;
  border-radius: 18px;
  background: var(--panel);
  border-left: 4px solid var(--line);
  animation: rise 0.18s ease-out;
}
.line.corey { border-left-color: var(--corey); }
.line.kana { border-left-color: var(--kana); }
.line.mine { align-self: flex-end; border-left: 0; border-right: 4px solid var(--line); }
.line.mine.corey { border-right-color: var(--corey); }
.line.mine.kana { border-right-color: var(--kana); }
.who-tag { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; }
.corey .who-tag { color: var(--corey); }
.kana .who-tag { color: var(--kana); }
.who-tag .kind { color: var(--muted); font-weight: 500; text-transform: none; margin-left: 6px; }

/* the line the reader needs is big; the other language is small */
.main { font-size: 1.45rem; line-height: 1.35; font-weight: 600; margin-top: 3px; word-break: break-word; }
.sub { font-size: 0.95rem; line-height: 1.35; color: var(--muted); margin-top: 4px; word-break: break-word; }
.note { margin-top: 8px; font-size: 0.88rem; color: var(--accent); }
.note::before { content: "💡 "; }
.line.interim .main { color: #c9d1dc; font-style: italic; font-weight: 500; }
.line.interim .main::after { content: " ▍"; color: var(--live); animation: blink 1s steps(2) infinite; }
.line.pending .main.pending-text { color: var(--muted); font-style: italic; font-weight: 500; font-size: 1.05rem; }
.line.failed .sub.fail { color: var(--live); }

.jump {
  position: fixed; right: 16px; bottom: calc(var(--safe-bottom) + 96px);
  border: 0; border-radius: 99px; padding: 8px 14px;
  background: var(--accent); color: #111; font-weight: 700;
}

#chat { flex: 1; min-width: 0; }
#chat-input {
  width: 100%; padding: 13px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--panel); font-size: 16px; /* 16px stops iOS zoom */
}
.mic {
  flex: 0 0 auto;
  min-width: 132px; height: 52px;
  border-radius: 99px; border: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 700;
  background: var(--line);
}
.mic { position: relative; overflow: visible; --level: 0; }
/* live mic level: a ring that grows with your voice, plus a bar along the bottom of the button */
.mic.on {
  background: var(--live);
  box-shadow: 0 0 0 calc(2px + var(--level) * 14px) rgba(255, 59, 78, calc(0.25 + var(--level) * 0.45));
  transition: box-shadow 60ms linear;
}
.level {
  position: absolute; left: 18px; right: 18px; bottom: 6px; height: 3px;
  border-radius: 2px; background: rgba(255, 255, 255, 0.25); overflow: hidden;
}
#level-bar {
  display: block; height: 100%; background: #fff;
  transform-origin: left center; transform: scaleX(0); transition: transform 60ms linear;
}

.call-bar {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 6px 12px; font-size: 0.82rem; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.call-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.call-bar.connecting .call-dot { background: var(--accent); animation: blink 1s steps(2) infinite; }
.call-bar.direct, .call-bar.relay { color: var(--ok); }
.call-bar.direct .call-dot, .call-bar.relay .call-dot { background: var(--ok); }

.banner {
  padding: 8px 14px;
  font-size: 0.85rem;
  line-height: 1.35;
  border-bottom: 1px solid var(--line);
  background: #161c25;
  color: var(--muted);
}
.banner.warn { background: color-mix(in srgb, var(--accent) 14%, var(--bg)); color: var(--accent); }
.banner.bad { background: color-mix(in srgb, var(--live) 16%, var(--bg)); color: #ff8b97; }
.mic-icon { font-size: 1.2rem; }

.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 64px); transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: #1c2430; border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: 0.9rem; z-index: 10;
}

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes blink { 50% { opacity: 0; } }

@media (min-width: 720px) {
  #stream { padding: 20px max(20px, calc((100% - 760px) / 2)); }
  .main { font-size: 1.7rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; }
}
