:root{
  --bg:#110d1f; --bg2:#1a1430; --panel:#1b1535; --line:#352b5c; --text:#f1ecff; --muted:#a79dc9;
  --accent:#ffc83d; --accent2:#b78cff; --radius:14px;
  --bg-image: radial-gradient(1100px 480px at 50% -120px, #2b1f57 0%, transparent 70%);
}
/* Shared arcade UI base (mobile-first). Game-specific theme + board styles follow. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-image, none);
  line-height: 1.4;
}
button, select, input { font: inherit; }
.app-header { text-align: center; padding: 14px 16px 6px; }
.logo { margin: 0; font-size: 26px; letter-spacing: .5px; color: var(--accent); }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.back-link { color: var(--accent2); text-decoration: none; font-size: 14px; }
.back-link:hover { text-decoration: underline; }
.help-btn { margin-top: 10px; }
.app-main { display: flex; flex-direction: column; gap: 14px; padding: 8px 16px 40px; max-width: 1040px; margin: 0 auto; }
.board-panel { width: 100%; min-width: 0; }
.side-panel { width: 100%; min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
@media (min-width: 900px) {
  .app-main { flex-direction: row; align-items: flex-start; gap: 22px; }
  .board-panel { flex: 1 1 auto; }
  .side-panel { flex: 0 0 340px; width: 340px; }
}
.panel-title { margin: 16px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--muted); }
.panel-title:first-child { margin-top: 0; }
.turn-indicator { display: flex; align-items: center; gap: 8px; font-weight: 600; min-height: 28px; }
.turn-dot { width: 16px; height: 16px; border-radius: 50%; flex: 0 0 16px; }
.result { display: none; padding: 10px 12px; border-radius: 10px; font-weight: 700; background: rgba(255,184,77,.12); border: 1px solid var(--accent); color: var(--accent); margin: 8px 0; }
.result.show { display: block; }
.stat-row { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin: 6px 0; }
.stat-row b { color: var(--text); }
.controls { display: flex; flex-direction: column; gap: 10px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }
.btn {
  appearance: none; border: 0; cursor: pointer; border-radius: 10px;
  background: var(--accent); color: #1a1205; font-weight: 700;
  padding: 11px 16px; min-height: 44px; font-size: 15px;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .4; cursor: default; filter: none; }
.btn-sm { padding: 7px 12px; font-size: 14px; min-height: 40px; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 600; }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.ctl { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
select, input[type=text] {
  width: 100%; min-height: 42px; padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--bg2); color: var(--text); font-size: 15px;
}
.chk { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: 14px; color: var(--text); cursor: pointer; }
.chk input { width: 20px; height: 20px; accent-color: var(--accent); flex: 0 0 20px; }
.note { margin: 0; color: var(--muted); font-size: 12.5px; }
.ai-status { font-size: 13px; color: var(--accent); min-height: 18px; font-style: italic; }
.tn-entry { display: flex; gap: 6px; margin-bottom: 8px; }
.tn-actions { display: flex; gap: 6px; margin: 8px 0; }
.tn-actions .btn { flex: 1; }
#ol-name { margin-bottom: 4px; }
.tn-body { font-size: 13px; }
.tn-result { font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.tn-king { color: var(--accent2); font-weight: 600; margin-bottom: 8px; }
.tn-sub { color: var(--muted); margin: 6px 0 4px; font-size: 12px; }
.tn-hint { color: var(--muted); font-style: italic; font-size: 12px; }
.tn-queue { margin: 0 0 8px; padding-left: 22px; max-height: 140px; overflow-y: auto; }
.move-log { margin: 0; padding: 0; list-style: none; max-height: 150px; overflow-y: auto; font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.move-log li { display: flex; align-items: center; gap: 4px; }
.mv-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.flash {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px);
  background: #1d2338; border: 1px solid var(--accent); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 70; max-width: 92vw; text-align: center;
}
.flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.help-overlay { display: none; position: fixed; inset: 0; background: rgba(5,8,16,.78); z-index: 80; align-items: center; justify-content: center; padding: 12px; }
.help-overlay.open { display: flex; }
.help-card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; padding: 20px 18px; }
.help-card h2 { color: var(--accent); margin: 0 36px 8px 0; font-size: 22px; }
.help-card h3 { color: var(--accent); font-size: 15px; margin: 18px 0 6px; }
.help-card p, .help-card li { font-size: 14px; line-height: 1.55; }
.help-card ul, .help-card ol { padding-left: 20px; margin: 6px 0; }
.help-card b { color: #fff; }
.help-close { position: absolute; top: 8px; right: 8px; width: 40px; height: 40px; border: 0; background: transparent; color: var(--muted); font-size: 28px; cursor: pointer; }
.help-close:hover { color: var(--accent); }
.help-actions { text-align: right; margin-top: 18px; }
.help-figs { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.help-figs figure { margin: 0; flex: 1 1 140px; min-width: 0; }
.help-figs svg { width: 100%; height: auto; display: block; border-radius: 8px; }
.help-figs figcaption { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; transition-delay: 0s !important; } }

/* ---------- Four in a Row board ---------- */
.turnbar { display: flex; justify-content: space-between; gap: 10px; margin: 0 auto 10px; max-width: 560px; }
.tb { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: var(--panel); border: 2px solid var(--line); font-size: 15px; min-width: 0; }
.tb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; color: var(--muted); }
.tb.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,200,61,.18); }
.tb.active .tb-name { color: var(--text); }
.chip, .turn-dot { display: inline-block; width: 20px; height: 20px; border-radius: 50%; flex: 0 0 auto; }
.gold { background: radial-gradient(circle at 35% 30%, #fff1b3 0%, #ffc83d 55%, #d4930a 100%); }
.violet { background: radial-gradient(circle at 35% 30%, #e0ccff 0%, #b78cff 55%, #7a49d6 100%); }

.fboard {
  --gap: 6px;
  display: grid; grid-template-columns: repeat(var(--w), 1fr); gap: 0;
  width: 100%; max-width: 560px; margin: 0 auto; padding: 8px;
  background: linear-gradient(160deg, #3a2f66, #2a2150); border: 3px solid #5a4a9a; border-radius: 18px;
  box-shadow: 0 14px 40px rgba(0,0,0,.5), inset 0 0 0 2px rgba(0,0,0,.35);
  overflow: hidden; position: relative;
}
.col {
  display: grid; grid-template-rows: repeat(var(--h), 1fr); padding: 0; margin: 0; border: 0; background: transparent;
  cursor: pointer; min-width: 0; min-height: 0; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  border-radius: 10px;
}
.col.full { cursor: not-allowed; }
.col.playable:hover { background: rgba(255,255,255,.07); }
.col:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.slot { position: relative; display: block; margin: 8%; border-radius: 50%; background: #0d0a1c; box-shadow: inset 0 3px 7px rgba(0,0,0,.75), 0 1px 0 rgba(255,255,255,.08); aspect-ratio: 1; }
.piece {
  position: absolute; inset: -4%; border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0,0,0,.5), inset 0 -4px 6px rgba(0,0,0,.25);
  animation: drop calc(.16s + var(--fall) * .06s) cubic-bezier(.45,0,.9,.55) both;
}
.piece.gold::after, .piece.violet::after { content: ""; position: absolute; inset: 22%; border: 3px solid rgba(0,0,0,.2); }
.piece.gold::after { border-radius: 50%; }
.piece.violet::after { transform: rotate(45deg); border-radius: 3px; inset: 28%; }
.piece.last::before { content: ""; position: absolute; left: 50%; top: 50%; width: 14%; height: 14%; margin: -7% 0 0 -7%; border-radius: 50%; background: rgba(0,0,0,.45); }
.piece.win { animation: drop calc(.16s + var(--fall) * .06s) cubic-bezier(.45,0,.9,.55) both, pulse 1s .5s ease-in-out infinite; box-shadow: 0 0 0 4px #fff, 0 0 18px 6px rgba(255,255,255,.7); z-index: 1; }
@keyframes drop {
  0% { transform: translateY(calc(var(--fall) * -112%)); }
  78% { transform: translateY(0); }
  88% { transform: translateY(-9%); }
  100% { transform: translateY(0); }
}
@keyframes pulse { 50% { filter: brightness(1.25); } }
@media (prefers-reduced-motion: reduce) { .piece, .piece.win { animation: none; } }
