:root {
  --ink: #3a2e5c;
  --panel: rgba(255, 255, 255, 0.94);
  --pri: #7c4dff;
  --pri-d: #5b34d6;
  --accent: #ffb703;
  --good: #2ecc71;
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", "Comic Sans MS", system-ui, sans-serif;
  --bs: min(calc(100vw - 20px), calc(100dvh - 300px));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: var(--font); color: var(--ink); }
body { background: linear-gradient(180deg, #bfe3ff 0%, #dff3ff 55%, #c9f0c4 100%); }
[hidden] { display: none !important; }
button { font-family: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- overlays & panels (same look as chess) ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
.overlay.dim { background: rgba(40, 20, 90, 0.35); backdrop-filter: blur(3px); z-index: 30; }
.panel {
  position: relative; width: min(560px, 100%); max-height: 100%; overflow: auto;
  background: var(--panel); border-radius: 28px; padding: 28px 26px 24px;
  box-shadow: 0 18px 50px rgba(60, 30, 140, 0.35), 0 0 0 4px rgba(255, 255, 255, 0.6) inset;
  text-align: center; animation: pop 0.35s cubic-bezier(.2, 1.4, .4, 1);
}
.panel.small { width: min(420px, 100%); }
.panel section { padding-top: 14px; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: none; opacity: 1; } }
h1 { margin: 6px 0 4px; font-size: clamp(1.7rem, 5vw, 2.4rem); }
h2 { margin: 0 0 6px; font-size: 1.6rem; }
.logo { display: inline-block; animation: wiggle 2.4s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
.sub { margin: 4px 0 16px; color: #62588a; font-size: 1.02rem; }
.label { margin: 14px 0 8px; font-weight: 700; }
.label small { font-weight: 400; color: #7a70a8; }
.hint-small { margin: 8px 0 0; font-size: 0.85rem; color: #7a70a8; }
.home-link { position: absolute; left: 18px; top: 14px; font-size: 0.85rem; color: #7a70a8; text-decoration: none; }
.home-link:hover { text-decoration: underline; }
.big-emoji { font-size: 4rem; line-height: 1; animation: wiggle 1.2s ease-in-out infinite; }
.rules { text-align: left; list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; font-weight: 600; }
.rules li { background: #f6f2ff; border-radius: 14px; padding: 10px 14px; }

/* ---------- buttons ---------- */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 8px; }
.card {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 16px 8px; cursor: pointer;
  background: linear-gradient(180deg, #fff, #f1ebff); border: 3px solid #d9ccff; border-radius: 20px;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s; font-size: 1rem;
}
.card .emoji { font-size: 2.4rem; }
.card small { color: #7a70a8; }
.card:hover, .card:focus-visible { transform: translateY(-4px) scale(1.03); border-color: var(--pri); box-shadow: 0 8px 18px rgba(124, 77, 255, 0.28); outline: none; }
.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.choice {
  display: flex; flex-direction: column; align-items: center; padding: 12px 6px; cursor: pointer; font-weight: 800; font-size: 1.2rem;
  background: #fff; border: 3px solid #e1d8fa; border-radius: 16px; transition: all 0.12s;
}
.choice:hover, .choice:focus-visible { border-color: var(--pri); outline: none; }
.choice.selected { border-color: var(--pri); background: #efe8ff; box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.2); }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.btn {
  border: 0; border-radius: 999px; padding: 12px 24px; font-size: 1.05rem; font-weight: 800; cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, filter 0.12s;
}
.btn.primary { background: linear-gradient(180deg, #9a73ff, var(--pri)); color: #fff; box-shadow: 0 5px 0 var(--pri-d); }
.btn.primary:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.06); }
.btn.primary:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--pri-d); }
.btn.primary:disabled { filter: grayscale(0.6) opacity(0.6); cursor: default; }
.btn.ghost { background: #efeaff; color: var(--pri-d); }
.btn.ghost:hover { background: #e4dbff; }

/* ---------- setup slots ---------- */
.slots { display: grid; gap: 8px; }
.slot { display: flex; align-items: center; gap: 8px; background: #f6f2ff; border-radius: 16px; padding: 6px 8px; border-left: 8px solid var(--c); }
.slot .kind { width: 46px; height: 46px; flex: none; border-radius: 50%; border: 0; background: #fff; font-size: 1.5rem; cursor: pointer; box-shadow: 0 2px 8px rgba(60, 30, 140, 0.2); }
.slot .kind:hover { transform: scale(1.08); }
.slot .pawn { font-size: 1.6rem; flex: none; }
.slot input { flex: 1; min-width: 0; font: inherit; font-size: 1.05rem; padding: 10px 12px; border: 3px solid #d9ccff; border-radius: 14px; color: var(--ink); }
.slot input:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; }
.topbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px; flex: none; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--panel); font-size: 1.3rem; cursor: pointer; flex: none;
  box-shadow: 0 4px 14px rgba(60, 30, 140, 0.25); transition: transform 0.12s;
}
.icon-btn:hover { transform: scale(1.1); }
.status {
  flex: 1; max-width: 520px; margin: 0 auto; text-align: center; font-weight: 800; font-size: 1.05rem; min-height: 46px;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel); padding: 8px 18px; border-radius: 999px; box-shadow: 0 4px 14px rgba(60, 30, 140, 0.25);
}
.status.good { background: #e8fff0; color: #1c7d45; }
.status.bad { background: #fff0f0; color: #c0392b; animation: shake 0.5s; }
@keyframes shake { 0%, 100% { transform: none; } 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(4px); } }

.game { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 0 10px 10px; overflow: auto; }
.board-wrap { width: var(--bs); height: var(--bs); flex: none; margin-bottom: calc(var(--bs) * 0.09); position: relative; }

/* ---------- board ---------- */
.board {
  position: relative; width: 100%; height: 100%; border-radius: 18px; border: 6px solid #fff; background: #fff;
  box-shadow: 0 12px 34px rgba(60, 30, 140, 0.35); display: grid; grid-template-columns: repeat(10, 1fr); grid-template-rows: repeat(10, 1fr);
  user-select: none;
}
.cell { position: relative; background: #fdf9ff; font-size: calc(var(--bs) * 0.026); font-weight: 800; color: #9b8cc9; padding: 2px 0 0 3px; line-height: 1; }
.cell.alt { background: #e9ddff; }
.cell:nth-child(1) { border-top-left-radius: 10px; }
.cell:nth-child(10) { border-top-right-radius: 10px; }
.cell.goal { background: #ffe7a0; color: #a56a00; }
.cell.goal .castle { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: calc(var(--bs) * 0.06); }
.cell.start-cell { background: #d9f7d9; color: #3b8a46; }
.art { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.art .ladder, .art .snake { filter: drop-shadow(0 0.5px 0.4px rgba(40, 20, 90, 0.35)); }
.start-lane { position: absolute; left: 0; right: 0; top: 100%; height: 9%; display: flex; align-items: center; padding-left: 4px; font-weight: 800; font-size: 0.8rem; color: #3b8a46; pointer-events: none; }
.token {
  position: absolute; width: 6.4%; height: 6.4%; transform: translate(-50%, -50%); border-radius: 50%; background: var(--c);
  border: 2px solid #fff; box-shadow: 0 2px 5px rgba(40, 20, 90, 0.45); display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--bs) * 0.04); line-height: 1; transition: left 0.2s ease-out, top 0.2s ease-out; z-index: 3; pointer-events: none;
}
.token.slide { transition: left 0.9s ease-in-out, top 0.9s ease-in-out; z-index: 4; }
.token.active { z-index: 5; animation: hop 0.8s ease-in-out infinite; }
@keyframes hop { 0%, 100% { margin-top: 0; } 50% { margin-top: -1.2%; } }
.token.hopping { animation: stephop 0.2s ease-out; }
@keyframes stephop { 0% { margin-top: 0; } 50% { margin-top: -2.4%; } 100% { margin-top: 0; } }

/* ---------- players & dice ---------- */
.side { display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(560px, 100%); }
.players { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pcard {
  display: flex; align-items: center; gap: 6px; background: var(--panel); padding: 6px 12px; border-radius: 999px; font-weight: 800;
  box-shadow: 0 4px 14px rgba(60, 30, 140, 0.2); border: 3px solid transparent; transition: border-color 0.2s, transform 0.2s; font-size: 0.95rem;
}
.pcard.turn { border-color: var(--accent); transform: scale(1.06); background: #fff8d9; }
.pcard .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c); border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15); }
.pcard .nm { max-width: 8.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .at { font-size: 0.8rem; color: #7a70a8; background: #efe8ff; border-radius: 999px; padding: 1px 8px; }
.roller { display: flex; align-items: center; gap: 16px; }
.dice {
  position: relative; width: 64px; height: 64px; border-radius: 16px; border: 3px solid #d9ccff; background: #fff; padding: 8px; cursor: pointer;
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); box-shadow: 0 5px 0 #cdbff5, 0 8px 16px rgba(60, 30, 140, 0.25);
}
.dice i { display: block; width: 100%; height: 100%; place-self: center; }
.dice i.on::after { content: ""; display: block; width: 70%; height: 70%; margin: 15%; border-radius: 50%; background: var(--ink); }
.dice:disabled { cursor: default; }
.dice.rolling { animation: tumble 0.5s linear infinite; }
@keyframes tumble { 0% { transform: rotate(0); } 25% { transform: rotate(-14deg) translateY(-6px); } 50% { transform: rotate(8deg); } 75% { transform: rotate(14deg) translateY(-4px); } 100% { transform: rotate(0); } }
.dice.ready { border-color: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

/* wide screens: board on the left, players and dice on the right */
@media (min-width: 860px) and (min-aspect-ratio: 11/10) {
  :root { --bs: min(calc(100dvh - 170px), calc(100vw - 440px)); }
  .game { flex-direction: row; justify-content: center; align-items: center; gap: 28px; }
  .board-wrap { margin-bottom: 0; }
  .side { width: 320px; }
  .players { flex-direction: column; align-items: stretch; width: 100%; }
  .pcard { justify-content: flex-start; }
  .pcard .at { margin-left: auto; }
}
@media (max-height: 640px) and (max-width: 859px) { :root { --bs: min(calc(100vw - 20px), calc(100dvh - 250px)); } }

/* ---------- confetti ---------- */
#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
#confetti span { position: absolute; top: -10%; font-size: 1.8rem; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(115vh) rotate(540deg); } }

@media (prefers-reduced-motion: reduce) {
  .logo, .big-emoji, .token.active, .dice.ready, .dice.rolling, #confetti span { animation: none; }
  .token, .token.slide { transition: none; }
}

/* ---------- 3D mode: the canvas fills the screen and the HUD floats on top ---------- */
#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; outline: none; z-index: 1; }
.toolbar { position: absolute; left: 10px; top: 66px; display: flex; flex-direction: column; gap: 8px; z-index: 2; }
.tool {
  display: flex; align-items: center; gap: 6px; height: 42px; padding: 0 12px; border-radius: 999px; border: 3px solid transparent; background: var(--panel);
  font-size: 0.9rem; font-weight: 800; cursor: pointer; box-shadow: 0 4px 14px rgba(60, 30, 140, 0.25); white-space: nowrap; transition: transform 0.12s;
}
.tool:hover { transform: scale(1.05); }
.tool.on { border-color: var(--accent); background: #fff8d9; }
.tool .state { display: inline-block; padding: 1px 7px; border-radius: 999px; background: #e6e0f5; color: #6c6190; font-size: 0.75rem; }
.tool.on .state { background: var(--good); color: #fff; }
body:not(.mode-3d) [data-3d] { display: none; }
.toolbar .tool:hover { transform: translateX(3px) scale(1.04); }
body.mode-3d #hud { pointer-events: none; }
body.mode-3d .topbar > *, body.mode-3d .toolbar { pointer-events: auto; }
body.mode-3d .board-wrap, body.mode-3d .dice { display: none; }
body.mode-3d .game { position: absolute; left: 0; right: 0; bottom: 0; flex: none; padding: 0 10px 12px; overflow: visible; pointer-events: none; }
body.mode-3d .players, body.mode-3d .roller { pointer-events: auto; }
body.mode-3d .pcard { font-size: 0.85rem; padding: 4px 10px; }
@media (min-width: 860px) {
  body.mode-3d .game { left: auto; right: 14px; bottom: auto; top: 76px; width: 260px; padding: 0; }
  body.mode-3d .side { width: 100%; align-items: stretch; }
  body.mode-3d .players { flex-direction: column; align-items: stretch; }
  body.mode-3d .roller { justify-content: center; }
}
@media (max-width: 859px) {
  .tool span:not(.e) { display: none; }
  .tool { width: 42px; padding: 0; justify-content: center; }
  .tool .e { font-size: 1.2rem; }
}
