:root {
  --bg: #0f1424;
  --bg2: #161d33;
  --panel: #1b2340;
  --panel2: #222b4d;
  --line: #2c3660;
  --text: #eef1fb;
  --muted: #98a2c6;
  --accent: #ffc94a;
  --accent-ink: #1a1400;
  --good: #33d17a;
  --bad: #ff5d5d;
  --warn: #ffb347;
  --cell: #2b3562;
  --cell-hl: #3a4785;
  --frame: #121831;
  --logo-bg: #1b2340;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font: system-ui, -apple-system, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', Roboto, sans-serif;
  --me: var(--accent);
  color-scheme: dark;
}
[data-theme='light'] {
  --bg: #f4efe6;
  --bg2: #ebe4d6;
  --panel: #fffaf2;
  --panel2: #f3ecdf;
  --line: #ddd2bf;
  --text: #2a2418;
  --muted: #7d7360;
  --accent: #e8a316;
  --accent-ink: #fff;
  --cell: #d9b98a;
  --cell-hl: #ecd3a8;
  --frame: #8a5a2b;
  --logo-bg: #8a5a2b;
  --shadow: 0 8px 26px rgba(80, 60, 20, 0.18);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { line-height: 1.6; margin: 0.4em 0; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }
.boot { display: grid; place-items: center; height: 100dvh; font-weight: 900; letter-spacing: 0.2em; color: var(--muted); }

.screen { min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35em;
  min-height: 44px; padding: 0 1.1em; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel2); cursor: pointer; text-decoration: none; font-weight: 600; white-space: nowrap;
  transition: transform 0.08s, background 0.15s, opacity 0.15s; touch-action: manipulation;
}
.btn:hover { background: var(--cell-hl); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 38px; padding: 0 0.8em; font-size: 0.9rem; border-radius: 10px; }
.btn.big { min-height: 54px; font-size: 1.08rem; width: 100%; margin-top: 18px; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; font-size: 1.6rem; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--panel2); }
.icon-btn.spacer { visibility: hidden; }
.chip { white-space: nowrap; display: inline-flex; align-items: center; gap: 0.2em; padding: 0.45em 0.8em; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); text-decoration: none; font-size: 0.9rem; }

.seg { display: inline-flex; background: var(--panel2); border-radius: 12px; padding: 3px; gap: 3px; border: 1px solid var(--line); }
.seg.wide { display: flex; width: 100%; }
.seg button { flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: 9px; padding: 0 0.9em; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 0.35em; touch-action: manipulation; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }
.seg button:disabled { opacity: 0.4; }
.seg .ico { font-size: 0.8em; }

.inp { width: 100%; min-height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); padding: 0 0.9em; font-size: 16px; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row .inp { flex: 1; }
.badge { font-size: 0.72rem; padding: 0.15em 0.5em; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); font-weight: 600; }
.badge.warn { color: var(--warn); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 4px;
  padding: calc(4px + env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) 4px max(6px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; text-align: center; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- home ---------- */
.home { max-width: 980px; width: 100%; margin: 0 auto; padding: env(safe-area-inset-top) 16px 24px; }
.home-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 900; letter-spacing: 0.12em; font-size: 1.25rem; }
.head-actions { display: flex; gap: 8px; }
.hero { padding: 26px 4px 18px; }
.hero h1 { font-size: clamp(1.5rem, 5vw, 2.4rem); font-weight: 900; }
.hero p { color: var(--muted); }
.live-stats { display: flex; align-items: center; gap: 6px; font-size: 0.88rem; color: var(--muted); min-height: 1.4em; margin: 6px 0; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 rgba(51, 209, 122, 0.7); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(51, 209, 122, 0); } 100% { box-shadow: 0 0 0 0 rgba(51, 209, 122, 0); } }
.newbie { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; margin: 0 0 14px; border-radius: var(--radius); background: linear-gradient(135deg, #2f6b3f, #1e4a6e); color: #fff; text-decoration: none; }
.modes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 720px) { .modes { grid-template-columns: repeat(4, 1fr); } }
.mode-card { display: flex; flex-direction: column; gap: 8px; padding: 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); text-decoration: none; transition: transform 0.12s, border-color 0.12s; min-height: 112px; }
.mode-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.mode-card.primary { grid-column: span 2; background: linear-gradient(135deg, #3b2f86, #a0326b); color: #fff; border: 0; flex-direction: row; align-items: center; }
.mode-card.primary .mode-ico { font-size: 2.6rem; }
.mode-card.primary small { color: rgba(255, 255, 255, 0.8); }
.mode-ico { font-size: 1.8rem; }
.mode-txt { display: flex; flex-direction: column; gap: 2px; }
.mode-txt b { font-size: 1.05rem; }
.mode-txt small { color: var(--muted); }
.live-list h3 { margin: 22px 0 8px; font-size: 1rem; }
.live-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); margin-bottom: 6px; text-decoration: none; }
.live-item small { color: var(--muted); }
.live-item .watch { grid-row: span 2; align-self: center; color: var(--accent); font-weight: 700; }
.foot { text-align: center; color: var(--muted); font-size: 0.82rem; padding: 26px 0 8px; }

/* ---------- generic page ---------- */
.page .panel { width: 100%; max-width: 560px; margin: 0 auto; padding: 16px; }
.panel h3 { margin: 22px 0 10px; font-size: 0.95rem; color: var(--muted); font-weight: 700; }
.panel h3:first-child { margin-top: 4px; }
.prose p { white-space: pre-wrap; }
.choice-list { display: flex; flex-direction: column; gap: 8px; }
.choice { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: var(--radius); background: var(--panel); border: 2px solid var(--line); cursor: pointer; text-align: left; }
.choice.on { border-color: var(--accent); background: var(--panel2); }
.choice-txt { flex: 1; display: flex; flex-direction: column; }
.choice-txt small { color: var(--muted); }
.lv-stars { color: var(--accent); font-size: 1.1rem; min-width: 4.5em; letter-spacing: -1px; }
.seat-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.seat-row { display: grid; grid-template-columns: 28px 70px 1fr; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.seat-row select { min-height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); padding: 0 8px; }
.tc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.tc { display: flex; flex-direction: column; align-items: center; padding: 12px 6px; border-radius: 12px; background: var(--panel); border: 2px solid var(--line); cursor: pointer; }
.tc b { font-size: 1.2rem; }
.tc small { color: var(--muted); font-size: 0.75rem; }
.tc.on { border-color: var(--accent); }
.toggles { display: flex; flex-direction: column; gap: 4px; margin-top: 16px; }
.toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.stat { background: var(--panel2); border-radius: 12px; padding: 10px; text-align: center; display: flex; flex-direction: column; }
.stat b { font-size: 1.2rem; }
.stat small { color: var(--muted); font-size: 0.75rem; }
.login { display: flex; flex-direction: column; gap: 8px; }
.btn.google { background: #fff; color: #222; border-color: #ddd; }
.btn.google .g { font-weight: 900; color: #4285f4; }
.hist-list { display: flex; flex-direction: column; gap: 6px; }
.hist-item { display: grid; grid-template-columns: 5.5em 1fr; gap: 2px 10px; padding: 10px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); text-decoration: none; border-left: 4px solid var(--muted); }
.hist-item.win { border-left-color: var(--good); }
.hist-item.lose { border-left-color: var(--bad); }
.hist-item small { grid-column: 2; color: var(--muted); }
.hist-res { font-weight: 800; grid-row: span 2; align-self: center; }
.hist-names { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ranking */
.rank-head, .rank-row { display: grid; grid-template-columns: 3em 1fr 5em 4em; gap: 8px; align-items: center; padding: 8px 10px; }
.rank-head { color: var(--muted); font-size: 0.8rem; margin-top: 12px; }
.rank-row { background: var(--panel); border-radius: 10px; margin-bottom: 4px; border: 1px solid var(--line); }
.rank-row.me { border-color: var(--accent); }
.rank-row .rk { font-weight: 800; text-align: center; }
.rank-row .rt { font-weight: 800; text-align: right; }
.rank-row .rg { color: var(--muted); text-align: right; font-size: 0.85rem; }
.rank-row .rn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-head span:nth-child(3), .rank-head span:nth-child(4) { text-align: right; }
.tiers { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tier { font-size: 0.75rem; color: var(--muted); }
.panel select.inp { margin-top: 10px; }

/* ---------- game screen ---------- */
.game-main { flex: 1; display: flex; flex-direction: column; align-items: center; width: 100%; }
.center {
  width: 100%; display: flex; flex-direction: column; align-items: center; padding: 6px max(6px, env(safe-area-inset-left)) 0;
  --bsize: max(280px, min(100vw - 12px, calc(100dvh - 300px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 760px));
}
.four .center { --bsize: max(280px, min(100vw - 12px, calc(100dvh - 330px), 760px)); }
.board-box { position: relative; width: 100%; max-width: var(--bsize); aspect-ratio: 1; }
.center > .pbars, .center > .status, .center > .actionbar { max-width: max(var(--bsize), 360px); }
.board-wrap { width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
svg.board { width: 100%; height: 100%; display: block; }
svg.board.pointer { cursor: pointer; }
.board .frame { fill: var(--frame); }
.board .cell { fill: var(--cell); }
.board .cell-hl { fill: var(--accent); opacity: 0.28; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: 0.1; } }
.board .coord { font-size: 3.2px; fill: var(--muted); text-anchor: middle; dominant-baseline: central; font-weight: 600; }
.board .dot { opacity: 0.55; pointer-events: none; }
.board .path { fill: none; stroke-width: 1.2; stroke-dasharray: 2 1.6; opacity: 0.75; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.board .wall { stroke: rgba(0, 0, 0, 0.35); stroke-width: 0.3; filter: drop-shadow(0 0.5px 0.6px rgba(0, 0, 0, 0.5)); }
.board .wall.last { animation: drop 0.25s ease-out; }
@keyframes drop { from { opacity: 0; transform: translateY(-2px); } }
.board .ghost { opacity: 0.55; pointer-events: none; }
.board .ghost.bad { fill: var(--bad) !important; opacity: 0.6; }
.board .hint { fill: none; stroke: var(--accent); stroke-width: 1; stroke-dasharray: 1.5 1; animation: blink 1s infinite; }
.board .hint-wall { fill: none; stroke: var(--accent); stroke-width: 0.6; stroke-dasharray: 1.2 0.8; animation: blink 1s infinite; pointer-events: none; }
.board .pawn { pointer-events: none; }
.board .pawn-shadow { fill: rgba(0, 0, 0, 0.35); }
.board .pawn-body { stroke: rgba(255, 255, 255, 0.85); stroke-width: 0.5; }
.board .pawn-dot { fill: rgba(255, 255, 255, 0.45); }
.board .pawn.turn .pawn-body { stroke: #fff; stroke-width: 0.9; }

.pbars { width: 100%; max-width: 760px; display: flex; gap: 6px; }
.pbars.top { margin-bottom: 6px; }
.pbars.bottom { margin-top: 6px; }
.pbar {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 12px;
  background: var(--panel); border: 2px solid transparent; position: relative; transition: border-color 0.2s;
}
.pbar.turn { border-color: var(--pc); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pc) 22%, transparent); }
.pbar.offline { opacity: 0.6; }
.pawn-icon { width: 22px; height: 22px; border-radius: 50%; background: var(--pc); border: 2px solid rgba(255, 255, 255, 0.8); flex: none; }
.pinfo { flex: 1; min-width: 0; }
.pname { display: flex; align-items: center; gap: 6px; font-weight: 700; white-space: nowrap; }
.pname .nm { overflow: hidden; text-overflow: ellipsis; }
.pname .rating { font-size: 0.82rem; font-weight: 800; }
.pmeta { display: flex; gap: 12px; font-size: 0.78rem; color: var(--muted); align-items: center; }
.pmeta b { color: var(--text); }
.pips { display: inline-flex; gap: 1.5px; margin-left: 5px; vertical-align: middle; }
.pips i { width: 3px; height: 10px; border-radius: 1px; background: var(--line); }
.pips i.on { background: var(--pc); }
.clock { font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.25rem; padding: 4px 10px; border-radius: 9px; background: var(--bg2); min-width: 4.2em; text-align: center; }
.clock.running { background: var(--text); color: var(--bg); }
.clock.low.running { background: var(--bad); color: #fff; }
.thinking { display: inline-flex; gap: 3px; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--pc); animation: bounce 1s infinite; }
.thinking i:nth-child(2) { animation-delay: 0.15s; }
.thinking i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 50% { transform: translateY(-4px); opacity: 0.5; } }
.emote-bubble { position: absolute; right: 10px; top: -22px; background: var(--text); color: var(--bg); border-radius: 12px; padding: 2px 10px; font-weight: 700; animation: pop 0.25s; z-index: 3; }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } }
.pbar.compact { padding: 5px 8px; gap: 6px; }
.pbar.compact .pmeta { gap: 6px; }
.pbar.compact .pips { display: none; }
.pbar.compact .pawn-icon { width: 16px; height: 16px; }

.status { width: 100%; max-width: 760px; min-height: 30px; margin-top: 6px; text-align: center; font-weight: 700; font-size: 0.95rem; color: var(--pc); display: flex; align-items: center; justify-content: center; padding: 0 8px; }
.status.bad { color: var(--bad); }
.actionbar { width: 100%; max-width: 760px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; padding: 8px 4px; }
.actionbar .tools { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }

.side { width: 100%; max-width: 760px; padding: 6px 10px 18px; }
.side h3 { font-size: 0.85rem; color: var(--muted); margin: 6px 0; }
.moves { max-height: 30vh; overflow: auto; }
.movelist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 2px 8px; font-variant-numeric: tabular-nums; }
.movelist li { display: flex; gap: 6px; align-items: center; }
.movelist .num { color: var(--muted); width: 2em; text-align: right; font-size: 0.8rem; }
.movelist .mv { padding: 2px 6px; border-radius: 6px; border-left: 3px solid var(--pc); background: transparent; border-top: 0; border-right: 0; border-bottom: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88rem; cursor: default; }
.movelist.click .mv { cursor: pointer; }
.movelist .mv.last { background: var(--panel2); font-weight: 800; }
.movelist.four { grid-template-columns: 1fr; }

.online-extras { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.banner { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center; padding: 10px; border-radius: 12px; background: var(--panel2); font-weight: 600; text-align: center; }
.banner.warn { background: color-mix(in srgb, var(--warn) 20%, var(--panel)); }
.banner.bad { background: color-mix(in srgb, var(--bad) 25%, var(--panel)); }
.invite { padding: 14px; border-radius: var(--radius); background: var(--panel); border: 2px dashed var(--accent); text-align: center; }
.invite-url { font-family: ui-monospace, monospace; background: var(--bg2); padding: 8px; border-radius: 8px; word-break: break-all; margin: 8px 0; user-select: all; }
.invite .row { justify-content: center; flex-wrap: wrap; }
.emotes { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.emote { min-width: 44px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-size: 1.1rem; font-weight: 800; }

.end-overlay { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(5, 8, 18, 0.45); border-radius: 8px; z-index: 5; padding: 12px; }
.end-overlay.show { display: flex; animation: fade 0.3s; }
@keyframes fade { from { opacity: 0; } }
.end-card { background: var(--panel); border-radius: 18px; padding: 22px 20px; text-align: center; box-shadow: var(--shadow); max-width: 340px; width: 100%; animation: pop 0.3s; }
.end-title { font-size: 2rem; font-weight: 900; }
.end-card.win .end-title { color: var(--good); }
.end-card.lose .end-title { color: var(--bad); }
.end-reason { color: var(--muted); margin: 4px 0 10px; }
.end-rating { font-weight: 800; font-size: 1.1rem; margin-bottom: 8px; }
.end-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.rematch p { margin: 4px 0; }

/* desktop layout */
@media (min-width: 960px) {
  .game-main { flex-direction: row; align-items: flex-start; justify-content: center; gap: 18px; padding: 10px 18px; }
  .center { flex: 1; max-width: 800px; --bsize: max(320px, min(100vw - 360px, calc(100dvh - 290px), 800px)); }
  .side { width: 300px; max-width: 300px; position: sticky; top: 70px; background: var(--panel); border-radius: var(--radius); border: 1px solid var(--line); padding: 14px; }
  .moves { max-height: 46vh; }
  .movelist { grid-template-columns: 1fr; }
}
/* mobile: moves as a horizontal strip */
@media (max-width: 959px) {
  .side h3 { display: none; }
  .moves { max-height: none; overflow: visible; }
  .game-screen .movelist { display: flex; overflow-x: auto; gap: 4px 10px; padding-bottom: 4px; scrollbar-width: none; }
  .game-screen .movelist li { flex: none; }
  .game-screen .actionbar { position: sticky; bottom: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); padding-bottom: max(8px, env(safe-area-inset-bottom)); z-index: 4; }
  .pmeta .steps { display: inline; }
}
@media (max-width: 560px) { .hide-sm { display: none; } }
@media (max-width: 380px) {
  .pbar { gap: 6px; padding: 6px 8px; }
  .clock { font-size: 1.05rem; min-width: 3.6em; padding: 3px 6px; }
  .btn.sm { padding: 0 0.6em; }
  .hide-sm { display: none; }
}
/* landscape phones: board left, controls right */
@media (orientation: landscape) and (max-height: 500px) {
  .game-main { flex-direction: row; align-items: flex-start; }
  .center { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto auto 1fr; column-gap: 10px; align-items: start; }
  .board-box { grid-column: 1; grid-row: 1 / span 4; width: calc(100dvh - 70px); max-width: none; }
  .pbars, .status, .actionbar { grid-column: 2; }
  .side { display: none; }
}

/* replay */
.replay-head { margin: 4px 0 8px; text-align: center; }
.replay-ctrl { display: flex; gap: 6px; align-items: center; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.counter { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 4em; text-align: center; }
.slider { width: 100%; max-width: 760px; margin: 10px 0; accent-color: var(--accent); }
.graph { margin: 12px 0; }
.graph-svg { width: 100%; height: 80px; background: var(--bg2); border-radius: 10px; }
.graph-cursor { stroke: var(--muted); stroke-width: 1; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 0.8rem; margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--pc); margin-right: 4px; }
.replay .side .btn { width: 100%; margin-top: 8px; }

/* tutorial */
.tut-main { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px; }
.tut-card { width: 100%; max-width: 760px; background: var(--panel); border-radius: var(--radius); padding: 14px 16px; border: 1px solid var(--line); }
.tut-card h2 { font-size: 1.25rem; margin: 2px 0 6px; }
.tut-step { color: var(--accent); font-weight: 800; font-size: 0.85rem; }
.tut-body p { margin: 0.3em 0; }
.tut-feedback { min-height: 1.6em; font-weight: 800; margin-top: 6px; }
.tut-feedback.ok { color: var(--good); }
.tut-feedback.bad { color: var(--bad); }
.tut-nav { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
.tutorial .board-box { max-width: min(100%, calc(100dvh - 380px), 640px); }
@media (min-width: 960px) {
  .tut-main { flex-direction: row-reverse; align-items: flex-start; justify-content: center; padding: 18px; gap: 18px; }
  .tut-card { max-width: 380px; position: sticky; top: 70px; }
  .tutorial .center { max-width: 720px; }
  .tutorial .board-box { max-width: min(100%, calc(100dvh - 160px), 720px); }
}

/* match */
.searching { text-align: center; padding: 30px 0 10px; }
.spinner { width: 54px; height: 54px; margin: 0 auto 18px; border-radius: 50%; border: 5px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.elapsed { font-variant-numeric: tabular-nums; color: var(--muted); }

/* puzzles */
.puzzle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 12px; }
.puzzle-card { display: flex; flex-direction: column; gap: 4px; align-items: center; padding: 8px; border-radius: 12px; background: var(--panel); border: 2px solid var(--line); text-decoration: none; font-weight: 700; }
.puzzle-card.solved { border-color: var(--good); }
.puzzle-card.next { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.pz-level { font-weight: 800; }
.pz-stars { color: var(--accent); font-size: 0.85rem; letter-spacing: 1px; }
.page.wide .panel { max-width: 900px; }
.puzzle-card .board-wrap { pointer-events: none; }

/* modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(5, 8, 18, 0.55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; opacity: 0; transition: opacity 0.2s; }
.modal-back.show { opacity: 1; }
.modal { background: var(--panel); border-radius: 18px; padding: 20px; width: 100%; max-width: 400px; box-shadow: var(--shadow); max-height: 90dvh; overflow: auto; }
.modal h2 { font-size: 1.15rem; margin-bottom: 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.menu-list { display: flex; flex-direction: column; gap: 4px; }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(130px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 60; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 700; box-shadow: var(--shadow); opacity: 0; transform: translateY(8px); transition: all 0.25s; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.rank-row { text-decoration: none; }
.player-head { display: flex; align-items: center; gap: 12px; margin: 6px 0 12px; }
.tier-badge { padding: 0.25em 0.8em; border-radius: 999px; font-weight: 800; font-size: 0.85rem; color: #111; background: var(--tc); }
.all-puzzles { margin-top: 12px; }
.transfer .code { font-family: ui-monospace, Menlo, monospace; font-size: 1.5rem; font-weight: 800; letter-spacing: 0.08em; background: var(--bg2); border: 2px dashed var(--accent); border-radius: 12px; padding: 12px; text-align: center; margin: 10px 0 4px; user-select: all; }
.acct .btn { margin-top: 6px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 46px; height: 46px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel); display: grid; place-items: center; cursor: pointer; }
.swatch .pawn-icon { width: 26px; height: 26px; }
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pc) 45%, transparent); }
