/* Fonts are self-hosted (SIL OFL, licenses in fonts/). */
@font-face { font-family: "Space Grotesk"; font-weight: 600; font-display: swap; src: url(fonts/space-grotesk-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Space Grotesk"; font-weight: 600; font-display: swap; src: url(fonts/space-grotesk-vietnamese-600-normal.woff2) format("woff2"); unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }
@font-face { font-family: "Space Grotesk"; font-weight: 700; font-display: swap; src: url(fonts/space-grotesk-latin-700-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Space Grotesk"; font-weight: 700; font-display: swap; src: url(fonts/space-grotesk-vietnamese-700-normal.woff2) format("woff2"); unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }
@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-display: swap; src: url(fonts/ibm-plex-sans-latin-400-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-display: swap; src: url(fonts/ibm-plex-sans-vietnamese-400-normal.woff2) format("woff2"); unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }
@font-face { font-family: "IBM Plex Sans"; font-weight: 500; font-display: swap; src: url(fonts/ibm-plex-sans-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Sans"; font-weight: 500; font-display: swap; src: url(fonts/ibm-plex-sans-vietnamese-500-normal.woff2) format("woff2"); unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-display: swap; src: url(fonts/ibm-plex-sans-latin-600-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-display: swap; src: url(fonts/ibm-plex-sans-vietnamese-600-normal.woff2) format("woff2"); unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }
@font-face { font-family: "JetBrains Mono"; font-weight: 500; font-display: swap; src: url(fonts/jetbrains-mono-latin-500-normal.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "JetBrains Mono"; font-weight: 500; font-display: swap; src: url(fonts/jetbrains-mono-vietnamese-500-normal.woff2) format("woff2"); unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }

:root {
  --primary: #7C3AED;
  --primary-deep: #4C1D95;
  --magenta: #C026D3;
  --bg: #0E0918;
  --bar: #130C21;
  --surface: #181026;
  --surface-2: #221836;
  --line: #2A1F40;
  --border: #34264F;
  --text: #F1ECFA;
  --text-2: #C9BCE3;
  --muted: #A897C6;
  --link: #C4B5FD;
  --ok: #34D399;
  --ok-text: #6EE7B7;
  --ok-bg: #10261F;
  --warn: #F59E0B;
  --err: #F87171;
  --radius: 14px;
  --display: "Space Grotesk", "IBM Plex Sans", system-ui, sans-serif;
  --body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}
[data-theme="light"] {
  --bg: #F6F3FC;
  --bar: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #F1ECFB;
  --line: #E6DDF5;
  --border: #D9CCEF;
  --text: #1E1033;
  --text-2: #3D2D5C;
  --muted: #5F4E80;
  --link: #6D28D9;
  --ok: #059669;
  --ok-text: #047857;
  --ok-bg: #E7F8F1;
  --err: #DC2626;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--body); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--err); min-height: 1.2em; margin: 0; }
a { color: var(--link); }
h1, h2 { margin: 0; font-family: var(--display); }
h2 { font-size: 16px; font-weight: 600; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--bar); position: sticky; top: 0; z-index: 5; }
.brand { text-decoration: none; color: var(--text); font: 700 20px/1 var(--display); letter-spacing: .5px; }
.brand-sub { color: var(--muted); font-weight: 600; }
.topnav { display: flex; gap: 8px; align-items: center; }

main { max-width: 1440px; margin: 0 auto; padding: 20px 24px 40px; }
#view-sessions, #view-login { max-width: 1100px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.narrow { max-width: 380px; margin: 48px auto; display: grid; gap: 12px; }
label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
input, select { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font: inherit; min-width: 0; min-height: 44px; }
input:focus-visible, select:focus-visible, canvas:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: 0 14px; min-height: 44px; font: 500 15px var(--body); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--primary-deep); border-color: var(--primary-deep); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); }
.btn.dashed { background: transparent; border-style: dashed; color: var(--link); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 44px; height: 44px; flex: none; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* ---- sessions list ---- */
.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-val { font: 700 22px var(--display); }
.row-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 16px; }
.row-form .error { grid-column: 1 / -1; }
.session-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.session { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 8px; animation: fade .2s ease; }
.session-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.session-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.badge.running { color: var(--ok-text); background: var(--ok-bg); border-color: transparent; }
.badge.running::before { content: ""; width: 8px; height: 8px; border-radius: 999px; background: var(--ok); }
.badge.starting, .badge.stopping { color: var(--warn); }
.badge.backoff { color: var(--err); }
.session-meta { color: var(--muted); font-size: 13px; display: grid; gap: 2px; }
.session-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.events { max-height: 140px; overflow: auto; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 6px; }
.events .error { color: var(--err); }
.events .warn { color: var(--warn); }
.admin-games { margin-top: 20px; display: grid; gap: 10px; }
.admin-games p { margin: 0; }
.admin-games .row-form { margin-bottom: 0; align-items: center; }
.game-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.game-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; font-size: 13px; overflow-wrap: anywhere; }
.ok { color: var(--ok-text); }

/* ---- play screen ---- */
.play { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.play-tabs { flex: 1 1 220px; max-width: 260px; display: flex; flex-direction: column; gap: 10px; }
.play-main { flex: 999 1 480px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.play-side { flex: 1 1 290px; max-width: 330px; display: flex; flex-direction: column; gap: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.tab-list { display: flex; flex-direction: column; gap: 8px; }
.tab-item { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--text); }
.tab-item:hover { border-color: var(--border); }
.tab-item[aria-current="page"] { background: var(--surface-2); border-color: var(--primary); }
.tab-item .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tab-item b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-item .dot { width: 10px; height: 10px; border-radius: 999px; flex: none; background: #5B4C78; }
.tab-item .dot.on { background: var(--ok); }
.tab-item span { font-size: 13px; color: var(--muted); }

.play-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.play-head .icon-btn { display: none; }
.play-title { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; } /* actions wrap below before the name is cut */
.play-title h1 { font-size: 28px; font-weight: 700; letter-spacing: -.3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.play-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.quality { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
#textBtn[aria-pressed="true"] { background: var(--primary-deep); border-color: var(--magenta); }

.stage { padding: 20px; border-radius: 18px; background: var(--bar); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.screen-wrap { position: relative; width: 100%; height: clamp(360px, calc(100vh - 250px), 1000px); border-radius: 12px; background: #07040D; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.screen-wrap:fullscreen { height: 100%; border-radius: 0; }
#screen { display: block; touch-action: none; image-rendering: auto; border-radius: 4px; box-shadow: 0 0 0 2px var(--primary); }
#screen.pixel { image-rendering: pixelated; image-rendering: crisp-edges; }
.title-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.live-badge { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font: 600 12px var(--body); color: var(--text); letter-spacing: .5px; }
.live-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--magenta); animation: pulse 1.6s ease-in-out infinite; }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(14, 9, 24, .78); color: #fff; cursor: pointer; }
.text-bar { display: grid; gap: 6px; }
.text-bar input { width: 100%; font-size: 16px; border-color: var(--primary); background: var(--bg); } /* >=16px stops iOS zooming on focus */
.stage-note { margin: 0; }

.panel { padding: 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.panel p { margin: 0; }
.panel .text { color: var(--text); }
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mini { padding: 9px 12px; border-radius: 10px; background: var(--surface-2); display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.mini span { font-size: 12px; color: var(--muted); }
.mini b { font: 500 15px var(--mono); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.meters { display: grid; gap: 12px; }
.meters-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.meter { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.meter-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--muted); }
.meter-head b { font: 500 15px var(--mono); color: var(--text); }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--primary); transition: width .6s ease, background-color .3s; }
.bar.warn span { background: var(--warn); }
.bar.high span { background: var(--err); }
.slots { display: grid; gap: 10px; }
.slots:empty { display: none; }
.slot { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
.slot-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 13px; }
.slot-head span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.slot-head b { font: 500 15px var(--mono); white-space: nowrap; }
.slot-note { font-size: 12px; color: var(--muted); }
.slot-note.full { color: var(--err); font-weight: 600; }
.slot-note.near { color: var(--warn); }
.online-tag { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.online-tag::before { content: ""; width: 8px; height: 8px; border-radius: 999px; background: #5B4C78; }
.online-tag.on::before { background: var(--ok); }
.limit-form { display: flex; align-items: center; gap: 6px; }
.limit-form input { width: 76px; min-height: 36px; padding: 6px 8px; }
.limit-form .btn { min-height: 36px; padding: 0 10px; font-size: 13px; }
.host-card { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }

.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; user-select: none; -webkit-user-select: none; }
.keypad button { min-height: 52px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: 600 16px var(--body); display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; touch-action: none; -webkit-tap-highlight-color: transparent; transition: background .08s; }
.keypad button small { font-size: 10px; font-weight: 500; letter-spacing: 1px; color: var(--muted); }
.keypad button.soft { background: var(--bar); color: var(--link); font-size: 13px; }
.keypad button.fire { background: var(--primary); border-color: var(--primary); color: #fff; }
.keypad button.fire small { color: #E9DDFE; }
.keypad button.down, .keypad button:active { background: var(--primary-deep); border-color: var(--magenta); color: #fff; }
.keypad .digit-5 { visibility: hidden; }
.show-sm { display: none; }
.small-btn { min-height: 40px; font-size: 14px; }

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .live-dot, .session { animation: none; } }

@media (max-width: 1100px) {
  .play-tabs { display: none; }
}
@media (max-width: 760px) {
  main { padding: 8px 8px 20px; }
  .topbar { padding: 10px 12px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .row-form { grid-template-columns: 1fr; }
  .play { gap: 12px; }
  .play-side { max-width: none; flex-basis: 100%; }
  .play-head .icon-btn { display: inline-flex; }
  .play-title h1 { font-size: 20px; }
  .hide-sm { display: none !important; }
  .show-sm { display: inline-flex; }
  .stage { padding: 0; border: 0; background: transparent; gap: 8px; }
  .stage-note { display: none; }
  /* As large as the phone allows: full width, leaving room below for the
     compact keypad (~4 rows) so playing needs no scrolling. */
  .screen-wrap {
    height: clamp(300px, min(calc((100vw - 16px) * 4 / 3), calc(100vh - 350px)), 2000px);
    height: clamp(300px, min(calc((100vw - 16px) * 4 / 3), calc(100svh - 350px)), 2000px);
    border-radius: 8px;
  }
  .play-side > .keypad-panel { order: -1; }   /* keypad right under the screen */
  /* One compact row: back · name · type · reconnect · fullscreen */
  .play-head { gap: 6px; flex-wrap: nowrap; }
  .play-title { flex: 1 1 0; }
  .play-title .muted { display: none; }
  .play-title h1 { font-size: 18px; }
  .play-actions { flex-wrap: nowrap; gap: 6px; }
  .play-actions .btn { width: 44px; padding: 0; }
  #me { display: none; }
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .mini { padding: 6px 8px; align-items: center; }
  .panel { padding: 0; border: 0; background: transparent; gap: 8px; }
  .keypad { gap: 6px; }
  .keypad button { min-height: 48px; }
  .keypad .digit { display: none; }
  .keypad .digit-5 { visibility: visible; }
  .keypad.digits .digit { display: flex; }
  .keypad.digits .digit-5 { visibility: hidden; }
  .panel-head { justify-content: flex-end; }
  .host-panel .panel-head { justify-content: space-between; }
  .host-panel .meters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .meters-row { grid-template-columns: 1fr; gap: 12px; }
}
