/* Chess for kids — same design language as the Go app: sunny paper
   background, heavy rounded type, chunky 3D buttons, big touch targets.
   Performance rule carried over from Go: no blur, no blurred shadows. */
:root {
  --paper: #fff7e0; --paper-dark: #fce6b8; --card: #fffef7;
  --wood: #e6b366; --wood-dark: #9e6b33;
  --ink: #292133; --ink-soft: #574f6b;
  --moss: #33a34d; --moss-dark: #217033;
  --sky: #0d8ae0; --sky-dark: #0a5c9e;
  --coral: #ed5447; --coral-dark: #b33329;
  --gold: #ffc71a; --gold-dark: #a86b00;
  --plum: #9454db; --plum-dark: #66339e;
  --mint: #b8f2db; --peach: #ffdbb3;
  --sq-light: #fbf0d9; --sq-dark: #86bd7e;
  --r: 22px;
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, -apple-system, sans-serif;
  --s: 1; /* 0.85 on phones */
  color-scheme: light;
}
@media (max-width: 600px), (max-height: 500px) { :root { --s: .85; } }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
  font-family: var(--font); color: var(--ink); background: var(--paper);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  font-weight: 600; touch-action: manipulation; overflow: hidden;
}
button { font-family: inherit; color: inherit; }
.bg {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: linear-gradient(#dbf5ff, var(--paper) 50%, var(--peach));
}
.bg i { position: absolute; border-radius: 50%; }

#app { position: fixed; inset: 0; }
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  animation: screenIn .22s ease-out;
}
@keyframes screenIn { from { opacity: 0; transform: translateX(24px); } }
.screen.back-in { animation-name: screenBack; }
@keyframes screenBack { from { opacity: 0; transform: translateX(-24px); } }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }

/* ---- type ---- */
.display { font-weight: 900; font-size: calc(46px * var(--s)); letter-spacing: -.02em; margin: 0; line-height: 1.05; }
.title { font-weight: 800; font-size: calc(26px * var(--s)); margin: 0; }
.body { font-size: calc(19px * var(--s)); line-height: 1.35; }
.small { font-size: calc(15px * var(--s)); color: var(--ink-soft); }
.muted { color: var(--ink-soft); }

/* ---- chunky buttons ---- */
.btn {
  --c: var(--sky); --e: var(--sky-dark); --t: #fff;
  appearance: none; border: 0; cursor: pointer; position: relative;
  background: var(--c); color: var(--t);
  font-weight: 800; font-size: calc(22px * var(--s));
  min-height: calc(64px * var(--s)); padding: calc(14px * var(--s)) calc(26px * var(--s));
  border-radius: var(--r);
  box-shadow: 0 6px 0 var(--e), inset 0 2px 0 rgba(255,255,255,.35);
  transition: transform .08s, box-shadow .08s;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  white-space: nowrap;
}
.btn:active, .btn.pressed { transform: translateY(5px); box-shadow: 0 1px 0 var(--e), inset 0 2px 0 rgba(255,255,255,.35); }
.btn.green { --c: var(--moss); --e: var(--moss-dark); }
.btn.gold { --c: var(--gold); --e: var(--gold-dark); --t: var(--ink); }
.btn.coral { --c: var(--coral); --e: var(--coral-dark); }
.btn.plum { --c: var(--plum); --e: var(--plum-dark); }
.btn.paper { --c: var(--card); --e: var(--paper-dark); --t: var(--ink); }
.btn.compact { min-height: calc(50px * var(--s)); font-size: calc(18px * var(--s)); padding: 8px 16px; }
.btn.wide { width: 100%; }
.btn[disabled], .btn.locked { filter: grayscale(.8); opacity: .55; }
.btn .ico { font-size: 1.15em; line-height: 1; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

.card {
  background: var(--card); border-radius: 26px; padding: calc(18px * var(--s));
  box-shadow: 0 5px 0 var(--paper-dark); border: 2px solid rgba(0,0,0,.04);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 99px;
  background: var(--card); font-weight: 800; font-size: calc(16px * var(--s)); box-shadow: 0 3px 0 var(--paper-dark);
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px 6px; min-height: 70px; flex: none;
}
.topbar .grow { flex: 1; min-width: 0; }
.topbar .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.round {
  width: calc(58px * var(--s)); height: calc(58px * var(--s)); border-radius: 50%; border: 0; flex: none;
  background: var(--card); box-shadow: 0 5px 0 var(--paper-dark); font-size: calc(26px * var(--s)); font-weight: 900;
  display: grid; place-items: center; cursor: pointer; color: var(--ink);
}
.round:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--paper-dark); }
.round.locked { opacity: .5; }

/* ---- board ---- */
.board-wrap {
  position: relative; width: var(--bs); height: var(--bs); flex: none;
  padding: calc(var(--bs) * .025); border-radius: 22px;
  background: var(--wood); box-shadow: 0 8px 0 var(--wood-dark);
}
.board {
  position: relative; width: 100%; height: 100%; border-radius: 10px; overflow: hidden;
  touch-action: none; cursor: pointer;
}
.board > div, .board > svg { position: absolute; inset: 0; }
.board .sqs .sq, .board .marks .mk, .board .pcs .pc, .board .fx .burst {
  position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%;
}
.sq { background: var(--sq-dark); }
.sq.light { background: var(--sq-light); }
.sq .co { position: absolute; font-size: calc(var(--bs) * .022); font-weight: 900; color: rgba(41,33,51,.55); }
.sq .co.f { right: 4%; bottom: 2%; }
.sq .co.r { left: 5%; top: 3%; }
.pc { will-change: transform; pointer-events: none; padding: .35%; transition: none; z-index: 2; }
.pc.moving { transition: transform .24s cubic-bezier(.3,.8,.4,1.1); z-index: 3; }
.pc.dragging { z-index: 5; filter: drop-shadow(0 6px 0 rgba(0,0,0,.18)); }
.pc.popped { animation: pop .36s ease-in forwards; }
@keyframes pop { to { opacity: 0; scale: 1.6; } }
.pc.bounce { animation: bounce .35s; }
@keyframes bounce { 40% { scale: 1.18; } 70% { scale: .95; } }
.pc.shake { animation: shake .4s; }
@keyframes shake { 20%,60% { translate: -6% 0; } 40%,80% { translate: 6% 0; } }
.board .arrows { pointer-events: none; z-index: 4; width: 100%; height: 100%; }
.marks { pointer-events: none; }
.mk { display: grid; place-items: center; }
.mk.last { background: rgba(255, 213, 79, .45); }
.mk.sel { background: rgba(13, 138, 224, .38); }
.mk.check { background: radial-gradient(circle, rgba(237,84,71,.95) 0%, rgba(237,84,71,.55) 45%, rgba(237,84,71,0) 72%); animation: pulse 1s infinite alternate; }
.mk.danger { background: rgba(237, 84, 71, .22); }
.mk.danger span { color: rgba(179,51,41,.55); font-weight: 900; font-size: calc(var(--bs) * .05); }
.mk.glow { background: rgba(255, 199, 26, .5); box-shadow: inset 0 0 0 4px #ffc71a; animation: pulse .8s infinite alternate; }
.mk.ring { box-shadow: inset 0 0 0 calc(var(--bs) * .008) var(--sky); border-radius: 50%; }
.mk.good { background: rgba(51, 163, 77, .35); }
.mk.good span { color: #fff; font-weight: 900; font-size: calc(var(--bs) * .06); text-shadow: 0 2px 0 var(--moss-dark); }
.mk.bad { background: rgba(237, 84, 71, .3); }
.mk.bad span { color: #fff; font-weight: 900; font-size: calc(var(--bs) * .06); }
.mk.dot::after { content: ""; width: 30%; height: 30%; border-radius: 50%; background: rgba(41,33,51,.28); }
.mk.dot.cap::after { width: 86%; height: 86%; background: none; box-shadow: inset 0 0 0 calc(var(--bs) * .008) rgba(237,84,71,.75); }
.mk.star { z-index: 1; }
.mk.star svg { width: 66%; height: 66%; fill: var(--gold); stroke: var(--gold-dark); stroke-width: 1.2; animation: twinkle 1.6s infinite alternate; }
@keyframes twinkle { to { transform: scale(1.12) rotate(8deg); } }
@keyframes pulse { to { opacity: .55; } }
.burst { pointer-events: none; z-index: 6; }
.burst i { position: absolute; left: 45%; top: 45%; width: 10%; height: 10%; border-radius: 50%; animation: fly .55s ease-out forwards; }
@keyframes fly { to { transform: rotate(var(--a)) translateY(-360%) scale(.4); opacity: 0; } }
.promo { position: absolute; inset: 0; background: rgba(41,33,51,.45); display: grid; place-items: center; z-index: 10; }
.promo-card { background: var(--card); border-radius: 24px; padding: 12px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: 86%; }
.promo-card button { border: 0; background: var(--paper); border-radius: 18px; padding: 6px; box-shadow: 0 4px 0 var(--paper-dark); }
.promo-card button:first-child { background: var(--gold); box-shadow: 0 4px 0 var(--gold-dark); }
.promo-card img { width: 100%; display: block; }

/* ---- game layouts ---- */
.play-area { flex: 1; display: flex; gap: 18px; padding: 6px 18px 16px; min-height: 0; align-items: center; justify-content: center; }
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; align-self: stretch; justify-content: center; }
@media (orientation: landscape) {
  .play-area { --bs: min(calc(100dvh - 130px), 60vw); }
  .side { width: min(420px, calc(100vw - var(--bs) - 70px)); }
}
@media (orientation: portrait) {
  .play-area { flex-direction: column; justify-content: flex-start; --bs: min(calc(100vw - 32px), calc(100dvh - 380px)); }
  .side { width: 100%; max-width: 640px; align-self: center; justify-content: flex-start; flex: 1; overflow-y: auto; }
}

/* ---- persona / speech ---- */
.avatar { width: calc(64px * var(--s)); height: calc(64px * var(--s)); flex: none; }
.avatar.big { width: calc(110px * var(--s)); height: calc(110px * var(--s)); }
.avatar.talking { animation: talk .5s infinite alternate; }
@keyframes talk { to { transform: translateY(-3px) rotate(-2deg); } }
.speech { display: flex; gap: 10px; align-items: flex-start; }
.bubble {
  position: relative; background: var(--card); border-radius: 22px; padding: 12px 16px; flex: 1;
  box-shadow: 0 4px 0 var(--paper-dark); font-size: calc(19px * var(--s)); line-height: 1.35;
}
.bubble::before { content: ""; position: absolute; left: -9px; top: 22px; border: 10px solid transparent; border-right-color: var(--card); border-left: 0; }
.bubble b { color: var(--sky-dark); }
.bubble .who { font-weight: 900; font-size: .8em; color: var(--plum-dark); display: block; }
.bubble.ok { background: #e3f8e6; } .bubble.ok::before { border-right-color: #e3f8e6; }
.bubble.oops { background: #ffe9e4; } .bubble.oops::before { border-right-color: #ffe9e4; }

/* ---- overlays ---- */
.overlay { position: fixed; inset: 0; background: rgba(41,33,51,.45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--card); border-radius: 30px; padding: calc(24px * var(--s)); width: min(560px, 100%); max-height: 92dvh; overflow-y: auto; text-align: center; box-shadow: 0 8px 0 var(--paper-dark); animation: popIn .3s cubic-bezier(.3,1.4,.5,1); }
@keyframes popIn { from { transform: scale(.7); opacity: 0; } }
.modal .display { margin-bottom: 6px; }
.modal .btns { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.stars-big { font-size: calc(64px * var(--s)); letter-spacing: 6px; }
.stars-big .s { display: inline-block; animation: starIn .5s cubic-bezier(.3,1.6,.5,1) backwards; }
.stars-big .s.off { filter: grayscale(1); opacity: .3; }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 12px; height: 18px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }
.toast { position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 70; background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 99px; font-weight: 800; animation: fade .2s; }

/* ---- menu ---- */
.menu { display: grid; gap: 18px; padding: 10px 20px 24px; max-width: 1100px; margin: 0 auto; width: 100%; }
@media (orientation: landscape) and (min-width: 900px) { .menu { grid-template-columns: 1fr 1.3fr; align-items: center; height: 100%; } }
.hero { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.hero .avatar { width: calc(150px * var(--s)); height: calc(150px * var(--s)); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tile {
  --c: var(--sky); --e: var(--sky-dark); border: 0; cursor: pointer;
  background: var(--c); color: #fff; border-radius: 28px; padding: calc(16px * var(--s)); text-align: left;
  box-shadow: 0 7px 0 var(--e); display: flex; flex-direction: column; gap: 4px; min-height: calc(130px * var(--s));
  position: relative; overflow: hidden;
}
.tile:active { transform: translateY(6px); box-shadow: 0 1px 0 var(--e); }
.tile .emoji { font-size: calc(44px * var(--s)); line-height: 1; }
.tile .name { font-weight: 900; font-size: calc(25px * var(--s)); }
.tile .sub { font-size: calc(15px * var(--s)); opacity: .95; font-weight: 700; }
.tile.big { grid-column: span 2; min-height: calc(150px * var(--s)); }
.tile.green { --c: var(--moss); --e: var(--moss-dark); }
.tile.gold { --c: var(--gold); --e: var(--gold-dark); color: var(--ink); }
.tile.coral { --c: var(--coral); --e: var(--coral-dark); }
.tile.plum { --c: var(--plum); --e: var(--plum-dark); }
.tile .deco { position: absolute; right: 4px; bottom: -6px; width: min(30%, 110px); opacity: .95; }
.tile .name, .tile .sub, .tile .emoji { position: relative; z-index: 1; max-width: 72%; }
.meter { height: 16px; background: rgba(0,0,0,.08); border-radius: 99px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--gold); border-radius: 99px; }

/* ---- lesson map ---- */
.map { position: relative; margin: 0 auto; width: min(560px, 100%); }
.map .trail { position: absolute; inset: 0; pointer-events: none; }
.map .node {
  position: absolute; width: calc(92px * var(--s)); height: calc(92px * var(--s)); margin: calc(-46px * var(--s)) 0 0 calc(-46px * var(--s));
  border-radius: 50%; border: 0; background: var(--sky); box-shadow: 0 7px 0 var(--sky-dark);
  display: grid; place-items: center; cursor: pointer; padding: 0;
}
.map .node:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--sky-dark); }
.map .node img { width: 64%; }
.map .node.done { background: var(--gold); box-shadow: 0 7px 0 var(--gold-dark); }
.map .node.locked { background: #d9d3c6; box-shadow: 0 7px 0 #b2aa99; }
.map .node.locked img { opacity: .45; filter: grayscale(1); }
.map .node.current { animation: nodePulse 1.2s infinite alternate; }
@keyframes nodePulse { to { transform: scale(1.08); } }
.map .node .st { position: absolute; bottom: -24px; font-size: 18px; letter-spacing: 1px; white-space: nowrap; }
.map .node .st .off { filter: grayscale(1); opacity: .35; }
.map .label { position: absolute; transform: translate(-50%, 0); font-weight: 800; font-size: calc(15px * var(--s)); text-align: center; width: 150px; color: var(--ink); }
.map .banner { position: absolute; left: 12px; right: 12px; border-radius: 26px; padding: 14px 18px; color: #fff; box-shadow: 0 6px 0 rgba(0,0,0,.18); }
.map .banner .title { font-size: calc(24px * var(--s)); }
.map .fog { position: absolute; left: 0; right: 0; display: grid; place-items: center; font-size: 60px; opacity: .8; }
.map .here { position: absolute; transform: translate(-50%, -100%); background: var(--coral); color: #fff; padding: 6px 14px; border-radius: 99px; font-weight: 900; white-space: nowrap; box-shadow: 0 4px 0 var(--coral-dark); animation: hop 1s infinite alternate; }
@keyframes hop { to { margin-top: -6px; } }

/* ---- lists / setup ---- */
.list { display: grid; gap: 14px; padding: 6px 18px 30px; max-width: 760px; margin: 0 auto; width: 100%; }
.pick { display: flex; align-items: center; gap: 14px; text-align: left; border: 0; background: var(--card); border-radius: 24px; padding: 12px 16px; box-shadow: 0 5px 0 var(--paper-dark); cursor: pointer; width: 100%; }
.pick:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--paper-dark); }
.pick.on { background: #e1f1ff; box-shadow: 0 5px 0 var(--sky); outline: 3px solid var(--sky); }
.pick .grow { flex: 1; min-width: 0; }
.pick .name { font-weight: 900; font-size: calc(22px * var(--s)); }
.seg { display: flex; background: rgba(0,0,0,.06); border-radius: 18px; padding: 5px; gap: 5px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 14px; padding: 12px 6px; font-weight: 800; font-size: calc(17px * var(--s)); cursor: pointer; }
.seg button.on { background: var(--card); box-shadow: 0 3px 0 var(--paper-dark); }
.section-title { font-weight: 900; font-size: calc(18px * var(--s)); color: var(--ink-soft); margin: 10px 4px 0; }

/* players bar in games */
.players { display: flex; gap: 10px; }
.player { flex: 1; display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 20px; padding: 8px 12px; box-shadow: 0 4px 0 var(--paper-dark); min-width: 0; border: 3px solid transparent; }
.player.turn { border-color: var(--gold); }
.player .name { font-weight: 900; font-size: calc(18px * var(--s)); }
.player .caps { display: flex; flex-wrap: wrap; min-height: 22px; }
.player .caps img { width: 22px; height: 22px; margin-right: -6px; }
.thinking { display: inline-flex; gap: 3px; }
.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-soft); animation: dots 1s infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; } .thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes dots { 50% { transform: translateY(-5px); } }

.stickers { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; font-size: 44px; }
.stickers span { display: grid; place-items: center; background: var(--paper); border-radius: 18px; aspect-ratio: 1; }
.stickers span.empty { opacity: .25; filter: grayscale(1); }

.keypad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.keypad button { border: 0; border-radius: 14px; background: var(--card); box-shadow: 0 4px 0 var(--paper-dark); font-weight: 900; font-size: 24px; padding: 10px 0; }
.codebox { display: flex; gap: 10px; justify-content: center; margin: 10px 0; }
.codebox span { width: 60px; height: 72px; border-radius: 16px; background: var(--card); box-shadow: inset 0 0 0 3px var(--sky); display: grid; place-items: center; font-size: 38px; font-weight: 900; }
.timer { font-weight: 900; font-size: calc(40px * var(--s)); font-variant-numeric: tabular-nums; }
.pill-stat { display: flex; gap: 10px; flex-wrap: wrap; }
.hidden { display: none !important; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 4px; border-bottom: 2px dashed rgba(0,0,0,.06); }
.switch { width: 64px; height: 38px; border-radius: 99px; background: #d4cfc4; position: relative; border: 0; flex: none; }
.switch::after { content: ""; position: absolute; top: 4px; left: 4px; width: 30px; height: 30px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch.on { background: var(--moss); }
.switch.on::after { left: 30px; }
select { font: inherit; font-size: 17px; padding: 8px; border-radius: 12px; border: 2px solid var(--paper-dark); background: var(--card); max-width: 60%; }
