:root {
  --navy: #14254a; --teal: #0b6f6a; --teal2: #0f8f86; --mint: #3fd1a1; --paper: #fff8ea; --paper2: #fdeccb;
  --tang: #ff8a1f; --tang2: #e06a00; --sky: #3aa3ff; --berry: #ff4f8b; --leaf: #52c46a; --gold: #ffc83d; --ink: #1d2340; --soft: #5b6284;
  --ok: #2fb86a; --bad: #ff5a5a;
  --font: "Trebuchet MS", "Segoe UI", "Nunito", "Helvetica Neue", Arial, system-ui, sans-serif;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body { background: #0d8b82 url(img/bg.jpg) center / cover no-repeat fixed; font-family: var(--font); color: var(--ink); user-select: none; -webkit-user-select: none; overflow: hidden; touch-action: manipulation; }
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#bar { flex: none; display: flex; align-items: center; justify-content: space-between; padding: max(6px, env(safe-area-inset-top)) 10px 6px; }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 900; font-size: 18px; color: #fff; text-shadow: 0 2px 0 var(--navy); letter-spacing: .5px; }
.brand img { width: 34px; height: 34px; object-fit: contain; filter: drop-shadow(0 2px 0 rgba(20,37,74,.5)); }
.barBtns { display: flex; gap: 8px; }
.ib { width: 44px; height: 44px; border-radius: 12px; border: 3px solid var(--navy); background: var(--paper); font-size: 20px; font-weight: 900; box-shadow: 0 4px 0 var(--navy); padding: 0; line-height: 1; }
.ib.off { opacity: .55; text-decoration: line-through; }
.screen { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 4px 10px max(14px, env(safe-area-inset-bottom)); -webkit-overflow-scrolling: touch; }
.card { background: var(--paper); border: 3px solid var(--navy); border-radius: 20px; box-shadow: 0 6px 0 var(--navy), 0 14px 30px rgba(0,0,0,.18); }

/* start */
.startCard { max-width: 880px; margin: 4px auto 10px; padding: 14px 16px 16px; }
.hero { display: flex; align-items: center; gap: 12px; }
.heroOwl { width: 112px; height: 112px; object-fit: contain; flex: none; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }
h1 { margin: 0 0 4px; font-size: 28px; line-height: 1.1; color: var(--navy); }
h1 em { font-style: normal; color: var(--tang2); display: inline-block; }
.intro { margin: 0; font-size: 15px; line-height: 1.4; color: var(--soft); font-weight: 600; }
.step { margin: 14px 0 7px; font-weight: 900; font-size: 15px; color: var(--navy); display: flex; align-items: center; gap: 7px; }
.step .num { width: 24px; height: 24px; border-radius: 50%; background: var(--navy); color: #fff; display: inline-grid; place-items: center; font-size: 13px; }
.step .optl { font-weight: 600; color: var(--soft); }
.classGrid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 6px; }
.cls { height: 58px; border-radius: 14px; border: 3px solid var(--navy); background: #fff; font-weight: 900; font-size: 22px; box-shadow: 0 4px 0 var(--navy); display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; transition: transform .08s; }
.cls small { font-size: 9.5px; letter-spacing: .5px; color: var(--soft); margin-bottom: 2px; }
.cls:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--navy); }
.cls.sel { background: var(--tang); color: #fff; }
.cls.sel small { color: #fff3dd; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode { border: 3px solid var(--navy); border-radius: 14px; background: #fff; padding: 9px 8px; text-align: left; box-shadow: 0 4px 0 var(--navy); }
.mode b { display: block; font-size: 16px; color: var(--navy); }
.mode small { font-size: 12px; color: var(--soft); font-weight: 600; }
.mode.sel { background: var(--mint); }
.mode.sel small { color: #12433a; }
.topics { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 2px solid var(--navy); border-radius: 999px; background: #fff; padding: 6px 11px; font-weight: 800; font-size: 13px; }
.chip.sel { background: var(--sky); color: #fff; }
.playRow { display: flex; align-items: center; gap: 14px; margin-top: 16px; flex-wrap: wrap; }
.big { border: 3px solid var(--navy); border-radius: 16px; background: var(--tang); color: #fff; font-weight: 900; font-size: 22px; padding: 12px 30px; box-shadow: 0 5px 0 var(--navy); text-shadow: 0 2px 0 rgba(20,37,74,.35); transition: transform .08s; }
.big:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--navy); }
.big.alt { background: #fff; color: var(--navy); text-shadow: none; }
#btnPlay { font-size: 26px; padding: 14px 44px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.04); } }
.best { font-weight: 800; color: var(--soft); font-size: 14px; }
.kbd { display: inline-block; border: 2px solid currentColor; border-radius: 6px; font-size: .62em; padding: 1px 5px; vertical-align: middle; opacity: .85; margin: 0 1px; font-weight: 900; text-shadow: none; }
.keys { margin-top: 12px; font-size: 13px; color: var(--soft); font-weight: 700; }

/* play */
#play { display: flex; flex-direction: column; gap: 8px; max-width: 900px; margin: 0 auto; width: 100%; }
#hud { display: flex; gap: 6px; }
.pill { flex: 1; background: var(--paper); border: 3px solid var(--navy); border-radius: 12px; text-align: center; font-weight: 900; font-size: 19px; padding: 2px 4px 3px; box-shadow: 0 3px 0 var(--navy); white-space: nowrap; overflow: hidden; }
.pill small { display: block; font-size: 9.5px; letter-spacing: 1px; color: var(--soft); }
.pill.hot { background: var(--gold); }
.pill.lvl span { color: var(--tang2); }
#timer { height: 12px; border: 3px solid var(--navy); border-radius: 99px; background: rgba(255,255,255,.6); overflow: hidden; }
#timer i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--mint), var(--gold)); transform-origin: left; }
#timer.low i { background: var(--bad); }
#duelBar { display: flex; align-items: center; gap: 8px; }
#duelBar .pl { flex: 1; border: 3px solid var(--navy); border-radius: 12px; padding: 4px 10px; display: flex; justify-content: space-between; align-items: center; font-size: 15px; color: #fff; box-shadow: 0 3px 0 var(--navy); }
#duelBar .pl span { font-size: 24px; font-weight: 900; }
#duelBar .vs { font-weight: 900; color: #fff; text-shadow: 0 2px 0 var(--navy); }
.p1 { background: var(--tang); } .p2 { background: var(--sky); }
.pl.turn { outline: 4px solid var(--gold); }
.stage { display: flex; align-items: stretch; gap: 8px; }
.owlBox { position: relative; width: 130px; flex: none; display: flex; align-items: flex-end; justify-content: center; }
#owl { width: 120px; height: 120px; object-fit: contain; transition: transform .2s; }
#owl.jump { animation: jump .5s; }
#owl.shake { animation: shake .45s; }
@keyframes jump { 30% { transform: translateY(-14px) scale(1.06); } }
@keyframes shake { 20%, 60% { transform: rotate(-7deg); } 40%, 80% { transform: rotate(7deg); } }
#bubble { position: absolute; top: -4px; left: 50%; transform: translateX(-50%); background: #fff; border: 2px solid var(--navy); border-radius: 12px; padding: 3px 8px; font-weight: 900; font-size: 13px; white-space: nowrap; color: var(--navy); }
.qCard { flex: 1; padding: 12px 16px 10px; min-height: 130px; display: flex; flex-direction: column; justify-content: center; position: relative; }
.topicTag { position: absolute; top: -12px; left: 14px; background: var(--navy); color: #fff; font-size: 12px; font-weight: 800; padding: 3px 10px; border-radius: 99px; max-width: calc(100% - 28px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qText { font-size: 26px; font-weight: 800; line-height: 1.35; text-align: center; color: var(--navy); }
.qText.long { font-size: 20px; }
.qText.vlong { font-size: 17px; }
.hint { text-align: center; font-size: 12.5px; color: var(--soft); font-weight: 700; margin-top: 6px; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt { position: relative; min-height: 64px; border: 3px solid var(--navy); border-radius: 16px; font-weight: 900; font-size: 23px; color: #fff; text-shadow: 0 2px 0 rgba(20,37,74,.35); padding: 8px 10px 8px 46px; box-shadow: 0 5px 0 var(--navy); text-align: left; transition: transform .08s, filter .15s; }
.opt:nth-child(1) { background: var(--tang); } .opt:nth-child(2) { background: var(--teal2); } .opt:nth-child(3) { background: var(--sky); } .opt:nth-child(4) { background: var(--berry); }
.opt .lt { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border-radius: 8px; background: rgba(255,255,255,.92); color: var(--navy); font-size: 15px; display: grid; place-items: center; text-shadow: none; border: 2px solid var(--navy); }
.opt:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--navy); }
.opt.locked { filter: saturate(.55) brightness(.92); }
.opt.dim { filter: grayscale(.8) brightness(1.1); opacity: .55; }
.opt.right { background: var(--ok) !important; filter: none; opacity: 1; animation: pop .4s; }
.opt.right::after { content: "✔"; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 24px; }
.opt.wrong { background: var(--bad) !important; filter: none; opacity: 1; animation: shake .4s; }
.opt.wrong::after { content: "✘"; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 24px; }
@keyframes pop { 40% { transform: scale(1.05); } }
.buzzers { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.buzz { min-height: 70px; border: 3px solid var(--navy); border-radius: 18px; color: #fff; font-weight: 900; font-size: 20px; box-shadow: 0 6px 0 var(--navy); text-shadow: 0 2px 0 rgba(20,37,74,.35); }
.buzz:disabled { opacity: .4; }
.buzz:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--navy); }
.solution { padding: 12px 16px 14px; animation: slide .25s ease-out; }
@keyframes slide { from { transform: translateY(14px); opacity: 0; } }
.solHead { font-weight: 900; font-size: 18px; color: var(--navy); }
.solHead .ok { color: var(--ok); } .solHead .no { color: var(--bad); }
.solution ol { margin: 8px 0 10px; padding-left: 22px; font-size: 16.5px; line-height: 1.5; font-weight: 600; }
.solution ol li::marker { color: var(--tang2); font-weight: 900; }
.solution b, .review b { color: var(--tang2); }
.solution .big { padding: 10px 26px; font-size: 20px; }

/* fractions and powers */
.fr { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; line-height: 1.05; margin: 0 2px; font-size: .86em; }
.fr i { font-style: normal; padding: 0 3px; }
.fr i:first-child { border-bottom: 2px solid currentColor; }
sup { font-size: .62em; line-height: 0; }

/* end */
.endCard { max-width: 880px; margin: 4px auto 10px; padding: 14px 16px 16px; }
.endTop { display: flex; align-items: center; gap: 14px; }
#endOwl { width: 120px; height: 120px; object-fit: contain; flex: none; }
h2 { margin: 0; font-size: 30px; color: var(--navy); }
.stars { font-size: 34px; letter-spacing: 4px; color: #d4d0c4; -webkit-text-stroke: 1.5px var(--navy); }
.stars .on { color: var(--gold); }
.endStats { font-weight: 800; color: var(--soft); font-size: 15px; line-height: 1.5; }
.endStats b { color: var(--navy); font-size: 18px; }
.endStats .nb { color: var(--berry); }
.endBtns { display: flex; gap: 10px; margin: 14px 0 6px; flex-wrap: wrap; }
h3 { margin: 14px 0 8px; color: var(--navy); font-size: 18px; }
.review { display: flex; flex-direction: column; gap: 8px; }
.rv { border: 2px solid var(--navy); border-radius: 14px; background: #fff; padding: 8px 12px; }
.rv.ok { border-left: 10px solid var(--ok); } .rv.no { border-left: 10px solid var(--bad); }
.rv .rq { font-weight: 800; font-size: 16px; color: var(--navy); }
.rv .ra { font-size: 14.5px; font-weight: 700; color: var(--soft); margin-top: 3px; }
.rv details { margin-top: 4px; font-size: 14.5px; }
.rv summary { cursor: pointer; font-weight: 800; color: var(--teal); }
.rv ol { margin: 4px 0 0; padding-left: 20px; line-height: 1.45; }

#fx { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 20; }
.pts { position: absolute; font-weight: 900; font-size: 28px; color: #fff; text-shadow: 0 3px 0 var(--navy), 0 0 8px rgba(0,0,0,.2); animation: up 1s ease-out forwards; white-space: nowrap; }
@keyframes up { to { transform: translateY(-70px); opacity: 0; } }
.conf { position: absolute; width: 10px; height: 14px; border-radius: 2px; animation: fall 1.4s ease-in forwards; }
@keyframes fall { to { transform: translate(var(--dx), 340px) rotate(540deg); opacity: 0; } }

@media (max-width: 700px) {
  .heroOwl { width: 84px; height: 84px; }
  h1 { font-size: 22px; }
  .intro { font-size: 13.5px; }
  .classGrid { grid-template-columns: repeat(5, 1fr); }
  .cls { height: 50px; font-size: 20px; }
  .modes { grid-template-columns: 1fr; }
  .mode { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
  #btnPlay { width: 100%; }
  .playRow { position: sticky; bottom: -16px; background: var(--paper); margin: 12px -16px -16px; padding: 10px 16px 14px; border-radius: 0 0 18px 18px; border-top: 2px dashed rgba(20,37,74,.2); z-index: 2; gap: 6px; }
  .playRow .best { width: 100%; text-align: center; }
  .screen#start { padding-bottom: 0; }
  .keys { display: none; }
  .pill { font-size: 15px; } .pill small { font-size: 8px; letter-spacing: .3px; }
  #hLevel { display: none; }
  .owlBox { width: 76px; } #owl { width: 74px; height: 74px; }
  #bubble { font-size: 10.5px; padding: 2px 4px; top: -10px; left: 0; transform: none; white-space: normal; width: 76px; text-align: center; line-height: 1.15; }
  .qCard { padding: 12px 10px 8px; min-height: 112px; }
  .qText { font-size: 21px; } .qText.long { font-size: 17px; } .qText.vlong { font-size: 15px; }
  .opts { grid-template-columns: 1fr; gap: 8px; }
  .opt { min-height: 52px; font-size: 19px; }
  .solution ol { font-size: 15px; }
  .endTop { gap: 8px; } #endOwl { width: 86px; height: 86px; } h2 { font-size: 24px; }
  .big { font-size: 19px; padding: 11px 20px; }
}
@media (max-height: 640px) and (min-width: 701px) {
  .owlBox { width: 100px; } #owl { width: 92px; height: 92px; }
  .qCard { min-height: 100px; }
  .opt { min-height: 52px; }
}

/* ---- embed fit: short frames (store page small window, landscape phones) ---- */
.topicSel { display: none; }
@media (max-height: 560px) {
  #bar { padding: 4px 8px 2px; }
  .brand { font-size: 15px; } .brand img { width: 26px; height: 26px; }
  .ib { width: 34px; height: 34px; font-size: 16px; border-radius: 10px; border-width: 2px; box-shadow: 0 3px 0 var(--navy); }
  .screen { padding: 2px 8px 6px; }
  .startCard, .endCard { margin: 2px auto 6px; padding: 8px 12px 10px; border-radius: 16px; }
  .heroOwl { display: none; }
  h1 { font-size: 20px; margin: 0; }
  .intro { display: none; }
  .step { margin: 7px 0 4px; font-size: 13.5px; }
  .step .num { width: 20px; height: 20px; font-size: 11px; }
  .classGrid { grid-template-columns: repeat(10, 1fr); gap: 5px; }
  .cls { height: 38px; font-size: 18px; border-width: 2px; border-radius: 10px; box-shadow: 0 3px 0 var(--navy); }
  .cls small { font-size: 7.5px; margin-bottom: 1px; }
  .modes { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .mode { display: block; padding: 4px 8px; border-width: 2px; border-radius: 11px; box-shadow: 0 3px 0 var(--navy); }
  .mode b { font-size: 14px; } .mode small { font-size: 10.5px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topicSel { display: block; flex: 1; min-width: 0; max-width: 380px; margin-left: 4px; font: inherit; font-size: 13.5px; font-weight: 800; color: var(--navy); background: #fff; border: 2px solid var(--navy); border-radius: 999px; padding: 4px 10px; }
  .topicSel[hidden] { display: none !important; }
  .topics .chip { display: none; }
  .topics .best { display: block; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .playRow { position: static; margin: 10px 0 0; padding: 0; background: none; border: 0; flex-wrap: nowrap; gap: 12px; }
  .playRow .best { width: auto; text-align: left; }
  #btnPlay { width: auto; font-size: 21px; padding: 7px 34px; }
  .keys { display: none; }
  /* play */
  #play { gap: 5px; }
  .pill { font-size: 15px; padding: 1px 4px 2px; border-width: 2px; border-radius: 10px; box-shadow: 0 2px 0 var(--navy); }
  .pill small { font-size: 8px; letter-spacing: .5px; }
  #timer { height: 9px; border-width: 2px; }
  #duelBar .pl { padding: 2px 10px; border-width: 2px; } #duelBar .pl span { font-size: 19px; }
  .owlBox { width: 74px; } #owl { width: 66px; height: 66px; }
  #bubble { font-size: 10.5px; padding: 2px 4px; top: -6px; left: 0; transform: none; white-space: normal; width: 74px; text-align: center; line-height: 1.15; }
  .qCard { min-height: 0; padding: 10px 12px 6px; border-radius: 16px; }
  .topicTag { top: -10px; font-size: 11px; padding: 2px 9px; }
  .qText { font-size: 21px; line-height: 1.25; } .qText.long { font-size: 17px; } .qText.vlong { font-size: 15px; }
  .hint { font-size: 11px; margin-top: 3px; }
  .opts { grid-template-columns: 1fr 1fr; gap: 7px; }
  .opt { min-height: 42px; font-size: 18px; padding: 5px 30px 5px 42px; border-radius: 13px; box-shadow: 0 3px 0 var(--navy); }
  .opt .lt { width: 24px; height: 24px; font-size: 13px; }
  .opt.right::after, .opt.wrong::after { font-size: 19px; right: 9px; }
  .buzzers { gap: 7px; } .buzz { min-height: 42px; font-size: 17px; border-radius: 13px; box-shadow: 0 3px 0 var(--navy); }
  .solution { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; align-items: center; padding: 7px 12px; border-radius: 16px; }
  .solHead { grid-column: 1; font-size: 15px; }
  .solution ol { grid-column: 1; margin: 2px 0 0; font-size: 14px; line-height: 1.35; }
  .solution #btnNext { grid-column: 2; grid-row: 1 / span 2; font-size: 18px; padding: 8px 18px; }
  /* end */
  #endOwl { width: 76px; height: 76px; }
  h2 { font-size: 23px; } .stars { font-size: 24px; } .endStats { font-size: 13.5px; line-height: 1.35; } .endStats b { font-size: 15px; }
  .endBtns { margin: 8px 0 4px; } .endBtns .big { font-size: 18px; padding: 7px 22px; }
  h3 { margin: 8px 0 6px; font-size: 16px; }
}
@media (max-height: 420px) {
  .owlBox { display: none; }
  .hint { display: none; }
  .cls { height: 34px; }
  .step { margin: 5px 0 3px; }
  .qText { font-size: 19px; } .qText.long { font-size: 16px; } .qText.vlong { font-size: 14px; }
  .opt { min-height: 38px; font-size: 17px; }
  #endOwl { width: 60px; height: 60px; }
}
