:root {
  --blue:#1687e8; --red:#ef3e4a; --green:#24b47e; --ink:#243447;
  --muted:#718096; --bg:#f3f7fc; --white:#fff; --yellow:#ffd34e;
}
* { box-sizing:border-box; -webkit-tap-highlight-color:transparent; }
html, body { margin:0; width:100%; min-height:100%; background:#72d8ff url("kids-math-bg.png") center/cover fixed; font-family:"Trebuchet MS",Arial,sans-serif; color:var(--ink); }
body { min-height:100dvh; overscroll-behavior:none; touch-action:manipulation; user-select:none; }
button { font:inherit; font-weight:800; color:var(--ink); border:0; border-radius:12px; cursor:pointer; touch-action:manipulation; }
.screen { display:none; min-height:100dvh; }
.screen.active { display:flex; }
#menu { overflow-y:auto; align-items:flex-start; padding:max(12px,env(safe-area-inset-top)) 0 max(20px,env(safe-area-inset-bottom)); }
.menu-card, .result-card { width:min(900px,94vw); margin:16px auto; padding:clamp(18px,3vw,34px); text-align:center; background:linear-gradient(145deg,#fff3a8ed,#ffc9e8ed 42%,#c9e8ffed 75%,#d6c7ffed); border:4px solid #fff4a8; border-radius:32px; box-shadow:0 14px 0 #7048bd55,0 22px 45px #24446738; backdrop-filter:blur(8px); }
h1 { margin:.25em 0; font-size:clamp(26px,5vw,52px); }
.menu-card h1 { color:#7048bd; text-shadow:0 3px #fff,0 6px #ffd34e; }
.mascot { font-size:64px; animation:bob 1.8s ease-in-out infinite; }
@keyframes bob { 50% { transform:translateY(-10px) rotate(8deg); } }
h2 { margin:1.35em 0 .55em; font-size:clamp(17px,2.4vw,25px); }
.subtitle { color:var(--muted); font-weight:800; font-size:clamp(12px,2vw,18px); }
.choices { display:grid; grid-template-columns:repeat(3,1fr); gap:12px; }
.choices button { min-height:64px; padding:10px; background:linear-gradient(145deg,#fff4a5,#ffcfeb); border:3px solid #ff9ccc; }
.choices button.selected { background:#bfe1ff; border-color:var(--blue); }
.mode-grid { display:grid; grid-template-columns:repeat(4,1fr); gap:10px; }
.mode-grid button { min-height:82px; padding:8px; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:4px; background:linear-gradient(145deg,#fff,#e8f5ff); border:3px solid #c9e7ff; transition:transform .15s,box-shadow .15s; }
.mode-grid button:nth-child(4n+2) { border-color:#ffc8da; background:linear-gradient(145deg,#fff,#fff0f5); }
.mode-grid button:nth-child(4n+3) { border-color:#d9c9ff; background:linear-gradient(145deg,#fff,#f3efff); }
.mode-grid button:nth-child(4n+4) { border-color:#ffe28a; background:linear-gradient(145deg,#fff,#fff8d9); }
.mode-grid button b { font-size:30px; }
.mode-grid button span { font-size:13px; }
.mode-grid button.selected { border-color:#7048bd; background:#eadfff; transform:translateY(-4px); box-shadow:0 6px 0 #7048bd; }
.primary { display:block; min-width:250px; min-height:62px; margin:28px auto 0; padding:14px 24px; background:linear-gradient(#3bd79a,#1ba975); box-shadow:0 7px 0 #117755; color:#fff; font-size:20px; }
.primary:active { transform:translateY(5px); box-shadow:0 2px 0 #117755; }
.quit-button { display:block; margin:18px auto 0; padding:12px 22px; background:linear-gradient(#ff7180,#e52f48); box-shadow:0 5px 0 #a91830; color:#fff; }
.quit-button:active { transform:translateY(3px); box-shadow:0 2px 0 #a91830; }
.sound-button { display:block; margin:16px auto 0; padding:11px 20px; background:linear-gradient(#8b72ff,#6846d9); box-shadow:0 5px 0 #462a9f; color:#fff; }
.countdown-screen { align-items:center; justify-content:center; flex-direction:column; background:radial-gradient(circle at 50% 35%,#7048bd,#362777 48%,#14234d); color:#fff; text-align:center; }
#countdown-value { color:var(--yellow); font-size:clamp(110px,25vw,240px); font-weight:900; }
#game { flex-direction:column; padding:max(8px,env(safe-area-inset-top)) max(8px,env(safe-area-inset-right)) max(8px,env(safe-area-inset-bottom)) max(8px,env(safe-area-inset-left)); background:linear-gradient(135deg,#73dcffdd,#ffe676dd 35%,#ff9bc9dd 68%,#a993ffdd); backdrop-filter:blur(4px); }
.game-header { height:70px; display:grid; grid-template-columns:100px 1fr 100px; align-items:center; gap:8px; text-align:center; }
.game-header h1 { font-size:clamp(16px,3vw,34px); }
.game-header button, #timer { padding:12px 8px; background:#fff3a8; border-radius:10px; font-weight:800; }
.header-actions { display:flex; gap:5px; }
.header-actions button { flex:1; padding:11px 5px; }
.header-actions .quit-button { margin:0; background:linear-gradient(#ff7180,#e52f48); color:#fff; box-shadow:none; }
.header-actions .sound-button { margin:0; background:linear-gradient(#8b72ff,#6846d9); color:#fff; box-shadow:none; }
.game-board { flex:1; display:grid; grid-template-columns:minmax(230px,1fr) minmax(180px,1.2fr) minmax(230px,1fr); gap:10px; }
.team, .arena { border:3px solid; border-radius:17px; overflow:hidden; box-shadow:0 7px 18px #24344722; }
.team { padding:0 12px 12px; text-align:center; }
.team.blue { border-color:var(--blue); background:linear-gradient(160deg,#d7f2ff,#a9d9ff 55%,#d9caff); }
.team.red { border-color:var(--red); background:linear-gradient(160deg,#ffe0ed,#ffb8ca 55%,#ffd59e); }
.team-title { margin:0 -12px 12px; padding:14px; color:#fff; display:flex; justify-content:space-between; font-size:clamp(16px,2vw,25px); }
.blue .team-title, .blue .go { background:var(--blue); } .red .team-title, .red .go { background:var(--red); }
.score { background:#fff; color:var(--ink); border-radius:20px; padding:3px 12px; }
.question { font-size:clamp(25px,4vw,48px); font-weight:900; margin:9px 0; }
.question.objects { font-size:clamp(22px,3vw,38px); line-height:1.15; letter-spacing:2px; overflow-wrap:anywhere; }
.answer { height:52px; padding:11px; background:#fff5b8; border:2px solid #ffc84a; border-radius:10px; font-size:24px; font-weight:800; }
.feedback { height:35px; padding:8px 0; color:var(--muted); font-weight:700; font-size:14px; }
.keypad { display:grid; grid-template-columns:repeat(3,1fr); gap:7px; }
.keypad button { min-height:clamp(48px,8vh,78px); background:linear-gradient(145deg,#fff7b5,#ffd884); border:2px solid #ffbd3d; font-size:clamp(18px,3vw,30px); }
.keypad button:nth-child(3n+2) { background:linear-gradient(145deg,#e2cfff,#c1a5ff); border-color:#9d77ec; }
.keypad button:nth-child(3n+3) { background:linear-gradient(145deg,#caffdf,#8fe6b8); border-color:#53bd85; }
.keypad .go { color:#fff; }
.choice-pad { display:grid; grid-template-columns:1fr; gap:9px; margin-top:10px; }
.choice-pad button { min-height:clamp(55px,10vh,85px); font-size:clamp(20px,3vw,34px); background:#fff3bd; border:3px solid #ffd34e; }
.arena { border-color:#efaa29; background:linear-gradient(180deg,#fff2a6,#ffd77c 58%,#9de5a9); display:flex; flex-direction:column; justify-content:space-between; text-align:center; color:#137344; }
#scoreline { padding:18px 4px; background:linear-gradient(90deg,#91d6ff,#f0dcff,#ff9fb8); color:var(--ink); font-weight:900; }
.rope-wrap { position:relative; height:150px; overflow:hidden; }
.tug-scene { position:absolute; inset:0; transition:transform .3s ease-out; will-change:transform; }
.rope { position:absolute; left:8%; right:8%; top:62px; height:8px; background:#9b6a43; border-radius:8px; }
.tug-team { position:absolute; top:12px; display:flex; align-items:flex-end; gap:2px; z-index:2; }
.tug-blue { left:3%; flex-direction:row-reverse; }
.tug-red { right:3%; }
.tug-player { position:relative; display:block; width:42px; padding-bottom:22px; font-size:42px; line-height:1; filter:drop-shadow(0 3px 1px #24344735); }
.tug-player::before { content:""; position:absolute; left:8px; bottom:17px; width:27px; height:23px; border-radius:8px 8px 4px 4px; z-index:-1; }
.tug-blue .tug-player::before { background:var(--blue); }
.tug-red .tug-player::before { background:var(--red); }
.tug-player::after { content:""; position:absolute; left:19px; bottom:0; width:6px; height:23px; background:var(--ink); border-radius:5px; transform:rotate(25deg); box-shadow:10px -2px 0 var(--ink); }
.tug-blue .tug-player { transform:scaleX(-1) rotate(-8deg); }
.tug-red .tug-player { transform:rotate(-8deg); }
#knot { position:absolute; left:50%; top:42px; transform:translateX(-50%); color:var(--yellow); font-size:50px; }
.arena strong { margin-bottom:25px; }
.result-screen { align-items:center; text-align:center; }
.result-screen { background:linear-gradient(135deg,#75dcffcc,#ffe878cc,#ff99c8cc); }
.result-card { border:5px solid var(--green); }
.result-card p { color:#d49c00; font-weight:900; font-size:24px; }
#home { margin:18px auto 0; padding:15px 28px; background:#cbb6ff; }
@media (max-width:760px) and (orientation:portrait) {
  .menu-card { margin:4px auto 20px; padding:12px 10px 22px; }
  .menu-card .mascot { font-size:40px; }
  .menu-card h1 { font-size:27px; margin:0; }
  .menu-card h2 { margin:14px 0 7px; font-size:15px; }
  .menu-card .subtitle { margin:6px 0; font-size:10px; }
  .mode-grid { grid-template-columns:repeat(3,1fr); gap:7px; }
  .mode-grid button { min-height:62px; padding:5px 3px; }
  .mode-grid button b { font-size:24px; }
  .mode-grid button span { font-size:11px; }
  .choices button { min-height:48px; padding:5px 2px; font-size:11px; }
  .primary { margin-top:18px; min-height:54px; }
  .game-header { height:55px; grid-template-columns:74px 1fr 74px; }
  .header-actions { gap:2px; }
  .header-actions button { padding:9px 2px; font-size:9px; }
  .game-header h1 { font-size:14px; }
  .game-board { grid-template-columns:1fr 1fr; grid-template-rows:auto 115px; }
  .arena { grid-column:1 / -1; grid-row:2; }
  .rope-wrap { height:55px; } .rope { top:25px; }
  .tug-team { top:2px; gap:0; }
  .tug-blue { left:2%; } .tug-red { right:2%; }
  .tug-player { width:25px; padding-bottom:11px; font-size:25px; }
  .tug-player::before { left:5px; bottom:8px; width:16px; height:14px; border-radius:5px; }
  .tug-player::after { left:11px; bottom:0; width:4px; height:12px; box-shadow:6px -1px 0 var(--ink); }
  #knot { top:7px; }
  .arena strong { display:none; }
  #scoreline { padding:8px; }
  .team { padding:0 5px 6px; }
  .team-title { margin:0 -5px 5px; padding:9px 5px; font-size:12px; }
  .question { font-size:24px; margin:5px 0; }
  .answer { height:38px; padding:6px; font-size:19px; }
  .feedback { height:27px; padding:5px 0; font-size:10px; }
  .keypad { gap:4px; }
  .keypad button { min-height:min(8.1vh,58px); font-size:18px; }
}
@media (max-width:350px) { .mode-grid { grid-template-columns:repeat(2,1fr); } }
@media (max-height:550px) {
  .game-header { height:48px; }
  .team-title { padding:7px; margin-bottom:3px; }
  .question { margin:3px; font-size:22px; }
  .answer { height:35px; padding:5px; }
  .feedback { height:24px; padding:3px; }
  .keypad button { min-height:48px; }
}

/* Keep all menu controls above decorative layers on touch devices and embedded browsers. */
#menu, #menu .menu-card { position:relative; z-index:10; pointer-events:auto; }
#menu button { position:relative; z-index:20; pointer-events:auto !important; -webkit-appearance:none; appearance:none; }
