/* Khel ON Ludo */
:root {
  --navy: #141721; --navy2: #1d2130; --navy3: #272c3f; --ink: #f4f5fb; --muted: #aab0c6;
  --orange: #ff9a3c; --pink: #f04fa8; --purple: #8b5cf6; --teal: #2fd4c8;
  --grad: linear-gradient(90deg, #ff9a3c, #f04fa8 55%, #8b5cf6);
  --red: #f0455a; --green: #22b573; --yellow: #ffc02e; --blue: #3d8bfd;
  --cur: var(--red);
  --head: 'Outfit', 'Segoe UI', system-ui, sans-serif;
  --body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--navy); color: var(--ink);
  font-family: var(--body); font-size: 16px; line-height: 1.4; overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
a { color: var(--teal); }
[hidden] { display: none !important; }

/* Header */
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(20, 23, 33, .94); border-bottom: 1px solid #2a2f44;
}
.bar::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--grad); opacity: .8; }
.home { display: flex; align-items: center; gap: 6px; color: var(--ink); text-decoration: none; font-family: var(--head); font-weight: 700; font-size: 15px; white-space: nowrap; }
.logo-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--grad); box-shadow: 0 0 0 3px rgba(255,255,255,.08); }
.bar h1 { flex: 1; margin: 0; text-align: center; font-family: var(--head); font-size: 20px; letter-spacing: .3px; }
.bar-btns { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px; border: 1px solid #343a52; background: var(--navy2);
  display: grid; place-items: center; cursor: pointer; font-weight: 800; font-size: 17px; padding: 0;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .spk { fill: var(--ink); }
#btnSound .mute { display: none; }
#btnSound[aria-pressed="false"] .mute { display: inline; }
#btnSound[aria-pressed="false"] .wave { display: none; }
.icon-btn:focus-visible, .btn:focus-visible, .die:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

main { max-width: 620px; margin: 0 auto; padding: 12px 12px 24px; }

/* Setup */
.hero { text-align: center; padding: 6px 0 10px; }
.hero h2 { font-family: var(--head); font-size: 26px; margin: 4px 0; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sub { margin: 0; color: var(--muted); }
.stars-total { margin: 6px 0 0; color: var(--yellow); font-weight: 800; }
.card { background: var(--navy2); border: 1px solid #2a2f44; border-radius: 18px; padding: 14px; margin: 12px 0; }
.card h3 { margin: 0 0 10px; font-family: var(--head); font-size: 17px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row.center { justify-content: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px;
  border-radius: 14px; border: 1px solid #39405a; background: var(--navy3); cursor: pointer; font-weight: 800;
}
.btn.primary { background: var(--grad); border: 0; color: #fff; box-shadow: 0 6px 18px rgba(240, 79, 168, .25); }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; font-size: 20px; min-height: 56px; font-family: var(--head); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chip-btn { font-size: 15px; padding: 8px 10px; }
.seat { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.seat + .seat { border-top: 1px dashed #30364c; }
.seat-dot { flex: none; width: 26px; height: 26px; border-radius: 50%; border: 3px solid rgba(255,255,255,.85); }
.seat-name { flex: none; width: 56px; font-weight: 800; }
.seg { flex: 1; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--navy); border-radius: 12px; padding: 3px; gap: 2px; min-width: 0; }
.seg button { border: 0; background: none; border-radius: 9px; padding: 8px 0; font-size: 13px; font-weight: 800; cursor: pointer; color: var(--muted); min-width: 0; }
.seg button[aria-pressed="true"] { background: var(--navy3); color: #fff; box-shadow: inset 0 0 0 2px var(--teal); }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0 0; }
.toggle { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; cursor: pointer; }
.toggle input { flex: none; width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--teal); }
.toggle small { color: var(--muted); }
.links { margin-top: 10px; }
.foot { text-align: center; color: var(--muted); font-size: 14px; margin-top: 14px; }
.resume p { margin: 0 0 10px; font-weight: 700; }

/* Game */
#game { display: flex; flex-direction: column; align-items: center; }
.board-wrap { width: min(100%, calc(100dvh - 190px), 600px); min-width: 280px; aspect-ratio: 1; }
@supports not (height: 1dvh) { .board-wrap { width: min(100%, calc(100vh - 190px), 600px); } }
#board { display: block; width: 100%; height: 100%; border-radius: 14px; background: #fbf7ef; box-shadow: 0 10px 30px rgba(0,0,0,.4); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
#board .cell { stroke: #1d2130; stroke-width: .04; }
#board .grid-line { stroke: #1d2130; stroke-width: .05; fill: none; }
#board .yard-in { fill: #fffdf8; }
#board .spot { fill: none; stroke-width: .07; opacity: .55; }
#board .star { fill: #c8c1b2; }
#board .arrow { fill: none; stroke-width: .08; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
#board .label { font-family: var(--head); font-weight: 800; font-size: .56px; fill: #1d2130; text-anchor: middle; dominant-baseline: middle; }
#board .yard-frame { fill: none; stroke: #fff; stroke-width: 0; }
#board .yard.active .yard-frame { stroke-width: .16; animation: glow 1.2s ease-in-out infinite; }
@keyframes glow { 50% { stroke-opacity: .35; } }
#board .yard.off { opacity: .35; }
.tok { transition: transform .13s ease-out; cursor: default; }
.tok.fly { transition: transform .45s cubic-bezier(.3,.7,.3,1); }
.tok .body { stroke: #1d2130; stroke-width: .05; }
.tok .shine { fill: rgba(255,255,255,.55); }
.tok .ring { fill: none; stroke: #fff; stroke-width: .07; }
.tok .halo { fill: none; stroke: #1d2130; stroke-width: .09; stroke-dasharray: .25 .14; opacity: 0; }
.tok.can { cursor: pointer; }
.tok.can .halo { opacity: 1; animation: spin 1.6s linear infinite; transform-box: fill-box; transform-origin: center; }
.tok.can .inner { animation: bob .7s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center bottom; }
.tok:focus { outline: none; }
.tok:focus-visible .halo { stroke: var(--teal); opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bob { to { transform: translateY(-.12px) scale(1.06); } }

.controls { width: min(100%, 600px); display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.turn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 16px; background: var(--navy2); border: 2px solid var(--cur); font-weight: 800; font-size: 17px; }
.turn span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.turn-dot { flex: none; width: 18px; height: 18px; border-radius: 50%; background: var(--cur); }
.die {
  flex: none; width: 74px; height: 74px; border-radius: 18px; border: 0; padding: 9px; cursor: pointer;
  background: #fff; box-shadow: 0 0 0 4px var(--cur), 0 8px 18px rgba(0,0,0,.45);
}
.die:disabled { cursor: default; box-shadow: 0 0 0 4px #39405a, 0 8px 18px rgba(0,0,0,.45); }
.die.ready { animation: nudge 1.1s ease-in-out infinite; }
@keyframes nudge { 0%, 70%, 100% { transform: none; } 80% { transform: rotate(-8deg) scale(1.05); } 90% { transform: rotate(8deg) scale(1.05); } }
.die.rolling { animation: tumble .5s linear; }
@keyframes tumble { 0% { transform: rotate(0) scale(1); } 50% { transform: rotate(200deg) scale(.85); } 100% { transform: rotate(360deg) scale(1); } }
.face { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); width: 100%; height: 100%; }
.pip { width: 12px; height: 12px; border-radius: 50%; background: #1d2130; place-self: center; visibility: hidden; }
.pip.on { visibility: visible; }
.face.six-glow .pip.on { background: var(--pink); }
.coach { width: min(100%, 600px); margin: 10px 0 0; padding: 10px 14px; border-radius: 14px; background: #20283a; border-left: 4px solid var(--teal); font-weight: 700; }

/* Overlays */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(8, 10, 16, .72); }
.sheet { width: min(100%, 460px); max-height: calc(100dvh - 32px); overflow-y: auto; background: var(--navy2); border: 1px solid #343a52; border-radius: 22px; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.sheet h2 { margin: 0 0 4px; font-family: var(--head); font-size: 23px; text-align: center; }
.sheet.small { width: min(100%, 360px); }
.sheet .btn { width: 100%; }
.sheet .row .btn { flex: 1; width: auto; }
.how-step { min-height: 240px; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; }
.how-step svg { width: 150px; height: 150px; border-radius: 14px; background: #fbf7ef; }
.how-step h3 { margin: 0; font-family: var(--head); font-size: 19px; }
.how-step p { margin: 0; color: #dfe2ee; }
.how-dots { display: flex; justify-content: center; gap: 6px; }
.how-dots i { width: 8px; height: 8px; border-radius: 50%; background: #3b4260; }
.how-dots i.on { background: var(--teal); }
.trophy { width: 84px; height: 84px; margin: 0 auto; border-radius: 50%; background: var(--grad); position: relative; }
.trophy::after { content: '★'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 46px; color: #fff; }
.res-stars { text-align: center; font-size: 30px; color: var(--yellow); margin: 0; letter-spacing: 4px; min-height: 1em; }
.res-stats { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.res-stats li { display: flex; align-items: center; gap: 8px; background: var(--navy); border-radius: 10px; padding: 6px 10px; font-size: 14px; }
.res-badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 10px; }
.badge { background: var(--navy); border: 1px solid #30364c; border-radius: 14px; padding: 10px; text-align: center; font-size: 13px; color: var(--muted); }
.badge b { display: block; color: var(--ink); font-size: 14px; margin-top: 6px; }
.badge .medal { width: 44px; height: 44px; margin: 0 auto; border-radius: 50%; background: #2c3248; display: grid; place-items: center; font-size: 22px; color: #5c6482; }
.badge.got .medal { background: var(--grad); color: #fff; }
.badge.new { border-color: var(--teal); }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; background: #fff; color: var(--navy); font-weight: 800; padding: 10px 18px; border-radius: 999px; box-shadow: 0 8px 24px rgba(0,0,0,.4); max-width: calc(100vw - 32px); text-align: center; }

@media (max-width: 480px) {
  .seat { flex-wrap: wrap; gap: 6px 10px; }
  .seg { flex-basis: 100%; }
  .seat-name { width: auto; }
}
@media (max-width: 400px) {
  .home { font-size: 0; gap: 0; }
  .bar h1 { font-size: 19px; }
  .seg button { font-size: 12px; }
  .die { width: 66px; height: 66px; padding: 8px; }
  .pip { width: 10px; height: 10px; }
  .turn { font-size: 15px; padding: 8px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .tok, .tok.fly { transition-duration: .01s; }
  .tok.can .halo, .tok.can .inner, .die.ready, #board .yard.active .yard-frame { animation: none; }
}
