/* Chess Pals — a bright, chunky, friendly look. Layout adapts from small phones to wide desktops (JS sets --board). */
:root {
  --ink: #2d2a4a; --ink-soft: #5d5a7e; --paper: #fffdf7; --paper-2: #f4efff;
  --sun: #ffc93c; --sun-d: #e9a10f; --grass: #5fd068; --grass-d: #33a944; --sky: #4cb8f5; --sky-d: #1f8fd6;
  --pink: #ff6f9f; --pink-d: #e0457a; --violet: #9b7bff;
  --radius: 22px; --shadow: 0 10px 30px rgba(45, 42, 74, 0.18);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Quicksand", "Varela Round", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --sq-light: #f6f9df; --sq-dark: #8fca72; --frame: #5aa34a; --frame-d: #3f7d33; --coord-l: #6aa955; --coord-d: #f6f9df;
  --mark-last: rgba(255, 214, 64, 0.55); --mark-sel: rgba(255, 238, 112, 0.85); --dot: rgba(45, 42, 74, 0.28);
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
body[data-theme="candy"] { --sq-light: #fff1f6; --sq-dark: #f7a6c4; --frame: #e86f9d; --frame-d: #bf4b78; --coord-l: #e07aa1; --coord-d: #fff1f6; }
body[data-theme="ocean"] { --sq-light: #e8f6ff; --sq-dark: #74b9ea; --frame: #3c8fd0; --frame-d: #276ea8; --coord-l: #5a9fd4; --coord-d: #e8f6ff; }
body[data-theme="wood"] { --sq-light: #f3dfbf; --sq-dark: #c48c5a; --frame: #8d5a35; --frame-d: #643c20; --coord-l: #b07a4b; --coord-d: #f3dfbf; }
body[data-theme="night"] { --sq-light: #c8c9f2; --sq-dark: #7376c9; --frame: #3c3f8f; --frame-d: #262866; --coord-l: #6a6dc0; --coord-d: #dedff8; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); color: var(--ink); background: #bfe6ff;
  overflow: hidden; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  font-size: 16px; line-height: 1.3; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; touch-action: manipulation; }
button:focus-visible, input:focus-visible, .board:focus-visible { outline: 4px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 7px var(--sky-d); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
svg { display: block; }

/* ---------- sky background ---------- */
.sky { position: fixed; inset: 0; overflow: hidden; z-index: 0; background: linear-gradient(180deg, #7cc6f2 0%, #b4e2ff 48%, #e3f6ff 70%, #fff8e6 100%); }
.sun { position: absolute; width: 34vmin; height: 34vmin; right: -6vmin; top: -8vmin; border-radius: 50%; background: radial-gradient(circle, #fff7c2 0 38%, #ffe680 40%, rgba(255, 230, 128, 0.35) 56%, rgba(255, 230, 128, 0) 70%); animation: sun 9s ease-in-out infinite; }
@keyframes sun { 50% { transform: scale(1.06) rotate(8deg); } }
.cloud { position: absolute; width: 180px; height: 56px; border-radius: 60px; background: #fff; opacity: 0.85; filter: drop-shadow(0 6px 0 rgba(130, 180, 220, 0.25)); animation: drift linear infinite; }
.cloud::before, .cloud::after { content: ""; position: absolute; background: #fff; border-radius: 50%; }
.cloud::before { width: 80px; height: 80px; left: 26px; top: -40px; }
.cloud::after { width: 104px; height: 104px; left: 70px; top: -58px; }
.c1 { top: 12%; animation-duration: 90s; animation-delay: -20s; transform: scale(0.9); }
.c2 { top: 30%; animation-duration: 120s; animation-delay: -75s; transform: scale(0.6); opacity: 0.7; }
.c3 { top: 6%; animation-duration: 140s; animation-delay: -110s; transform: scale(0.45); opacity: 0.65; }
.c4 { top: 46%; animation-duration: 105s; animation-delay: -40s; transform: scale(0.75); opacity: 0.6; }
@keyframes drift { from { left: -260px; } to { left: calc(100% + 60px); } }
.hills { position: absolute; left: 0; right: 0; bottom: 0; height: 30vh; }
.hill { position: absolute; bottom: -40vh; border-radius: 50%; }
.h1 { left: -20vw; width: 90vw; height: 70vh; background: #9fdd7f; }
.h2 { right: -25vw; width: 100vw; height: 64vh; background: #86d06a; }
.h3 { left: 20vw; width: 80vw; height: 56vh; background: #74c45a; bottom: -44vh; }

/* ---------- screens ---------- */
#app { position: fixed; inset: 0; z-index: 1; }
.screen { position: absolute; inset: 0; display: none; padding: calc(var(--safe-t) + 12px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 16px); overflow-y: auto; overflow-x: hidden; }
.screen.active { display: flex; animation: screen-in 0.45s cubic-bezier(.2,.9,.3,1.2) both; }
.screen.leaving { display: flex; animation: screen-out 0.22s ease-in both; pointer-events: none; }
@keyframes screen-in { from { opacity: 0; transform: translateY(26px) scale(0.97); } }
@keyframes screen-out { to { opacity: 0; transform: translateY(-14px) scale(0.98); } }

/* ---------- buttons ---------- */
.big-btn {
  --c: var(--sun); --cd: var(--sun-d);
  position: relative; display: flex; align-items: center; gap: 14px; width: 100%; min-height: 72px; padding: 12px 20px 12px 14px; text-align: left;
  border-radius: var(--radius); background: var(--c); color: var(--ink);
  box-shadow: 0 6px 0 var(--cd), 0 12px 24px rgba(45, 42, 74, 0.18); transform: translateY(0);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.2s;
  animation: pop-in 0.5s cubic-bezier(.3,1.6,.5,1) both; animation-delay: calc(var(--i, 0) * 70ms + 120ms);
}
.big-btn::after { content: ""; position: absolute; inset: 4px 10px auto 10px; height: 40%; border-radius: 16px 16px 40px 40px; background: linear-gradient(rgba(255,255,255,0.45), rgba(255,255,255,0)); pointer-events: none; }
.big-btn:hover { filter: brightness(1.05); transform: translateY(-2px); box-shadow: 0 8px 0 var(--cd), 0 16px 28px rgba(45, 42, 74, 0.2); }
.big-btn:active { transform: translateY(5px); box-shadow: 0 1px 0 var(--cd), 0 4px 10px rgba(45, 42, 74, 0.2); }
.big-btn:disabled { filter: grayscale(0.6) opacity(0.6); pointer-events: none; }
.big-btn.c-sun { --c: var(--sun); --cd: var(--sun-d); }
.big-btn.c-grass { --c: var(--grass); --cd: var(--grass-d); }
.big-btn.c-sky { --c: var(--sky); --cd: var(--sky-d); color: #fff; }
.big-btn.c-pink { --c: var(--pink); --cd: var(--pink-d); color: #fff; }
.big-btn.c-white { --c: #fff; --cd: #d9d3f0; }
.big-btn.btn-continue { --c: #fff; --cd: #d6cff5; }
.big-btn.slim { min-height: 56px; justify-content: center; text-align: center; }
.bb-icon { flex: none; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 16px; background: rgba(255,255,255,0.5); font-size: 30px; }
.c-sky .bb-icon { background: rgba(255,255,255,0.25); }
.bb-text { display: flex; flex-direction: column; min-width: 0; }
.bb-text b { font-size: 21px; font-weight: 800; letter-spacing: 0.01em; }
.bb-text small { font-size: 14.5px; font-weight: 600; opacity: 0.75; }
.small-btn { padding: 12px 20px; border-radius: 999px; background: rgba(255,255,255,0.75); font-weight: 800; color: var(--ink-soft); box-shadow: 0 3px 0 rgba(45,42,74,0.12); transition: transform 0.12s; animation: pop-in 0.5s cubic-bezier(.3,1.6,.5,1) both; animation-delay: calc(var(--i, 0) * 70ms + 120ms); }
.small-btn:active { transform: translateY(3px); box-shadow: none; }
.icon-btn { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 16px; background: rgba(255,255,255,0.8); box-shadow: 0 4px 0 rgba(45,42,74,0.13); transition: transform 0.12s, box-shadow 0.12s; flex: none; font-size: 24px; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(45,42,74,0.13); }
.icon-btn svg { width: 26px; height: 26px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
#btn-settings svg { fill: var(--ink); stroke: none; }
#btn-menu svg circle { fill: var(--ink); stroke: none; }
.flag { width: 30px; height: 20px; border-radius: 5px; overflow: hidden; box-shadow: 0 0 0 2px rgba(45,42,74,0.15); background-size: cover; }
.flag.en { background: linear-gradient(90deg, transparent 42%, #c8102e 42% 58%, transparent 58%), linear-gradient(transparent 38%, #c8102e 38% 62%, transparent 62%), linear-gradient(90deg, transparent 36%, #fff 36% 64%, transparent 64%), linear-gradient(transparent 30%, #fff 30% 70%, transparent 70%), linear-gradient(33deg, transparent 46%, #fff 46% 54%, transparent 54%), linear-gradient(-33deg, transparent 46%, #fff 46% 54%, transparent 54%), #012169; }
.flag.sv { background: linear-gradient(90deg, transparent 31%, #fecc02 31% 44%, transparent 44%), linear-gradient(transparent 40%, #fecc02 40% 60%, transparent 60%), #006aa7; }
@keyframes pop-in { from { opacity: 0; transform: scale(0.7) translateY(14px); } }

/* ---------- home ---------- */
.home { width: 100%; max-width: 520px; margin: auto; display: flex; flex-direction: column; align-items: stretch; gap: clamp(14px, 3vh, 28px); padding-top: 40px; }
.topright { position: fixed; top: calc(var(--safe-t) + 12px); right: calc(var(--safe-r) + 14px); display: flex; gap: 10px; z-index: 3; }
.logo { text-align: center; }
.logo-pieces { position: relative; height: clamp(96px, 18vh, 150px); width: clamp(180px, 40vh, 280px); margin: 0 auto 4px; }
.lp { position: absolute; bottom: 0; transform-origin: 50% 95%; }
.lp svg { width: 100%; height: 100%; }
.lp1 { left: 0; width: 34%; height: 76%; animation: hop 2.4s ease-in-out infinite; animation-delay: -0.6s; }
.lp2 { left: 28%; width: 44%; height: 100%; animation: hop 2.4s ease-in-out infinite; z-index: 1; }
.lp3 { right: 0; width: 34%; height: 76%; animation: hop 2.4s ease-in-out infinite; animation-delay: -1.2s; }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0) scale(1); } 70% { transform: translateY(0) scale(1.08, 0.9); } 82% { transform: translateY(-18%) scale(0.95, 1.06); } 92% { transform: translateY(0) scale(1.05, 0.95); } }
.title { font-size: clamp(42px, 10vw, 66px); font-weight: 900; letter-spacing: 0.01em; line-height: 1; color: #fff; paint-order: stroke fill; -webkit-text-stroke: 9px var(--ink); text-shadow: 0 7px 0 var(--ink); }
.title .ch { display: inline-block; animation: wave 3.2s ease-in-out infinite; animation-delay: calc(var(--n) * 90ms); }
.title .ch:nth-child(4n+1) { color: #ffd84d; } .title .ch:nth-child(4n+2) { color: #ff8fb8; } .title .ch:nth-child(4n+3) { color: #7fe08a; } .title .ch:nth-child(4n) { color: #7cd3ff; }
@keyframes wave { 0%, 40%, 100% { transform: translateY(0) rotate(0); } 20% { transform: translateY(-10px) rotate(-4deg); } }
.tagline { margin: 14px 0 0; font-weight: 700; font-size: 17px; color: var(--ink-soft); }
.menu { display: flex; flex-direction: column; gap: 16px; }
.menu .small-btn { align-self: center; }

/* ---------- setup / lobby screens ---------- */
.panel-screen { width: 100%; max-width: 560px; margin: auto; display: flex; flex-direction: column; gap: 16px; padding: 4px 0 12px; }
.screen-head { display: flex; align-items: center; gap: 12px; }
.screen-head h2 { font-size: clamp(22px, 5vw, 28px); font-weight: 900; }
.panel-screen h3 { font-size: 18px; font-weight: 800; color: var(--ink-soft); margin-top: 4px; }
.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.level { position: relative; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; padding: 12px 10px 14px; border-radius: 20px; background: var(--paper); box-shadow: 0 5px 0 #ddd5f3, 0 10px 18px rgba(45,42,74,0.1); transition: transform 0.15s, box-shadow 0.15s; animation: pop-in 0.5s cubic-bezier(.3,1.6,.5,1) both; animation-delay: calc(var(--i) * 60ms + 80ms); }
.level .em { font-size: 44px; line-height: 1.1; transition: transform 0.3s cubic-bezier(.3,1.8,.5,1); }
.level b { font-size: 18px; font-weight: 900; }
.level small { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.level .stars { font-size: 12px; letter-spacing: 1px; color: #f2a90b; }
.level[aria-checked="true"] { background: #fff5c4; box-shadow: 0 5px 0 var(--sun-d), 0 0 0 4px var(--sun), 0 12px 22px rgba(233,161,15,0.3); transform: translateY(-3px); }
.level[aria-checked="true"] .em { transform: scale(1.18) rotate(-6deg); animation: wiggle 1.6s ease-in-out infinite; }
@keyframes wiggle { 0%, 100% { transform: scale(1.18) rotate(-6deg); } 50% { transform: scale(1.18) rotate(6deg); } }
.sides { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.side { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px 12px; border-radius: 20px; background: var(--paper); font-weight: 800; box-shadow: 0 5px 0 #ddd5f3; transition: transform 0.15s, box-shadow 0.15s; }
.side-pc { display: block; width: 58px; height: 58px; }
.side-pc svg { width: 100%; height: 100%; }
.side-mix { position: relative; }
.side-mix > span { position: absolute; width: 74%; height: 74%; }
.side-mix > span:first-child { left: -6%; top: 0; } .side-mix > span:last-child { right: -6%; bottom: 0; }
.side[aria-checked="true"] { background: #e8f7ff; box-shadow: 0 5px 0 var(--sky-d), 0 0 0 4px var(--sky); transform: translateY(-3px); }
.go { margin-top: 6px; justify-content: center; }
.go .bb-text { align-items: center; } .go .bb-text b { font-size: 24px; }

.me-card { display: flex; align-items: center; gap: 14px; padding: 12px 14px; border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); animation: pop-in 0.5s cubic-bezier(.3,1.6,.5,1) both; }
.me-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.me-text small { font-weight: 700; color: var(--ink-soft); }
.me-text b { font-size: 21px; font-weight: 900; }
.avatar { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(145deg, #fff, #f0e9ff); box-shadow: inset 0 -3px 0 rgba(45,42,74,0.08), 0 0 0 3px #fff; font-size: 26px; flex: none; }
.avatar.big { width: 62px; height: 62px; font-size: 38px; }
.avatar svg { width: 82%; height: 82%; }
.dice:active { animation: roll 0.5s ease; }
@keyframes roll { 50% { transform: rotate(180deg) scale(1.2); } }
.lobby { display: flex; flex-direction: column; gap: 14px; }
.lobby .big-btn:nth-child(1) { --i: 1; } .lobby .big-btn:nth-child(2) { --i: 2; } .lobby .big-btn:nth-child(3) { --i: 3; }
.lobby-sub { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 20px 16px; border-radius: var(--radius); background: rgba(255,255,255,0.88); box-shadow: var(--shadow); animation: pop-in 0.45s cubic-bezier(.3,1.5,.5,1) both; }
.lead { margin: 0; font-weight: 800; font-size: 18px; text-align: center; }
.row { display: flex; gap: 12px; align-items: center; justify-content: center; width: 100%; }
.row .big-btn { width: auto; flex: 1; max-width: 220px; }
.code-boxes { display: flex; gap: 10px; }
.code-boxes input { width: clamp(54px, 15vw, 70px); height: clamp(64px, 18vw, 82px); text-align: center; font: 900 clamp(32px, 9vw, 44px) var(--font); color: var(--ink); text-transform: uppercase; border: 0; border-radius: 18px; background: #fff; box-shadow: inset 0 -5px 0 #e3dcf7, 0 0 0 3px #e3dcf7; caret-color: var(--sky-d); -webkit-user-select: text; user-select: text; transition: box-shadow 0.15s, transform 0.15s; }
.code-boxes input:focus { outline: none; box-shadow: inset 0 -5px 0 #bfe4fb, 0 0 0 4px var(--sky); transform: translateY(-2px); }
.code-boxes.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.code-show { display: flex; gap: 10px; }
.code-show span { display: grid; place-items: center; width: clamp(56px, 15vw, 72px); height: clamp(66px, 18vw, 84px); border-radius: 18px; background: var(--sun); box-shadow: 0 6px 0 var(--sun-d); font: 900 clamp(34px, 9vw, 46px) var(--font); animation: pop-in 0.5s cubic-bezier(.3,1.8,.5,1) both; animation-delay: calc(var(--n) * 90ms); }
.code-show span:nth-child(2) { background: #ff9ec3; box-shadow: 0 6px 0 var(--pink-d); } .code-show span:nth-child(3) { background: #8fe29a; box-shadow: 0 6px 0 var(--grass-d); } .code-show span:nth-child(4) { background: #8fd3ff; box-shadow: 0 6px 0 var(--sky-d); }
.waiting { display: flex; align-items: center; gap: 10px; font-weight: 800; color: var(--ink-soft); }
.bouncy-dots { display: inline-flex; gap: 5px; }
.bouncy-dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--sky-d); animation: dot 1s ease-in-out infinite; }
.bouncy-dots i:nth-child(2) { animation-delay: 0.15s; background: var(--pink); } .bouncy-dots i:nth-child(3) { animation-delay: 0.3s; background: var(--sun-d); }
@keyframes dot { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-8px); } }
.radar { position: relative; width: 170px; height: 170px; display: grid; place-items: center; }
.radar-ring { position: absolute; inset: 0; border-radius: 50%; border: 4px solid var(--sky); animation: ring 2.1s ease-out infinite; opacity: 0; }
.radar-ring.r2 { animation-delay: 0.7s; } .radar-ring.r3 { animation-delay: 1.4s; }
@keyframes ring { from { transform: scale(0.3); opacity: 1; } to { transform: scale(1); opacity: 0; } }
.radar-me { width: 74px; height: 74px; border-radius: 50%; display: grid; place-items: center; background: #fff; box-shadow: 0 0 0 5px var(--sky), var(--shadow); font-size: 42px; animation: hop 1.4s ease-in-out infinite; }
.net-note { text-align: center; font-weight: 800; color: var(--pink-d); margin: 0; }

/* ---------- game layout ---------- */
#screen-game { padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 10px) calc(var(--safe-b) + 8px) calc(var(--safe-l) + 10px); overflow: hidden; }
.game { --board: 320px; position: relative; width: 100%; height: 100%; display: grid; gap: 8px; justify-content: center; align-content: center;
  grid-template-columns: var(--board); grid-template-rows: auto auto auto auto auto; grid-template-areas: "top" "opp" "board" "me" "controls"; }
.game.wide { grid-template-columns: var(--board) minmax(250px, 340px); grid-template-rows: auto auto 1fr auto auto; grid-template-areas: "board top" "board opp" "board info" "board me" "board controls"; column-gap: clamp(14px, 2.5vw, 30px); row-gap: 10px; align-content: center; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 8px; }
.topbar-title { flex: 1; min-width: 0; text-align: center; font-weight: 900; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .icon-btn { width: 44px; height: 44px; border-radius: 14px; }
#btn-sound .snd-off { display: none; } body.muted #btn-sound .snd-on { display: none; } body.muted #btn-sound .snd-off { display: block; }
#player-top { grid-area: opp; } #player-bottom { grid-area: me; }
.board-area { grid-area: board; position: relative; width: var(--board); height: var(--board); align-self: center; z-index: 2; }
.side-info { grid-area: info; display: none; min-height: 0; flex-direction: column; gap: 8px; }
.game.wide .side-info { display: flex; }
.controls { grid-area: controls; display: flex; gap: 8px; justify-content: center; }

/* player cards */
.player { display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 7px 12px 7px 8px; border-radius: 20px; background: rgba(255,255,255,0.82); box-shadow: 0 4px 0 rgba(45,42,74,0.08); transition: background 0.3s, box-shadow 0.3s, transform 0.3s; position: relative; z-index: 1; }
.player.turn { background: #fff; box-shadow: 0 4px 0 rgba(45,42,74,0.08), 0 0 0 4px var(--sun); transform: scale(1.015); }
.player .avatar { width: 44px; height: 44px; }
.player.turn .avatar { animation: hop 1.8s ease-in-out infinite; }
.p-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.p-name { font-weight: 900; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-sub { font-weight: 700; font-size: 13.5px; color: var(--ink-soft); min-height: 17px; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.p-sub .bouncy-dots i { width: 6px; height: 6px; }
.p-sub.warn { color: var(--pink-d); }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--grass); box-shadow: 0 0 0 2px #fff; flex: none; }
.conn-dot.away { background: #ffb020; animation: pulse 1s infinite; } .conn-dot.gone { background: #c9c3dc; }
.tray { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; max-width: 52%; min-height: 24px; }
.tray .ti { width: 24px; height: 24px; margin-left: -9px; }
.tray .ti:first-child { margin-left: 0; }
.tray .ti.new { animation: tray-pop 0.45s cubic-bezier(.3,1.8,.5,1); }
.tray .ti + .ti.gap { margin-left: 2px; }
.tray .adv { margin-left: 6px; font-weight: 900; font-size: 14px; color: var(--grass-d); background: #e7f9e6; border-radius: 999px; padding: 1px 7px; }
@keyframes tray-pop { from { transform: scale(2.2); } }
.emote-float { position: absolute; right: 12px; top: -8px; font-size: 40px; pointer-events: none; animation: emote 2.2s ease-out forwards; z-index: 5; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.2)); }
@keyframes emote { 0% { transform: scale(0) translateY(0); opacity: 0; } 15% { transform: scale(1.4) translateY(-10px); opacity: 1; } 30% { transform: scale(1) translateY(-16px); } 80% { opacity: 1; } 100% { transform: scale(0.9) translateY(-60px); opacity: 0; } }

/* the board */
.board-frame { position: absolute; inset: 0; padding: calc(var(--board) * 0.028); border-radius: calc(var(--board) * 0.05); background: var(--frame); box-shadow: inset 0 3px 0 rgba(255,255,255,0.35), 0 calc(var(--board) * 0.018) 0 var(--frame-d), 0 calc(var(--board) * 0.045) calc(var(--board) * 0.06) rgba(45, 42, 74, 0.28); transition: background 0.4s; }
.board { position: relative; width: 100%; height: 100%; border-radius: calc(var(--board) * 0.028); touch-action: none; outline: none; }
.squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border-radius: inherit; overflow: hidden; box-shadow: inset 0 0 0 2px rgba(0,0,0,0.06); }
.sq { position: relative; transition: background-color 0.4s; }
.sq.light { background: var(--sq-light); } .sq.dark { background: var(--sq-dark); }
.sq::after { content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 0.2s; }
.sq.last::after { opacity: 1; background: var(--mark-last); }
.sq.sel::after { opacity: 1; background: var(--mark-sel); box-shadow: inset 0 0 0 calc(var(--board) * 0.006) rgba(255,255,255,0.8); }
.sq.hint::after { opacity: 1; background: rgba(120, 220, 255, 0.45); animation: pulse 1.1s ease-in-out infinite; }
.sq.check::after { opacity: 1; background: radial-gradient(circle, rgba(255, 70, 90, 0.95) 0%, rgba(255, 70, 90, 0.6) 40%, rgba(255, 70, 90, 0) 75%); animation: pulse 0.9s ease-in-out infinite; }
.sq.kbd { box-shadow: inset 0 0 0 calc(var(--board) * 0.008) var(--sky-d); z-index: 1; }
.sq.over::after { opacity: 1; background: rgba(255,255,255,0.55); }
@keyframes pulse { 50% { opacity: 0.55; } }
.sq.tgt::before { content: ""; position: absolute; left: 50%; top: 50%; width: 30%; height: 30%; margin: -15% 0 0 -15%; border-radius: 50%; background: var(--dot); z-index: 1; animation: dot-in 0.35s cubic-bezier(.3,1.8,.5,1) both; animation-delay: var(--d, 0ms); pointer-events: none; }
.sq.tgt.cap::before { width: 92%; height: 92%; margin: -46% 0 0 -46%; background: none; border: calc(var(--board) * 0.009) solid var(--dot); }
@keyframes dot-in { from { transform: scale(0); opacity: 0; } }
.sq .rank, .sq .file { position: absolute; font-weight: 900; font-size: max(9px, calc(var(--board) * 0.026)); line-height: 1; pointer-events: none; }
.sq .rank { left: 5%; top: 5%; } .sq .file { right: 6%; bottom: 4%; }
.sq.light .rank, .sq.light .file { color: var(--coord-l); } .sq.dark .rank, .sq.dark .file { color: var(--coord-d); }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 3; overflow: visible; }
.hint-arrow { fill: #2bb6ff; stroke: #2bb6ff; filter: drop-shadow(0 0.04px 0.04px rgba(0,0,0,0.25)); animation: arrow 1.2s ease-in-out infinite; }
.hint-arrow line { stroke-width: 0.16; stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 0.5s ease-out forwards; }
.hint-arrow path { stroke-width: 0.05; stroke-linejoin: round; opacity: 0; animation: fade-in 0.2s 0.4s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade-in { to { opacity: 1; } }
@keyframes arrow { 50% { opacity: 0.7; } }
.pieces { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.piece { position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; will-change: transform; }
.piece .pi { position: absolute; inset: 0; transform-origin: 50% 86%; transition: transform 0.15s ease; }
.piece .pi svg { width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 calc(var(--board) * 0.004) 0 rgba(45,42,74,0.18)); }
.piece .shadow { position: absolute; left: 22%; right: 22%; bottom: 6%; height: 9%; border-radius: 50%; background: rgba(30, 30, 60, 0.0); transform-origin: 50% 50%; }
.piece.moving, .piece.dragging, .piece.captured { z-index: 5; }
.piece.moving .shadow, .piece.dragging .shadow, .piece.captured .shadow { background: rgba(30, 30, 60, 0.22); }
.piece.dragging { transition: none; }
.piece.dragging .pi { transform: scale(1.22); }
.piece.hovered .pi { transform: translateY(-4%) scale(1.04); }
.piece.selected .pi { animation: selected 1s ease-in-out infinite; }
@keyframes selected { 0%, 100% { transform: translateY(0) scale(1.04); } 50% { transform: translateY(-6%) scale(1.06, 1.02); } }
.piece .eyes { transform-box: fill-box; transform-origin: center; animation: blink var(--blink-dur, 6s) infinite; animation-delay: var(--blink-delay, 0s); }
@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97% { transform: scaleY(0.1); } }
.piece.toppled .eyes { animation: none; transform: scaleY(0.15); }
.promo { position: absolute; inset: 0; z-index: 8; }
.promo-veil { position: absolute; inset: -4%; background: rgba(45, 42, 74, 0.35); border-radius: calc(var(--board) * 0.05); animation: fade-in-full 0.2s both; }
@keyframes fade-in-full { from { opacity: 0; } }
.promo-btn { position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; border-radius: 50%; background: radial-gradient(circle, #fff 0 55%, #fff4c2 70%); box-shadow: 0 0 0 calc(var(--board) * 0.006) var(--sun), 0 6px 14px rgba(0,0,0,0.25); }
.promo-btn .pi { position: absolute; inset: 4%; animation: pop-in 0.4s cubic-bezier(.3,1.8,.5,1) both; animation-delay: calc(var(--i) * 60ms); }
.promo-btn .pi svg { width: 100%; height: 100%; }
.promo-btn:hover .pi, .promo-btn:focus-visible .pi { transform: scale(1.12); }

/* banner over the board: Check! etc. */
.banner { position: absolute; left: 50%; top: 50%; z-index: 9; pointer-events: none; font-weight: 900; font-size: calc(var(--board) * 0.11); color: #fff; white-space: nowrap; paint-order: stroke fill; -webkit-text-stroke: calc(var(--board) * 0.018) var(--ink); text-shadow: 0 calc(var(--board) * 0.012) 0 var(--ink); opacity: 0; transform: translate(-50%, -50%); }
.banner.show { animation: banner 1.3s cubic-bezier(.3,1.5,.5,1) both; }
.banner.check { color: #ff6b81; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.2) rotate(-10deg); } 18% { opacity: 1; transform: translate(-50%, -50%) scale(1.15) rotate(3deg); } 30% { transform: translate(-50%, -50%) scale(1) rotate(-2deg); } 80% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -60%) scale(0.9); } }

/* controls */
.ctl { flex: 1; max-width: 110px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 4px 7px; border-radius: 18px; background: rgba(255,255,255,0.85); font-weight: 800; font-size: 13px; color: var(--ink-soft); box-shadow: 0 4px 0 rgba(45,42,74,0.12); transition: transform 0.12s, box-shadow 0.12s, opacity 0.2s; }
.ctl-i { font-size: 24px; line-height: 1.15; transition: transform 0.3s cubic-bezier(.3,1.8,.5,1); }
.ctl:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(45,42,74,0.12); }
.ctl:active .ctl-i { transform: scale(1.25) rotate(-10deg); }
.ctl:disabled { opacity: 0.4; pointer-events: none; }
.game.wide .controls { justify-content: stretch; } .game.wide .ctl { max-width: none; }
.emote-bar { position: absolute; z-index: 20; left: 50%; bottom: calc(var(--safe-b) + 84px); transform: translateX(-50%); display: flex; gap: 4px; padding: 8px; border-radius: 999px; background: #fff; box-shadow: var(--shadow); animation: pop-in 0.3s cubic-bezier(.3,1.6,.5,1); }
.emote-bar button { width: 46px; height: 46px; border-radius: 50%; font-size: 28px; transition: transform 0.15s; }
.emote-bar button:hover, .emote-bar button:active { transform: scale(1.3); background: #fff6d6; }

/* side info (wide) */
.status { padding: 12px 14px; border-radius: 18px; background: rgba(255,255,255,0.82); font-weight: 900; font-size: 18px; text-align: center; }
.movelist { flex: 1; min-height: 0; overflow-y: auto; margin: 0; padding: 10px 12px; border-radius: 18px; background: rgba(255,255,255,0.65); list-style: none; display: grid; grid-template-columns: 2.4em 1fr 1fr; gap: 3px 6px; align-content: start; font-weight: 700; font-size: 15px; counter-reset: mv; }
.movelist li { display: contents; }
.movelist .no { color: var(--ink-soft); opacity: 0.7; }
.movelist .mv { padding: 2px 6px; border-radius: 8px; }
.movelist .mv.now { background: var(--sun); animation: pop-in 0.3s cubic-bezier(.3,1.6,.5,1); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px); background: rgba(45, 42, 74, 0.45); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade-in-full 0.25s both; }
.modal.closing { animation: screen-out 0.2s ease-in both; }
.modal-card { position: relative; width: min(440px, 100%); max-height: 100%; overflow-y: auto; padding: 24px 20px 20px; border-radius: 28px; background: var(--paper); box-shadow: 0 10px 0 #ddd5f3, 0 30px 60px rgba(30,20,60,0.35); text-align: center; animation: modal-in 0.5s cubic-bezier(.3,1.5,.5,1) both; }
@keyframes modal-in { from { opacity: 0; transform: scale(0.6) translateY(40px); } }
.modal-card h2 { font-size: 30px; font-weight: 900; margin: 6px 0 6px; }
.modal-card p { margin: 4px 0 0; font-weight: 700; color: var(--ink-soft); }
.modal-card .actions { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.modal-card .actions .big-btn { justify-content: center; min-height: 60px; }
.modal-card .actions .big-btn .bb-text { align-items: center; }
.modal-card .actions.two { flex-direction: row; } .modal-card .actions.two .big-btn { flex: 1; }
.trophy { font-size: 84px; line-height: 1; display: inline-block; animation: trophy 1.2s cubic-bezier(.3,1.6,.5,1) both, float 2.6s 1.2s ease-in-out infinite; }
@keyframes trophy { from { transform: scale(0) rotate(-30deg); } }
@keyframes float { 50% { transform: translateY(-8px) rotate(4deg); } }
.result-reason { display: inline-block; margin-top: 6px !important; padding: 4px 12px; border-radius: 999px; background: #f1ecff; color: var(--ink) !important; }
.rematch-note { color: var(--grass-d) !important; animation: pulse 1s infinite; }
.menu-list { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.menu-item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 18px; background: #fff; box-shadow: 0 4px 0 #e6e0f7; font-weight: 800; font-size: 17px; text-align: left; }
.menu-item:active { transform: translateY(3px); box-shadow: 0 1px 0 #e6e0f7; }
.menu-item .mi-i { font-size: 24px; }
.menu-item.danger { color: var(--pink-d); }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 4px; border-bottom: 2px dashed #ece6fb; text-align: left; font-weight: 800; }
.setting:last-child { border-bottom: 0; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: #f1ecff; }
.seg button { padding: 7px 12px; border-radius: 999px; font-weight: 800; font-size: 14px; color: var(--ink-soft); }
.seg button[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: 0 2px 0 #ddd5f3; }
.switch { position: relative; width: 58px; height: 34px; border-radius: 999px; background: #ddd7ee; flex: none; transition: background 0.2s; }
.switch::after { content: ""; position: absolute; left: 4px; top: 4px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.2); transition: transform 0.25s cubic-bezier(.3,1.6,.5,1); }
.switch[aria-checked="true"] { background: var(--grass); }
.switch[aria-checked="true"]::after { transform: translateX(24px); }
.themes { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.theme-sw { width: 40px; height: 40px; border-radius: 12px; overflow: hidden; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; box-shadow: 0 0 0 3px #fff, 0 0 0 5px #e3dcf7; transition: transform 0.2s; }
.theme-sw i:nth-child(1), .theme-sw i:nth-child(4) { background: var(--l); } .theme-sw i:nth-child(2), .theme-sw i:nth-child(3) { background: var(--d); }
.theme-sw[aria-pressed="true"] { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--sky-d); transform: scale(1.1); }

/* toast + connection pill */
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 22px); z-index: 60; max-width: calc(100% - 32px); padding: 13px 20px; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 800; text-align: center; box-shadow: var(--shadow); transform: translate(-50%, 160%); opacity: 0; transition: transform 0.4s cubic-bezier(.3,1.5,.5,1), opacity 0.3s; pointer-events: none; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.conn-pill { position: fixed; top: calc(var(--safe-t) + 10px); left: 50%; z-index: 30; transform: translateX(-50%); padding: 8px 16px; border-radius: 999px; background: #fff3cd; color: #8a5a00; font-weight: 800; box-shadow: var(--shadow); animation: pop-in 0.3s; display: flex; gap: 8px; align-items: center; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

/* small screens and short landscape phones */
@media (max-height: 560px) {
  .home { padding-top: 6px; gap: 10px; }
  .big-btn { min-height: 58px; } .bb-icon { width: 42px; height: 42px; font-size: 24px; }
  .logo-pieces { display: none; }
}
@media (max-width: 380px) {
  .bb-text b { font-size: 18px; } .bb-text small { font-size: 13px; }
  .ctl { font-size: 11.5px; } .ctl-i { font-size: 21px; }
  .player { min-height: 50px; } .player .avatar { width: 38px; height: 38px; font-size: 22px; } .p-name { font-size: 15px; }
}
.game.compact .player { min-height: 44px; padding: 4px 10px 4px 6px; } .game.compact .player .avatar { width: 36px; height: 36px; font-size: 21px; }
.game.compact .p-sub { font-size: 12px; min-height: 14px; } .game.compact .ctl { flex-direction: row; gap: 6px; justify-content: center; padding: 6px 4px; } .game.compact .ctl-i { font-size: 20px; }
.game.compact .topbar .icon-btn { width: 38px; height: 38px; }
@media (prefers-reduced-motion: reduce) {
  .cloud, .sun, .lp, .title .ch, .piece .eyes, .player.turn .avatar, .trophy { animation: none !important; }
  .screen.active, .big-btn, .level, .modal-card { animation-duration: 0.01s !important; }
}

/* the adaptive opponent: a rainbow edge */
.level.adaptive { border: 3px solid transparent; background: linear-gradient(var(--paper), var(--paper)) padding-box, linear-gradient(120deg, #ff7aa2, #ffd166, #06d6a0, #4cc9f0, #9b5de5) border-box; }
.level.adaptive[aria-checked="true"] { background: linear-gradient(#f2fff4, #f2fff4) padding-box, linear-gradient(120deg, #ff7aa2, #ffd166, #06d6a0, #4cc9f0, #9b5de5) border-box; box-shadow: 0 5px 0 var(--grass-d), 0 12px 22px rgba(51, 169, 68, 0.3); }
.levels.compact { grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 10px; margin-top: 14px; }
.levels.compact .level { padding: 8px 6px 10px; }
.levels.compact .level .em { font-size: 34px; }
.levels.compact .level small { display: none; }
.adapt-note { margin-top: 10px !important; padding: 8px 12px; border-radius: 14px; background: #eafbe9; color: var(--grass-d) !important; }
.adapt-note .stars { color: #f2a90b; letter-spacing: 1px; white-space: nowrap; }

/* learn to play */
.learn { gap: 12px; }
.teacher { display: flex; align-items: flex-start; gap: 10px; animation: pop-in 0.45s cubic-bezier(.3,1.5,.5,1) both; }
.teacher-face { flex: none; display: grid; place-items: center; width: 58px; height: 58px; border-radius: 50%; background: #fff; box-shadow: 0 4px 0 rgba(45,42,74,0.12); font-size: 38px; }
.bubble { position: relative; flex: 1; padding: 12px 16px; border-radius: 20px; background: #fff; box-shadow: 0 4px 0 rgba(45,42,74,0.1); font-weight: 700; font-size: 17px; line-height: 1.35; min-height: 58px; }
.bubble::before { content: ""; position: absolute; left: -9px; top: 20px; border: 9px solid transparent; border-right-color: #fff; border-left: 0; }
.bubble.happy { background: #eafbe9; color: var(--grass-d); } .bubble.happy::before { border-right-color: #eafbe9; }
.lesson-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 6px; }
.lesson-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 8px 14px; border-radius: 22px; background: var(--paper); box-shadow: 0 5px 0 #ddd5f3, 0 10px 18px rgba(45,42,74,0.1); font-size: 19px; font-weight: 900; transition: transform 0.15s; animation: pop-in 0.5s cubic-bezier(.3,1.6,.5,1) both; animation-delay: calc(var(--i) * 70ms + 100ms); }
.lesson-card:hover { transform: translateY(-3px); } .lesson-card:active { transform: translateY(3px); }
.lc-pc { width: 76px; height: 76px; transition: transform 0.3s cubic-bezier(.3,1.8,.5,1); } .lc-pc svg { width: 100%; height: 100%; }
.lesson-card:hover .lc-pc { transform: translateY(-6px) rotate(-6deg); }
.lesson-card.done { background: #f2fff1; box-shadow: 0 5px 0 #b6e7b4, 0 10px 18px rgba(51,169,68,0.15); }
.tick { position: absolute; top: 8px; right: 10px; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--grass); color: #fff; font-size: 17px; box-shadow: 0 3px 0 var(--grass-d); }
.lesson { --board: 320px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.lesson .teacher { align-self: stretch; }
.lesson-bar { display: flex; align-items: center; gap: 10px; width: var(--board); max-width: 100%; }
.lesson-bar .ctl { flex: none; width: 84px; }
.lesson-bar .big-btn { flex: 1; width: auto; animation-delay: 0s; }
.star-count { flex: 1; display: flex; gap: 3px; font-size: 30px; color: #dcd6ee; -webkit-text-stroke: 1.5px #c9c1e3; }
.star-count span.got { color: #ffc93c; -webkit-text-stroke: 1.5px #d9860b; }
.lesson-bar:has(.big-btn:not([hidden])) .star-count { flex: none; font-size: 22px; }
.tokens { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.token { position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; }
.token .tk { position: absolute; inset: 14%; animation: twinkle 1.6s ease-in-out infinite; animation-delay: var(--d, 0s); filter: drop-shadow(0 calc(var(--board) * 0.005) 0 rgba(150, 90, 10, 0.35)); }
.token svg { width: 100%; height: 100%; }
@keyframes twinkle { 0%, 100% { transform: scale(1) rotate(-6deg); } 50% { transform: scale(1.12) rotate(6deg); } }
