/* CHINGKAO — Black & Gold theme (อิงโทนจากโลโก้) */
:root {
  --bg: #0a0907;
  --panel: #14120e;
  --panel-2: #1b1813;
  --line: rgba(232, 176, 74, 0.16);
  --line-strong: rgba(232, 176, 74, 0.42);
  --text: #efe8da;
  --muted: #9b927f;
  --gold: #e8b04a;
  --gold-hi: #f6d68c;
  --x: #f0b54d;
  --x-soft: rgba(240, 181, 77, 0.16);
  --o: #8cc0ea;
  --o-soft: rgba(140, 192, 234, 0.15);
  --danger: #e66a5c;
  --ok: #6fbf86;
  --radius: 12px;
  --font: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  --display: 'Cinzel', 'Times New Roman', serif;
  --mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  overflow-x: hidden;
}
.bg-glow {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 60% 45% at 50% 0%, rgba(232, 176, 74, 0.10), transparent 70%),
    radial-gradient(ellipse 40% 30% at 50% 100%, rgba(232, 176, 74, 0.06), transparent 70%);
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.4; }
h2, h3 { margin: 0; }

/* ---------- Screens ---------- */
.screen { display: none; position: relative; z-index: 1; padding: 20px 16px 48px; max-width: 1240px; margin: 0 auto; }
.screen.active { display: block; animation: fade 0.25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.brand-mini { font-family: var(--display); letter-spacing: 0.2em; font-size: 13px; color: var(--muted); }
.proto-tag { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--gold); border: 1px solid var(--line-strong); border-radius: 4px; padding: 1px 6px; margin-left: 8px; }
.player-chip {
  display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 14px 6px 8px;
}
.player-chip .rp { font-family: var(--mono); color: var(--muted); font-size: 13px; }

/* ---------- Hero ---------- */
.hero { text-align: center; margin: 4px auto 18px; }
.hero-logo {
  width: min(460px, 100%); aspect-ratio: 3 / 2; object-fit: contain; display: block; margin: -10px auto -34px;
  filter: drop-shadow(0 0 30px rgba(232, 176, 74, 0.25));
  animation: float 6s ease-in-out infinite;
}
@keyframes float { 50% { transform: translateY(-6px); } }
.wordmark {
  font-family: var(--display); font-weight: 900; font-size: clamp(38px, 8vw, 68px); letter-spacing: 0.18em;
  margin: 0; padding-left: 0.18em;
  background: linear-gradient(180deg, #fff3cf 0%, var(--gold) 55%, #9a6a1e 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.tagline { color: var(--muted); margin: 4px 0 0; letter-spacing: 0.04em; }

.menu-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; max-width: 1100px; margin: 26px auto 0; align-items: start; }
.menu-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }

/* King board on home */
.king-board { padding: 18px; display: flex; flex-direction: column; gap: 12px; background: linear-gradient(170deg, rgba(232, 176, 74, 0.10), var(--panel) 45%); border-color: var(--line-strong); }
.kb-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.kb-title { font-family: var(--display); font-weight: 700; letter-spacing: 0.1em; color: var(--gold-hi); font-size: 18px; display: flex; align-items: center; gap: 8px; }
.kb-title svg { width: 22px; height: 22px; }
.kb-live { font-family: var(--mono); font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kb-live i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); animation: pulse 1.6s infinite; }
.kb-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kb-stats div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.kb-stats b { display: block; font-family: var(--mono); font-size: 15px; color: var(--text); }
.kb-stats small { color: var(--muted); font-size: 11px; }
.kb-podium { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; align-items: end; }
.kb-pod { text-align: center; border-radius: 10px; padding: 10px 6px 8px; background: var(--panel-2); border: 1px solid var(--line); min-width: 0; }
.kb-pod .pn { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-pod .pr { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.kb-pod .medal { font-family: var(--display); font-weight: 900; font-size: 22px; line-height: 1.1; }
.kb-pod.p1 { padding-top: 18px; border-color: rgba(246, 214, 140, 0.6); background: linear-gradient(180deg, rgba(246, 214, 140, 0.16), var(--panel-2)); }
.kb-pod.p1 .medal { color: #f6d68c; }
.kb-pod.p2 .medal { color: #d5dbe3; }
.kb-pod.p3 .medal { color: #d79b6a; }
.kb-pod.p1 { order: 2; } .kb-pod.p2 { order: 1; } .kb-pod.p3 { order: 3; }
.kb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.kb-list li { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 10px; align-items: center; padding: 6px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.04); font-size: 13.5px; }
.kb-list .kp { font-family: var(--mono); color: var(--gold-hi); font-size: 12px; }
.kb-list .kn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-list .kr { font-family: var(--mono); }
.kb-list .kw { font-family: var(--mono); color: var(--muted); font-size: 12px; min-width: 46px; text-align: right; }
.kb-me { background: var(--panel-2); border: 1px dashed var(--line-strong); border-radius: 8px; padding: 8px 10px; font-size: 13px; color: var(--muted); }
.kb-me b { color: var(--text); }
.kb-me.is-king { border-style: solid; color: var(--gold-hi); }
.kb-foot { display: flex; justify-content: flex-end; }
.menu-btn {
  text-align: left; background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 16px 14px; display: flex; flex-direction: column; gap: 2px;
  transition: border-color 0.15s, transform 0.15s;
}
.menu-btn:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.menu-btn.primary { border-color: var(--line-strong); background: linear-gradient(160deg, rgba(232, 176, 74, 0.18), var(--panel) 70%); }
.mb-title { font-weight: 700; font-size: 16px; }
.menu-btn.primary .mb-title { color: var(--gold-hi); }
.mb-sub { color: var(--muted); font-size: 13px; }
.footnote { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 28px; }

/* ---------- Pages ---------- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.page-head h2 { font-family: var(--display); letter-spacing: 0.08em; font-size: 24px; color: var(--gold-hi); }
.back { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; color: var(--muted); }
.back:hover { color: var(--text); border-color: var(--line-strong); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.panel h3 { font-size: 16px; color: var(--gold-hi); margin-bottom: 10px; }
.note { color: var(--muted); font-size: 12.5px; margin: 12px 0 0; }
.setup { max-width: 560px; display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { color: var(--muted); font-size: 13px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px;
}
.seg button.on { border-color: var(--gold); color: var(--gold-hi); background: rgba(232, 176, 74, 0.12); }

.cta {
  background: linear-gradient(180deg, #f3c768, #c98d2b); color: #1a1205; border: 0; border-radius: 10px;
  padding: 12px 20px; font-weight: 700; font-size: 16px; letter-spacing: 0.02em;
}
.cta:hover { filter: brightness(1.08); }
.cta.secondary { background: var(--panel-2); color: var(--gold-hi); border: 1px solid var(--line-strong); }
.ghost { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; }
.ghost:hover { border-color: var(--line-strong); }
.ghost.danger { color: var(--danger); border-color: rgba(230, 106, 92, 0.35); }
.text-in {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; color: var(--text);
  font: inherit; font-family: var(--mono); letter-spacing: 0.06em;
}
.text-in:focus { outline: none; border-color: var(--gold); }

/* Ranked / Private */
.ranked-card { max-width: 560px; display: flex; flex-direction: column; gap: 16px; }
.ranked-rules { margin: 0; padding-left: 18px; color: var(--muted); }
.rank-head { display: flex; align-items: center; gap: 16px; }
.rank-head .big-rp { font-family: var(--mono); font-size: 28px; color: var(--gold-hi); }
.progress { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, #9a6a1e, var(--gold)); }
.private-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 900px; }
.room-code { font-family: var(--mono); font-size: 34px; letter-spacing: 0.14em; color: var(--gold-hi); text-align: center; padding: 10px; border: 1px dashed var(--line-strong); border-radius: 10px; }

/* Rank emblem */
.emblem {
  --c: #999; width: 26px; height: 26px; flex: none; transform: rotate(45deg); border-radius: 4px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--c) 90%, white), color-mix(in srgb, var(--c) 60%, black));
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5), 0 0 12px color-mix(in srgb, var(--c) 40%, transparent);
}
.emblem.lg { width: 48px; height: 48px; border-radius: 7px; margin: 8px; }
.emblem.sm { width: 14px; height: 14px; border-radius: 3px; }
.rank-name { font-weight: 700; }
.rank-badge { display: inline-flex; align-items: center; gap: 8px; }

/* ---------- Game layout ---------- */
#screen-game, #screen-replay { max-width: 1320px; }
.game-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr) 270px; gap: 18px; align-items: start; }
.side-left, .side-right { display: flex; flex-direction: column; gap: 12px; }
.side-right { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; max-height: calc(100vh - 60px); position: sticky; top: 16px; }
.side-title { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.mode-pill { font-family: var(--mono); font-size: 12px; color: var(--gold); letter-spacing: 0.1em; }

.pcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; transition: border-color 0.2s, box-shadow 0.2s;
}
.pcard.active { border-color: var(--line-strong); box-shadow: 0 0 0 1px var(--line-strong), 0 0 24px rgba(232, 176, 74, 0.08); }
.pcard .glyph { grid-row: span 2; font-family: var(--display); font-weight: 900; font-size: 34px; line-height: 1; width: 36px; text-align: center; }
.pcard.X .glyph { color: var(--x); }
.pcard.O .glyph { color: var(--o); }
.pcard .pname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .pmeta { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.pcard .clock {
  grid-column: 1 / -1; font-family: var(--mono); font-size: 30px; font-weight: 600; letter-spacing: 0.04em;
  background: var(--panel-2); border-radius: 8px; padding: 4px 10px; text-align: center; margin-top: 6px; color: var(--muted);
}
.pcard.active .clock { color: var(--text); }
.pcard .clock.low { color: var(--danger); }
.pcard .reloc { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.pip { width: 11px; height: 11px; transform: rotate(45deg); border: 1px solid var(--gold); border-radius: 2px; }
.pip.full { background: var(--gold); }
.thinking { color: var(--gold); font-size: 12px; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.score-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; text-align: center; }
.score-strip div { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 4px; }
.score-strip b { display: block; font-family: var(--mono); font-size: 20px; }
.score-strip small { color: var(--muted); font-size: 11.5px; }
.score-strip .sx b { color: var(--x); }
.score-strip .so b { color: var(--o); }
.game-actions { display: flex; gap: 8px; }
.game-actions button { flex: 1; }

.board-col { display: flex; flex-direction: column; align-items: center; gap: 12px; min-width: 0; }
.status {
  min-height: 44px; display: flex; align-items: center; justify-content: center; text-align: center;
  font-weight: 600; font-size: 16px; padding: 8px 16px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); width: min(100%, 660px);
}
.status .tag { font-family: var(--mono); color: var(--gold-hi); margin: 0 4px; }
.status.free { border-color: var(--line-strong); color: var(--gold-hi); }
.status.over { border-color: var(--gold); background: linear-gradient(90deg, rgba(232, 176, 74, 0.12), var(--panel), rgba(232, 176, 74, 0.12)); }

.mode-toggle { display: flex; gap: 8px; }
.mode-toggle button { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 18px; font-weight: 700; display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.mode-toggle button small { font-weight: 400; color: var(--muted); font-size: 11.5px; }
.mode-toggle button.on { border-color: var(--gold); background: rgba(232, 176, 74, 0.12); color: var(--gold-hi); }

/* ---------- Board (ทุกสีมาจากตัวแปรธีม) ---------- */
.board-host { width: min(100%, 660px); }
.bframe {
  display: grid; grid-template-columns: 18px 1fr; grid-template-rows: 18px 1fr; gap: 10px 4px;
  background: var(--frame-bg); padding: var(--frame-pad); border-radius: 16px; box-shadow: var(--frame-shadow);
}
.lbl-cols, .lbl-rows, .macro { display: grid; gap: 8px; }
.lbl-cols { grid-template-columns: repeat(3, 1fr); }
.lbl-rows { grid-template-rows: repeat(3, 1fr); }
.lbl-group { display: grid; gap: 3px; padding: 0 6px; }
.lbl-cols .lbl-group { grid-template-columns: repeat(3, 1fr); }
.lbl-rows .lbl-group { grid-template-rows: repeat(3, 1fr); padding: 6px 0; }
.lbl-group span { font-family: var(--mono); font-size: 11px; color: var(--label); display: flex; align-items: center; justify-content: center; }
.macro { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }

.sub {
  position: relative; border: 1px solid var(--sub-border); border-radius: var(--sub-radius); padding: 5px; background: var(--sub-bg);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.sub .cells { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.sub-name {
  position: absolute; top: -9px; left: 8px; font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em;
  background: var(--name-bg); padding: 0 5px; color: var(--name-color); border-radius: 3px; z-index: 2;
}
.sub.target { border-color: var(--target); box-shadow: 0 0 0 1px var(--target), 0 0 22px var(--target-glow); background: var(--target-bg); }
.sub.target .sub-name { color: var(--target); }
.sub.freeopen { border-color: var(--free-border); background: var(--free-bg); }
.sub.won-X { background: linear-gradient(135deg, color-mix(in srgb, var(--x) 24%, var(--sub-bg)), color-mix(in srgb, var(--x) 8%, var(--sub-bg))); border-color: color-mix(in srgb, var(--x) 55%, transparent); }
.sub.won-O { background: linear-gradient(135deg, color-mix(in srgb, var(--o) 24%, var(--sub-bg)), color-mix(in srgb, var(--o) 8%, var(--sub-bg))); border-color: color-mix(in srgb, var(--o) 55%, transparent); }
.sub.neutral { background: repeating-linear-gradient(135deg, var(--neutral-a) 0 7px, var(--neutral-b) 7px 14px); border-color: var(--sub-border); }
.sub.winline { box-shadow: 0 0 0 2px var(--accent), 0 0 30px color-mix(in srgb, var(--accent) 50%, transparent); }
.sub-owner {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
  font-family: var(--piece-font); font-weight: 900; font-size: clamp(56px, 13vw, 128px); line-height: 1; opacity: 0.32; z-index: 1;
}
.sub.won-X .sub-owner { color: var(--x); }
.sub.won-O .sub-owner { color: var(--o); }
.sub.neutral .sub-owner { font-family: var(--mono); font-size: clamp(11px, 2vw, 14px); letter-spacing: 0.2em; opacity: 0.85; color: var(--label); }
.sub.locked .cell { cursor: default; }
.sub.locked .cell.x, .sub.locked .cell.o { opacity: 0.55; }

.cell {
  aspect-ratio: 1; border: 0; border-radius: var(--cell-radius); background: var(--cell-bg); display: flex; align-items: center; justify-content: center;
  font-family: var(--piece-font); font-weight: 900; font-size: clamp(14px, 3.6vw, 30px); line-height: 1; padding: 0; position: relative;
  box-shadow: var(--cell-shadow); transition: background 0.12s, transform 0.08s;
}
.cell.alt { background: var(--cell-alt); }
.cell.x { color: var(--x); text-shadow: var(--x-glow); }
.cell.o { color: var(--o); text-shadow: var(--o-glow); }
.cell.legal { background: var(--cell-legal); box-shadow: var(--cell-shadow), inset 0 0 0 1px color-mix(in srgb, var(--target) 35%, transparent); }
.cell.legal:hover { background: var(--cell-hover); }
.cell.legal:hover::after { content: attr(data-ghost); opacity: 0.35; color: var(--ghost); }
.cell.last { box-shadow: inset 0 0 0 2px var(--accent); }
.cell.src { box-shadow: inset 0 0 0 1.5px var(--target); background: var(--cell-legal); }
.cell.src:hover { background: var(--cell-hover); }
.cell.sel { background: var(--target); color: var(--sel-text) !important; text-shadow: none; }
.cell.dst::before { content: ''; width: 26%; height: 26%; border-radius: 50%; background: var(--target); opacity: 0.75; }
.cell.dst:hover::before { opacity: 1; }
.cell.from-ghost::before { content: ''; width: 34%; height: 34%; border-radius: 50%; border: 1.5px dashed var(--label); }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cell:not(.legal):not(.src):not(.dst) { cursor: default; }
.cell.pop { animation: pop 0.22s ease; }
@keyframes pop { from { transform: scale(0.6); } to { transform: scale(1); } }

/* ---------- Board themes ---------- */
[data-theme] {
  --frame-bg: transparent; --frame-pad: 0px; --frame-shadow: none;
  --sub-bg: var(--panel); --sub-border: var(--line); --sub-radius: 9px;
  --cell-bg: #221e17; --cell-alt: var(--cell-bg); --cell-legal: #2b2519; --cell-hover: #3a301c; --cell-radius: 5px; --cell-shadow: 0 0 0 transparent;
  --target: var(--gold); --target-glow: rgba(232, 176, 74, 0.28); --target-bg: #1d1810;
  --free-bg: #18150f; --free-border: var(--line-strong);
  --neutral-a: #15140f; --neutral-b: #1b1a15; --name-bg: var(--bg); --name-color: var(--muted); --label: var(--muted);
  --accent: var(--gold-hi); --sel-text: #1a1205; --ghost: currentColor;
  --piece-font: var(--display); --x-glow: none; --o-glow: none;
}
/* Marble — ตามโลโก้ใหม่ หินอ่อนขาว-ดำสลับ ขอบทอง */
[data-theme="marble"] {
  --x: #d39a2c; --o: #4f8fd0;
  --frame-bg: radial-gradient(ellipse at 50% 30%, #1d1912, #0b0a08 75%); --frame-pad: 12px; --frame-shadow: 0 0 0 1px rgba(232, 176, 74, 0.35), 0 0 50px rgba(232, 176, 74, 0.12);
  --sub-bg: #0e0d0b; --sub-border: rgba(232, 176, 74, 0.45); --sub-radius: 6px;
  --cell-bg: linear-gradient(135deg, #f6f3ec 0%, #e3ddd1 55%, #f1ece2 100%);
  --cell-alt: linear-gradient(135deg, #2a2a2b 0%, #141415 55%, #262627 100%);
  --cell-legal: linear-gradient(135deg, #fff6dc, #f0dfb3); --cell-hover: linear-gradient(135deg, #ffe9ad, #f2cf7c);
  --cell-radius: 3px; --cell-shadow: inset 0 0 0 1px rgba(232, 176, 74, 0.35);
  --target-bg: #17130c; --free-bg: #12100c; --neutral-a: #1a1917; --neutral-b: #24221f;
  --o-glow: 0 0 1px #000; --x-glow: 0 0 1px #000;
}
/* Jade Temple */
[data-theme="jade"] {
  --x: #f2c46b; --o: #c9f2dc;
  --sub-bg: #0c1813; --sub-border: rgba(120, 210, 160, 0.22); --cell-bg: #16301f; --cell-legal: #1d4330; --cell-hover: #27583f;
  --target: #7fe0a8; --target-glow: rgba(127, 224, 168, 0.28); --target-bg: #10261a; --free-bg: #0f2017; --free-border: rgba(127, 224, 168, 0.4);
  --neutral-a: #0f1b15; --neutral-b: #15241c; --name-bg: #07100c; --name-color: #7ea893; --label: #7ea893; --accent: #b9f5d2; --sel-text: #062012;
  --frame-bg: #07100c; --frame-pad: 10px; --frame-shadow: 0 0 0 1px rgba(127, 224, 168, 0.18);
}
/* Neon Grid */
[data-theme="neon"] {
  --x: #ff3ea5; --o: #19e6ff;
  --frame-bg: #05050c; --frame-pad: 10px; --frame-shadow: 0 0 0 1px rgba(25, 230, 255, 0.25), 0 0 40px rgba(255, 62, 165, 0.12);
  --sub-bg: #07071a; --sub-border: rgba(25, 230, 255, 0.28); --sub-radius: 4px;
  --cell-bg: #0e0e24; --cell-legal: #15153a; --cell-hover: #1f1f52; --cell-radius: 2px;
  --target: #19e6ff; --target-glow: rgba(25, 230, 255, 0.45); --target-bg: #0a0f2a; --free-bg: #0a0a20; --free-border: rgba(255, 62, 165, 0.45);
  --neutral-a: #0a0a18; --neutral-b: #12122a; --name-bg: #05050c; --name-color: #19e6ff; --label: #6b6bb0; --accent: #fff; --sel-text: #05050c;
  --piece-font: var(--mono); --x-glow: 0 0 8px #ff3ea5, 0 0 18px rgba(255, 62, 165, 0.6); --o-glow: 0 0 8px #19e6ff, 0 0 18px rgba(25, 230, 255, 0.6);
}
/* Wooden Board */
[data-theme="wood"] {
  --x: #1c1410; --o: #a3241c;
  --frame-bg: linear-gradient(160deg, #7a4c26, #5b3519 60%, #6e4321); --frame-pad: 12px; --frame-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25), 0 10px 30px rgba(0, 0, 0, 0.5);
  --sub-bg: #b9874c; --sub-border: rgba(50, 25, 8, 0.45); --sub-radius: 6px;
  --cell-bg: linear-gradient(180deg, #e8c690, #dcb57a); --cell-legal: linear-gradient(180deg, #f3d9a8, #ebca8f); --cell-hover: #f8e3bb;
  --cell-radius: 3px; --cell-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
  --target: #fff1c9; --target-glow: rgba(255, 241, 201, 0.5); --target-bg: #c9975a; --free-bg: #c1904f; --free-border: rgba(255, 241, 201, 0.55);
  --neutral-a: #8f6436; --neutral-b: #9c6f3e; --name-bg: #5b3519; --name-color: #f3dfb8; --label: #f0d6a6; --accent: #fffaf0; --sel-text: #3b200b;
  --piece-font: Georgia, 'Times New Roman', serif;
}
/* Frost */
[data-theme="ice"] {
  --x: #1b5fa8; --o: #7b47c9;
  --frame-bg: linear-gradient(160deg, #1a2a3c, #0f1a28); --frame-pad: 10px; --frame-shadow: 0 0 0 1px rgba(154, 215, 255, 0.25);
  --sub-bg: #a9c6de; --sub-border: rgba(255, 255, 255, 0.5); --cell-bg: linear-gradient(160deg, #f4f9fd, #dbe9f5); --cell-alt: linear-gradient(160deg, #e9f2fa, #cfe1f0);
  --cell-legal: #ffffff; --cell-hover: #e2f3ff; --cell-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
  --target: #3aa8ff; --target-glow: rgba(58, 168, 255, 0.45); --target-bg: #bcdaf2; --free-bg: #b5d1e8; --free-border: #3aa8ff;
  --neutral-a: #8eabc4; --neutral-b: #9cb8cf; --name-bg: #0f1a28; --name-color: #9ad7ff; --label: #9ad7ff; --accent: #0b3a6b; --sel-text: #fff;
}
/* Ink & Paper */
[data-theme="paper"] {
  --x: #1d1a16; --o: #b8322a;
  --frame-bg: #efe6d2; --frame-pad: 12px; --frame-shadow: 0 8px 26px rgba(0, 0, 0, 0.45);
  --sub-bg: #f7f0e0; --sub-border: rgba(60, 40, 20, 0.45); --sub-radius: 4px;
  --cell-bg: #fbf7ec; --cell-legal: #fff5d8; --cell-hover: #ffeab0; --cell-radius: 2px; --cell-shadow: inset 0 0 0 1px rgba(60, 40, 20, 0.12);
  --target: #b8322a; --target-glow: rgba(184, 50, 42, 0.2); --target-bg: #fbe9dc; --free-bg: #f4ead6; --free-border: rgba(184, 50, 42, 0.5);
  --neutral-a: #e6dcc6; --neutral-b: #ddd1b8; --name-bg: #efe6d2; --name-color: #6b5a3c; --label: #8a7a5c; --accent: #1d1a16; --sel-text: #fff;
  --piece-font: 'Kalam', 'Comic Sans MS', cursive;
}
/* Royal Velvet */
[data-theme="royal"] {
  --x: #f0c35a; --o: #efe6ff;
  --frame-bg: linear-gradient(160deg, #241334, #120a1c); --frame-pad: 10px; --frame-shadow: 0 0 0 1px rgba(200, 155, 255, 0.25);
  --sub-bg: #1c1029; --sub-border: rgba(200, 155, 255, 0.25); --cell-bg: #2b1a3d; --cell-legal: #3a2453; --cell-hover: #4a2f6a;
  --target: #c89bff; --target-glow: rgba(200, 155, 255, 0.35); --target-bg: #26163a; --free-bg: #221433; --free-border: rgba(240, 195, 90, 0.45);
  --neutral-a: #1a1024; --neutral-b: #22152f; --name-bg: #120a1c; --name-color: #c89bff; --label: #a58cc4; --accent: #f0c35a; --sel-text: #1a0a2a;
}

/* Theme picker */
.theme-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.theme-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.theme-card.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.theme-card .tname { font-weight: 600; font-size: 13px; }
.theme-card .tdesc { font-size: 11px; color: var(--muted); line-height: 1.3; }
.tprev { background: var(--frame-bg, transparent); padding: 4px; border-radius: 6px; }
.tprev .sub { padding: 3px; border-radius: 4px; }
.tprev .sub .cells { gap: 2px; }
.tprev .cell { font-size: 13px; cursor: pointer !important; }
.theme-quick { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
.theme-select { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; font: inherit; font-size: 13px; }

/* Move list */
.movelist { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; font-size: 13px; min-height: 120px; }
.movelist li { display: grid; grid-template-columns: 28px 1fr auto; gap: 6px; align-items: baseline; padding: 4px 6px; border-radius: 6px; }
.movelist li:nth-child(odd) { background: rgba(255, 255, 255, 0.02); }
.movelist .mn { color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
.movelist .mt { font-family: var(--mono); font-size: 12.5px; }
.movelist .mt .px { color: var(--x); font-weight: 600; }
.movelist .mt .po { color: var(--o); font-weight: 600; }
.movelist .mt .rl { color: var(--gold-hi); }
.movelist .tl { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.movelist .ev { grid-column: 2 / -1; font-size: 11.5px; color: var(--gold); }
.movelist.clickable li { cursor: pointer; }
.movelist.clickable li:hover { background: rgba(232, 176, 74, 0.08); }
.movelist li.cur { background: rgba(232, 176, 74, 0.16) !important; }
.movelist .empty { color: var(--muted); display: block; }

/* Replay */
.replay-controls { display: flex; align-items: center; gap: 8px; }
.replay-controls button { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; width: 44px; height: 38px; }
.replay-controls button:hover { border-color: var(--line-strong); }
#r-counter { font-family: var(--mono); min-width: 80px; text-align: center; color: var(--muted); }
#r-slider { width: min(100%, 660px); accent-color: var(--gold); }
.replay-info { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; font-size: 13.5px; display: flex; flex-direction: column; gap: 4px; }
.replay-info .vs { font-weight: 700; font-size: 15px; }

/* Leaderboard */
.lb-tabs { margin-bottom: 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12.5px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.04); white-space: nowrap; }
.num { text-align: right; font-family: var(--mono); }
tr.me td { background: rgba(232, 176, 74, 0.12); }
tr.cut td { border-top: 2px dashed var(--gold); }
td.pos { font-family: var(--mono); color: var(--muted); }
tr.king td.pos { color: var(--gold-hi); }

/* Profile */
.profile-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; }
.stat-grid div { background: var(--panel-2); border-radius: 8px; padding: 10px; text-align: center; }
.stat-grid b { display: block; font-family: var(--mono); font-size: 20px; }
.stat-grid small { color: var(--muted); }
.ladder td { padding: 9px 8px; }
.ladder tr.cur td { background: rgba(232, 176, 74, 0.12); }

/* History */
.hist-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.05); align-items: center; }
.hist-item .h-top { font-weight: 600; }
.hist-item .h-sub { color: var(--muted); font-size: 13px; }
.res-win { color: var(--ok); }
.res-loss { color: var(--danger); }
.res-nc { color: var(--muted); }

/* How to */
.howto { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.howto p, .howto ul, .howto ol { margin: 0 0 8px; }
.howto ul, .howto ol { padding-left: 20px; }
.mini-map { display: grid; grid-template-columns: repeat(3, 48px); gap: 4px; margin: 8px 0; }
.mini-map span { font-family: var(--mono); font-size: 12px; text-align: center; padding: 10px 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; color: var(--gold-hi); }

/* Modal & toast */
.overlay { position: fixed; inset: 0; background: rgba(5, 4, 3, 0.72); backdrop-filter: blur(3px); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.overlay[hidden] { display: none; }
.modal { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 16px; padding: 26px; width: min(440px, 100%); text-align: center; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); animation: fade 0.2s ease; }
.modal h2 { font-family: var(--display); letter-spacing: 0.06em; font-size: 28px; color: var(--gold-hi); margin-bottom: 4px; }
.modal .sub-title { color: var(--muted); margin-bottom: 14px; }
.modal .rp-change { font-family: var(--mono); font-size: 26px; margin: 8px 0; }
.modal .rp-change.up { color: var(--ok); }
.modal .rp-change.down { color: var(--danger); }
.modal table { margin: 10px 0 4px; font-size: 13px; }
.modal td, .modal th { padding: 5px 8px; text-align: center; }
.modal td:first-child, .modal th:first-child { text-align: left; }
.modal tr.decider td { color: var(--gold-hi); font-weight: 600; }
.modal .btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.searching .spinner { width: 54px; height: 54px; margin: 10px auto 16px; transform: rotate(45deg); border: 2px solid var(--gold); border-radius: 6px; animation: spin 1.4s ease-in-out infinite; }
@keyframes spin { 50% { transform: rotate(225deg) scale(0.8); } 100% { transform: rotate(405deg); } }
.searching .wait { font-family: var(--mono); color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 60;
  background: #2a1d17; border: 1px solid rgba(230, 106, 92, 0.5); color: #ffd9d3; padding: 10px 18px; border-radius: 10px; transition: 0.2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.info { background: #221c10; border-color: var(--line-strong); color: var(--gold-hi); }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .game-layout { grid-template-columns: 1fr; }
  .side-left { display: grid; grid-template-columns: 1fr 1fr; order: 0; }
  .side-left .mode-pill, .side-left .score-strip, .side-left .game-actions, .side-left .back, .side-left .replay-info, .side-left .theme-quick { grid-column: 1 / -1; }
  .board-col { order: 1; }
  .side-right { order: 2; position: static; max-height: 300px; }
  .pcard .clock { font-size: 24px; }
}
@media (max-width: 900px) {
  .menu-layout { grid-template-columns: 1fr; }
  .theme-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .menu-grid { grid-template-columns: repeat(2, 1fr); }
  .private-grid, .profile-grid, .howto { grid-template-columns: 1fr; }
  .pcard { padding: 10px; gap: 2px 8px; }
  .pcard .glyph { font-size: 26px; width: 26px; }
  .macro, .lbl-cols, .lbl-rows { gap: 5px; }
  .sub { padding: 3px; border-radius: 6px; }
  .sub .cells, .lbl-group { gap: 2px; }
  .lbl-group { padding: 0 4px; }
  .lbl-rows .lbl-group { padding: 4px 0; }
  .bframe { grid-template-columns: 14px 1fr; grid-template-rows: 14px 1fr; gap: 9px 3px; }
  .cell { border-radius: 3px; }
  .sub-name { font-size: 9px; top: -8px; left: 5px; }
}
.kb-title { white-space: nowrap; }
@media (max-width: 480px) {
  .kb-title { font-size: 16px; }
  .kb-live { display: none; }
}

/* ---------- Rank icons (โฟลเดอร์ Rank Icons) ---------- */
.ricon { width: 32px; height: 32px; object-fit: contain; flex: none; display: inline-block; vertical-align: middle; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5)); }
.ricon.xs { width: 22px; height: 22px; }
.ricon.sm { width: 28px; height: 28px; }
.ricon.md { width: 44px; height: 44px; }
.ricon.lg { width: 84px; height: 84px; }
.ricon.xl { width: 120px; height: 120px; filter: drop-shadow(0 0 24px rgba(232, 176, 74, 0.25)); }
.rank-badge { gap: 6px; }
.rank-head { gap: 18px; }
.rank-name.big { font-family: var(--display); font-size: 24px; letter-spacing: 0.06em; }
.player-chip .ricon { margin: -4px 0; }
.kb-title .ricon { margin: -10px -2px -10px -6px; }
.kb-me { display: flex; align-items: center; gap: 10px; }

.progress-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.progress-main { flex: 1; min-width: 0; }
.ricon.next-rank { opacity: 0.55; filter: grayscale(0.6) drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5)); }

.ladder td { vertical-align: middle; }
.ladder td.ic { width: 56px; }
.ladder tr.locked .ricon { filter: grayscale(0.85) brightness(0.7); opacity: 0.55; }
.ladder tr.locked td { color: var(--muted); }
.ladder tr.cur .ricon { width: 56px; height: 56px; }

.rank-gallery { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; text-align: center; }
.rg-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.rg-item .ricon { width: 72px; height: 72px; }
.how-ranks { grid-column: 1 / -1; }

/* Rank change in result modal */
.rank-change { margin: 10px auto 0; padding: 12px; border-radius: 12px; border: 1px solid var(--line-strong); background: linear-gradient(180deg, rgba(232, 176, 74, 0.10), transparent); }
.rank-change.down { border-color: rgba(230, 106, 92, 0.35); background: linear-gradient(180deg, rgba(230, 106, 92, 0.08), transparent); }
.rc-label { font-family: var(--display); letter-spacing: 0.1em; font-weight: 700; color: var(--gold-hi); }
.rank-change.down .rc-label { color: var(--danger); }
.rc-icons { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 6px 0 2px; }
.rc-icons .ricon.lg { animation: rankpop 0.7s cubic-bezier(.2, 1.6, .4, 1); }
.rc-arrow { color: var(--muted); font-size: 20px; }
@keyframes rankpop { from { transform: scale(0.3) rotate(-12deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* Match found */
.vs-icons { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin: 10px 0; }
.vs-icons > div { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.vs-icons .pn { font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vs-sep { font-family: var(--display); font-weight: 900; color: var(--gold); font-size: 20px; }

/* Language switch */
.topbar-right { display: flex; align-items: center; gap: 10px; }
.lang-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; background: var(--panel); }
.lang-switch button { background: none; border: 0; border-radius: 999px; padding: 4px 10px; font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: 0.04em; }
.lang-switch button.on { background: rgba(232, 176, 74, 0.16); color: var(--gold-hi); box-shadow: inset 0 0 0 1px var(--gold); }
.lang-switch.big { align-self: flex-start; border-radius: 10px; }
.lang-switch.big button { padding: 8px 18px; font-size: 14px; border-radius: 8px; }

@media (max-width: 900px) {
  .rank-gallery { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 480px) {
  .brand-mini .proto-tag { display: none; }
  .player-chip .rp { display: none; }
  .ricon.xl { width: 92px; height: 92px; }
  .rank-gallery { grid-template-columns: repeat(3, 1fr); }
  .rg-item .ricon { width: 60px; height: 60px; }
}

/* ================= Auth ================= */
.auth-wrap { min-height: calc(100vh - 68px); display: grid; grid-template-columns: 1fr minmax(0, 440px); gap: 40px; align-items: center; max-width: 1040px; margin: 0 auto; }
.auth-brand { text-align: center; }
.auth-logo { width: min(420px, 100%); aspect-ratio: 3 / 2; object-fit: contain; margin-bottom: -30px; filter: drop-shadow(0 0 30px rgba(232, 176, 74, 0.25)); animation: float 6s ease-in-out infinite; }
.wordmark.sm { font-size: clamp(32px, 6vw, 54px); }
.auth-card { display: flex; flex-direction: column; gap: 14px; padding: 24px; }
.auth-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.auth-tabs button { padding: 8px 16px; font-weight: 600; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.auth-form small { font-size: 11.5px; color: var(--muted); opacity: 0.8; }
.auth-form .text-in { font-family: var(--font); letter-spacing: 0; }
.auth-err { background: rgba(230, 106, 92, 0.12); border: 1px solid rgba(230, 106, 92, 0.45); color: #ffc7bf; border-radius: 8px; padding: 9px 12px; font-size: 13.5px; }
.auth-or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.auth-or::before, .auth-or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.demo-box { border: 1px dashed var(--line-strong); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.demo-title { font-size: 12px; color: var(--gold); font-weight: 600; }
.demo-acc { text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-family: var(--mono); font-size: 13px; }
.demo-acc:hover { border-color: var(--line-strong); }
.demo-acc span { font-family: var(--font); color: var(--muted); font-size: 12px; }
.demo-box .note { margin: 4px 0 0; font-size: 11.5px; }

/* Role visibility */
.admin-only { display: none !important; }
body.is-admin .admin-only { display: flex !important; }
.menu-btn.admin-only { border-color: rgba(192, 108, 240, 0.5); background: linear-gradient(160deg, rgba(192, 108, 240, 0.16), var(--panel) 70%); }
.menu-btn.admin-only .mb-title { color: #e2c4ff; }
.role-tag { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em; color: #e2c4ff; border: 1px solid rgba(192, 108, 240, 0.5); border-radius: 4px; padding: 0 5px; }
.role-tag.guest { color: var(--muted); border-color: var(--line-strong); }
.admin-badge { font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; color: #e2c4ff; border: 1px solid rgba(192, 108, 240, 0.5); border-radius: 4px; padding: 2px 8px; }
.role-note { margin-top: 12px; font-size: 13px; color: #e2c4ff; background: rgba(192, 108, 240, 0.08); border: 1px solid rgba(192, 108, 240, 0.3); border-radius: 8px; padding: 8px 10px; }
.icon-btn { width: 38px; height: 38px; padding: 0; border-radius: 50%; font-size: 16px; color: var(--muted); }
.icon-btn:hover { color: var(--danger); border-color: rgba(230, 106, 92, 0.5); }
.lock-note { background: var(--panel-2); border: 1px dashed var(--line-strong); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; color: var(--gold-hi); }
.seg button small { color: var(--muted); font-size: 11px; margin-left: 4px; }

/* King board — full Top 500 */
.kb-search { display: flex; align-items: center; gap: 10px; }
.kb-search .text-in { flex: 1; min-width: 0; padding: 7px 10px; font-family: var(--font); letter-spacing: 0; font-size: 13px; }
.kb-count { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.kb-list { max-height: 320px; overflow-y: auto; padding-right: 4px; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.kb-list li.me { background: rgba(232, 176, 74, 0.12); }

/* Leaderboard tools */
.lb-tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.lb-tools .text-in { flex: 1 1 220px; font-family: var(--font); letter-spacing: 0; }
.lb-pager { display: flex; flex-wrap: wrap; gap: 4px; }
.lb-pager button { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 9px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.lb-pager button.on { border-color: var(--gold); color: var(--gold-hi); background: rgba(232, 176, 74, 0.12); }
.lb-pager .gap { color: var(--muted); padding: 0 4px; }
#ap-pager { margin-top: 12px; justify-content: center; }
.sub-id { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* Profile extras */
.stat-grid .span2 { grid-column: span 2; }
.stat-grid .hours b { color: var(--gold-hi); }
.mode-split { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.mode-split span { background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 12.5px; color: var(--muted); }
.mode-split b { color: var(--text); font-family: var(--mono); margin-left: 4px; }
dl.acct { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 14px 0 0; font-size: 13.5px; text-align: left; }
dl.acct dt { color: var(--muted); }
dl.acct dd { margin: 0; font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }

/* ================= Admin ================= */
#screen-admin { max-width: 1320px; --chart-1: #e8b04a; }
.admin-tabs { margin-bottom: 16px; }
.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; }
.kpi-grid.sm { grid-template-columns: repeat(4, 1fr); margin: 14px 0 6px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi b { font-family: var(--mono); font-size: 22px; color: var(--text); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.kpi-grid.sm .kpi b { font-size: 16px; }
.kpi span { font-size: 12.5px; color: var(--muted); }
.kpi small { font-size: 11px; color: var(--muted); opacity: 0.8; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #5b5650; display: inline-block; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(111, 191, 134, 0.18); }
.dot.mid { background: var(--gold); }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.chart-card h3 { margin-bottom: 4px; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: rgba(255, 255, 255, 0.06); stroke-width: 1; }
.chart .base { stroke: rgba(255, 255, 255, 0.22); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--mono); }
.chart .bar { transition: opacity 0.15s; }
.chart .bar-g.hl .bar { opacity: 0.75; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .line { fill: none; stroke: var(--chart-1); stroke-width: 2; stroke-linejoin: round; }
.chart .area { fill: rgba(232, 176, 74, 0.10); }
.chart .pt { fill: var(--chart-1); stroke: var(--panel); stroke-width: 2; opacity: 0; }
.chart .pt.last { opacity: 1; }
.chart .xhair { stroke: rgba(255, 255, 255, 0.25); stroke-dasharray: 3 3; opacity: 0; }
.chart .pt-g.hl .pt, .chart .pt-g.hl .xhair { opacity: 1; }
.chart-tip { position: fixed; z-index: 70; pointer-events: none; background: #1d1a14; border: 1px solid var(--line-strong); border-radius: 8px; padding: 6px 10px; font-size: 12.5px; line-height: 1.45; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); }
.adm-table th.sortable { cursor: pointer; user-select: none; }
.adm-table th.sorted { color: var(--gold-hi); }
.adm-table tr.total td { border-top: 2px solid var(--line-strong); font-weight: 600; }
.adm-table.players tbody tr { cursor: pointer; }
.adm-table.players tbody tr:hover td { background: rgba(232, 176, 74, 0.06); }
.adm-table tr.local td { background: rgba(192, 108, 240, 0.06); }
.adm-table .mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); }
.adm-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.adm-tools .text-in { flex: 1 1 260px; font-family: var(--font); letter-spacing: 0; }
.adm-tools .theme-select { padding: 9px 8px; }
.adm-count { color: var(--muted); font-size: 13px; margin-left: auto; }
.status-b { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; white-space: nowrap; }
.status-b.inactive { color: var(--muted); }
.modal.wide { width: min(640px, 100%); text-align: left; max-height: calc(100vh - 32px); overflow-y: auto; }
.modal.wide .btns { justify-content: flex-end; }
.pd-head { display: flex; align-items: center; gap: 14px; }
.pd-head h2 { margin: 0; font-size: 24px; }
.act-strip { display: grid; grid-template-columns: repeat(30, 1fr); gap: 3px; }
.act-strip i { aspect-ratio: 1; border-radius: 2px; background: var(--panel-2); border: 1px solid var(--line); }
.act-strip i.on { background: var(--gold); border-color: var(--gold); }

@media (max-width: 1080px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .auth-wrap { grid-template-columns: 1fr; gap: 10px; }
  .auth-logo { width: min(260px, 70%); margin-bottom: -20px; }
}
@media (max-width: 560px) {
  .kpi-grid, .kpi-grid.sm { grid-template-columns: repeat(2, 1fr); }
  .adm-count { margin-left: 0; }
  .topbar-right { gap: 6px; }
}

/* ================= Global header + user dropdown ================= */
.app-header { position: relative; z-index: 30; max-width: 1240px; margin: 0 auto; padding: 16px 16px 0; }
.app-header .brand-mini { background: none; border: 0; padding: 0; }
.app-header .brand-mini:hover { color: var(--gold-hi); }
.user-menu-wrap { position: relative; }
.player-chip { cursor: pointer; }
.player-chip .chip-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-chip .chev { color: var(--muted); font-size: 11px; margin-left: 2px; transition: transform 0.15s; }
.player-chip[aria-expanded="true"] { border-color: var(--line-strong); }
.player-chip[aria-expanded="true"] .chev { transform: rotate(180deg); }
.user-menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 300px; max-width: calc(100vw - 32px);
  background: #16130e; border: 1px solid var(--line-strong); border-radius: 14px; padding: 8px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6); animation: fade 0.15s ease;
}
.um-head { display: flex; align-items: center; gap: 10px; padding: 8px 8px 10px; border-bottom: 1px solid var(--line); }
.um-head b { font-size: 15px; }
.um-ranks { display: flex; flex-direction: column; gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.um-rank { display: grid; grid-template-columns: 24px 44px 1fr auto auto; gap: 8px; align-items: center; background: none; border: 0; border-radius: 8px; padding: 5px 8px; text-align: left; font-size: 13px; }
.um-rank:hover { background: rgba(232, 176, 74, 0.08); }
.um-m { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.um-rn { font-weight: 600; }
.um-rp { font-family: var(--mono); font-size: 12px; }
.um-pos { font-family: var(--mono); font-size: 11px; color: var(--muted); min-width: 46px; text-align: right; }
.um-note { font-size: 12.5px; color: var(--muted); padding: 4px 8px; }
.um-items { display: flex; flex-direction: column; padding: 6px 0; border-bottom: 1px solid var(--line); }
.um-items button, .um-logout { display: flex; align-items: center; gap: 10px; background: none; border: 0; border-radius: 8px; padding: 9px 10px; text-align: left; font-size: 14px; width: 100%; }
.um-items button:hover, .um-logout:hover { background: rgba(232, 176, 74, 0.08); }
.um-items button.admin-only { color: #e2c4ff; }
.um-ic { width: 20px; text-align: center; color: var(--gold); }
.um-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }
.um-logout { color: var(--danger); margin-top: 4px; }
.um-logout .um-ic { color: var(--danger); }

/* Guest locks */
body.is-guest [data-guest-lock] { opacity: 0.55; position: relative; }
body.is-guest .seg .member-only { opacity: 0.45; }
body.is-guest .seg .member-only::after { content: ' 🔒'; }
body.is-guest [data-guest-lock]::after { content: '🔒'; position: absolute; top: 10px; right: 12px; font-size: 14px; }
.menu-btn.normal { border-color: rgba(140, 192, 234, 0.35); }
.menu-btn.normal .mb-title { color: #cfe6fa; }
body.is-guest .menu-btn.normal { border-color: var(--o); box-shadow: 0 0 0 1px rgba(140, 192, 234, 0.35); }
.unranked-tag { font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; color: #cfe6fa; border: 1px solid rgba(140, 192, 234, 0.45); border-radius: 4px; padding: 2px 8px; }
.normal-intro { margin: 0; color: var(--muted); }
.vs-icons.plain .pn { font-size: 18px; }
.rp-change small { font-size: 13px; color: var(--muted); margin-left: 6px; }

/* Mode tabs */
.mode-seg button { display: inline-flex; align-items: baseline; gap: 2px; }
.kb-modes { display: grid; grid-template-columns: repeat(3, 1fr); }
.kb-modes button { justify-content: center; padding: 7px 6px; }
.kb-foot { justify-content: space-between; align-items: center; gap: 10px; }
.lb-modes { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.lb-mode-note { font-size: 12.5px; color: var(--muted); }
.ladder-wrap .mode-seg, #screen-profile .mode-seg { margin-bottom: 10px; }
.admin-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.admin-bar .admin-tabs { margin-bottom: 0; }
.admin-mode { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }

/* Profile — per-mode rank cards */
.sec-title { margin: 18px 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
.mode-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.mode-card { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.mode-card.on { border-color: var(--line-strong); }
.mc-head { display: flex; align-items: baseline; gap: 6px; font-size: 14px; }
.mc-head small { color: var(--muted); font-size: 11.5px; }
.mc-pos { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.mc-body { display: flex; align-items: center; gap: 8px; }
.mc-rp { font-family: var(--mono); font-size: 15px; color: var(--gold-hi); }
.mc-rec { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.mode-card .progress-row { margin-top: 2px; gap: 6px; }
.mode-card .progress-row .note { font-size: 11px; }
.mode-card .ricon.next-rank { width: 28px; height: 28px; }
.pd-modes { margin: 12px 0 4px; font-size: 13px; }
.pd-modes td, .pd-modes th { padding: 6px 8px; }

@media (max-width: 760px) {
  .mode-cards { grid-template-columns: 1fr; }
  .player-chip .rp { display: none; }
  .player-chip .chip-name { max-width: 110px; }
}
.ladder td { white-space: normal; }
@media (max-width: 480px) {
  .mode-seg button small { display: none; }
  .mode-seg button { padding: 7px 12px; }
  .kb-foot { flex-direction: column; align-items: stretch; }
}

/* ================= Support / donate ================= */
.support-card {
  max-width: 1100px; margin: 22px auto 0; display: flex; align-items: center; gap: 18px; padding: 18px 22px;
  border-radius: var(--radius); border: 1px solid rgba(236, 111, 140, 0.35);
  background: linear-gradient(120deg, rgba(236, 111, 140, 0.12), var(--panel) 45%, rgba(232, 176, 74, 0.08));
}
.support-ic { width: 46px; height: 46px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 22px; color: #ff8fab; background: rgba(236, 111, 140, 0.14); border: 1px solid rgba(236, 111, 140, 0.35); }
.support-text { flex: 1; min-width: 0; }
.support-text h3 { margin: 0 0 4px; font-size: 16px; color: #ffd0dc; }
.support-text p { margin: 0; color: var(--muted); font-size: 13.5px; }
.support-btn { text-decoration: none; white-space: nowrap; background: linear-gradient(180deg, #ff9db5, #e0607f); color: #2a0711; }
.support-btn:hover { filter: brightness(1.08); }
.um-support { display: flex; align-items: center; gap: 10px; border-radius: 8px; padding: 9px 10px; font-size: 14px; color: #ffb3c6; text-decoration: none; margin-top: 4px; }
.um-support:hover { background: rgba(236, 111, 140, 0.1); }
.um-support .um-ic { color: #ff8fab; }
.auth-support { align-self: center; font-size: 13px; color: #ffb3c6; text-decoration: none; }
.auth-support:hover { text-decoration: underline; }
@media (max-width: 640px) {
  .support-card { flex-direction: column; text-align: center; }
  .support-btn { width: 100%; text-align: center; }
}
.menu-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mb-title, .mb-sub { overflow-wrap: anywhere; }
@media (max-width: 900px) { .menu-layout { grid-template-columns: minmax(0, 1fr); } }

/* ================= Online version ================= */
.conn-pill { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 80; background: #2a1d17; border: 1px solid rgba(230, 106, 92, 0.5); color: #ffd9d3; padding: 6px 14px; border-radius: 999px; font-size: 13px; }
.off-tag { font-size: 11px; color: var(--danger); border: 1px solid rgba(230, 106, 92, 0.45); border-radius: 4px; padding: 0 5px; }
.room-wait { display: flex; flex-direction: column; gap: 10px; }
.room-wait .note { margin: 0; text-align: center; }
.pw-form { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 14px; }
.pw-form h3 { margin: 0; font-size: 14px; color: var(--muted); }
.pw-form .text-in { font-family: var(--font); letter-spacing: 0; }
.status .starts { color: var(--gold-hi); font-family: var(--mono); }
