:root {
  --ink: #1b1024;
  --ink2: #2b1a38;
  --card: rgba(30, 17, 40, 0.78);
  --card-b: rgba(255, 190, 120, 0.22);
  --lava: #ff6a1a;
  --lava2: #ff9d2e;
  --gold: #ffc43d;
  --cream: #fff4dc;
  --ok: #58d66b;
  --bad: #ff5a4a;
  --font: "Fredoka", "Baloo 2", "Trebuchet MS", "Segoe UI Rounded", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0710; color: var(--cream); font-family: var(--font); user-select: none; -webkit-user-select: none; touch-action: manipulation; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
.hidden { display: none !important; }
button { font-family: inherit; }

#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 55%, transparent 55%, rgba(20, 5, 5, .55) 100%); z-index: 2; }
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 60; background: radial-gradient(ellipse at center, rgba(255, 60, 30, .05), rgba(255, 30, 10, .65)); opacity: 0; transition: opacity .5s ease-out; }
#flash.on { opacity: 1; transition: none; }
#fade { position: fixed; inset: 0; pointer-events: none; z-index: 70; background: #0b0710; opacity: 0; transition: opacity .7s ease; }
#fade.on { opacity: 1; }

.screen { position: fixed; inset: 0; z-index: 20; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.screen.center { display: flex; align-items: center; justify-content: center; padding: 16px; }

/* ---------- cartões e botões ---------- */
.card { background: var(--card); border: 1.5px solid var(--card-b); border-radius: 26px; backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2); box-shadow: 0 18px 50px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .08); padding: 22px; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h3 { font-size: 1.05rem; margin: 18px 0 10px; color: var(--gold); letter-spacing: .3px; }

.btn { appearance: none; border: 0; cursor: pointer; font-weight: 700; font-size: 1.15rem; color: #3a1400; padding: 13px 28px; border-radius: 18px; background: linear-gradient(#ffd25a, #ff9d2e); box-shadow: 0 5px 0 #b3560a, 0 10px 22px rgba(255, 120, 20, .35); transition: transform .08s, box-shadow .08s, filter .15s; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #b3560a, 0 4px 10px rgba(255, 120, 20, .3); }
.btn.big { width: 100%; font-size: 1.5rem; padding: 16px; margin-top: 8px; background: linear-gradient(#ff9a3a, #ff5a1a); color: #fff; text-shadow: 0 2px 0 rgba(120, 30, 0, .5); box-shadow: 0 6px 0 #a83a08, 0 12px 26px rgba(255, 90, 20, .45); }
.btn.ghost { background: rgba(255, 255, 255, .1); color: var(--cream); box-shadow: 0 4px 0 rgba(0, 0, 0, .35); border: 1.5px solid rgba(255, 255, 255, .18); }
.btn.small { font-size: .9rem; padding: 9px 16px; border-radius: 14px; }
.link { background: none; border: 0; color: var(--lava2); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.link.tiny { font-size: .78rem; opacity: .7; margin-top: 10px; }
.warn { color: #ffb3a6; text-align: center; margin: 10px 0 0; font-weight: 600; }
.error { color: #ffb3a6; }
.col { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }

/* ---------- carregando ---------- */
#loading { background: radial-gradient(ellipse at 50% 30%, #4a1d2e, #120a1a 70%); z-index: 50; }
.load-box { text-align: center; width: min(420px, 90vw); }
.load-icon { font-size: 4.5rem; animation: bob 1.4s ease-in-out infinite; }
.bar { height: 14px; background: rgba(255, 255, 255, .12); border-radius: 99px; overflow: hidden; margin: 16px 0 8px; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ff6a1a, #ffd25a); border-radius: 99px; transition: width .2s; }
@keyframes bob { 50% { transform: translateY(-10px) rotate(4deg); } }

/* ---------- menu ---------- */
#menu { background: linear-gradient(180deg, rgba(10, 4, 20, .15), rgba(10, 4, 20, .55) 60%, rgba(10, 4, 20, .8)); }
.menu-wrap { width: min(1080px, 100%); margin: 0 auto; padding: 22px 18px 34px; }
.logo { text-align: center; margin-bottom: 18px; text-shadow: 0 4px 18px rgba(0, 0, 0, .55); }
.logo-top { font-size: 2.6rem; line-height: 1; }
.logo-badge { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.logo-dragon { display: inline-block; animation: bob 1.9s ease-in-out .3s infinite; }
.logo h1 { font-size: clamp(2.2rem, 6vw, 4rem); letter-spacing: .5px; line-height: 1.05; color: #fff; -webkit-text-stroke: 2px rgba(90, 20, 0, .55); paint-order: stroke fill; }
.logo h1 span { color: var(--lava2); background: linear-gradient(#ffd25a, #ff5a1a); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; -webkit-text-stroke: 0; filter: drop-shadow(0 3px 0 rgba(120, 30, 0, .6)); }
.logo p { margin: 8px auto 0; max-width: 620px; font-size: 1.1rem; opacity: .95; }
.menu-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 18px; align-items: start; }
.field { display: block; margin-bottom: 16px; }
.field > span, .field-row span { display: block; font-weight: 600; margin-bottom: 7px; color: var(--gold); font-size: .95rem; }
.field-row { display: grid; grid-template-columns: 1fr auto; gap: 14px; }
input, select { font-family: inherit; }
#playerName { width: 100%; font-size: 1.1rem; padding: 11px 14px; border-radius: 14px; border: 1.5px solid rgba(255, 255, 255, .2); background: rgba(0, 0, 0, .3); color: #fff; outline: none; user-select: text; -webkit-user-select: text; }
#playerName:focus { border-color: var(--lava2); box-shadow: 0 0 0 3px rgba(255, 157, 46, .3); }
.seg { display: flex; gap: 6px; background: rgba(0, 0, 0, .28); padding: 5px; border-radius: 16px; }
.seg button { flex: 1; cursor: pointer; border: 0; padding: 9px 12px; border-radius: 12px; background: transparent; color: var(--cream); font-weight: 600; font-size: .98rem; transition: background .15s; white-space: nowrap; }
.seg button.on { background: linear-gradient(#ffb03a, #ff7a1a); color: #3a1400; box-shadow: 0 2px 0 #b3560a; }
.topics-head { display: flex; align-items: baseline; gap: 8px; }
.topics-head small { opacity: .7; font-weight: 500; }
.topics-head em { margin-left: auto; font-style: normal; font-size: .85rem; font-weight: 500; }
.topic-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.topic { display: flex; align-items: center; gap: 9px; text-align: left; cursor: pointer; padding: 9px 12px; border-radius: 14px; border: 1.5px solid rgba(255, 255, 255, .14); background: rgba(255, 255, 255, .06); color: var(--cream); font-size: .95rem; font-weight: 500; transition: transform .1s, background .15s, border-color .15s; line-height: 1.15; }
.topic:hover { transform: translateY(-1px); background: rgba(255, 255, 255, .12); }
.topic .em { font-size: 1.35rem; }
.topic.on { border-color: var(--lava2); background: linear-gradient(135deg, rgba(255, 140, 30, .35), rgba(255, 70, 20, .25)); box-shadow: 0 0 0 1px rgba(255, 157, 46, .4) inset; }
.topic .ck { margin-left: auto; opacity: 0; font-weight: 700; color: var(--gold); }
.topic.on .ck { opacity: 1; }

.side .history { max-height: 300px; overflow-y: auto; }
.side-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.quality { font-size: .85rem; display: flex; align-items: center; gap: 6px; margin-left: auto; }
.quality.language { margin-left: 0; }
.quality select { background: rgba(0, 0, 0, .35); color: var(--cream); border: 1.5px solid rgba(255, 255, 255, .2); border-radius: 10px; padding: 5px 8px; }

.history { display: flex; flex-direction: column; gap: 6px; }
.history .empty { opacity: .65; padding: 10px 0; font-size: .95rem; }
.hrow { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 12px; background: rgba(255, 255, 255, .06); font-size: .92rem; }
.hrow.best { background: linear-gradient(90deg, rgba(255, 196, 61, .25), rgba(255, 255, 255, .06)); }
.hrow.now { outline: 2px solid var(--lava2); }
.hrow .rank { font-weight: 700; color: var(--gold); min-width: 1.6em; }
.hrow .who { line-height: 1.2; }
.hrow .who small { display: block; opacity: .65; font-size: .78rem; }
.hrow .pts { font-weight: 700; font-size: 1.05rem; color: #fff; text-align: right; }
.hrow .pts small { display: block; font-weight: 500; opacity: .65; font-size: .75rem; }

/* ---------- modal ---------- */
#howto, #pause { background: rgba(8, 3, 14, .62); }
.modal { width: min(560px, 100%); }
.modal h2 { font-size: 1.8rem; text-align: center; color: var(--gold); }
.how { padding-left: 1.2em; line-height: 1.45; font-size: 1.05rem; margin: 14px 0 20px; }
.how li { margin-bottom: 9px; }
kbd { background: rgba(255, 255, 255, .18); border-radius: 6px; padding: 1px 7px; font-family: inherit; font-weight: 700; border-bottom: 2px solid rgba(0, 0, 0, .35); }
#howto .btn { display: block; margin: 0 auto; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-top { display: grid; grid-template-columns: 1fr minmax(0, 720px) 1fr; gap: 12px; padding: max(12px, env(safe-area-inset-top)) 14px 0; align-items: start; }
.hud-left, .hud-right { display: flex; flex-direction: column; gap: 8px; }
.hud-right { align-items: flex-end; }
.hearts { font-size: 1.8rem; line-height: 1; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .5)); display: flex; gap: 2px; flex-wrap: wrap; }
.hearts .h { display: inline-block; transition: transform .2s; }
.hearts .h.lost { filter: grayscale(1) brightness(.5); transform: scale(.85); }
.hearts.hit { animation: shake .45s; }
.hearts .more { font-size: 1.2rem; font-weight: 700; align-self: center; margin-left: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: rgba(20, 8, 28, .6); border: 1.5px solid rgba(255, 255, 255, .16); border-radius: 99px; padding: 5px 14px; font-weight: 600; width: fit-content; backdrop-filter: blur(8px); }
.chip b { color: var(--gold); font-size: 1.1em; }
.dots { display: flex; gap: 5px; flex-wrap: wrap; max-width: 200px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: rgba(255, 255, 255, .2); border: 2px solid rgba(255, 255, 255, .35); }
.dots i.on { background: radial-gradient(circle at 35% 30%, #fff5b0, #ffb020); border-color: #ffd25a; box-shadow: 0 0 10px rgba(255, 190, 40, .8); }
.score { background: rgba(20, 8, 28, .6); border: 1.5px solid rgba(255, 255, 255, .16); border-radius: 18px; padding: 4px 16px 6px; text-align: right; backdrop-filter: blur(8px); }
.score small { display: block; font-size: .65rem; letter-spacing: 2px; opacity: .7; }
.score b { font-size: 1.7rem; color: #fff; line-height: 1; font-variant-numeric: tabular-nums; }
.score.bump b { animation: pop .3s; }
.btns { display: flex; gap: 8px; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid rgba(255, 255, 255, .22); background: rgba(20, 8, 28, .65); color: #fff; font-size: 1.2rem; cursor: pointer; backdrop-filter: blur(8px); }
.round:hover { background: rgba(60, 25, 60, .8); }

.qcard { background: linear-gradient(180deg, rgba(255, 248, 228, .97), rgba(255, 232, 186, .96)); color: #2b1a0e; border-radius: 24px; padding: 10px 22px 16px; text-align: center; border: 4px solid #7a4a1e; box-shadow: 0 8px 0 rgba(90, 45, 10, .55), 0 18px 38px rgba(0, 0, 0, .45); position: relative; transition: transform .25s, opacity .25s; }
.qcard.enter { animation: dropIn .5s cubic-bezier(.2, 1.4, .4, 1); }
.qcard.off { opacity: 0; transform: translateY(-20px); }
.qtopic { font-size: .82rem; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: #a5581c; }
.qtext { font-size: clamp(1.4rem, 3.4vw, 2.5rem); font-weight: 700; line-height: 1.25; margin: 2px 0 8px; }
.timer { height: 12px; border-radius: 99px; background: rgba(90, 45, 10, .25); overflow: hidden; }
.timer i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #58d66b, #b6e04a); border-radius: 99px; transform-origin: left; }
.timer.warn i { background: linear-gradient(90deg, #ffb020, #ff8a1a); }
.timer.danger i { background: linear-gradient(90deg, #ff5a4a, #ff2a2a); animation: blink .35s infinite alternate; }
.timer.danger { animation: shake .25s infinite; }

.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 .12em; line-height: 1.02; font-size: .84em; }
.frac .n { border-bottom: .09em solid currentColor; padding: 0 .18em .02em; }
.frac .d { padding: .02em .18em 0; }

.track { position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(520px, 70vw); display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; background: rgba(20, 8, 28, .55); border: 1.5px solid rgba(255, 255, 255, .14); border-radius: 99px; padding: 6px 16px; backdrop-filter: blur(8px); font-size: 1.3rem; }
.track small { position: absolute; left: 0; right: 0; top: -20px; text-align: center; font-size: .8rem; opacity: .85; text-shadow: 0 1px 4px #000; }
.t-line { position: relative; height: 10px; border-radius: 99px; background: rgba(255, 255, 255, .18); }
.t-line i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 99px; background: linear-gradient(90deg, #ffd25a, #ff5a1a); }
#trackHero { position: absolute; top: 50%; left: 0; transform: translate(-50%, -58%); font-size: 1.5rem; filter: drop-shadow(0 2px 3px #000); }

.reveal { position: absolute; left: 50%; top: 34%; transform: translateX(-50%); width: min(560px, 92vw); text-align: center; padding: 14px 20px; border-radius: 22px; font-size: 1.2rem; font-weight: 600; line-height: 1.35; backdrop-filter: blur(10px); animation: dropIn .4s cubic-bezier(.2, 1.4, .4, 1); box-shadow: 0 12px 34px rgba(0, 0, 0, .5); }
.reveal.bad { background: rgba(120, 20, 20, .88); border: 2px solid #ff8a7a; }
.reveal.good { background: rgba(20, 100, 40, .88); border: 2px solid #8aff9a; }
.reveal.time { background: rgba(110, 60, 10, .9); border: 2px solid #ffc060; }
.reveal b { font-size: 1.25em; color: #ffe27a; }
.reveal .ex { display: block; font-weight: 500; font-size: .95rem; opacity: .92; margin-top: 4px; }
.hint { position: absolute; left: 50%; bottom: 74px; transform: translateX(-50%); text-align: center; font-weight: 600; font-size: 1.05rem; color: #fff; text-shadow: 0 2px 8px #000, 0 0 3px #000; width: min(640px, 92vw); }

.banner { position: fixed; left: 0; right: 0; top: 28%; z-index: 30; text-align: center; pointer-events: none; text-shadow: 0 4px 0 rgba(90, 20, 0, .7), 0 8px 30px rgba(0, 0, 0, .6); animation: bannerIn .6s cubic-bezier(.2, 1.3, .4, 1); padding: 0 16px; }
.banner h2 { font-size: clamp(2.2rem, 7vw, 4.6rem); color: #fff; -webkit-text-stroke: 2px rgba(120, 40, 0, .6); paint-order: stroke fill; line-height: 1.05; }
.banner p { margin: 8px 0 0; font-size: clamp(1.1rem, 3vw, 1.7rem); color: var(--gold); font-weight: 600; }
.banner.out { animation: bannerOut .5s ease-in forwards; }

#floaters { position: fixed; inset: 0; pointer-events: none; z-index: 12; overflow: hidden; }
.floater { position: absolute; transform: translate(-50%, -50%); font-weight: 700; font-size: 2rem; color: #ffe27a; text-shadow: 0 3px 0 rgba(120, 50, 0, .8), 0 0 14px rgba(255, 170, 40, .8); animation: floatUp 1.3s ease-out forwards; white-space: nowrap; }
.floater.good { color: #9dff9a; text-shadow: 0 3px 0 rgba(0, 80, 20, .8), 0 0 14px rgba(80, 255, 100, .7); }
.floater.bad { color: #ff9a8a; text-shadow: 0 3px 0 rgba(90, 0, 0, .8); }

/* ---------- resultados ---------- */
#results { background: linear-gradient(180deg, rgba(10, 4, 20, .5), rgba(10, 4, 20, .85)); z-index: 25; }
.results-wrap { width: min(760px, 100%); margin: 0 auto; padding: 22px 16px 40px; }
.res-head { text-align: center; }
.res-emoji { font-size: 4rem; animation: bob 2s ease-in-out infinite; }
.res-head h2 { font-size: clamp(1.8rem, 5vw, 2.6rem); color: #fff; }
.stars { font-size: 2.6rem; letter-spacing: 6px; margin-top: 4px; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .4)); }
.stars .off { filter: grayscale(1) brightness(.45); }
.stars span { display: inline-block; animation: starIn .6s both; }
.res-score { text-align: center; margin: 12px 0 6px; }
.res-score small { display: block; letter-spacing: 3px; opacity: .7; }
.res-score b { font-size: clamp(3rem, 12vw, 5rem); line-height: 1; color: var(--gold); text-shadow: 0 4px 0 rgba(120, 50, 0, .7); font-variant-numeric: tabular-nums; }
.res-score span { display: block; font-weight: 600; margin-top: 2px; }
.res-score span.new { color: #9dff9a; animation: pop .6s infinite alternate; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
.stat { background: rgba(255, 255, 255, .07); border-radius: 16px; padding: 10px 12px; text-align: center; }
.stat b { display: block; font-size: 1.6rem; color: #fff; }
.stat small { opacity: .75; font-size: .82rem; }
.topics-res { display: flex; flex-direction: column; gap: 8px; }
.tr { display: grid; grid-template-columns: 1fr 64px; gap: 10px; align-items: center; font-size: .95rem; }
.tr .bar2 { height: 12px; border-radius: 99px; background: rgba(255, 255, 255, .14); overflow: hidden; margin-top: 4px; }
.tr .bar2 i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #ff5a4a, #ffb020 50%, #58d66b); background-size: 100vw 100%; }
.tr .pc { text-align: right; font-weight: 700; }
.missed { margin-top: 18px; background: rgba(255, 90, 60, .12); border: 1.5px solid rgba(255, 130, 100, .3); border-radius: 16px; padding: 10px 14px; }
.missed summary { cursor: pointer; font-weight: 700; color: #ffb3a6; }
.missed ul { margin: 10px 0 2px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.missed li { background: rgba(0, 0, 0, .25); border-radius: 12px; padding: 8px 12px; font-size: .95rem; line-height: 1.35; }
.missed li .q { font-weight: 700; }
.missed li .a { color: #9dff9a; }
.missed li .w { color: #ff9a8a; }
.actions { justify-content: center; margin-top: 22px; }

/* ---------- animações ---------- */
@keyframes pop { 50% { transform: scale(1.18); } }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@keyframes blink { to { filter: brightness(1.5); } }
@keyframes dropIn { from { transform: translateY(-40px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
.reveal { animation-name: revealIn; }
@keyframes revealIn { from { transform: translate(-50%, -20px) scale(.9); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
@keyframes bannerIn { from { transform: scale(.4) translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes bannerOut { to { transform: translateY(-40px) scale(1.1); opacity: 0; } }
@keyframes floatUp { 0% { transform: translate(-50%, -50%) scale(.6); opacity: 0; } 15% { transform: translate(-50%, -80%) scale(1.15); opacity: 1; } 100% { transform: translate(-50%, -260%) scale(1); opacity: 0; } }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- telas pequenas ---------- */
@media (max-width: 900px) {
  .menu-grid { grid-template-columns: 1fr; }
  .hud-top { grid-template-columns: 1fr auto; grid-template-areas: "l r" "c c"; row-gap: 8px; }
  .hud-left { grid-area: l; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .hud-right { grid-area: r; flex-direction: row; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
  .hud-center { grid-area: c; }
  .score b { font-size: 1.3rem; }
  .dots { display: none; }
  .track { width: 86vw; bottom: 8px; }
  .hint { bottom: 60px; font-size: .95rem; }
  .qcard { padding: 8px 14px 12px; border-width: 3px; }
}
@media (max-width: 560px) {
  .field-row { grid-template-columns: 1fr; }
  .seg button { font-size: .85rem; padding: 8px 6px; }
  .card { padding: 16px; border-radius: 22px; }
  .topic-grid { grid-template-columns: 1fr 1fr; }
  .topic { font-size: .82rem; padding: 8px; gap: 6px; }
  .topic .em { font-size: 1.1rem; }
  .hearts { font-size: 1.4rem; }
  .round { width: 38px; height: 38px; }
  .chip { padding: 3px 10px; font-size: .9rem; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .qtext { font-size: 1.3rem; margin-bottom: 4px; }
  .qcard { padding: 4px 16px 8px; }
  .track { display: none; }
  .hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { .logo-badge, .logo-dragon, .load-icon, .res-emoji { animation: none; } }
