:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --text: #1c1c22;
  --muted: #6c6c75;
  --border: #e4e4df;
  --accent: #5b57e8;
  --accent-ink: #ffffff;
  --accent-soft: #ecebff;
  --good: #1f9d5a;
  --bad: #d64545;
  --warn: #c98a00;
  --tile: #fff4d6;
  --tile-edge: #e6d3a3;
  --tile-text: #2a2117;
  --tile-new: #d9f5e3;
  --tile-new-edge: #8fd1a8;
  --cell: #ecebe5;
  --p-T: #f2a7a0;
  --p-D: #ffd98a;
  --p-t: #9cc9f5;
  --p-d: #ffc59a;
  --p-star: #c7c2ff;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --radius: 14px;
  --font: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --pixel: 'Pixelify Sans', 'IBM Plex Sans Thai', monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111215; --surface: #1a1b20; --surface-2: #23242b; --text: #ececf1; --muted: #9b9ba6; --border: #2d2e36;
    --accent: #8a87ff; --accent-ink: #0f0f14; --accent-soft: #26254a; --good: #45c980; --bad: #ff6b6b; --warn: #f0b429;
    --tile: #f3e6c4; --tile-edge: #b9a77b; --tile-text: #1f1a12; --tile-new: #b9ecc9; --tile-new-edge: #5fb784;
    --cell: #24252c; --p-T: #8a3f3a; --p-D: #8a6a1f; --p-t: #2e5d8a; --p-d: #8a5530; --p-star: #4b4690;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111215; --surface: #1a1b20; --surface-2: #23242b; --text: #ececf1; --muted: #9b9ba6; --border: #2d2e36;
  --accent: #8a87ff; --accent-ink: #0f0f14; --accent-soft: #26254a; --good: #45c980; --bad: #ff6b6b; --warn: #f0b429;
  --tile: #f3e6c4; --tile-edge: #b9a77b; --tile-text: #1f1a12; --tile-new: #b9ecc9; --tile-new-edge: #5fb784;
  --cell: #24252c; --p-T: #8a3f3a; --p-D: #8a6a1f; --p-t: #2e5d8a; --p-d: #8a5530; --p-star: #4b4690;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1.05rem; }
.pixel { font-family: var(--pixel); letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 14px; padding: 10px 16px; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); font-family: var(--pixel); font-size: 1.35rem; font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand .ace { color: var(--accent); }
.nav { display: flex; gap: 2px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; white-space: nowrap; font-size: .92rem; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); }
.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; flex: none; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn svg { width: 18px; height: 18px; }
.lang-btn { width: auto; min-width: 36px; padding: 0 7px; font: 700 .78rem/1 inherit; font-family: inherit; }
#menuBtn { display: none; }
.nav-group { display: none; }
.nav-sep { width: 1px; background: var(--border); margin: 6px 4px; flex: none; }
.dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.ai-feature {
  display: flex; align-items: center; gap: 20px; padding: 22px; color: var(--text); flex-wrap: wrap;
  border: 2px solid var(--accent); background: linear-gradient(135deg, var(--accent-soft), var(--surface) 70%);
  transition: transform .12s;
}
.ai-feature:hover { text-decoration: none; transform: translateY(-2px); }
.ai-mons { display: flex; gap: 6px; }
.ai-mons .mon:nth-child(2) { animation-delay: .3s; } .ai-mons .mon:nth-child(3) { animation-delay: .6s; }
@media (max-width: 520px) {
  .ai-feature { flex-direction: column; text-align: center; gap: 12px; }
  .ai-feature .btn { width: 100%; }
}
@media (max-width: 900px) {
  #menuBtn { display: grid; margin-left: auto; }
  .nav { display: none; position: absolute; top: 57px; left: 0; right: 0; flex-direction: column; background: var(--surface); border-bottom: 1px solid var(--border); padding: 8px 16px 14px; }
  .nav.open { display: flex; }
  .nav a { padding: 10px; }
  .nav-group { display: block; font-size: .75rem; letter-spacing: .06em; color: var(--muted); padding: 10px 10px 2px; font-weight: 600; }
  .nav-sep { width: auto; height: 1px; margin: 6px 0; }
}

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 22px 16px 40px; }
footer { border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
footer .in { max-width: 1180px; margin: 0 auto; padding: 16px; display: flex; gap: 12px; justify-content: space-between; flex-wrap: wrap; }

/* ---------- primitives ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  padding: 9px 16px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  transition: transform .06s, border-color .15s, background .15s; text-decoration: none !important; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: .88rem; border-radius: 8px; }
.btn.lg { padding: 13px 22px; font-size: 1.05rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: .9rem; color: var(--muted); }
label.field > span { color: var(--text); font-weight: 500; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 500; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.good { color: var(--good); }
.badge.bad { color: var(--bad); }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-weight: 500; color: var(--muted); font-size: .85rem; }
td.num, th.num { text-align: right; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); }

/* ---------- monsters ---------- */
.mon { display: inline-block; image-rendering: pixelated; flex: none; }
.mon svg { display: block; width: 100%; height: 100%; }
.mon.bob { animation: bob 1.6s steps(2) infinite; }
.mon.jump { animation: jump .5s ease-out 3; }
@keyframes bob { 50% { transform: translateY(-3px); } }
@keyframes jump { 40% { transform: translateY(-14px) scale(1.05); } }
@media (prefers-reduced-motion: reduce) { .mon.bob, .mon.jump { animation: none; } }

/* ---------- home ---------- */
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 24px; align-items: center; margin-bottom: 26px; }
.hero h1 { font-family: var(--pixel); font-size: clamp(2.2rem, 6vw, 3.6rem); margin-bottom: 6px; }
.hero h1 .ace { color: var(--accent); }
.hero p { color: var(--muted); font-size: 1.05rem; max-width: 46ch; }
.parade { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; justify-items: center; }
.parade .mon { width: 72px; height: 72px; }
.parade .mon:nth-child(2n) { animation-delay: .4s; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; } .parade .mon { width: 54px; height: 54px; } }
.menu-card { display: flex; gap: 14px; align-items: center; color: var(--text); padding: 16px; transition: transform .12s, border-color .12s; }
.menu-card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent); }
.menu-card .mon { width: 48px; height: 48px; }
.menu-card h3 { margin: 0 0 2px; }
.menu-card p { margin: 0; color: var(--muted); font-size: .88rem; }
.section-title { margin: 26px 0 12px; font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* ---------- board ---------- */
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
@media (max-width: 980px) { .game-layout { grid-template-columns: 1fr; } }
.board-wrap { width: 100%; max-width: min(680px, calc(100vh - 250px)); min-width: min(100%, 320px); margin: 0 auto; }
.board {
  display: grid; grid-template-columns: repeat(15, 1fr); gap: 2px; padding: 6px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; aspect-ratio: 1; user-select: none; box-shadow: var(--shadow);
}
.cell {
  position: relative; background: var(--cell); border-radius: 3px; display: grid; place-items: center; cursor: pointer;
  font-size: clamp(6px, 1.25vw, 9px); color: color-mix(in srgb, var(--text) 60%, transparent); font-weight: 600; line-height: 1; text-align: center; overflow: hidden;
}
.cell.T { background: var(--p-T); } .cell.D { background: var(--p-D); } .cell.t { background: var(--p-t); } .cell.d { background: var(--p-d); }
.cell.star { background: var(--p-star); }
.cell.drop { outline: 2px solid var(--accent); outline-offset: -2px; }
.cell.hl .tile { box-shadow: 0 0 0 2px var(--accent) inset; }
.tile {
  position: absolute; inset: 0; background: var(--tile); border: 1px solid var(--tile-edge); border-bottom-width: 2px; border-radius: 3px; color: var(--tile-text);
  display: grid; place-items: center; font-weight: 700; font-size: clamp(9px, 2.3vw, 17px); font-family: var(--font); line-height: 1;
}
.tile .pt { position: absolute; right: 2px; bottom: 1px; font-size: .48em; font-weight: 600; opacity: .7; }
.tile.blank { color: #8a5cd6; }
.tile.blank .pt { display: none; }
.tile.new { background: var(--tile-new); border-color: var(--tile-new-edge); }
.tile.last { box-shadow: 0 0 0 2px var(--warn) inset; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: 8px; justify-content: center; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }

.rack { display: flex; gap: 6px; justify-content: center; margin-top: 12px; flex-wrap: wrap; min-height: 56px; }
.rtile {
  position: relative; width: 50px; height: 54px; background: var(--tile); border: 1px solid var(--tile-edge); border-bottom-width: 3px; border-radius: 8px;
  color: var(--tile-text); font-weight: 700; font-size: 1.35rem; display: grid; place-items: center; cursor: pointer; transition: transform .08s; touch-action: none;
}
.rtile .pt { position: absolute; right: 4px; bottom: 2px; font-size: .62rem; opacity: .7; }
.rtile.sel { transform: translateY(-6px); outline: 2px solid var(--accent); }
.rtile.used { opacity: .2; pointer-events: none; }
.rtile.mark { outline: 2px dashed var(--bad); }
.rtile.ghost { position: fixed; z-index: 100; pointer-events: none; transform: scale(1.08); box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.lbl-s { display: none; }
.zoom-btn { display: none !important; margin-top: 6px; }
.board-scroll { width: 100%; }
.board, .rack, .controls, .btn, .key, .clock-side { touch-action: manipulation; }
@media (max-width: 520px) {
  .lbl-l { display: none; }
  .lbl-s { display: inline; font-size: 8px; opacity: .85; }
  .zoom-btn { display: inline-flex !important; }
  .board-scroll { overflow: auto; -webkit-overflow-scrolling: touch; border-radius: 12px; }
  .board-scroll.zoomed .board-wrap { width: 640px; max-width: none; }
  .board-scroll.zoomed { max-height: 52vh; border: 1px solid var(--border); }
  .board-scroll.zoomed .lbl-s { font-size: 11px; }
  .board-scroll.zoomed .tile { font-size: 17px; }
  .legend { display: none; }
  main { padding: 14px 10px 30px; }
  .rack { gap: 4px; }
  .rtile { width: 37px; height: 44px; font-size: 1.05rem; }
  .kbd-hint { display: none; }
}
@media (max-width: 980px) {
  .game-layout { display: flex; flex-direction: column; align-items: stretch; }
  .game-layout > .side { display: contents; }
  .game-layout #players, .game-layout #pl { order: -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .game-layout .player { padding: 8px; gap: 8px; }
  .game-layout .player .mon { width: 30px !important; height: 30px !important; }
  .game-layout .player .sc { font-size: 1.3rem; }
}

.controls { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.status-line { text-align: center; min-height: 1.6em; margin-top: 10px; font-size: .92rem; }
.status-line.ok { color: var(--good); } .status-line.err { color: var(--bad); }

.side .card { padding: 14px; }
.player { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.player.turn { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.player .mon { width: 40px; height: 40px; }
.player .nm { font-weight: 600; line-height: 1.2; }
.player .sc { margin-left: auto; font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.player .clk { font-size: .82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.player .clk.neg { color: var(--bad); font-weight: 600; }
.movelog { max-height: 300px; overflow: auto; font-size: .86rem; }
.movelog .mv { display: grid; grid-template-columns: 22px 1fr auto; gap: 6px; padding: 6px 2px; border-bottom: 1px dashed var(--border); cursor: default; }
.movelog .mv:last-child { border-bottom: 0; }
.movelog .eq { font-family: ui-monospace, Consolas, monospace; word-break: break-all; }
.movelog .mv.clickable { cursor: pointer; }
.movelog .mv.cur { background: var(--accent-soft); border-radius: 6px; }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10,10,15,.45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .12s; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 20px; width: min(460px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { margin-bottom: 10px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
.face-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.face-grid .rtile { width: auto; }
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: .92rem; box-shadow: var(--shadow); animation: fade .15s; max-width: 90vw; }
.toast.err { background: var(--bad); color: #fff; }

/* ---------- clock ---------- */
.clock-page { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: grid; grid-template-rows: 1fr auto 1fr; }
.clock-side {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; cursor: pointer; user-select: none; border: 0; font: inherit;
  background: var(--surface-2); color: var(--muted); transition: background .15s;
}
.clock-side.top { transform: rotate(180deg); }
.clock-side.active { background: var(--accent); color: var(--accent-ink); }
.clock-side.neg .time { color: var(--bad); }
.clock-side.active.neg { background: var(--bad); color: #fff; }
.clock-side.active.neg .time { color: #fff; }
.clock-side .time { font-size: clamp(3.5rem, 18vw, 9rem); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; letter-spacing: -.02em; }
.clock-side .who { font-size: 1.1rem; font-weight: 600; }
.clock-side .pen { font-size: 1rem; min-height: 1.4em; }
.clock-bar { display: flex; gap: 8px; justify-content: center; align-items: center; padding: 10px; background: var(--surface); border-block: 1px solid var(--border); flex-wrap: wrap; }
@media (orientation: landscape) and (min-width: 700px) {
  .clock-page { grid-template-rows: none; grid-template-columns: 1fr auto 1fr; }
  .clock-side.top { transform: none; }
  .clock-bar { flex-direction: column; border-block: 0; border-inline: 1px solid var(--border); }
}

/* ---------- recorder ---------- */
.keypad { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 6px; }
.key { position: relative; border: 1px solid var(--tile-edge); border-bottom-width: 3px; background: var(--tile); color: var(--tile-text); border-radius: 8px; padding: 8px 0 10px; font: inherit; font-weight: 700; font-size: 1.05rem; cursor: pointer; }
.key small { position: absolute; right: 4px; bottom: 1px; font-size: .62rem; font-weight: 600; opacity: .65; }
.key .cnt { position: absolute; left: 4px; top: 1px; font-size: .6rem; font-weight: 600; color: var(--muted); }
.key:disabled { opacity: .3; cursor: not-allowed; }
.key.zero .cnt { color: var(--bad); }
.eqline { display: flex; gap: 4px; flex-wrap: wrap; min-height: 48px; padding: 8px; background: var(--surface-2); border-radius: 10px; align-items: center; }
.eqline .rtile { width: 38px; height: 42px; font-size: 1rem; }
.eqline .rtile.onboard { opacity: .45; border-style: dashed; }
.remain { display: grid; grid-template-columns: repeat(auto-fill, minmax(54px, 1fr)); gap: 6px; }
.remain div { text-align: center; border: 1px solid var(--border); border-radius: 8px; padding: 4px 0; background: var(--surface); }
.remain b { display: block; font-size: 1.05rem; }
.remain span { font-size: .78rem; color: var(--muted); }
.remain .zero { opacity: .35; }

/* ---------- referee ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; font: inherit; color: var(--muted); padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.pair { display: grid; grid-template-columns: 40px 1fr 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.pair:last-child { border-bottom: 0; }
.pair .res { font-variant-numeric: tabular-nums; font-weight: 600; }
.pair .win { color: var(--good); }
@media (max-width: 640px) { .pair { grid-template-columns: 30px 1fr; } .pair > :nth-child(3) { grid-column: 2; } .pair > :nth-child(4) { grid-column: 2; } }
.score-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.score-form .side-h { font-weight: 600; margin-bottom: 4px; }
.calc { font-size: .9rem; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; font-variant-numeric: tabular-nums; }
.rank-1 td:first-child, .rank-2 td:first-child, .rank-3 td:first-child { font-weight: 700; }
.medal { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; font-size: .78rem; font-weight: 700; color: #3b2a00; }
.medal.g { background: #ffd34d; } .medal.s { background: #d7dce3; } .medal.b { background: #e7a36b; }

/* ---------- support ---------- */
.support { display: grid; grid-template-columns: 320px 1fr; gap: 24px; align-items: start; }
.support img { width: 100%; border-radius: 16px; border: 1px solid var(--border); background: #fff; }
@media (max-width: 760px) { .support { grid-template-columns: 1fr; } .support img { max-width: 340px; margin: 0 auto; display: block; } }

/* ---------- replay ---------- */
.replay-bar { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.replay-bar input[type=range] { flex: 1; padding: 0; }

@media print {
  .topbar, footer, .no-print, .tabs { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border: 0; padding: 0; }
  main { padding: 0; max-width: none; }
}

/* =================== GAME MODE =================== */
.wallet { display: flex; gap: 6px; flex: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); font-weight: 600; font-size: .85rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chip:hover { text-decoration: none; border-color: var(--accent); }
@media (max-width: 520px) { .chip { padding: 3px 8px; font-size: .78rem; } }
button.chip { font: inherit; font-weight: 600; font-size: .85rem; cursor: pointer; }
@media (max-width: 520px) { button.chip { font-size: .78rem; } .wallet { gap: 4px; } }
@media (max-width: 430px) {
  .topbar .brand .logo { display: none; }   /* phones: monster icon only, wallet needs the room */
  .chip, button.chip { padding: 3px 7px; font-size: .74rem; gap: 2px; }
  .wallet { margin-left: auto; }
}
.tabs a { color: var(--muted); padding: 9px 14px; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
tr.me-row td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.energy-bar { margin-bottom: 12px; padding: 12px 14px; }
.energy-bar .lpbar { max-width: none; margin-top: 8px; }
/* challenge checker */
.eq-input { font-size: 1.4rem; font-family: var(--mono, ui-monospace, monospace); letter-spacing: .04em; text-align: center; }
.eq-tiles { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; min-height: 48px; }
.eq-tiles .rtile { width: 38px; height: 42px; font-size: 1rem; }
.keypad { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.keypad button { padding: 10px 0; font-size: 1.05rem; font-weight: 600; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.keypad button.op { background: var(--surface-2); }
.keypad button.wide { grid-column: span 2; }
.verdict { padding: 16px; border-radius: 14px; text-align: center; }
.verdict.ok { background: color-mix(in srgb, var(--good) 14%, transparent); border: 1px solid var(--good); }
.verdict.bad { background: color-mix(in srgb, var(--bad) 12%, transparent); border: 1px solid var(--bad); }
.verdict h2 { margin: 0 0 4px; }
.rules-list li { margin-bottom: 6px; }

/* avatar + rank glow under the feet */
.avatar { position: relative; display: inline-block; flex: none; vertical-align: middle; }
.avatar .sprite { position: absolute; inset: 0; z-index: 1; image-rendering: pixelated; }
.avatar .sprite svg, .avatar .sprite img, .avatar .sprite canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.mon img { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
/* breathing is drawn on the canvas (avatar.js) */
.avatar .glow { position: absolute; left: 14%; right: 14%; bottom: 0; height: 16%; border-radius: 50%; z-index: 0;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--gc) 85%, transparent), transparent); opacity: .55; }
.avatar .glow.g0, .avatar .glow.g1 { opacity: .35; }
.avatar .glow.g3, .avatar .glow.g4, .avatar .glow.g5 { opacity: .8; animation: glowPulse 2s ease-in-out infinite; }
.avatar .glow.g6, .avatar .glow.g7, .avatar .glow.g8 { opacity: .95; left: 4%; right: 4%; height: 22%; animation: glowPulse 1.4s ease-in-out infinite;
  box-shadow: 0 0 18px 4px color-mix(in srgb, var(--gc) 50%, transparent); }
.avatar .glow.g7::after, .avatar .glow.g8::after, .avatar .glow.g9::after { content: ''; position: absolute; left: 15%; right: 15%; bottom: 60%; height: 260%;
  background: linear-gradient(to top, color-mix(in srgb, var(--gc) 45%, transparent), transparent); border-radius: 40% 40% 0 0; animation: glowPulse 1.4s ease-in-out infinite; }
.avatar .glow.g9 { opacity: 1; left: 0; right: 0; height: 24%; background: conic-gradient(from 0deg, #ff5d5d, #ffd34d, #6fd38a, #5fd3e6, #9b6cf0, #ff5d5d);
  filter: blur(4px); animation: spinHue 2.5s linear infinite; }
@keyframes glowPulse { 50% { transform: scale(1.12); filter: brightness(1.25); } }
@keyframes spinHue { to { filter: blur(4px) hue-rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .avatar .glow, .avatar.bob .sprite { animation: none !important; } }
.rank-badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--rc); background: color-mix(in srgb, var(--rc) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--rc) 45%, transparent); padding: 3px 10px; border-radius: 999px; font-size: .9rem; white-space: nowrap; }
.rank-badge i { width: 10px; height: 10px; background: var(--rc); transform: rotate(45deg); border-radius: 2px; }
.rank-badge.sm { font-size: .72rem; padding: 1px 7px; }
.lpbar { height: 8px; width: 100%; max-width: 260px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 0 auto; }
.lpbar i { display: block; height: 100%; border-radius: 99px; }

/* login */
.login { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; padding-top: 10px; }
.login h1 { font-size: clamp(2.4rem, 10vw, 3.6rem); margin: 0; }
.login h1 .ace { color: var(--accent); }
.parade.small { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.fb-btn { background: #1877f2; color: #fff; border-color: #1877f2; border-radius: 999px; }

/* lobby */
.lobby-hero { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; background: linear-gradient(135deg, var(--accent-soft), var(--surface) 65%); }
.lobby-av { flex: none; }
.lobby-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.lobby-tile { display: flex; gap: 12px; align-items: center; color: var(--text); padding: 16px; transition: transform .12s, border-color .12s; }
.lobby-tile:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent); }
.lobby-tile h3 { margin: 0 0 2px; } .lobby-tile p { margin: 0; color: var(--muted); font-size: .86rem; }
.lt-icon { font-size: 2rem; width: 48px; text-align: center; flex: none; }
.lobby-tile.big { grid-column: span 2; padding: 22px; }
.lobby-tile.big .lt-icon { font-size: 2.6rem; }
.lobby-tile.a { background: linear-gradient(135deg, color-mix(in srgb, #6fd38a 22%, var(--surface)), var(--surface)); }
.lobby-tile.b { background: linear-gradient(135deg, color-mix(in srgb, #f2c14e 25%, var(--surface)), var(--surface)); }
@media (max-width: 520px) {
  .lobby-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .lobby-tile { flex-direction: column; text-align: center; padding: 12px 8px; gap: 4px; }
  .lobby-tile.big { flex-direction: row; text-align: left; }
  .lobby-tile h3 { font-size: .98rem; } .lobby-tile p { font-size: .76rem; }
  .lobby-hero { justify-content: center; text-align: center; } .lobby-hero .row { justify-content: center; }
}

/* adventure */
.chap-seg { overflow-x: auto; flex-wrap: nowrap; max-width: 100%; }
.chap-seg button { white-space: nowrap; }
/* adventure: winding road map */
.zone-chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; }
.zone-chips::-webkit-scrollbar { display: none; }
.zone-chips button { flex: none; border: 2px solid var(--road); background: var(--surface); color: var(--text); border-radius: 999px; padding: 5px 12px; font: inherit; font-size: .82rem; cursor: pointer; white-space: nowrap; }
.zone-chips button b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--road); color: #fff; font-size: .72rem; margin-right: 4px; }
.zone-chips button.on { background: var(--road); color: #fff; font-weight: 700; }
.zone-chips button.on b { background: #fff; color: var(--road); }
.zone-chips button.lock { opacity: .55; }
.saga { position: relative; width: 100%; max-width: 520px; margin: 0 auto; border-radius: 22px; overflow: hidden;
  background: radial-gradient(circle at 15% 20%, #ffffff88 0 40px, transparent 41px), radial-gradient(circle at 80% 45%, #ffffff66 0 60px, transparent 61px),
    radial-gradient(circle at 30% 75%, #ffffff55 0 50px, transparent 51px), linear-gradient(180deg, var(--sky) 0%, var(--ground) 100%);
  box-shadow: inset 0 0 0 3px color-mix(in srgb, var(--road) 35%, transparent), 0 8px 24px #0002; }
.saga svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.saga path { fill: none; vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round; }
.saga .road-edge { stroke: color-mix(in srgb, var(--road) 70%, #000); stroke-width: 30; opacity: .35; }
.saga .road { stroke: #fff8ec; stroke-width: 24; }
.saga .road-done { stroke: var(--road); stroke-width: 24; opacity: .55; }
.saga .road-dash { stroke: #fff; stroke-width: 4; stroke-dasharray: 2 14; opacity: .95; }
.sdeco { position: absolute; transform: translate(-50%, -50%); font-size: 28px; pointer-events: none; filter: drop-shadow(0 3px 2px #0002); }
.sdeco.big { font-size: 56px; }
.snode { position: absolute; transform: translate(-50%, -50%); width: 56px; height: 56px; border-radius: 50%; border: 4px solid #fff; cursor: pointer; padding: 0;
  font: inherit; color: #fff; display: grid; place-items: center; z-index: 2;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--road) 55%, #fff) 0 22%, var(--road) 60%, color-mix(in srgb, var(--road) 70%, #000) 100%);
  box-shadow: 0 5px 0 color-mix(in srgb, var(--road) 55%, #000), 0 8px 14px #0003; }
.snode b { font-size: 1.15rem; text-shadow: 0 2px 0 #0004; }
.snode:active { transform: translate(-50%, -46%); box-shadow: 0 2px 0 color-mix(in srgb, var(--road) 55%, #000); }
.snode.locked { background: radial-gradient(circle at 35% 30%, #e9e9ef 0 22%, #b9bac6 60%, #8d8e9c 100%); box-shadow: 0 5px 0 #6f7080, 0 6px 10px #0002; cursor: not-allowed; }
.snode.locked b { font-size: .95rem; text-shadow: none; }
.snode.cur { width: 64px; height: 64px; background: radial-gradient(circle at 35% 30%, #fff6c2 0 22%, #ffc93c 60%, #e39a1c 100%); box-shadow: 0 5px 0 #b97300, 0 0 0 8px #ffffff99, 0 0 24px 8px #ffd34d; animation: nodePulse 1.4s ease-in-out infinite; }
.snode.cur b { color: #7a4a00; text-shadow: 0 1px 0 #fff8; }
.snode.boss { width: 70px; height: 70px; border-width: 5px; }
.snode.boss.done, .snode.boss.locked { box-shadow: 0 6px 0 #0005, 0 0 0 6px #ffffff66, 0 10px 16px #0003; }
.scrown { position: absolute; top: -20px; font-size: 22px; filter: drop-shadow(0 2px 1px #0003); }
.sboss { position: absolute; right: -40px; top: -12px; }
.sme { position: absolute; bottom: 52px; left: 50%; transform: translateX(-50%); pointer-events: none; }
.sstars { position: absolute; bottom: -16px; display: flex; gap: 0; font-size: 14px; line-height: 1; }
.sstars i { font-style: normal; color: #ffffffcc; -webkit-text-stroke: 1px #0003; }
.sstars i.on { color: #ffcf1f; -webkit-text-stroke: 1px #b97300; }
.sstars i:nth-child(2) { transform: translateY(4px); }
.zone-sign { position: absolute; left: 50%; transform: translateX(-50%); z-index: 3; text-align: center; }
.zone-sign.top { top: 18px; }
.zone-sign.bottom { bottom: 14px; white-space: nowrap; display: flex; flex-direction: column; align-items: center; gap: 4px; background: #ffffffd9; color: #2a2a35; border: 3px solid var(--road); border-radius: 16px; padding: 6px 16px; box-shadow: 0 4px 0 color-mix(in srgb, var(--road) 60%, #000); }
.zone-sign.bottom span { font-size: .78rem; color: #555; }
.zone-sign .btn { box-shadow: 0 3px 0 #0002; }
@keyframes nodePulse { 50% { box-shadow: 0 5px 0 #b97300, 0 0 0 12px #ffffff66, 0 0 34px 12px #ffd34d; } }
@media (prefers-reduced-motion: reduce) { .snode.cur { animation: none; } }
.stage-map { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.stage-node { position: relative; aspect-ratio: 1; border-radius: 14px; border: 2px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; box-shadow: var(--shadow); }
.stage-node b { font-size: 1.15rem; }
.stage-node .stars { font-size: .7rem; color: #f2b01e; letter-spacing: -1px; } .stage-node .stars i { color: var(--border); font-style: normal; }
.stage-node.current { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); animation: bob 1.6s steps(2) infinite; }
.stage-node.boss { background: linear-gradient(160deg, color-mix(in srgb, #ef5d5d 20%, var(--surface)), var(--surface)); border-color: color-mix(in srgb, #ef5d5d 50%, var(--border)); }
.stage-node .bossicon { position: absolute; top: -9px; font-size: .9rem; }
.stage-node.locked { opacity: .45; cursor: not-allowed; box-shadow: none; }
.stage-info { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; font-size: .92rem; background: var(--surface-2); padding: 12px; border-radius: 12px; }
.big-stars { font-size: 2.4rem; color: #f2b01e; letter-spacing: 4px; } .big-stars i { color: var(--border); font-style: normal; }

/* special cells */
.rock { position: absolute; inset: 8%; border-radius: 30% 40% 35% 30%; background: radial-gradient(circle at 35% 30%, #a3a3a8, #6b6b72 60%, #4a4a50);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.3); }
.special { font-size: clamp(10px, 3.2vw, 18px); line-height: 1; animation: bob 1.8s steps(2) infinite; }
.board.small-board .tile { font-size: clamp(13px, 4.6vw, 26px); }
.board.small-board .cell { font-size: clamp(8px, 2.2vw, 12px); }
.board.small-board .lbl-s { font-size: clamp(9px, 2.6vw, 13px); }
.items-bar { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; align-items: center; margin-top: 8px; }
.item-chip { position: relative; border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 6px 10px; font: inherit; cursor: pointer; display: flex; align-items: center; gap: 4px; }
.item-chip span { font-size: 1.05rem; font-weight: 700; }
.item-chip small { background: var(--accent); color: var(--accent-ink); border-radius: 99px; padding: 0 6px; font-size: .7rem; font-weight: 700; }
.item-chip:disabled { opacity: .35; cursor: not-allowed; }
.item-chip.armed { border-color: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 30%, transparent); }

/* wardrobe & shop */
.wardrobe { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.preview-card { position: sticky; top: 74px; }
@media (max-width: 760px) { .wardrobe { grid-template-columns: 1fr; } .preview-card { position: static; } }
.mon-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.mon-btn { flex-direction: column; padding: 8px 4px; gap: 2px; white-space: normal; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--border); cursor: pointer; }
.swatch.on { outline: 3px solid var(--accent); outline-offset: 2px; }
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.item-card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); font: inherit; color: var(--text); cursor: pointer; text-align: center; }
.item-card.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.item-card .ic { font-size: 1.8rem; height: 64px; display: grid; place-items: center; color: var(--muted); }
.tier { font-size: .68rem; font-weight: 700; padding: 0 7px; border-radius: 99px; }
.t-c { background: var(--surface-2); color: var(--muted); } .t-r { background: #dbeafe; color: #1d4ed8; }
.t-e { background: #ede4ff; color: #6d28d9; } .t-l { background: #fff1c2; color: #a16207; }
.tryon { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; position: sticky; top: 64px; z-index: 5; padding: 10px 16px; }
.item-icon { font-size: 1.6rem; width: 52px; height: 52px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; flex: none; font-weight: 700; }
@media (max-width: 520px) { .item-grid { grid-template-columns: repeat(3, 1fr); } .shop-grid .item-card .avatar { width: 60px !important; height: 60px !important; } }

/* stickers / chat */
.chat-log { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; margin: 6px 0; max-height: 140px; overflow: auto; }
.chat-log .me { color: var(--accent); }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 4px; }
.sticker { font-size: 1.4rem; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 4px 0; cursor: pointer; }
.sticker:hover { border-color: var(--accent); transform: scale(1.08); }
.chat-pop { position: fixed; top: 80px; left: 50%; transform: translateX(-50%); z-index: 70; background: var(--surface); border: 2px solid var(--accent); border-radius: 18px;
  padding: 10px 18px; font-weight: 700; box-shadow: 0 10px 30px rgba(0,0,0,.25); display: flex; align-items: center; gap: 8px; animation: popIn .25s ease-out; }
.chat-pop span { font-size: 2rem; }
.chat-pop.mine { top: auto; bottom: 120px; border-color: var(--good); }
@keyframes popIn { from { transform: translateX(-50%) scale(.6); opacity: 0; } }
.spinner { width: 18px; height: 18px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.rank-card { align-items: center; }

/* live card: players online + top 3 */
.live-card { padding: 14px 16px; }
.live-card .lv-top { display: flex; align-items: center; gap: 10px; }
.live-card .lv-n { font-size: 1.9rem; line-height: 1; color: #22c55e; }
.live-card .lv-dot { width: 10px; height: 10px; border-radius: 50%; background: #22c55e; animation: lvpulse 1.6s infinite; flex: none; }
.live-card .lv-dot.off { background: var(--muted); animation: none; }
@keyframes lvpulse { 0% { box-shadow: 0 0 0 0 #22c55e88; } 70% { box-shadow: 0 0 0 8px #22c55e00; } 100% { box-shadow: 0 0 0 0 #22c55e00; } }
.live-card .lv-tabs { display: flex; gap: 6px; margin: 12px 0 6px; }
.live-card .lv-tabs button { flex: 1; border: 1px solid var(--border); background: transparent; color: var(--muted); border-radius: 999px; padding: 4px 0; font: inherit; font-size: .85rem; cursor: pointer; }
.live-card .lv-tabs button.on { background: var(--accent, #7c6cf0); border-color: transparent; color: #fff; font-weight: 600; }
.live-card .lv-list { list-style: none; margin: 0 0 8px; padding: 0; }
.live-card .lv-list li { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--border); }
.live-card .lv-list li b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-card .lv-m { width: 24px; text-align: center; }
.live-card .lv-v { font-size: .85rem; font-weight: 600; white-space: nowrap; }

/* =================== FANTASY PASTEL PIXEL THEME (2026 redesign) ===================
 * Frames and buttons are pixel-stepped boxes drawn with box-shadows (no images);
 * icons and scene backgrounds are PixelLab art in art/icons and art/bg. */
:root {
  --bg: #f7f1ff; --surface: #fffaf3; --surface-2: #f1e9ff; --text: #3a2f5b; --muted: #7b6f99; --border: #dccff5;
  --accent: #8a6cf0; --accent-ink: #ffffff; --accent-soft: #ece4ff;
  --ink: #4b3a7a; --frame-shade: #eadffc; --frame-light: #ffffff;
  --tile: #fffaf0; --tile-edge: #c9b6ef; --tile-text: #5b3fb0;
  --cell: #e6f6ee; --p-T: #ffd6de; --p-D: #ffe5c9; --p-t: #eadcff; --p-d: #d6ecff; --p-star: #fff1b8;
  --shadow: none; --radius: 0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1730; --surface: #2a2346; --surface-2: #342c56; --text: #f1ebff; --muted: #b3a8d6; --border: #463b70;
    --accent: #b49cff; --accent-ink: #1c1730; --accent-soft: #3b3166;
    --ink: #0f0b1e; --frame-shade: #231d3d; --frame-light: #3d3463;
    --tile: #fff4dc; --tile-edge: #b9a4e6; --tile-text: #4b2fa0;
    --cell: #2f3a3e; --p-T: #6b3a4c; --p-D: #6b5233; --p-t: #4b3b78; --p-d: #2f4f72; --p-star: #6e6230;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1730; --surface: #2a2346; --surface-2: #342c56; --text: #f1ebff; --muted: #b3a8d6; --border: #463b70;
  --accent: #b49cff; --accent-ink: #1c1730; --accent-soft: #3b3166;
  --ink: #0f0b1e; --frame-shade: #231d3d; --frame-light: #3d3463;
  --tile: #fff4dc; --tile-edge: #b9a4e6; --tile-text: #4b2fa0;
  --cell: #2f3a3e; --p-T: #6b3a4c; --p-D: #6b5233; --p-t: #4b3b78; --p-d: #2f4f72; --p-star: #6e6230;
}
body {
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 86%, transparent), color-mix(in srgb, var(--bg) 94%, transparent)),
    url(../art/bg/lobby.png) center top / cover fixed;
  image-rendering: auto;
}
.topbar { background: color-mix(in srgb, var(--surface) 90%, transparent); border-bottom: 4px solid var(--ink); }
.brand { color: var(--text); }
img.ico { image-rendering: pixelated; vertical-align: middle; flex: none; }

/* pixel frame: 4px ink outline with stepped corners, light top edge, shaded bottom edge */
.card, .player, .stage-info, .chip, .seg, .badge, input, select, textarea, .rtile, .key, .item-card {
  border: 0 !important; border-radius: 0 !important;
}
.card, .player, .stage-info, .item-card {
  margin: 4px; box-shadow: 0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink),
    inset 0 -4px 0 0 var(--frame-shade), inset 0 4px 0 0 var(--frame-light);
}
.player.turn { box-shadow: 0 -4px 0 0 var(--accent), 0 4px 0 0 var(--accent), -4px 0 0 0 var(--accent), 4px 0 0 0 var(--accent),
    inset 0 -4px 0 0 var(--frame-shade), inset 0 4px 0 0 var(--frame-light), 0 0 0 8px var(--accent-soft); }
.chip, .seg, input, select, textarea, .badge {
  margin: 3px; box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 -3px 0 0 var(--frame-shade);
}
.badge { box-shadow: 0 -2px 0 0 var(--border), 0 2px 0 0 var(--border), -2px 0 0 0 var(--border), 2px 0 0 0 var(--border); }
input:focus, select:focus, textarea:focus { outline: none; box-shadow: 0 -3px 0 0 var(--accent), 0 3px 0 0 var(--accent), -3px 0 0 0 var(--accent), 3px 0 0 0 var(--accent); }
.seg button { border-radius: 0; } .seg button.on { box-shadow: inset 0 -3px 0 0 var(--frame-shade); background: var(--surface); }

/* buttons: chunky pixel buttons with a pressed state */
.btn {
  --b: var(--surface); --bd: var(--frame-shade); --bl: var(--frame-light);
  border: 0 !important; border-radius: 0 !important; margin: 4px; font-weight: 700; background: var(--b);
  box-shadow: 0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink), inset 0 -4px 0 0 var(--bd), inset 0 3px 0 0 var(--bl);
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(2px); box-shadow: 0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink), inset 0 -1px 0 0 var(--bd), inset 0 3px 0 0 var(--bl); }
.btn.primary { --b: #ff8fc0; --bd: #d9609b; --bl: #ffc4de; color: #fff; text-shadow: 0 2px 0 #d9609b; }
.btn.on { --b: var(--accent-soft); }
.btn.ghost { --b: transparent; --bd: transparent; --bl: transparent; box-shadow: none; }
.btn.danger { --b: #ffe1e1; --bd: #f0b3b3; color: #c43b3b; }
.btn.sm { margin: 3px; }
.btn img.ico { width: 20px; height: 20px; }
.icon-btn { border: 0; border-radius: 0; box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 -3px 0 0 var(--frame-shade); }
.chip img.ico { width: 20px; height: 20px; margin-left: -4px; }

/* lobby: floating-island scene behind the hero, pixel icon tiles */
.lobby-hero { background: linear-gradient(90deg, color-mix(in srgb, var(--surface) 94%, transparent) 0 55%, color-mix(in srgb, var(--surface) 40%, transparent)),
  url(../art/bg/lobby.png) center / cover; image-rendering: pixelated; }
.lobby-tile .lt-icon img { width: 48px; height: 48px; image-rendering: pixelated; display: block; margin: 0 auto; }
.lobby-tile:hover { transform: translateY(-2px); }
.lobby-tile.a { background: color-mix(in srgb, #ffd3e8 45%, var(--surface)); }
.lobby-tile.b { background: color-mix(in srgb, #ffe6a3 45%, var(--surface)); }
.rank-card { background: linear-gradient(180deg, color-mix(in srgb, var(--surface) 30%, transparent), color-mix(in srgb, var(--surface) 92%, transparent) 70%),
  url(../art/bg/arena.png) center top / cover; image-rendering: pixelated; }

/* board: magic-classroom backdrop, pastel stone cells, gem marks on premium squares */
.board { border: 0; border-radius: 0; background: #b9a4e6;
  box-shadow: 0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink); }
.cell { border-radius: 0; box-shadow: inset -2px -2px 0 0 #0000001a, inset 2px 2px 0 0 #ffffff80; }
.cell.T, .cell.D, .cell.t, .cell.d, .cell.star { background-repeat: no-repeat; background-position: center; background-size: 70%; image-rendering: pixelated; }
.cell.T { background-image: url(../art/icons/gem-ruby.png); background-color: var(--p-T); }
.cell.D { background-image: url(../art/icons/gem-topaz.png); background-color: var(--p-D); }
.cell.t { background-image: url(../art/icons/gem-amethyst.png); background-color: var(--p-t); }
.cell.d { background-image: url(../art/icons/gem-sapphire.png); background-color: var(--p-d); }
.cell.star { background-image: url(../art/icons/star.png); background-color: var(--p-star); }
.cell .lbl-l, .cell .lbl-s { position: relative; z-index: 1; color: #3a2f5b; text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 3px #fff; }
.tile { border: 0; border-radius: 0; box-shadow: inset 0 -3px 0 0 var(--tile-edge), inset 0 2px 0 0 #fff, 0 0 0 1px #4b3a7a55; }
.rtile { box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset 0 -4px 0 0 var(--tile-edge), inset 0 3px 0 0 #fff; margin: 3px; }
.rtile.sel { outline: none; box-shadow: 0 -3px 0 0 var(--accent), 0 3px 0 0 var(--accent), -3px 0 0 0 var(--accent), 3px 0 0 0 var(--accent), inset 0 -4px 0 0 var(--tile-edge), inset 0 3px 0 0 #fff; }
.game-layout { background: linear-gradient(color-mix(in srgb, var(--bg) 55%, transparent), color-mix(in srgb, var(--bg) 55%, transparent)),
  url(../art/bg/game.png) center / cover; image-rendering: pixelated; padding: 14px; }
.game-layout > * { image-rendering: auto; }
footer { border-top: 4px solid var(--ink); background: color-mix(in srgb, var(--surface) 85%, transparent); }
.legend { background: color-mix(in srgb, var(--surface) 88%, transparent); padding: 4px 10px; width: fit-content; margin-left: auto; margin-right: auto; }
@media (max-width: 520px) {
  .topbar-in { gap: 8px; padding: 8px 10px; }
  .wallet { gap: 2px; }
  .chip, button.chip { margin: 3px 2px; }
  .icon-btn { width: 32px; height: 32px; }
  .chip img.ico { width: 16px; height: 16px; margin-left: -2px; }
}
/* tile skin previews (shop / wardrobe) */
.tile-prev { display: inline-flex; gap: 2px; justify-content: center; padding: 6px 0; }
.tile-prev .rtile { width: 28px; height: 32px; font-size: .95rem; margin: 3px; cursor: inherit; }
.tile-prev .rtile .pt { font-size: .5rem; right: 2px; bottom: 1px; }
.tile-prev.big .rtile { width: 46px; height: 52px; font-size: 1.4rem; }
.tile-prev.big .rtile .pt { font-size: .62rem; }

/* ---- game screen: players beside the board (me left, opponent right), big monsters ---- */
.game-layout.duel { display: grid; grid-template-columns: 190px minmax(0, 1fr) 250px; grid-template-areas: "pl main side"; gap: 16px; align-items: start; }
.game-layout.duel > .seat-l { grid-area: pl; }
.game-layout.duel > .main { grid-area: main; min-width: 0; }
.game-layout.duel > .side { grid-area: side; display: flex; }
.player.big { flex-direction: column; text-align: center; gap: 6px; padding: 12px 10px 14px; }
.player.big .pav { display: grid; place-items: center; }
.player.big .avatar { width: 140px !important; height: 140px !important; }
.player.big .pinfo { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.player.big .nm { font-size: 1.05rem; }
.player.big .clk { font-size: 1rem; font-weight: 600; }
.player.big .sc { margin: 2px 0 0; font-size: 2.2rem; line-height: 1; }
.seat-l .player.big, .seat-r .player.big { position: sticky; top: 74px; }
/* narrower screens: both players side by side above the board */
@media (max-width: 1100px) and (orientation: portrait) {
  .game-layout.duel { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "pl pr" "main main"; gap: 10px; }
  .game-layout.duel > .side { display: contents; }
  .game-layout.duel > .side > .seat-r { grid-area: pr; }
  .game-layout.duel > .side > :not(.seat-r) { grid-column: 1 / -1; }
  .seat-l .player.big, .seat-r .player.big { position: static; }
  .player.big { flex-direction: row; text-align: left; padding: 8px 10px; gap: 8px; margin: 4px; }
  .player.big .avatar { width: 84px !important; height: 84px !important; }
  .player.big .pinfo { align-items: flex-start; min-width: 0; }
  .player.big .sc { margin-left: auto; font-size: 1.6rem; }
}
@media (max-width: 520px) {
  .player.big { flex-direction: column; text-align: center; padding: 6px 6px 8px; gap: 2px; }
  .player.big .avatar { width: 72px !important; height: 72px !important; }
  .player.big .pinfo { align-items: center; }
  .player.big .nm { font-size: .9rem; }
  .player.big .sc { margin: 0; font-size: 1.4rem; }
  .player.big .rank-badge { display: none; }
}

/* ---- landscape: tablets keep players beside the board, just narrower ---- */
@media (max-width: 1100px) and (orientation: landscape) {
  .game-layout.duel { grid-template-columns: 150px minmax(0, 1fr) 220px; gap: 10px; padding: 10px; }
  .player.big .avatar { width: 110px !important; height: 110px !important; }
  .player.big .sc { font-size: 1.8rem; }
}
/* ---- landscape phones (short screens): board fits the height, players stacked on the left,
        status + rack + buttons + bag + log on the right, close to the thumbs ---- */
@media (orientation: landscape) and (max-height: 620px) {
  .topbar { position: static; }
  .topbar-in { padding: 4px 10px; }
  main { padding: 6px 8px 16px; }
  .game-layout.duel { grid-template-columns: minmax(118px, 1fr) auto minmax(210px, 1.5fr); grid-template-areas: none; gap: 6px 10px; padding: 6px; align-items: start; }
  .game-layout.duel > .main, .game-layout.duel > .side { display: contents; }
  .game-layout.duel > .seat-l { grid-column: 1; grid-row: 1 / span 3; }
  .game-layout.duel .seat-r { grid-column: 1; grid-row: 4 / span 4; }
  .game-layout.duel #bs { grid-column: 2; grid-row: 1 / span 7; }
  .game-layout.duel > .main > :not(#bs), .game-layout.duel > .side > :not(.seat-r) { grid-column: 3; }
  .game-layout.duel #zoomRow, .game-layout.duel .legend { display: none !important; }
  .game-layout.duel .board-wrap { width: min(calc(100dvh - 24px), 50vw); max-width: none; min-width: 0; margin: 0; }
  .game-layout.duel .status-line { margin-top: 0; font-size: .82rem; text-align: left; }
  .game-layout.duel .rack { justify-content: flex-start; gap: 2px; margin-top: 0; min-height: 0; }
  .game-layout.duel .rtile { width: 34px; height: 40px; font-size: 1rem; margin: 3px 2px; }
  .game-layout.duel .controls { justify-content: flex-start; margin-top: 2px; gap: 2px; }
  .game-layout.duel .controls .btn { padding: 6px 9px; font-size: .82rem; margin: 3px; }
  .game-layout.duel .movelog { max-height: 120px; }
  .player.big { flex-direction: column; text-align: center; padding: 6px 4px 8px; gap: 2px; }
  .player.big .avatar { width: 64px !important; height: 64px !important; }
  .player.big .pinfo { align-items: center; }
  .player.big .nm { font-size: .85rem; }
  .player.big .clk { font-size: .85rem; }
  .player.big .sc { margin: 0; font-size: 1.3rem; }
  .player.big .rank-badge, .player.big .pinfo .small { display: none; }
  .seat-l .player.big, .seat-r .player.big { position: static; }
}
@media (orientation: landscape) and (max-height: 620px) {
  .game-layout.duel .lbl-l { display: none; }
  .game-layout.duel .lbl-s { display: inline; font-size: 7px; }
}
/* keep board + rack + buttons on one screen: board height leaves room for the rack and the buttons */
.game-layout.duel .board-wrap { max-width: min(680px, calc(100dvh - 320px)); min-width: min(100%, 300px); }
@media (orientation: landscape) and (max-height: 620px) {
  .game-layout.duel .board-wrap { width: min(calc(100dvh - 24px), 50vw); max-width: none; min-width: 0; }
}
@media (max-width: 1100px) and (orientation: portrait) {
  .game-layout.duel .board-wrap { max-width: min(680px, calc(100dvh - 420px)); }
}
/* phones in portrait: compact one-row player cards so the rack and buttons stay on screen */
@media (max-width: 520px) and (orientation: portrait) {
  .player.big { flex-direction: row; text-align: left; padding: 4px 6px; gap: 4px; align-items: center; }
  .player.big .avatar { width: 56px !important; height: 56px !important; }
  .player.big .pinfo { align-items: flex-start; min-width: 0; }
  .player.big .nm { font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .player.big .nm .badge { display: none; }
  .player.big .clk { font-size: .8rem; }
  .player.big .pinfo .small { display: none; }
  .player.big .sc { margin-left: auto; font-size: 1.25rem; }
  .player.big.turn { box-shadow: 0 -3px 0 0 var(--accent), 0 3px 0 0 var(--accent), -3px 0 0 0 var(--accent), 3px 0 0 0 var(--accent), inset 0 -3px 0 0 var(--frame-shade); }
}

/* ---- Equamon Arena wordmark ---- */
.logo { display: inline-flex; flex-direction: column; align-items: flex-start; line-height: 1; font-family: var(--pixel); }
.logo .lg-main { display: inline-flex; gap: .28em; align-items: baseline; font-size: 1em; letter-spacing: .01em; white-space: nowrap; }
.logo b { font-weight: 600; }
.logo .lg-eq { color: #8a6cf0; text-shadow: .06em .06em 0 #4b3a7a, -.03em -.03em 0 #fff; }
.logo .lg-ar { color: #ffc94d; text-shadow: .06em .06em 0 #b07400, .06em .06em 0 #4b3a7a, -.03em -.03em 0 #fff; -webkit-text-stroke: .015em #b07400; }
.logo .lg-by { font-family: var(--font); font-size: .34em; font-weight: 600; color: var(--muted); letter-spacing: .04em; margin-top: .25em; margin-left: .1em; }
.logo.sm { font-size: 1.25rem; }
.logo.sm .lg-by { font-size: .5em; margin-top: .1em; }
.brand { gap: 6px; }
#brandLogo { display: inline-flex; align-items: center; gap: 6px; }
h1 .logo { font-size: clamp(2.2rem, 7vw, 3.6rem); }
@media (max-width: 430px) { .topbar .logo .lg-by { display: none; } .topbar .logo.sm { font-size: 1.05rem; } }
:root[data-theme="dark"] .logo .lg-eq { color: #b49cff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo .lg-eq { color: #b49cff; } }
