/* Khel ON Chess */
:root {
  --navy: #141721; --panel: #1d2131; --panel2: #262b3f; --line: #343a55;
  --text: #f5f1ea; --muted: #a9adc4;
  --orange: #ff9a3c; --pink: #f04fa8; --purple: #8b5cf6; --teal: #2fd4c8;
  --grad: linear-gradient(90deg, #ff9a3c, #f04fa8 55%, #8b5cf6);
  --sq-light: #f1e6d3; --sq-dark: #8a79cf;
  --pw-fill: #fffaf1; --pw-line: #141721;
  --pb-fill: #262a3d; --pb-line: #0b0d14; --pb-detail: #cfd3ea;
  --font-head: 'Outfit', 'Lilita One', 'Nunito', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--navy); color: var(--text); font-family: var(--font-body); -webkit-tap-highlight-color: transparent; }
body { min-height: 100vh; overflow-x: hidden; }
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }

.app { max-width: 560px; margin: 0 auto; padding: 0 12px calc(16px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.home-link svg { width: 20px; height: 20px; color: var(--muted); align-self: center; }
.home-link { text-decoration: none; font-family: var(--font-head); font-weight: 800; font-size: 22px; letter-spacing: .2px; display: inline-flex; gap: 4px; align-items: baseline; }
.brand-k { color: var(--text); }
.brand-on { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.topbar-title { flex: 1; font-family: var(--font-head); font-weight: 700; font-size: 17px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; width: 42px; height: 42px; cursor: pointer; font-size: 18px; }

h1, h2, h3, h4 { font-family: var(--font-head); margin: 0 0 8px; }
h1 { font-size: 40px; line-height: 1.05; }
h2 { font-size: 26px; margin-top: 6px; }
h3 { font-size: 22px; }
h4 { font-size: 16px; margin-top: 14px; color: var(--teal); }
p { line-height: 1.5; }
.sub, .tag { color: var(--muted); margin: 0 0 14px; }
.small { font-size: 13px; color: var(--muted); }

.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 14px; padding: 11px 16px; cursor: pointer; font-weight: 700; font-size: 16px; min-height: 46px; transition: transform .08s ease, filter .15s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--grad); border: 0; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.btn.big { width: 100%; font-size: 18px; min-height: 56px; display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn.small { padding: 8px 10px; font-size: 14px; min-height: 42px; flex: 1; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, .chip:focus-visible, .sq:focus-visible, .lesson:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
.linkbtn { background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; margin-top: 10px; font-size: 15px; }
.pill { background: rgba(255,255,255,.12); border-radius: 999px; padding: 2px 10px; font-size: 14px; }

.hero { text-align: center; padding: 12px 0 6px; }
.hero-pieces { display: flex; justify-content: center; gap: 4px; margin-bottom: 4px; }
.hero-pieces .pc { width: 64px; height: 64px; }
.menu { display: grid; gap: 12px; margin-top: 10px; }
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.newbie { text-align: center; color: var(--muted); margin-top: 16px; }
.newbie b { color: var(--teal); }

.setup-block { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin: 12px 0; }
.label { font-weight: 800; margin-bottom: 10px; }
.chips { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.chip { background: var(--panel2); border: 2px solid var(--line); border-radius: 12px; padding: 10px 8px; font-weight: 800; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 50px; justify-content: center; }
.chip small { font-weight: 600; color: var(--muted); font-size: 12px; }
.chip[aria-checked="true"] { border-color: var(--teal); background: rgba(47,212,200,.14); }
.toggle { display: flex; gap: 10px; align-items: center; cursor: pointer; font-weight: 600; }
.toggle input { width: 22px; height: 22px; accent-color: var(--teal); flex: none; }
.setup-actions { display: flex; gap: 10px; margin-top: 16px; }
.setup-actions .btn { flex: 1; }

/* board */
.board-wrap { position: relative; margin: 0 auto; width: min(100%, 520px, calc(100vh - 290px)); min-width: 280px; }
.board { display: grid; grid-template-columns: repeat(8, 1fr); width: 100%; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden; box-shadow: 0 8px 28px rgba(0,0,0,.45), 0 0 0 3px #2a2f45; touch-action: none; user-select: none; -webkit-user-select: none; }
.sq { position: relative; border: 0; padding: 0; margin: 0; background: var(--sq-light); cursor: pointer; aspect-ratio: 1 / 1; display: block; min-width: 0; }
.sq.dk { background: var(--sq-dark); }
.sq .pc { position: absolute; inset: 4%; width: 92%; height: 92%; pointer-events: none; z-index: 2; }
.sq.last::before { content: ''; position: absolute; inset: 0; background: rgba(255,154,60,.38); z-index: 0; }
.sq.sel::before { content: ''; position: absolute; inset: 0; background: rgba(47,212,200,.55); z-index: 0; }
.sq.hint::before { content: ''; position: absolute; inset: 0; background: rgba(47,212,200,.5); z-index: 0; animation: pulse 1s ease-in-out infinite alternate; }
.sq.check::after { content: ''; position: absolute; inset: 0; background: radial-gradient(circle, rgba(240,79,168,.95) 0%, rgba(240,79,168,.55) 45%, rgba(240,79,168,0) 72%); z-index: 1; }
.sq.danger .pc { filter: drop-shadow(0 0 3px #ff9a3c) drop-shadow(0 0 3px #ff9a3c); }
.sq .dot { position: absolute; left: 35%; top: 35%; width: 30%; height: 30%; border-radius: 50%; background: rgba(20,23,33,.32); z-index: 3; pointer-events: none; }
.sq .ring { position: absolute; inset: 3%; border-radius: 50%; border: 5px solid rgba(20,23,33,.32); z-index: 3; pointer-events: none; }
.sq .coord { position: absolute; font-size: 10px; font-weight: 800; z-index: 1; pointer-events: none; opacity: .8; }
.sq .coord.f { right: 3px; bottom: 1px; }
.sq .coord.r { left: 3px; top: 1px; }
.sq.dk .coord { color: var(--sq-light); }
.sq:not(.dk) .coord { color: var(--sq-dark); }
.sq .starmark { position: absolute; inset: 18%; width: 64%; height: 64%; fill: #ffc93c; stroke: #b36b00; stroke-width: 4; z-index: 1; pointer-events: none; animation: twinkle 1.4s ease-in-out infinite alternate; }
.sq .starmark.got { fill: rgba(255,255,255,.3); stroke: none; animation: none; }
.sq.drag-from .pc { opacity: .35; }
.ghost { position: fixed; z-index: 50; pointer-events: none; transform: translate(-50%, -60%); }
.ghost .pc { width: 100%; height: 100%; }
@keyframes pulse { from { opacity: .35; } to { opacity: .9; } }
@keyframes twinkle { from { transform: scale(.9); } to { transform: scale(1.05); } }

/* pieces */
.pc { display: block; }
.pc .f { stroke-width: 3.2; stroke-linejoin: round; }
.pc .d { fill: none; stroke-width: 3; stroke-linecap: round; }
.pc.w { fill: var(--pw-fill); stroke: var(--pw-line); }
.pc.w .d { stroke: var(--pw-line); }
.pc.w .e { fill: var(--pw-line); }
.pc.b { fill: var(--pb-fill); stroke: var(--pb-line); }
.pc.b .d { stroke: var(--pb-detail); }
.pc.b .e { fill: var(--pb-detail); }

.player-bar { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 4px 2px; font-weight: 800; }
.player-bar .who { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.player-bar .who .dotc { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #000; display: inline-block; }
.player-bar .who .dotc.w { background: var(--pw-fill); }
.player-bar .who .dotc.b { background: var(--pb-fill); border-color: var(--pb-detail); }
.player-bar.turn .who { color: var(--teal); }
.player-bar .caps { display: flex; flex-wrap: wrap; flex: 1; min-width: 0; }
.player-bar .caps .pc { width: 18px; height: 18px; margin-right: -4px; }
.player-bar .adv { color: var(--muted); font-size: 14px; }
.thinking { display: inline-flex; gap: 3px; margin-left: 4px; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--teal); animation: bob .9s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes bob { 0%, 100% { transform: translateY(0); opacity: .4; } 50% { transform: translateY(-4px); opacity: 1; } }

.coach { min-height: 48px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin: 6px 0 10px; font-weight: 600; line-height: 1.35; }
.coach b { color: var(--teal); }
.coach.warn { border-color: var(--orange); }
.coach.good { border-color: var(--teal); }
.game-actions, .lesson-actions { display: flex; gap: 8px; }
.movelist { list-style: none; margin: 12px 0 0; padding: 8px 10px; background: var(--panel); border-radius: 12px; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 14px; color: var(--muted); max-height: 92px; overflow-y: auto; }
.movelist:empty { display: none; }
.movelist li span { color: var(--text); font-weight: 700; margin-left: 4px; }

/* lessons */
.lesson-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lesson { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.lesson .ltop { display: flex; align-items: center; gap: 8px; }
.lesson .pc { width: 34px; height: 34px; flex: none; }
.lesson .lnum { color: var(--muted); font-size: 12px; font-weight: 800; }
.lesson .lname { font-weight: 800; font-size: 16px; }
.stars { display: inline-flex; gap: 2px; }
.stars svg { width: 18px; height: 18px; fill: #4a506c; }
.stars svg.on { fill: #ffc93c; }

/* badges */
.star-total { font-family: var(--font-head); font-size: 34px; font-weight: 800; display: flex; align-items: center; gap: 8px; margin: 6px 0 12px; }
.star-total .st { width: 34px; height: 34px; fill: #ffc93c; }
.star-total .of { font-size: 17px; color: var(--muted); font-weight: 700; }
.level-stars { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.level-stars div { background: var(--panel); border-radius: 12px; padding: 10px; font-weight: 800; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.badge { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.badge .bi { font-size: 30px; display: block; filter: grayscale(1); opacity: .35; }
.badge.on .bi { filter: none; opacity: 1; }
.badge.on { border-color: var(--teal); }
.badge .bn { font-weight: 800; display: block; margin-top: 4px; }
.badge .bd { font-size: 12px; color: var(--muted); }

/* modals */
.modal { position: fixed; inset: 0; background: rgba(8,10,16,.72); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 20px; width: 100%; max-width: 420px; text-align: center; max-height: calc(100vh - 32px); overflow-y: auto; }
.card.rules { text-align: left; max-width: 520px; }
.card.rules ul { padding-left: 20px; margin: 6px 0; }
.card.rules li { margin: 6px 0; line-height: 1.4; }
.rules-list { list-style: none; padding: 0 !important; }
.rules-list li { display: flex; gap: 10px; align-items: center; }
.rules-list .pc { width: 36px; height: 36px; flex: none; }
.card-actions { display: flex; gap: 10px; margin-top: 14px; }
.card-actions .btn { flex: 1; }
.stack { display: grid; gap: 10px; text-align: left; }
.promo-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.promo-row button { background: var(--sq-light); border: 2px solid var(--line); border-radius: 12px; padding: 6px; cursor: pointer; aspect-ratio: 1; }
.promo-row .pc { width: 100%; height: 100%; }
.result-stars { display: flex; justify-content: center; gap: 6px; margin-bottom: 6px; }
.result-stars svg { width: 44px; height: 44px; fill: #4a506c; }
.result-stars svg.on { fill: #ffc93c; animation: pop .4s ease-out both; }
.result-stars svg.on:nth-child(2) { animation-delay: .15s; }
.result-stars svg.on:nth-child(3) { animation-delay: .3s; }
@keyframes pop { from { transform: scale(.2); } 70% { transform: scale(1.2); } to { transform: scale(1); } }
.new-badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.new-badges .badge { min-width: 120px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--teal); padding: 10px 16px; border-radius: 12px; z-index: 60; font-weight: 700; max-width: calc(100vw - 32px); }

@media (max-width: 380px) {
  h1 { font-size: 34px; }
  .btn.small { font-size: 13px; padding: 6px 4px; }
  .chips { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
