:root {
  /* Backgrounds */
  --bg-base: #1a1a2e;
  --bg-panel: #16213e;
  --bg-sunken: #0d1117;
  --bg-sunken-alt: #0f0f1e;

  /* Borders */
  --border-line: #0f3460;
  --border-subtle: #333;
  --border-userbar: #1e2a4a;

  /* Brand accents (UI-5: phosphor amber replaces the generic mint-teal —
     evokes classic amber CRT monitors, distinct from the dark-dashboard
     default. --accent-alert stays red: universally read as danger/warn,
     changing it would blur that signal) */
  --accent-primary: #ffb454;
  --accent-alert: #e94560;
  --kofi: #00b9fe;
  --kofi-hover: #009dd9;

  /* Text */
  --text-body: #e0e0e0;
  --text-muted: #888;
  --text-faint: #666;
  --white: #fff;
  --black: #000;

  /* Misc grays (organic one-off values from incremental feature additions;
     kept distinct rather than consolidated so UI-4 stays visually
     byte-identical -- see docs/phases/phase-UI.md UI-4) */
  --gray-999: #999;
  --gray-ccc: #ccc;
  --gray-aaa: #aaa;
  --gray-bbb: #bbb;
  --gray-ddd: #ddd;
  --gray-a0: #a0a0a0;
  --gray-777: #777;
  --gray-555: #555;
  --gray-222: #222;
  --gray-444: #444;
  --gray-eee: #eee;

  /* Semantic (non-brand) colors */
  --medal-gold: #ffd700;
  --medal-silver: #c0c0c0;
  --medal-bronze: #cd7f32;
  --status-warn: #e9a546;

  /* Typography */
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "Cascadia Code", "Fira Code", "SF Mono", Menlo, monospace;
  /* UI-7: self-hosted CRT display font. Applied only to header h1 and
     #status (LIVE badge) -- long body text stays on --font-ui for
     readability. Falls back to --font-mono (metrics-close monospace) to
     minimize reflow during font-display: swap. */
  --font-display: "VT323", var(--font-mono);

  /* Shape */
  --radius-card: 6px;
  --radius-ctl: 4px;
  --radius-crt: 10px;

  /* UI-6: terminal bezel glow (rgba of --accent-primary #ffb454; can't
     reference a custom property's channels directly inside rgba()) */
  --accent-primary-glow: rgba(255, 180, 84, 0.35);

  /* UI-9b: death-beat glow (rgba of --accent-alert #e94560, same reason
     as --accent-primary-glow above) */
  --accent-alert-glow: rgba(233, 69, 96, 0.5);
}

/* UI-7: self-hosted CRT display font (VT323, OFL 1.1, see fonts/OFL.txt).
   Latin-subset single weight (~17.5KB), served statically via /static/. */
@font-face {
  font-family: "VT323";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/vt323.woff2") format("woff2");
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-ui);
  background: var(--bg-base);
  color: var(--text-body);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border-line);
  flex-wrap: wrap;
  flex-shrink: 0;
}

header h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--accent-alert);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.header-icon {
  height: 1.4rem;
  width: auto;
}

nav { display: flex; gap: 0.25rem; }

.nav-toggle { display: none; }
.nav-overlay { display: none; }

.tab {
  padding: 0.5rem 1.2rem;
  background: transparent;
  color: var(--gray-a0);
  border: 1px solid var(--border-subtle);
  border-radius: 4px 4px 0 0;
  cursor: pointer;
  font-size: 0.9rem;
}
.tab.active {
  background: var(--bg-base);
  color: var(--white);
  border-bottom-color: var(--bg-base);
}

#status {
  margin-left: auto;
  font-family: var(--font-display);
  font-size: 1.05rem;
  color: var(--accent-primary);
  white-space: nowrap;
}

/* UI-6: power-LED indicator. Uses currentColor so it automatically tracks
   the inline color app.js already sets per state (live=amber/paused=red/
   restarting=gray) without a second color mapping to keep in sync. */
#status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: middle;
  background: currentColor;
  box-shadow: 0 0 4px currentColor;
}
#status:not([data-state])::before { display: none; }
#status[data-state="live"]::before { animation: led-pulse 1.6s ease-in-out infinite; }
#status[data-state="paused"]::before,
#status[data-state="restarting"]::before { animation: none; }

@keyframes led-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 4px currentColor; }
  50% { opacity: 0.45; box-shadow: 0 0 9px currentColor; }
}

.tab-content { display: none; padding: 0.75rem; }
.tab-content.active { display: block; }

/* Live/VOD tabs: pin body to viewport, no page scrollbar.
   Scoped to layouts where .live-layout/.vod-layout render side-by-side
   (row) — matching the desktop bezel rule above (>=1181px, or 769-1180px
   landscape) vs. the "Tablet portrait layout" and "Mobile layout" blocks
   further down, which stack .live-layout/.vod-layout into a column. On
   stacked/touch viewports this lock is NOT applied: body flows and
   scrolls normally, which is what keeps <header> (body's first flex
   child) from being squashed by iOS Safari's dvh/overflow:hidden
   compositor interaction (root-caused via iPad Safari report — see
   docs/phases/phase-UI.md UI-10). This media condition must stay the
   exact complement of the tablet-portrait/mobile queries below. */
@media (min-width: 1181px), (min-width: 769px) and (orientation: landscape) {
  body:has(#tab-live.tab-content.active),
  body:has(#tab-vod.tab-content.active) {
    height: 100vh;
    height: 100dvh; /* iOS Safari: excludes URL bar + toolbar */
    overflow: hidden;
  }

  /* Live/VOD tab-content fills remaining body height */
  #tab-live.tab-content.active,
  #tab-vod.tab-content.active {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
}

/* ── Description text ── */
.desc {
  font-weight: normal;
  font-size: 0.75rem;
  color: var(--text-faint);
}
.viewer-count {
  font-weight: normal;
  font-size: 0.75rem;
  color: var(--accent-primary);
  margin-left: 0.75rem;
}

/* ── Hall of Fame ── */
.hof-list {
  padding: 0.25rem 0.5rem;
  overflow-x: auto;
}
.hof-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}
.hof-table thead th {
  text-align: left;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border-line);
  color: var(--text-muted);
  font-weight: normal;
  white-space: nowrap;
}
.hof-table tbody tr:nth-child(even) {
  background: var(--bg-panel);
}
.hof-table tbody td {
  padding: 0.3rem 0.5rem;
  vertical-align: middle;
  white-space: nowrap;
}
.hof-rank { color: var(--text-muted); text-align: right; }
.hof-table tbody tr:nth-child(1) .hof-rank { color: var(--medal-gold); font-weight: bold; }
.hof-table tbody tr:nth-child(2) .hof-rank { color: var(--medal-silver); font-weight: bold; }
.hof-table tbody tr:nth-child(3) .hof-rank { color: var(--medal-bronze); font-weight: bold; }
.hof-name { color: var(--text-body); font-weight: bold; }
.hof-score { color: var(--accent-primary); text-align: right; }
.hof-level, .hof-depth { color: var(--text-muted); text-align: right; }
.hof-death { color: var(--accent-alert); max-width: 12rem; overflow: hidden; text-overflow: ellipsis; }
.hof-date { color: var(--gray-555); }
.panel-desc {
  font-size: 0.75rem;
  color: var(--text-faint);
  padding: 0.25rem 0.5rem 0.5rem;
  line-height: 1.4;
}

/* ── Layout: Desktop (side-by-side) ── */
.live-layout, .vod-layout {
  display: flex;
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
  height: auto;
}

.panel {
  background: var(--bg-panel);
  border-radius: var(--radius-card);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
}

.panel h2 {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 0.5rem;
}

.terminal-panel {
  flex: 0 0 auto;
  min-width: 0;
  overflow: hidden;
}

.side-panel {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

#terminal, #vod-terminal {
  background: transparent;
  border-radius: var(--radius-crt);
  padding: 4px;
  overflow: visible;
  width: fit-content;
  /* UI-6: signature glow. box-shadow doesn't affect the layout box, so
     scaleTerminalToFit()'s offsetWidth/getBoundingClientRect() measurements
     (app.js) stay unaffected. Kept small enough to sit inside the
     .terminal-panel padding (0.5rem) without being clipped by its
     overflow:hidden. */
  box-shadow: 0 0 8px 0 var(--accent-primary-glow);
}

/* ── Ko-fi tip button ── */
.kofi-tip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.kofi-button {
  padding: 0.4rem 1rem;
  background: var(--kofi);
  color: var(--white);
  border: none;
  border-radius: var(--radius-ctl);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: bold;
  white-space: nowrap;
}
.kofi-button:hover {
  background: var(--kofi-hover);
}
.kofi-desc {
  font-size: 0.75rem;
  color: var(--text-faint);
}
.kofi-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.kofi-modal-content {
  position: relative;
  width: 380px;
  height: 680px;
  max-width: 95vw;
  max-height: 90vh;
  background: var(--white);
  border-radius: 8px;
  overflow: hidden;
}
.kofi-modal-close {
  position: absolute;
  top: 4px;
  right: 8px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-faint);
  cursor: pointer;
  z-index: 1;
  line-height: 1;
}
.kofi-modal-close:hover {
  color: var(--black);
}

/* ── Game intro (collapsible) ── */
.game-intro {
  margin-top: 0.5rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-ctl);
  font-size: 0.8rem;
  color: var(--gray-999);
  line-height: 1.6;
  width: 0;
  min-width: 100%;
}
.game-intro summary {
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.8rem;
  user-select: none;
}
.game-intro summary:hover {
  color: var(--gray-ccc);
}
.game-intro[open] summary {
  border-bottom: 1px solid var(--border-subtle);
  color: var(--gray-ccc);
}
.game-intro p {
  padding: 0.4rem 0.6rem 0;
}
.game-intro p:last-of-type {
  padding-bottom: 0.5rem;
}
.game-intro code {
  background: var(--bg-sunken);
  padding: 0.1em 0.3em;
  border-radius: 3px;
  color: var(--accent-primary);
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.game-intro a {
  color: var(--accent-primary);
  text-decoration: none;
}
.game-intro a:hover {
  text-decoration: underline;
}
/* ── Recordings userbar ── */
#recordings-userbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-userbar);
  font-size: 0.85rem;
  color: var(--gray-aaa);
}
#recordings-username { flex: 1; }
.text-btn {
  background: transparent;
  border: 1px solid var(--gray-444);
  color: var(--gray-bbb);
  border-radius: var(--radius-ctl);
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.text-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }

/* ── Password change modal ── */
.pw-modal-content {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border-line);
  border-radius: 8px;
  padding: 1.5rem;
  width: 360px;
  max-width: calc(100vw - 2rem);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.pw-modal-content h2 { font-size: 1rem; margin-bottom: 0.2rem; }
.pw-modal-content label { font-size: 0.8rem; color: var(--gray-aaa); margin-bottom: 0.1rem; }
.pw-modal-content input[type="password"] {
  width: 100%;
  background: var(--border-line);
  border: 1px solid var(--border-subtle);
  color: var(--text-body);
  border-radius: var(--radius-ctl);
  padding: 0.4rem 0.6rem;
  font-size: 0.9rem;
}
.pw-modal-content input[type="password"]:focus { border-color: var(--accent-primary); outline: none; }
#pw-current-row { display: flex; flex-direction: column; gap: 0.1rem; }
.pw-hint { font-size: 0.75rem; color: var(--text-faint); }
.pw-modal-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.4rem;
  flex-wrap: wrap;
}
.pw-error { color: var(--accent-alert); font-size: 0.8rem; flex: 1; }
.btn-changepw {
  background: transparent;
  border: 1px solid var(--gray-555);
  color: var(--gray-bbb);
  border-radius: var(--radius-ctl);
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-changepw:hover { border-color: var(--accent-primary); color: var(--accent-primary); }

.disclaimer {
  color: var(--gray-777);
  font-size: 0.7rem;
  font-style: italic;
  margin-top: 0.4rem;
}

/* ── Sub-tabs ── */
.subtabs-toggle { display: none; }

.sub-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.sub-tab {
  padding: 0.35rem 0.9rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.85rem;
}
.sub-tab.active { background: var(--bg-base); color: var(--white); }

.sub-content { display: none; flex: 1; overflow: hidden; }
.sub-content.active { display: flex; flex-direction: column; flex: 1; }

.scrollable {
  overflow-y: auto;
  flex: 1;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  line-height: 1.5;
  padding: 0.5rem;
  background: var(--bg-sunken);
  border-radius: var(--radius-ctl);
  -webkit-overflow-scrolling: touch;
}

/* === iOS custom scrollbar indicator (injected by JS on touch devices) === */
.scrollable-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.scrollable-wrap > .scrollable {
  flex: 1;
  min-height: 0;
}
.ios-scrollbar {
  position: absolute;
  right: 2px;
  top: 4px;
  bottom: 4px;
  width: 4px;
  border-radius: 2px;
  pointer-events: none;
  display: none;
}
.ios-scrollbar-thumb {
  position: absolute;
  left: 0;
  right: 0;
  min-height: 24px;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 2px;
}

#log-output div, #vod-log-output div {
  padding: 1px 0;
  border-bottom: 1px solid var(--bg-base);
}

#lessons-live-list li, #vod-lessons-list li {
  padding: 0.25rem 0;
  list-style: disc inside;
  color: var(--accent-primary);
}
#lessons-live-list li.new {
  animation: highlight 2s ease-out;
}
@keyframes highlight {
  /* rgb(255, 180, 84) mirrors --accent-primary (#ffb454) -- rgba() can't
     reference a CSS custom property's channels directly, so keep this in
     sync by hand if --accent-primary ever changes again. */
  from { background: rgba(255, 180, 84, 0.3); }
  to { background: transparent; }
}

/* ── Auth form ── */
#auth-form {
  max-width: 340px;
  margin: 2rem auto;
  text-align: center;
}
#auth-form h2 { color: var(--accent-alert); margin-bottom: 0.5rem; }
#login-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
#login-form input {
  padding: 0.6rem;
  background: var(--bg-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-ctl);
  color: var(--text-body);
  font-size: 1rem;
}
#login-form button {
  padding: 0.6rem;
  background: var(--accent-alert);
  color: var(--white);
  border: none;
  border-radius: var(--radius-ctl);
  cursor: pointer;
  font-size: 1rem;
}
#login-error { color: var(--accent-alert); font-size: 0.8rem; }

/* ── Recordings filter ── */
#recordings-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.75rem 0 0.25rem;
}
#recordings-filter select {
  background: var(--bg-panel);
  color: var(--text-body);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-ctl);
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  cursor: pointer;
}
#recordings-filter select:disabled { opacity: 0.4; cursor: default; }
#recordings-filter select:not(:disabled):hover { border-color: var(--accent-primary); }
#filter-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 0.25rem;
}

/* ── Recordings list ── */
#recordings-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 700px;
  margin-top: 0.5rem;
}

.rec-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-panel);
  border-radius: var(--radius-card);
  cursor: pointer;
  border: 1px solid var(--border-subtle);
}
.rec-card:hover { border-color: var(--accent-primary); }
.rec-card .play-btn {
  font-size: 1.5rem;
  color: var(--accent-primary);
}
.rec-card .rec-info { flex: 1; }
.rec-card .rec-id { font-weight: bold; }
.rec-card .rec-meta { font-size: 0.8rem; color: var(--text-muted); }
.rec-delete-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius-ctl);
  line-height: 1;
  flex-shrink: 0;
}
.rec-delete-btn:hover { color: var(--accent-alert); background: rgba(233,69,96,0.1); }

#vod-back {
  background: transparent;
  color: var(--accent-primary);
  border: 1px solid var(--accent-primary);
  padding: 0.4rem 1rem;
  border-radius: var(--radius-ctl);
  cursor: pointer;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

/* asciinema player overrides */
#vod-terminal .ap-wrapper {
  border-radius: var(--radius-ctl);
}

/* ── VOD sync styles ── */
.vod-log-line {
  transition: opacity 0.15s, background 0.15s;
}
.vod-hidden {
  display: none !important;
}
.vod-current {
  /* rgb(255, 180, 84) mirrors --accent-primary (#ffb454), see the
     `highlight` keyframe comment above for why this can't reference the
     custom property directly. */
  background: rgba(255, 180, 84, 0.15);
  border-left: 3px solid var(--accent-primary) !important;
  padding-left: 0.4rem !important;
}
.vod-log-line.lesson-line {
  color: var(--accent-primary);
}
.vod-lesson-item {
  transition: opacity 0.2s;
}
.vod-lesson-item.vod-hidden {
  display: none !important;
}

/* ── Pause overlay ── */
#pause-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  border-radius: var(--radius-card);
}
#tab-live { position: relative; }
.pause-message {
  font-size: 2rem;
  color: var(--accent-alert);
  text-align: center;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  #status[data-state="live"]::before { animation: none; }
  .pause-message { animation: none; }
  #death-flash.active { animation: none; opacity: 0; }
  #death-modal.active { animation: none; }
  #terminal.death-glow-flash, #vod-terminal.death-glow-flash { animation: none; }
}

/* ── Death beat (Phase UI-9b): fixed overlay, shown on /ws/death receipt.
   Independent of #tab-live/#pause-overlay (position: fixed, not scoped
   to the live panel) so it reads regardless of which tab is active. ── */
#death-flash {
  position: fixed;
  inset: 0;
  background: var(--accent-alert);
  opacity: 0;
  pointer-events: none;
  z-index: 2000;
}
#death-flash.active {
  animation: death-flash 0.6s ease-out;
}
@keyframes death-flash {
  0% { opacity: 0.85; }
  100% { opacity: 0; }
}

#death-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1999;
}
#death-modal.active {
  display: flex;
  animation: death-modal-fade 0.4s ease-in;
}
@keyframes death-modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.death-tombstone {
  font-family: var(--font-display);
  color: var(--accent-primary);
  text-align: center;
  border: 2px solid var(--accent-alert);
  border-radius: var(--radius-crt);
  background: var(--bg-sunken);
  padding: 2rem 3rem;
  box-shadow: 0 0 30px var(--accent-alert-glow);
  max-width: 90vw;
}
.death-tombstone h2 {
  font-size: 3rem;
  color: var(--accent-alert);
  margin-bottom: 1rem;
  letter-spacing: 0.15em;
}
.death-tombstone p {
  font-size: 1.4rem;
  margin: 0.3rem 0;
  color: var(--text-body);
  font-family: var(--font-ui);
}
.death-dismiss {
  margin-top: 1.5rem;
}

/* Terminal glow briefly shifts amber -> red -> amber. filter/drop-shadow
   is used instead of box-shadow so this doesn't have to fight the
   desktop-bezel box-shadow layering (base rule + min-width:769px
   override, see #terminal/#vod-terminal above) — filter stacks as an
   independent compositing pass. */
@keyframes death-terminal-pulse {
  0%, 100% { filter: none; }
  40% { filter: drop-shadow(0 0 16px var(--accent-alert)); }
}
#terminal.death-glow-flash,
#vod-terminal.death-glow-flash {
  animation: death-terminal-pulse 1.5s ease-out;
}

/* ── Admin panel ── */
.admin-login {
  max-width: 340px;
  margin: 2rem auto;
  text-align: center;
}
.admin-login h2 { color: var(--accent-alert); margin-bottom: 0.5rem; }
#admin-login-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
#admin-login-form input {
  padding: 0.6rem;
  background: var(--bg-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-ctl);
  color: var(--text-body);
  font-size: 1rem;
}
#admin-login-form button {
  padding: 0.6rem;
  background: var(--accent-alert);
  color: var(--white);
  border: none;
  border-radius: var(--radius-ctl);
  cursor: pointer;
  font-size: 1rem;
}
#admin-login-error { color: var(--accent-alert); font-size: 0.8rem; }

.admin-section {
  background: var(--bg-panel);
  border-radius: var(--radius-card);
  padding: 1rem;
  margin-bottom: 1rem;
  max-width: 700px;
}
.admin-section h2 {
  font-size: 1rem;
  color: var(--text-body);
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.3rem;
}
.admin-section h3 {
  font-size: 0.9rem;
  color: var(--gray-aaa);
  margin: 0.75rem 0 0.4rem;
}

.admin-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.75rem 0;
  flex-wrap: wrap;
}

/* UI-8: tokenized admin inline styles (width stays inline per-element) */
.admin-input {
  padding: 4px 8px;
  background: var(--bg-base);
  color: var(--text-body);
  border: 1px solid var(--gray-444);
  border-radius: var(--radius-ctl);
}
.admin-textarea {
  width: 100%;
  font-family: monospace;
  font-size: 0.85em;
  background: var(--bg-base);
  color: var(--text-body);
  border: 1px solid var(--gray-444);
  padding: 8px;
  box-sizing: border-box;
  resize: vertical;
}
.admin-status-alert { color: var(--accent-alert); }

.btn {
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: var(--radius-ctl);
  cursor: pointer;
  font-size: 0.9rem;
  min-height: 44px;
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-warn { background: var(--accent-alert); color: var(--white); }
.btn-ok { background: var(--accent-primary); color: var(--bg-base); }

#game-state-label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.admin-slider {
  margin: 1rem 0 0.5rem;
}
.admin-slider label {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
  color: var(--gray-ccc);
}
.admin-slider input[type="range"] {
  width: 100%;
  accent-color: var(--accent-primary);
  height: 6px;
}
.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-faint);
  margin-top: 0.2rem;
}

/* Users table */
#users-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.85rem;
}
#users-table th {
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-muted);
}
#users-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--bg-base);
}
.role-admin { color: var(--accent-alert); }
.role-viewer { color: var(--accent-primary); }

.btn-delete {
  padding: 0.25rem 0.6rem;
  background: transparent;
  color: var(--accent-alert);
  border: 1px solid var(--accent-alert);
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.8rem;
}

.admin-add-user form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.4rem;
}
.admin-add-user input, .admin-add-user select {
  padding: 0.5rem;
  background: var(--bg-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-ctl);
  color: var(--text-body);
  font-size: 0.9rem;
}
.admin-add-user select {
  min-width: 100px;
}
#add-user-error { color: var(--accent-alert); font-size: 0.8rem; display: block; margin-top: 0.3rem; }

/* ════════════════════════════════════════
   Desktop CRT bezel (UI-6, >=769px only)
   - transform:scale() isn't applied here, so the .xterm-screen fills the
     #terminal content box exactly and a full frame lines up correctly.
   - On mobile the scaled screen leaves a right/bottom gap inside the
     fit-content box, so a colored bezel there would look lopsided —
     kept to the glow-only base rule instead (see #terminal, #vod-terminal
     above).
   - Only box-shadow/background/border-radius here: none of these affect
     offsetWidth/getBoundingClientRect(), so app.js's scaleTerminalToFit()
     (mobile-only anyway) stays untouched.
   ════════════════════════════════════════ */
@media (min-width: 769px) {
  #terminal, #vod-terminal {
    background: var(--bg-sunken);
    box-shadow:
      inset 0 0 40px rgba(0, 0, 0, 0.6),
      inset 0 0 0 1px var(--accent-primary-glow),
      0 0 8px 0 var(--accent-primary-glow);
  }
}

/* ════════════════════════════════════════
   Tablet portrait layout (iPad, 769px–1180px, portrait)
   - Vertical stacking (terminal + side panel below)
   - No effect on landscape tablets or desktop
   ════════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 1180px) and (orientation: portrait) {
  .live-layout, .vod-layout {
    flex-direction: column;
    height: auto;
    gap: 0.5rem;
  }

  .side-panel {
    min-height: 40vh;
  }

  /* Scrollable panels get explicit height on tablet portrait */
  .scrollable {
    max-height: 45vh;
  }
}

/* ════════════════════════════════════════
   Mobile layout (iPhone Safari, <768px)
   - Vertical stacking
   - Larger tap targets
   - Terminal fits screen width
   ════════════════════════════════════════ */
@media (max-width: 768px) {
  header {
    padding: 0.5rem 0.5rem;
    gap: 0.5rem;
    flex-wrap: nowrap;
  }
  header h1 { font-size: 1.25rem; }

  /* Hamburger button — visible on mobile only */
  .nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    font-size: 1.4rem;
    background: transparent;
    color: var(--text-body);
    border: none;
    cursor: pointer;
    flex-shrink: 0;
  }

  /* Drawer: off-screen by default, slides in from left */
  #main-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 70vw;
    max-width: 260px;
    background: var(--bg-panel);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 3.5rem 1rem 1rem;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  #main-nav.open { transform: translateX(0); }

  /* Drawer tab buttons: full-width vertical list */
  #main-nav .tab {
    width: 100%;
    text-align: left;
    border-radius: var(--radius-ctl);
    padding: 0.75rem 1rem;
    font-size: 1rem;
    min-height: 44px;
  }

  /* Semi-transparent overlay behind drawer */
  .nav-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }
  .nav-overlay[hidden] { display: none; }

  #status { font-size: 1rem; }

  .tab-content { padding: 0.5rem; }

  /* Stack vertically; inherit parent's constrained height so terminal doesn't overflow */
  .live-layout, .vod-layout {
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: auto;
    gap: 0.5rem;
    overflow: hidden;
  }

  .terminal-panel {
    flex: 0 0 auto;
    overflow: visible; /* JS sets #terminal height after scaling */
  }

  .side-panel {
    flex: 1;
    min-height: 0;
  }

  /* Sub-tabs: hidden by default, shown when .open */
  .subtabs-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    width: 100%;
    background: var(--bg-base);
    color: var(--gray-a0);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-ctl);
    cursor: pointer;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    flex-shrink: 0;
  }
  .subtabs-toggle[aria-expanded="true"] { color: var(--white); }

  #subtabs-live {
    display: none;
  }
  #subtabs-live.open {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* transform: scale() does not affect layout size, so overflow: visible prevents
     the .xterm-screen layout rect from being clipped when the container shrinks. */
  #terminal, #vod-terminal {
    overflow: visible;
    max-width: 100%;
  }

  /* JS sets transform: scale() here after measuring actual render width */
  #terminal .xterm-screen,
  #vod-terminal .xterm-screen {
    transform-origin: top left;
  }

  /* Larger sub-tab buttons for touch */
  .sub-tab {
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .sub-tabs {
    gap: 0.35rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sub-tab { flex: 0 0 auto; white-space: nowrap; }

  /* Scrollable panels get explicit height on mobile */
  .scrollable {
    max-height: 50vh;
    font-size: 0.75rem;
  }

  /* Auth form full width */
  #auth-form {
    max-width: 100%;
    padding: 0 0.5rem;
  }
  #login-form input,
  #login-form button {
    padding: 0.75rem;
    font-size: 1.1rem;
    min-height: 48px;
  }

  /* Recording cards larger tap target */
  .rec-card {
    padding: 1rem;
    min-height: 60px;
  }
  .rec-card .play-btn { font-size: 1.8rem; }
  .rec-card .rec-id { font-size: 1rem; }
  .rec-card .rec-meta { font-size: 0.85rem; }

  #vod-back {
    padding: 0.6rem 1.2rem;
    font-size: 1rem;
    min-height: 44px;
  }

  .panel-desc {
    font-size: 0.7rem;
  }
}

/* Small phones (<400px) - even more compact */
@media (max-width: 400px) {
  header h1 { font-size: 1.125rem; }
  .tab { padding: 0.5rem 0.75rem; font-size: 0.9rem; }
  .desc { display: none; }
}

/* --- X (Twitter) integration --- */

#x-post-form textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-sunken-alt);
  color: var(--gray-eee);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-ctl);
  padding: 0.5rem;
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

.x-post-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

#x-post-count {
  color: var(--text-muted);
  font-size: 0.85rem;
}

#x-post-status {
  font-size: 0.85rem;
}

.x-history {
  max-height: 300px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-ctl);
  padding: 0.5rem;
  background: var(--bg-sunken-alt);
}

.x-history-row {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--gray-222);
}

.x-history-row:last-child {
  border-bottom: none;
}

.x-history-meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.x-history-text {
  font-size: 0.9rem;
  color: var(--gray-ddd);
  white-space: pre-wrap;
  word-break: break-word;
}

.x-status-ok { color: var(--accent-primary); }
.x-status-warn { color: var(--status-warn); }
.x-status-err { color: var(--accent-alert); }

/* --- Tips tab --- */
.tips-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.95rem;
  color: var(--gray-ccc);
  flex-wrap: wrap;
}

.tips-banner-icon {
  font-size: 1.3rem;
}

.tips-kofi-btn {
  white-space: nowrap;
  margin-left: 0.5rem;
  vertical-align: middle;
  font-size: 0.85rem;
  padding: 0.25rem 0.6rem;
}

.tips-table-wrap {
  overflow-x: auto;
}

.tips-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.tips-table th,
.tips-table td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.85rem;
}

.tips-table th {
  color: var(--text-muted);
  font-weight: 500;
  background: var(--bg-sunken-alt);
}

.tips-table td:nth-child(3) {
  white-space: nowrap;
  color: var(--accent-primary);
}

.tips-table td:nth-child(4) {
  color: var(--gray-ddd);
  word-break: break-word;
}

.tips-empty {
  color: var(--text-muted);
  padding: 1rem 0;
}

/* --- Admin: viewer advice --- */
.viewer-advice-list {
  max-height: 300px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-ctl);
  padding: 0.5rem;
  background: var(--bg-sunken-alt);
}

.viewer-advice-entries {
  list-style: none;
  padding: 0;
}

.viewer-advice-entry {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--gray-222);
  font-size: 0.9rem;
  color: var(--gray-ddd);
  word-break: break-word;
}

.viewer-advice-entry:last-child {
  border-bottom: none;
}

.viewer-advice-delete {
  margin-left: auto;
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--gray-555);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0 0.2rem;
  line-height: 1;
}

.viewer-advice-delete:hover {
  color: var(--accent-alert);
}

.viewer-advice-amount {
  color: var(--accent-primary);
  font-weight: 600;
  margin-right: 0.4rem;
}
