:root {
  --ink:#343e32; --muted:#737967; --accent:#476443;
  --tint:#eaf0dc; --paper:#faf6ec; --line:#e4e2d4;
}
* { box-sizing:border-box; }
html,body { margin:0; height:100%; }
body { background:var(--paper); color:var(--ink); min-width:320px; font-family:var(--site-font); }
button,input { font:inherit; }
button,input,a { -webkit-tap-highlight-color:transparent; touch-action:manipulation; }
button { cursor:pointer; }
button:active { transform:translateY(1px); }
button:focus-visible,a:focus-visible { outline:3px solid #9b651d; outline-offset:3px; }
[hidden] { display:none!important; }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip-path:inset(50%); white-space:nowrap; }
.topbar { position:relative; height:64px; display:flex; justify-content:center; align-items:center; border-bottom:1px solid var(--line); }
.topbar a { position:absolute; left:24px; color:var(--ink); text-decoration:none; font-size:16px; }
h1 { font-size:clamp(24px,3vw,32px); font-weight:700; margin:0; letter-spacing:2px; }
main { height:calc(100dvh - 64px); max-width:1100px; margin:auto; padding:14px 24px; display:flex; flex-direction:column; gap:12px; }
.settings { flex:none; width:min(100%,620px); margin:0 auto; }
fieldset { border:0; padding:0; margin:0; min-width:0; }
.ranges { display:flex; gap:8px; }
.settings button { border:1px solid var(--line); background:#fffdf6; border-radius:10px; min-height:42px; flex:1; color:var(--ink); font-size:19px; }
.settings button[aria-pressed=true] { border:2px solid var(--accent); background:var(--tint); color:var(--accent); }
.game { flex:1; min-height:0; position:relative; border:1px solid #dedfce; border-radius:20px; background:#fffef9; padding:16px 28px; display:flex; flex-direction:column; gap:10px; }
.game-top { display:flex; justify-content:space-between; font-size:15px; color:var(--muted); flex:none; }
.progress { display:flex; gap:7px; height:5px; flex:none; }
.progress span { border-radius:4px; background:#e9e9de; flex:1; }
.progress span.done { background:var(--accent); }
#play { min-height:0; flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:10px; text-align:center; }
h2 { font-size:32px; margin:0; }
.instruction { color:var(--muted); font-size:16px; margin:0; flex:none; }
.neighbors { container-type:size; width:min(100%,740px); flex:1; min-height:100px; max-height:310px; display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:20px; align-items:center; }
.neighbor { display:grid; grid-template-rows:1.4em minmax(0,1fr) 1.6em; align-items:center; justify-items:center; height:100%; gap:8px; padding:4px 0; font-size:22px; min-width:0; }
.shape { position:relative; display:grid; place-items:center; width:100%; max-width:244px; max-height:100%; width:min(100%,calc((100cqh - 90px)*1.1613),244px); aspect-ratio:180/155; margin:0; }
.shape svg { position:absolute; inset:0; display:block; width:100%; height:100%; pointer-events:none; filter:drop-shadow(0 4px 0 #513f1710); }
.shape input,.shape strong { position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); width:75%; height:60%; padding:8px 0 0; margin:0; text-align:center; font:700 clamp(30px,5vw,56px) var(--site-font); color:#443a2b; background:transparent; border:0; border-radius:10px; min-height:0; outline:none; }
.shape strong { display:grid; place-items:center; }
.shape input::placeholder { color:#8b7852; opacity:.65; }
.shape:focus-within,.shape.drop-target { outline:3px dashed var(--accent); outline-offset:0; border-radius:35%; }
.shape input[aria-invalid=true] { background:transparent; box-shadow:0 0 0 2px #b65336; }
.shape input.correct { background:transparent; color:#2c6637; }
.shape input:disabled { opacity:1; -webkit-text-fill-color:currentColor; }
.math-note { position:relative; z-index:1; font-size:18px; line-height:1.6; color:var(--accent); white-space:nowrap; }
#feedback { flex:none; width:100%; height:50px; margin:0; font-size:18px; color:var(--accent); line-height:1.4; display:flex; align-items:center; justify-content:center; }
#feedback.error { color:#a14027; }
.keypad { flex:none; display:grid; grid-template-columns:repeat(6,minmax(0,1fr)); gap:8px; width:min(100%,480px); }
.keypad button { height:50px; border:1px solid #dfe1d3; border-bottom:3px solid #dfe1d3; background:#fff; border-radius:10px; font-size:28px; color:var(--ink); }
.keypad button[data-value] { touch-action:none; cursor:grab; user-select:none; }
.keypad button[data-value]:active { cursor:grabbing; }
#play .keypad[hidden] { display:grid!important; visibility:hidden; pointer-events:none; }
.actions { display:flex; flex:none; justify-content:center; gap:12px; }
#play .actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); width:min(100%,400px); }
#hint { grid-column:1; grid-row:1; }
#check,#next { grid-column:2; grid-row:1; }
#play #hint[hidden] { display:block!important; visibility:hidden; pointer-events:none; }
.actions button,.finish button { min-height:46px; border-radius:11px; padding:8px 22px; font-size:18px; }
.primary { background:var(--accent); color:white; border:1px solid var(--accent); box-shadow:0 3px 0 #26362125; }
.secondary { border:1px solid #d6dacb; background:transparent; color:var(--accent); }
.hint-line { display:flex; flex:none; height:32px; gap:8px; justify-content:center; align-items:center; font-size:17px; }
#play .hint-line[hidden] { display:flex!important; visibility:hidden; pointer-events:none; }
.hint-line span,.hint-line strong { padding:3px 12px; background:var(--tint); border-radius:8px; }
.hint-line strong { border:2px solid var(--accent); }
.finish { flex:1; min-height:0; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:18px; text-align:center; }
.finish h2 { font-size:clamp(36px,7vw,60px); color:var(--accent); }
.medal { font-size:64px; }
#summary { font-size:19px; line-height:1.7; margin:0; max-width:550px; }
#collection { font-size:25px; letter-spacing:4px; }
.drag-number { position:fixed; z-index:100; pointer-events:none; transform:translate(-50%,-50%); display:grid; place-items:center; width:62px; height:56px; border-radius:12px; background:#fffdf6; color:var(--ink); border:2px solid var(--accent); box-shadow:0 8px 24px #0002; font-size:30px; }
.game-fireworks { position:fixed; inset:0; width:100vw; height:100dvh; z-index:200; pointer-events:none; }
body[data-theme=apple] { --accent:#7e4939; --tint:#f6e7df; }
body[data-theme=star] { --accent:#625388; --tint:#eee9f8; }
body[data-theme=ocean] { --accent:#34737b; --tint:#e2f2ef; }
@media(max-width:650px) {
  .topbar { height:54px; padding-left:75px; padding-right:8px; }
  .topbar a { left:10px; font-size:13px; }
  h1 { font-size:24px; letter-spacing:0; }
  main { height:calc(100dvh - 54px); padding:10px; gap:8px; }
  .game { padding:12px; gap:8px; border-radius:16px; }
  .game-top { font-size:13px; }
  .settings button { min-height:40px; font-size:18px; }
  .instruction { font-size:14px; }
  .neighbors { gap:8px; }
  .neighbor { font-size:17px; }
  .shape { width:min(100%,calc((100cqh - 74px)*1.1613),168px); }
  .shape input,.shape strong { font-size:32px; }
  .math-note { font-size:15px; }
  #feedback { font-size:15px; height:42px; }
  .keypad { gap:6px; }
  .keypad button { height:46px; font-size:24px; }
  .actions { gap:10px; }
  .actions button { font-size:16px; padding:8px 15px; min-height:43px; }
  .finish { gap:12px; }
  .medal { font-size:48px; }
  #summary { font-size:17px; line-height:1.5; }
  #collection { letter-spacing:0; font-size:23px; }
}
@media(max-height:650px) {
  .topbar { height:44px; }
  main { height:calc(100dvh - 44px); padding:6px 12px; gap:6px; }
  .game { padding:8px 16px; gap:5px; }
  #play { gap:5px; }
  .settings button { min-height:34px; }
  .instruction { font-size:13px; }
  .neighbor { font-size:16px; }
  .neighbors { min-height:100px; }
  .neighbor { gap:4px; padding:0; }
  .shape { width:min(100%,calc((100cqh - 56px)*1.1613)); }
  .shape input,.shape strong { font-size:26px; padding-top:5px; width:80%; }
  .math-note { display:block; font-size:13px; }
  #feedback { height:40px; font-size:14px; }
  .keypad button { height:36px; font-size:22px; }
  .actions button { min-height:35px; padding:4px 16px; font-size:15px; }
  .finish { gap:8px; }
  .medal { font-size:40px; }
  .finish h2 { font-size:32px; line-height:1.2; }
  #summary { font-size:15px; line-height:1.4; }
  #collection { font-size:20px; }
  .finish button { min-height:35px; padding:4px 16px; font-size:15px; }
}

@media(max-height:430px) {
  #play > .instruction { display:none; }
  #play { gap:4px; }
  .hint-line { font-size:14px; height:26px; }
  .hint-line span,.hint-line strong { padding:1px 8px; }
}

#feedback.success { color:#237343; font-weight:700; }
.answer-correct .neighbor:not(.given) .shape { outline:3px solid #3a9951; outline-offset:0; border-radius:35%; }
.answer-correct .neighbor:not(.given) .shape::after { content:"✓"; position:absolute; top:4px; right:4px; display:grid; place-items:center; width:30px; height:30px; border-radius:50%; background:#318447; color:white; font-size:23px; box-shadow:0 2px 6px #246b3533; animation:neighbor-check-in .45s ease-out; }
.answer-correct .shape svg { animation:neighbor-answer-glow .7s ease-out; }
@keyframes neighbor-check-in { from { opacity:0; transform:scale(.4); } to { opacity:1; transform:scale(1); } }
@keyframes neighbor-answer-glow { 40% { filter:drop-shadow(0 0 10px #63b46f); } }
@media(prefers-reduced-motion:reduce) { .answer-correct .shape svg,.answer-correct .neighbor:not(.given) .shape::after { animation:none; } }
