/* Khel ON · Snakes & Ladders */
:root {
  --bg: var(--ko-bg, #141721); --bg2: var(--ko-bg-2, #1b1d2e); --panel: var(--ko-panel, #20223a);
  --line: var(--ko-line, rgba(255,255,255,.1)); --ink: var(--ko-ink, #f5f3ff); --dim: var(--ko-dim, #a9a8c6);
  --orange: var(--ko-orange, #ff9a3c); --pink: var(--ko-pink, #f04fa8); --purple: var(--ko-purple, #8b5cf6); --teal: var(--ko-teal, #2fd4c8);
  --grad: var(--ko-grad, linear-gradient(90deg, #ff9a3c, #f04fa8, #8b5cf6));
  --display: var(--ko-display, Outfit, "Segoe UI", system-ui, sans-serif);
  --body: var(--ko-body, Nunito, "Segoe UI", system-ui, sans-serif);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font-family: var(--body); font-weight: 600;
  background-image: radial-gradient(120% 60% at 50% -10%, #2a1f4a 0%, transparent 60%);
  overflow-x: hidden; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Header */
.top { display: flex; align-items: center; gap: 10px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); position: sticky; top: 0; z-index: 5; background: rgba(20,23,33,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.home img { display: block; height: 28px; width: auto; }
.top h1 { flex: 1; margin: 0; font-family: var(--display); font-weight: 800; font-size: clamp(15px, 4.4vw, 22px); line-height: 1.05; min-width: 0; }
.top h1 span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tools { display: flex; align-items: center; gap: 6px; }
.icon { width: 36px; height: 36px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 17px; font-weight: 800; display: grid; place-items: center; padding: 0; }
.icon[aria-pressed="false"] { opacity: .55; }
.starcount { font-family: var(--display); font-weight: 800; color: #ffd166; font-size: 15px; padding: 0 4px; white-space: nowrap; }
.starcount.bump { animation: bump .5s ease; }
@keyframes bump { 40% { transform: scale(1.35); } }

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

/* Setup */
.setup h2 { font-family: var(--display); font-weight: 800; font-size: 18px; margin: 18px 0 10px; }
.continue { width: 100%; padding: 14px; border-radius: 16px; border: 0; background: var(--teal); color: #0d1a1d; font-family: var(--display); font-weight: 800; font-size: 18px; margin-top: 6px; }
.boards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.boardcard { text-align: left; border: 2px solid var(--line); background: var(--panel); border-radius: 18px; padding: 8px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.boardcard svg { width: 100%; height: auto; border-radius: 10px; display: block; }
.boardcard b { font-family: var(--display); font-size: 16px; }
.boardcard small { color: var(--dim); font-size: 12.5px; line-height: 1.3; }
.boardcard[aria-checked="true"] { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(47,212,200,.25); }
.players { display: grid; gap: 8px; }
.prow { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 8px 10px; }
.prow svg { width: 34px; height: 34px; flex: none; }
.prow .pname { flex: 1; font-family: var(--display); font-weight: 700; font-size: 16px; min-width: 0; }
.prow.off .pname, .prow.off svg { opacity: .4; }
.seg { display: inline-flex; background: var(--bg2); border-radius: 12px; padding: 3px; gap: 2px; border: 1px solid var(--line); flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 10px; border-radius: 9px; font-weight: 800; font-size: 14px; color: var(--dim); }
.seg button[aria-checked="true"] { background: var(--grad); color: #fff; }
.seg button:disabled { opacity: .35; cursor: default; }
.hint { color: var(--dim); font-size: 13.5px; margin: 8px 2px; line-height: 1.4; }
.rules { display: grid; gap: 8px; }
.rule { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 8px 10px; }
.rule > span { font-weight: 800; }
.start { display: block; width: 100%; margin: 20px 0 30px; padding: 15px; border: 0; border-radius: 18px; background: var(--grad); color: #fff; font-family: var(--display); font-weight: 800; font-size: 20px; box-shadow: 0 8px 24px rgba(240,79,168,.3); }
.start:disabled { opacity: .45; box-shadow: none; }
.ghost { border: 1px solid var(--line); background: var(--panel); border-radius: 14px; padding: 10px 14px; font-weight: 800; }

/* Play */
.play { display: grid; gap: 12px; }
.boardwrap { width: 100%; max-width: min(100%, calc(100vh - 230px)); min-width: 280px; margin: 0 auto; }
#board { display: block; width: 100%; height: auto; border-radius: 16px; box-shadow: 0 10px 30px rgba(0,0,0,.45); touch-action: manipulation; user-select: none; }
.side { display: flex; flex-direction: column; gap: 10px; }
.strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 6px; }
.pchip { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 14px; background: var(--panel); border: 2px solid transparent; min-width: 0; }
.pchip svg { width: 24px; height: 24px; flex: none; }
.pchip div { min-width: 0; line-height: 1.1; }
.pchip b { display: block; font-family: var(--display); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pchip small { color: var(--dim); font-size: 12px; }
.pchip.now { border-color: var(--teal); background: #1d2c3c; }
.status { margin: 0; min-height: 2.6em; font-size: 15.5px; line-height: 1.3; text-align: center; }
.diebtn { display: flex; align-items: center; justify-content: center; gap: 14px; border: 0; border-radius: 20px; padding: 12px; background: var(--panel); border: 2px solid var(--line); }
.diebtn:not(:disabled) { border-color: var(--teal); }
.diebtn:not(:disabled) .die { animation: nudge 1.6s ease-in-out infinite; }
.diebtn:disabled { cursor: default; }
.diebtn:disabled .dielabel { color: var(--dim); }
.dielabel { font-family: var(--display); font-weight: 800; font-size: 18px; }
.die { width: 64px; height: 64px; border-radius: 16px; background: #fff; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 9px; box-shadow: inset 0 -5px 0 #d9d4f0, 0 4px 12px rgba(0,0,0,.35); }
.die i { width: 12px; height: 12px; border-radius: 50%; place-self: center; background: transparent; }
.die.rolling { animation: tumble .12s linear infinite; }
@keyframes tumble { 0% { transform: rotate(0) scale(1); } 50% { transform: rotate(14deg) scale(.92); } 100% { transform: rotate(-10deg) scale(1); } }
@keyframes nudge { 0%, 70%, 100% { transform: none; } 80% { transform: rotate(-8deg); } 90% { transform: rotate(8deg); } }
.die[data-v="1"] i:nth-child(5),
.die[data-v="2"] i:nth-child(1), .die[data-v="2"] i:nth-child(9),
.die[data-v="3"] i:nth-child(1), .die[data-v="3"] i:nth-child(5), .die[data-v="3"] i:nth-child(9),
.die[data-v="4"] i:nth-child(1), .die[data-v="4"] i:nth-child(3), .die[data-v="4"] i:nth-child(7), .die[data-v="4"] i:nth-child(9),
.die[data-v="5"] i:nth-child(1), .die[data-v="5"] i:nth-child(3), .die[data-v="5"] i:nth-child(5), .die[data-v="5"] i:nth-child(7), .die[data-v="5"] i:nth-child(9),
.die[data-v="6"] i:nth-child(1), .die[data-v="6"] i:nth-child(3), .die[data-v="6"] i:nth-child(4), .die[data-v="6"] i:nth-child(6), .die[data-v="6"] i:nth-child(7), .die[data-v="6"] i:nth-child(9) { background: var(--die-pip, #141721); }
.die[data-v="6"] i { --die-pip: #f04fa8; }
.gamebtns { display: flex; justify-content: center; }

@media (min-width: 860px) {
  .play { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
  .boardwrap { max-width: min(100%, calc(100vh - 110px)); }
  .side { position: sticky; top: 70px; }
  .strip { grid-template-columns: 1fr 1fr; }
}

/* Board svg bits */
.num { font-family: var(--display); font-weight: 700; fill: rgba(30,25,60,.55); }
.token { transition: none; }
.tokshadow { fill: rgba(0,0,0,.25); }
.cellhi { fill: none; stroke: #fff; stroke-width: 6; opacity: 0; }
.cellhi.on { animation: hi 1s ease-out; }
@keyframes hi { 0% { opacity: 1; } 100% { opacity: 0; } }

/* Sheets */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(8,9,16,.66); display: grid; place-items: center; padding: 16px; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.card { position: relative; width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 24px; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.5); animation: pop .25s cubic-bezier(.2,1.4,.5,1); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.card h3 { margin: 0 0 8px; font-family: var(--display); font-weight: 800; font-size: 22px; }
.card .row { display: flex; gap: 8px; flex-wrap: wrap; }
.card .row .start { flex: 1; margin: 12px 0 0; font-size: 17px; padding: 12px; }
.card .row .ghost { margin-top: 12px; }
.howlist { padding-left: 20px; line-height: 1.45; }
.howlist li { margin-bottom: 8px; }
.quizcard { text-align: center; }
.quizwho { margin: 0; color: var(--dim); font-size: 14px; }
.quizart { width: 100%; height: auto; background: #f7f3ff; border-radius: 16px; margin: 6px 0 12px; }
.answers { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.answers button { border: 2px solid var(--line); background: var(--panel); border-radius: 16px; padding: 14px 8px; font-family: var(--display); font-weight: 800; font-size: 20px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.answers button svg { width: 40px; height: 40px; }
.answers button.right { background: #1f8f62; border-color: #3ee09a; }
.answers button.wrong { background: #6b2a3e; border-color: #f04f7a; }
.quizmsg { min-height: 1.4em; font-weight: 800; font-size: 17px; margin: 12px 0 0; }
.wincard { text-align: center; overflow: hidden; }
.wincard canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.trophy { font-size: 64px; line-height: 1; animation: pop .6s cubic-bezier(.2,1.6,.5,1); }
.ranks { text-align: left; display: grid; gap: 6px; padding: 0; list-style: none; margin: 12px 0; }
.ranks li { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 12px; padding: 6px 10px; }
.ranks svg { width: 26px; height: 26px; }
.ranks small { margin-left: auto; color: var(--dim); }
.winstars { color: #ffd166; font-weight: 800; }
.badgelist { list-style: none; padding: 0; display: grid; gap: 8px; }
.badgelist li { display: flex; gap: 10px; align-items: center; background: var(--panel); border-radius: 14px; padding: 8px 10px; }
.badgelist li .b { font-size: 28px; width: 40px; text-align: center; }
.badgelist li.locked .b { filter: grayscale(1); opacity: .35; }
.badgelist li div { line-height: 1.25; }
.badgelist li small { color: var(--dim); }

/* Coach & toast */
.coach, .toast { position: fixed; left: 50%; transform: translateX(-50%); z-index: 15; max-width: min(420px, calc(100vw - 24px)); border-radius: 16px; padding: 10px 14px; font-weight: 800; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: rise .3s ease; }
.coach { bottom: max(16px, env(safe-area-inset-bottom)); background: #fff; color: #1b1d2e; }
.coach::before { content: "💡 "; }
.toast { top: 70px; background: var(--grad); color: #fff; }
@keyframes rise { from { transform: translate(-50%, 12px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
@media (max-width: 380px) {
  .seg button { padding: 6px 8px; font-size: 13px; }
  .die { width: 54px; height: 54px; padding: 7px; }
  .die i { width: 10px; height: 10px; }
  .top { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .icon { width: 32px; height: 32px; }
  .home img { height: 24px; }
}
