/* Khel ON · Snakes & Ladders */
:root {
  --bg: #121521; --bg2: #1c2133; --panel: #252b40;
  --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;
  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: game name + one line of context (all controls live in the dock at the bottom) */
.top { position: relative; z-index: 5; display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--bg); border-bottom: 1px solid rgba(255,255,255,.07); }
.top::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--grad); opacity: .7; }
.bar-t { flex: 1; display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.top h1 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 24px; line-height: 1.1; white-space: nowrap; }
.top h1 span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.ctx { margin: 0; color: var(--dim); font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ctx:empty { display: none; }
.starcount { font-family: var(--display); font-weight: 800; color: #ffd166; font-size: 16px; padding: 6px 12px; border-radius: 999px; background: rgba(255, 209, 102, .1); white-space: nowrap; }
.starcount.bump { animation: bump .5s ease; }
@keyframes bump { 40% { transform: scale(1.25); } }

main { 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 */
.boardwrap { position: relative; border-radius: 16px; }
#board { display: block; width: 100%; height: auto; border-radius: inherit; box-shadow: 0 10px 30px rgba(0,0,0,.45); touch-action: manipulation; user-select: none; }
.diebtn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 24px; padding: 12px 14px; background: transparent; min-width: 96px; }
.diebtn:disabled { cursor: default; }
.diebtn:not(:disabled) .die { animation: nudge 1.6s ease-in-out infinite; box-shadow: inset 0 -5px 0 #d9d4f0, 0 0 0 4px var(--cur, #2fd4c8), 0 0 28px 4px var(--cur, #2fd4c8); }
.diebtn:not(:disabled):hover { background: rgba(255,255,255,.05); }
.diebtn:disabled .dielabel { color: var(--dim); }
.diebtn:disabled .die { opacity: .8; }
.dielabel { font-family: var(--display); font-weight: 800; font-size: 16px; white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.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; }

/* 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); }

/* toast: over the bottom of the board; the coach tip lives in the side panel (.gp-tip) */
.toast { position: absolute; left: 50%; bottom: 6%; transform: translateX(-50%); z-index: 3; max-width: calc(100% - 24px); border-radius: 16px; padding: 10px 16px; font-weight: 800; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,.4); background: var(--grad); color: #fff; pointer-events: none; animation: rise .3s ease; white-space: nowrap; }
@keyframes rise { from { transform: translate(-50%, 12px); opacity: 0; } }
.coach::before { content: "💡 "; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
/* online with friends */
.continue.online { margin: -16px 0 30px; background: transparent; color: var(--teal); border: 2px solid var(--teal); }
.answers button.picked { border-color: #ffd166; box-shadow: 0 0 0 2px #ffd166 inset; }

/* No text caret, no text selection, no tap flash anywhere in the game (mouse double-clicks and caret browsing included).
   The only real text box is the online table-code field, which keeps its caret. Keyboard focus rings stay (:focus-visible). */
html, body { caret-color: transparent; -webkit-tap-highlight-color: transparent; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input[type=text], input:not([type]), textarea, .kn-in { caret-color: auto; -webkit-user-select: text; user-select: text; }
button, [role=button], [role=radio], a, svg, canvas, img { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
img, svg image { -webkit-user-drag: none; }

/* ---------- front door era: pointer only on things you can click, sheets above the front door ---------- */
html, body, body * { cursor: default; }
button:not(:disabled), button:not(:disabled) *, a[href], a[href] * { cursor: pointer; }
html.kl-open .sheet { z-index: 2147482950; }

/* ---------- Option A layout: board left, side panel filling the rest, the dock at the bottom ---------- */
:root { --hdr: 56px; }
.play:not([hidden]) { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.boardwrap { width: min(100%, 600px, calc(100dvh - var(--hdr) - var(--kd-h, 0px) - 200px)); min-width: 280px; }
.gp-side { width: min(100%, 600px); }
.sheet { padding-bottom: calc(16px + var(--kd-h, 0px)); }
.card { max-height: calc(100dvh - 32px - var(--kd-h, 0px)); }
@media (max-width: 899px) {
  .play:not([hidden]) { min-height: calc(100dvh - var(--hdr) - var(--kd-h, 0px) - 28px); justify-content: center; }
  .top { justify-content: center; }
  .bar-t { flex-direction: column; align-items: center; gap: 0; flex: none; }
  .top h1 { font-size: 21px; }
  .ctx { font-size: 13px; }
  .starcount { position: absolute; right: 12px; font-size: 14px; padding: 4px 10px; }
  .diebtn { min-width: 0; padding: 4px 6px; gap: 4px; }
  .dielabel { font-size: 13px; max-width: 110px; }
  .die { width: 58px; height: 58px; padding: 8px; }
  .die i { width: 10px; height: 10px; }
  .toast { white-space: normal; }
}
@media (max-width: 400px) { .top .starcount { display: none; } }
@media (min-width: 900px) {
  :root { --hdr: 64px; }
  .top { min-height: 64px; padding-left: 28px; padding-right: 28px; }
  main { max-width: none; padding: 20px 28px; }
  .play:not([hidden]) { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 28px; align-items: stretch; }
  .boardwrap { width: min(calc(100dvh - var(--hdr) - var(--kd-h, 0px) - 40px), calc(100vw - 56px - 28px - 400px)); min-width: 420px; border-radius: 22px; }
  .gp-side { width: auto; height: calc(100dvh - var(--hdr) - var(--kd-h, 0px) - 40px); min-height: 420px; }
  .gp-grid { overflow: auto; }
  .die { width: 96px; height: 96px; padding: 13px; border-radius: 22px; }
  .die i { width: 17px; height: 17px; }
  .dielabel { font-size: 18px; }
  .toast { font-size: 18px; padding: 12px 22px; }
}
@container gpside (min-width: 560px) {
  .die { width: 136px; height: 136px; padding: 18px; border-radius: 30px; }
  .die i { width: 24px; height: 24px; }
  .dielabel { font-size: 20px; max-width: 260px; }
}
