/* LIVE CHESS — Midnight (dark) + Arctic (light) themes, mobile-first, desktop arena */
/* Arctic = original light theme. Midnight = new dark default. */
:root {
  --body-bg: linear-gradient(165deg, #2159c9, #123a9e 55%, #0a245e);
  --card: rgba(255,255,255,.96); --ink: #0a245e; --muted: #5b6b8c;
  --accent: #2f7bff; --accent-soft: #a9c8ff; --gold: #ffd23f;
  --danger: #ff5c7a; --ok: #3dffa2;
  --topbar-bg: rgba(10,36,94,.55);
  --pcard-bg: rgba(10,36,94,.4); --pcard-border: rgba(255,255,255,.12);
  --panel: rgba(10,36,94,.4);
  --clock-bg: rgba(255,255,255,.14);
  --ghost-bg: rgba(47,123,255,.14); --ghost-ink: #2f7bff; --ghost-border: #2f7bff;
  --input-bg: #fff; --input-border: #dfe7fb; --input-ink: #0a245e;
  --giftcell-bg: #f4f7ff;
  --sect-title: #123a9e;
  --sq-light: #edf2ff; --sq-dark: #5b86e0;
}
[data-theme="midnight"] {
  --body-bg: #070b16;
  --card: #0d1425; --ink: #eef2ff; --muted: #8b98b8;
  --topbar-bg: rgba(10,15,30,.85);
  --pcard-bg: #0d1425; --pcard-border: rgba(255,255,255,.08);
  --panel: rgba(255,255,255,.04);
  --clock-bg: rgba(255,255,255,.07);
  --ghost-bg: rgba(255,255,255,.06); --ghost-ink: #dfe6fa; --ghost-border: rgba(255,255,255,.16);
  --input-bg: rgba(255,255,255,.06); --input-border: rgba(255,255,255,.16); --input-ink: #eef2ff;
  --giftcell-bg: rgba(255,255,255,.05);
  --sect-title: #a9c8ff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--body-bg); background-attachment: fixed; color: #fff; min-height: 100dvh;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.hidden { display: none !important; }
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
@media (min-width: 1000px) {
  #app { max-width: 1400px; }
  #screen-menu .hero, #screen-menu .card, #screen-menu .banner { max-width: 620px; margin-left: auto; margin-right: auto; }
  #screen-watch .screen-head, #screen-watch .watch-list { max-width: 760px; margin-left: auto; margin-right: auto; }
}

/* top bar */
#topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  position: sticky; top: 0; z-index: 20;
  background: var(--topbar-bg); backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,.14);
}
.logo { font-weight: 900; letter-spacing: 1px; font-size: 18px; cursor: pointer; white-space: nowrap; }
#mainnav { display: flex; gap: 4px; }
#mainnav button {
  border: none; background: transparent; color: var(--muted); font-size: 14px; font-weight: 700;
  padding: 8px 12px; border-radius: 10px; cursor: pointer;
}
#mainnav button.active { color: #fff; background: rgba(47,123,255,.22); }
.topbar-right { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.pill {
  border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.12); color: #fff;
  border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
#theme-toggle { font-size: 15px; }

/* screens */
#main { flex: 1; padding: 14px 14px calc(20px + env(safe-area-inset-bottom)); }
.screen { display: none; }
.screen.active { display: block; animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.hero { text-align: center; padding: 18px 0 6px; }
.hero-knight { font-size: 64px; line-height: 1; filter: drop-shadow(0 4px 12px rgba(0,0,0,.4)); }
.hero h1 { margin: 8px 0 2px; font-size: 40px; letter-spacing: 3px; font-weight: 900; }
.tagline { margin: 0 0 8px; letter-spacing: 4px; font-size: 12px; color: var(--accent-soft); font-weight: 700; }

.card {
  background: var(--card); color: var(--ink); border-radius: 18px;
  padding: 16px; margin: 12px 0; box-shadow: 0 8px 24px rgba(4,18,60,.35);
}
[data-theme="midnight"] .card { border: 1px solid rgba(255,255,255,.08); }
.card-title { font-weight: 800; font-size: 16px; margin-bottom: 10px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; text-align: center; }
.hint a { color: var(--accent); font-weight: 700; }
.live-now b { color: var(--danger); }
.bullets { margin: 0 0 10px; padding-left: 4px; list-style: none; font-size: 14px; }
.bullets li { margin: 6px 0; }

.banner {
  background: rgba(255,210,63,.16); border: 1px solid rgba(255,210,63,.5);
  border-radius: 12px; padding: 10px 12px; margin: 10px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px;
}
.badge {
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 800;
  border-radius: 999px; padding: 2px 8px; vertical-align: middle;
}

/* buttons */
.btn {
  border: none; border-radius: 14px; padding: 12px 18px; font-size: 15px; font-weight: 800;
  background: var(--accent); color: #fff; cursor: pointer; letter-spacing: .5px;
  box-shadow: 0 4px 14px rgba(47,123,255,.45); transition: transform .06s ease;
}
.btn:active { transform: scale(.97); }
.btn-big { width: 100%; font-size: 18px; padding: 16px; margin-top: 12px; letter-spacing: 2px; }
.btn-small { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn-ghost { background: var(--ghost-bg); color: var(--ghost-ink); box-shadow: none; border: 1.5px solid var(--ghost-border); }
.btn-danger { background: rgba(255,92,122,.16); color: #ffb3c2; box-shadow: none; border: 1.5px solid rgba(255,92,122,.6); }
.btn-gold { background: linear-gradient(180deg, #ffd23f, #f5a623); color: #4a2f00; box-shadow: 0 4px 14px rgba(245,166,35,.5); }

.tc-row { display: flex; gap: 8px; }
.tc-btn {
  flex: 1; border: 2px solid rgba(47,123,255,.25); background: var(--card); border-radius: 12px;
  padding: 10px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; color: var(--ink);
}
.tc-btn b { font-size: 17px; } .tc-btn span { font-size: 11px; color: var(--muted); }
.tc-btn.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47,123,255,.25); }

/* watch list */
.screen-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.screen-head h2 { margin: 0; font-size: 20px; }
.watch-list { display: flex; flex-direction: column; gap: 10px; }
.watch-card {
  background: var(--card); color: var(--ink); border-radius: 14px; padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center; cursor: pointer;
}
[data-theme="midnight"] .watch-card { border: 1px solid rgba(255,255,255,.08); }
.watch-card .names { font-weight: 800; font-size: 15px; }
.watch-card .meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.live-dot { color: var(--danger); font-weight: 800; font-size: 12px; }

/* ============ game screen: subbar + arena ============ */
#subbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 4px;
  font-size: 13px; color: var(--muted); flex-wrap: wrap;
}
#subbar .tc { font-weight: 800; color: #fff; font-size: 14px; }
#subbar .watching b { color: #fff; }
#subbar .game-id { margin-left: auto; font-size: 12px; opacity: .8; }

#arena { display: block; }
@media (min-width: 1000px) {
  #arena { display: grid; grid-template-columns: 250px minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
  #arena-center { width: 100%; max-width: 780px; margin: 0 auto; }
  .prow { flex-wrap: wrap; }
  .pname { max-width: 128px; }
}

/* video-forward player cards */
#arena-left { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
@media (min-width: 1000px) {
  #arena-left { display: flex; flex-direction: column; gap: 16px; margin-bottom: 0; }
}
.pcard {
  background: var(--pcard-bg); border: 1px solid var(--pcard-border);
  border-radius: 16px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.35);
  transition: box-shadow .3s ease;
}
.pcard.mylow { box-shadow: 0 0 0 2px rgba(255,92,122,.7), 0 10px 30px rgba(0,0,0,.35); }
.pvideo {
  position: relative; aspect-ratio: 16/10; max-height: 120px; width: 100%;
  background: linear-gradient(135deg, #1b2a55 0%, #0e1a3d 55%, #251a4d 100%);
  overflow: hidden;
}
@media (min-width: 1000px) { .pvideo { aspect-ratio: 16/9; max-height: none; } }
.pvideo video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pvideo:not(.has-video) video { display: none; }
.pvideo-ph { position: absolute; inset: 0; display: grid; place-items: center; }
.pvideo-ph span { font-size: 30px; font-weight: 800; letter-spacing: 2px; color: rgba(255,255,255,.8); }
.pvideo.has-video .pvideo-ph { display: none; }
.live-badge {
  position: absolute; top: 8px; left: 8px; font-size: 10px; font-weight: 800; letter-spacing: .8px;
  background: var(--danger); color: #fff; padding: 3px 8px; border-radius: 7px;
  display: flex; align-items: center; gap: 5px;
}
.live-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #fff; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .35; } }
.vid-label {
  position: absolute; left: 8px; bottom: 6px; right: 40px;
  font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 4px rgba(0,0,0,.85);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mic-state {
  position: absolute; bottom: 6px; right: 8px; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(0,0,0,.55); display: grid; place-items: center; font-size: 13px;
}
.pmeta { padding: 8px 10px 10px; }
.prow { display: flex; align-items: center; gap: 8px; }
.pwho { min-width: 0; flex: 1; }
.pname { font-weight: 800; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prating { font-size: 11px; color: var(--accent-soft); }
.clock {
  font-variant-numeric: tabular-nums; font-weight: 900; font-size: 19px;
  background: var(--clock-bg); border-radius: 10px; padding: 5px 10px; min-width: 74px; text-align: center;
}
.clock.low { background: rgba(255,92,122,.35); color: #ffdfe6; animation: pulse 1s infinite; }
.clock.active-turn { outline: 2px solid var(--gold); }
@keyframes pulse { 50% { opacity: .75; } }
.captured { min-height: 20px; margin-top: 6px; font-size: 12px; color: var(--ok); font-weight: 800; }
.cap { width: 18px; height: 18px; margin-right: -6px; vertical-align: -4px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.5)); }
.cam-controls { display: flex; gap: 6px; margin-top: 8px; }
.cam-controls button {
  flex: 1; border: 1px solid var(--pcard-border); background: rgba(255,255,255,.06);
  color: #fff; border-radius: 9px; padding: 7px 4px; font-size: 12px; font-weight: 700; cursor: pointer;
}

/* board */
#board-wrap { position: relative; width: 100%; aspect-ratio: 1; margin: 4px 0 8px; }
#board { width: 100%; height: 100%; border-radius: 12px; display: block; touch-action: none; box-shadow: 0 10px 30px rgba(4,18,60,.5); }
#spectate-tag {
  position: absolute; top: 8px; left: 8px; background: rgba(255,92,122,.9); color: #fff;
  font-size: 11px; font-weight: 800; padding: 4px 10px; border-radius: 999px; letter-spacing: 1px;
}
#evalbar { display: flex; align-items: center; gap: 10px; margin: 2px 0 8px; font-size: 12.5px; color: var(--muted); }
.eval-cap { font-weight: 700; white-space: nowrap; }
.eval-track { flex: 1; height: 8px; border-radius: 99px; background: rgba(255,255,255,.12); overflow: hidden; }
.eval-fill { height: 100%; width: 50%; border-radius: 99px; background: linear-gradient(90deg, #eef2ff, #a9c8ff); transition: width .4s ease; }
#eval-label { font-weight: 800; color: #fff; min-width: 44px; text-align: right; }
.board-swatches { display: flex; gap: 6px; margin-left: 4px; }
.board-swatches button {
  width: 30px; height: 20px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; padding: 0;
}
.board-swatches button[data-bt="arctic"] { background: linear-gradient(90deg, #edf2ff 50%, #5b86e0 50%); }
.board-swatches button[data-bt="classic"] { background: linear-gradient(90deg, #f0d9b5 50%, #b58863 50%); }
.board-swatches button.selected { border-color: var(--gold); }

/* right panel */
.rpanel {
  background: var(--pcard-bg); border: 1px solid var(--pcard-border);
  border-radius: 16px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
.tabs { display: flex; border-bottom: 1px solid var(--pcard-border); }
.tab {
  flex: 1; padding: 12px; border: none; border-bottom: 2.5px solid transparent; cursor: pointer;
  background: transparent; color: var(--muted); font-weight: 800; font-size: 14px;
}
.tab.active { color: #fff; border-bottom-color: var(--accent); background: rgba(47,123,255,.08); }
.tabpane { display: none; padding: 10px 12px; min-height: 120px; max-height: 240px; overflow-y: auto; }
.tabpane.active { display: block; }
.movelist { font-size: 14px; line-height: 1.9; color: #dbe6ff; }
.movelist .mvnum { color: var(--accent-soft); margin-right: 4px; font-size: 12px; }
.chatlist { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.chat-msg b { color: var(--accent-soft); }
.chat-msg.sys { color: var(--gold); font-style: italic; }
.chat-input-row { display: flex; gap: 8px; margin-top: 8px; }
#chat-input {
  flex: 1; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1);
  border-radius: 10px; padding: 10px; color: #fff; font-size: 16px; user-select: text; -webkit-user-select: text;
}
#chat-input::placeholder { color: rgba(255,255,255,.45); }
.controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 12px 14px 0; }
.gift-cta { width: calc(100% - 28px); margin: 10px 14px 0; padding: 13px; font-size: 15px; }
.spec-strip { padding: 10px 14px 14px; font-size: 12.5px; color: var(--muted); }
.spec-strip b { color: #fff; }
.spec-strip b.gold { color: var(--gold); }

#claim-flag-wrap, #draw-offer-wrap { margin: 8px 0; }

/* modals */
.modal {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(4,18,60,.7); backdrop-filter: blur(4px); padding: 20px;
}
.modal-box {
  background: var(--card); color: var(--ink); border-radius: 20px; padding: 22px; width: 100%; max-width: 380px;
  text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.5); max-height: 86dvh; overflow-y: auto;
}
[data-theme="midnight"] .modal-box { border: 1px solid rgba(255,255,255,.1); }
.modal-box h3 { margin: 0 0 8px; }
.modal-small { max-width: 280px; }
.spinner {
  width: 44px; height: 44px; margin: 6px auto 12px; border-radius: 50%;
  border: 4px solid rgba(47,123,255,.2); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.gift-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.gift-btn {
  border: 2px solid rgba(47,123,255,.2); background: var(--giftcell-bg); border-radius: 12px; padding: 10px 4px;
  cursor: pointer; font-size: 26px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--ink);
}
.gift-btn small { font-size: 11px; font-weight: 700; }
.gift-btn .price { font-size: 11px; color: #b8860b; font-weight: 800; }
.gift-target-row { display: flex; gap: 8px; justify-content: center; margin: 8px 0; }
.gift-target-row .btn.selected { outline: 3px solid var(--gold); }
.promote-row { display: flex; gap: 10px; justify-content: center; }
.promote-row button { font-size: 44px; background: var(--giftcell-bg); border: 2px solid var(--accent); border-radius: 12px; padding: 6px 12px; cursor: pointer; color: var(--ink); }
.go-emoji { font-size: 56px; }
.go-rating { font-size: 15px; font-weight: 700; }
.go-buttons { display: flex; gap: 8px; margin-top: 12px; }
.go-buttons .btn { flex: 1; }
.prof-row { display: flex; justify-content: space-between; padding: 8px 2px; border-bottom: 1px solid rgba(127,140,170,.25); font-size: 14px; }

/* gift overlay + toast */
#gift-overlay {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none;
}
#gift-emoji { font-size: 110px; animation: giftpop 2.2s ease forwards; filter: drop-shadow(0 8px 24px rgba(0,0,0,.5)); }
#gift-text { font-size: 18px; font-weight: 900; color: #fff; text-shadow: 0 2px 12px rgba(0,0,0,.7); margin-top: 8px; animation: giftpop 2.2s ease forwards; }
@keyframes giftpop {
  0% { transform: scale(.2); opacity: 0; } 15% { transform: scale(1.25); opacity: 1; }
  30% { transform: scale(1); } 80% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.1) translateY(-30px); }
}
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(10,36,94,.95); color: #fff; border: 1px solid rgba(255,255,255,.25);
  padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 700; z-index: 70;
  max-width: 90vw; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: fadein .2s ease;
}

/* auth + streaming */
.prof-section-title { font-weight: 900; font-size: 14px; margin: 16px 0 4px; color: var(--sect-title); }
.auth-btn-row { display: flex; gap: 8px; margin: 8px 0; }
.auth-email-row { display: flex; gap: 8px; margin: 12px 0; }
.auth-email-row input, .stream-row input {
  background: var(--input-bg); border: 2px solid var(--input-border); color: var(--input-ink);
  padding: 10px 12px; border-radius: 10px; font-size: 16px;
}
.auth-email-row input { flex: 1; }
.auth-div { text-align: center; color: #8aa; font-size: 13px; margin: 4px 0 10px; }
.btn-oauth { width: 100%; margin-bottom: 8px; }
.stream-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.stream-row span { width: 64px; font-size: 13px; font-weight: 700; color: var(--muted); }
.stream-row input { flex: 1; padding: 9px 10px; font-size: 14px; }
.modal-box a { color: #2f7bff; }
#stream-wrap { margin: 10px 0; }
.stream-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.stream-player { position: relative; width: 100%; aspect-ratio: 16/9; border-radius: 12px; overflow: hidden; background: #000; border: 2px solid rgba(255,255,255,.14); }
.stream-player iframe { position: absolute; inset: 0; width: 100%; height: 100%; }

/* captured material piece images */
.cap { width: 20px; height: 20px; margin-right: -7px; vertical-align: -5px; }

/* ---------- responsive ---------- */
#mainnav { display: none; }
@media (min-width: 1000px) { #mainnav { display: flex; } }

@media (max-width: 480px) {
  #main { padding: 10px 10px calc(16px + env(safe-area-inset-bottom)); }
  .hero h1 { font-size: 32px; }
  .pvideo { max-height: 96px; }
  .pvideo-ph span { font-size: 22px; }
  .pname { font-size: 12px; }
  .clock { font-size: 16px; min-width: 64px; padding: 4px 8px; }
  .pmeta { padding: 6px 8px 8px; }
  .cap { width: 15px; height: 15px; }
  .cam-controls button { font-size: 11px; padding: 6px 2px; }
  .tabpane { max-height: 170px; min-height: 100px; }
  .logo { font-size: 15px; }
  #topbar { gap: 8px; }
  .topbar-right { gap: 6px; }
  .pill { padding: 6px 8px; font-size: 12.5px; }
  #btn-auth .pill-txt { display: none; }
  #profile-pill { max-width: 104px; overflow: hidden; text-overflow: ellipsis; }
  #subbar { font-size: 12px; gap: 10px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .pvideo { max-height: 72px; }
  #board-wrap { width: min(100%, 58dvh); margin-left: auto; margin-right: auto; }
  .tabpane { max-height: 140px; min-height: 90px; }
  .hero-knight { font-size: 40px; }
  .hero h1 { font-size: 26px; }
}
