:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --surface: #141926;
  --surface-2: #1b2233;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #4f8cff;
  --accent-dim: #2c5db8;
  --live: #22c55e;
  --danger: #ef4444;
  --radius: 14px;
}

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

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    max(10px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

/* ---------- header ---------- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px 10px;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: .2px;
}

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #3a4256;
  flex: none;
}
body[data-state="connecting"] .dot,
body[data-state="stopping"] .dot { background: #eab308; }
body[data-state="live"] .dot {
  background: var(--live);
  animation: pulse 1.6s ease-out infinite;
}
body[data-state="error"] .dot { background: var(--danger); }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .45); }
  100% { box-shadow: 0 0 0 9px rgba(34, 197, 94, 0); }
}

.badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .8px;
  color: var(--accent);
  background: rgba(79, 140, 255, .12);
  border: 1px solid rgba(79, 140, 255, .35);
  padding: 3px 9px;
  border-radius: 999px;
}

/* ---------- mode switcher ---------- */
#modeNav {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  background: var(--surface);
  padding: 5px;
  border-radius: var(--radius);
  margin-bottom: 10px;
}

.mode {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 600 13px/1 system-ui, sans-serif;
  padding: 11px 4px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.mode:active { transform: scale(.97); }
.mode.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- toast ---------- */
#toast {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(92vw, 480px);
  background: #2a1518;
  color: #ffb4b4;
  border: 1px solid rgba(239, 68, 68, .4);
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 50;
}

/* ---------- feed ---------- */
#feed {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px 2px 12px;
  scroll-behavior: smooth;
}

#placeholder {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  margin-top: 34vh;
}

.utt { padding: 8px 0; }

.utt .orig {
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
  margin-bottom: 3px;
}

.utt .tr {
  font-size: 19px;
  line-height: 1.4;
  font-weight: 600;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.utt.divider {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: .5px;
  padding: 12px 0 6px;
  user-select: none;
}

#live { opacity: .8; }
#live .tr::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1.1s step-end infinite;
  margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- footer ---------- */
footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding-top: 8px;
}

.round {
  appearance: none;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #fff;
  transition: transform .12s, background .15s;
}
.round:active { transform: scale(.93); }

.small {
  width: 44px; height: 44px;
  background: var(--surface);
  color: var(--muted);
}

.big {
  width: 74px; height: 74px;
  background: var(--accent);
  box-shadow: 0 6px 22px rgba(79, 140, 255, .35);
}
body[data-state="live"] .big {
  background: var(--danger);
  box-shadow: 0 6px 22px rgba(239, 68, 68, .35);
  animation: ring 1.6s ease-out infinite;
}
body[data-state="connecting"] .big,
body[data-state="stopping"] .big { background: #eab308; box-shadow: none; }

@keyframes ring {
  0% { box-shadow: 0 6px 22px rgba(239, 68, 68, .35), 0 0 0 0 rgba(239, 68, 68, .35); }
  100% { box-shadow: 0 6px 22px rgba(239, 68, 68, .35), 0 0 0 14px rgba(239, 68, 68, 0); }
}

.footer-spacer { width: 44px; }

/* ---------- pin gate ---------- */
#pinGate {
  position: fixed;
  inset: 0;
  background: rgba(11, 14, 20, .92);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 100;
}

#pinForm {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 18px;
  padding: 28px 24px;
  width: min(86vw, 320px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#pinForm h2 { margin: 0 0 4px; font-size: 18px; text-align: center; }
#pinForm input {
  background: var(--surface-2);
  border: 1px solid #2a3348;
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 18px;
  text-align: center;
  letter-spacing: 4px;
  outline: none;
}
#pinForm input:focus { border-color: var(--accent); }
#pinForm button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font: 600 15px system-ui;
  padding: 12px;
  cursor: pointer;
}
#pinErr { color: #ffb4b4; font-size: 13px; text-align: center; min-height: 16px; }

[hidden] { display: none !important; }
