:root {
  --teal: #0f5c4d; --teal2: #177a65; --teal3: #d7efe6; --cream: #fff6e0; --paper: #fffdf7; --ink: #22302c; --muted: #62736d;
  --coral: #f2654a; --coral2: #d94c31; --sun: #ffc93c; --ok: #1d9a56; --bad: #e0413a; --ghost: #7a5ad8; --line: #e9dfc4;
  --hh: 2.9rem;
  font-size: clamp(11px, calc(min(2.25vh, 1.5vw) + 4px), 23px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--cream); color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body { touch-action: manipulation; overscroll-behavior: none; }
#bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; display: block; }
#app { position: relative; z-index: 1; height: 100%; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* header */
#top { height: var(--hh); flex: none; display: flex; align-items: center; gap: .6rem; padding: 0 .7rem; background: var(--teal); color: #fff;
  box-shadow: 0 .15rem 0 #0a4136; }
#brand { display: flex; align-items: center; gap: .4rem; font-weight: 800; font-size: 1.1rem; white-space: nowrap; }
#brand img { width: 1.9rem; height: auto; }
#tabs { display: flex; gap: .25rem; margin-left: auto; background: #0a4136; border-radius: 99px; padding: .2rem; }
#tabs button { border: 0; background: transparent; color: #cfe9df; padding: .3rem .8rem; border-radius: 99px; font-weight: 700; font-size: .9rem; white-space: nowrap; }
#tabs button.on { background: var(--sun); color: #3b2a00; }
#tools { display: flex; gap: .35rem; }
.ico { width: 2.1rem; height: 2.1rem; border-radius: 50%; border: 2px solid #ffffff55; background: #ffffff18 center/62% no-repeat; }
.ico.off { opacity: .55; }

/* main */
#main { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: .6rem; padding: .7rem 1rem .8rem; }
#hud { width: min(100%, 56rem); display: flex; align-items: center; justify-content: space-between; gap: .5rem; flex: none; }
.stat { background: var(--paper); border: 2px solid var(--line); border-radius: .8rem; padding: .3rem .7rem; min-width: 5.2rem; text-align: center;
  box-shadow: 0 .18rem 0 var(--line); }
.stat b { display: block; font-size: 1.45rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat span { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.stat.time b { color: var(--teal); }
.ghoststat b { color: var(--ghost); }
.gauge { position: relative; width: 9.5rem; height: 5.6rem; flex: none; }
.gauge canvas { width: 100%; height: 100%; display: block; }
.gnum { position: absolute; left: 0; right: 0; bottom: .15rem; text-align: center; line-height: 1; }
.gnum b { font-size: 1.7rem; display: block; font-variant-numeric: tabular-nums; }
.gnum span { font-size: .68rem; font-weight: 800; color: var(--muted); letter-spacing: .08em; }

#box { width: min(100%, 56rem); flex: none; --fs: 1.75rem; --pad: .8rem; height: calc(var(--fs) * 1.75 * 3 + var(--pad) * 2 + 4px); overflow: hidden; position: relative;
  background: var(--paper); border: 2px solid var(--line); border-radius: 1rem; padding: var(--pad) 1.1rem; box-shadow: 0 .3rem 0 var(--line);
  background-image: repeating-linear-gradient(transparent 0, transparent calc(var(--fs) * 1.75 - 1px), #efe6cf calc(var(--fs) * 1.75 - 1px), #efe6cf calc(var(--fs) * 1.75));
  background-position: 0 var(--pad); background-origin: padding-box; }
#clip { height: calc(var(--fs) * 1.75 * 3); overflow: hidden; }
#words { font-size: var(--fs); line-height: 1.75; transition: transform .18s ease-out; font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif; }
.w { display: inline; padding: 0 .02em; border-radius: .25em; color: #3d4a46; position: relative; }
.w.cur { background: #fff1b8; box-shadow: 0 0 0 .12em #fff1b8; }
.w.ok { color: var(--ok); }
.w.bad { color: var(--bad); text-decoration: underline wavy #e0413a88; text-decoration-thickness: 1px; }
.c.ok { color: var(--ok); }
.c.bad { color: #fff; background: var(--bad); border-radius: .12em; }
.c.extra { color: #fff; background: #f08b80; border-radius: .12em; }
.c.next { box-shadow: inset 0 -.14em 0 var(--teal2); }
.c.gh { box-shadow: inset 0 -.2em 0 var(--ghost); }
.ghosttag { position: absolute; top: -.95em; left: 50%; transform: translateX(-50%); font-size: .42em; line-height: 1; background: var(--ghost); color: #fff;
  border-radius: .5em; padding: .15em .4em; white-space: nowrap; pointer-events: none; font-weight: 800; }

#inrow { width: min(100%, 56rem); flex: none; display: flex; flex-direction: column; align-items: center; gap: .35rem; }
#tin { width: min(100%, 30rem); font: inherit; font-size: 1.5rem; padding: .45rem .9rem; border-radius: .8rem; border: 3px solid var(--teal2); background: #fff;
  color: var(--ink); outline: none; text-align: center; box-shadow: 0 .25rem 0 #0f5c4d33; }
#tin:focus { border-color: var(--sun); box-shadow: 0 0 0 .25rem #ffc93c55; }
#tin.bad { border-color: var(--bad); background: #fff0ee; }
#tin.shake { animation: shake .22s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.tip { margin: 0; font-size: .85rem; color: var(--muted); text-align: center; }
.kc { display: inline-block; border: 1.5px solid #b9ad8f; border-bottom-width: 3px; border-radius: .35rem; padding: 0 .35rem; background: #fff; font-weight: 700; font-size: .8em; color: var(--ink); }

.btn { border: 0; background: var(--coral); color: #fff; font-weight: 800; border-radius: .9rem; padding: .55rem 1.3rem; font-size: 1.05rem;
  box-shadow: 0 .28rem 0 var(--coral2); transition: transform .08s; white-space: nowrap; }
.btn:active { transform: translateY(.2rem); box-shadow: 0 .08rem 0 var(--coral2); }
.btn.big { font-size: 1.4rem; padding: .65rem 2.6rem; }
.btn.small { font-size: .85rem; padding: .4rem .8rem; }
.btn.ghostbtn { background: var(--paper); color: var(--teal); border: 2px solid var(--teal2); box-shadow: 0 .22rem 0 var(--teal2); }

/* overlays */
.overlay { position: absolute; left: 0; right: 0; top: var(--hh); bottom: 0; display: none; align-items: center; justify-content: center; padding: .7rem;
  background: rgba(255, 246, 224, .72); backdrop-filter: blur(2px); z-index: 5; }
.overlay.on { display: flex; }
.panel { background: var(--paper); border: 3px solid var(--teal); border-radius: 1.3rem; box-shadow: 0 .45rem 0 var(--teal), 0 1rem 2.5rem #0f5c4d33;
  width: min(100%, 52rem); max-height: 100%; display: flex; flex-direction: column; overflow: hidden; animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } }
.pscroll { display: flex; gap: 1.2rem; padding: 1.1rem 1.3rem .4rem; overflow: auto; min-height: 0; flex: 1; }
.pcol { flex: 1; min-width: 0; }
.pcol.art { flex: none; width: 11rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4rem; }
.mascot { width: 10rem; height: auto; animation: hover 2.4s ease-in-out infinite; }
@keyframes hover { 50% { transform: translateY(-.5rem) rotate(-3deg); } }
.you { background: var(--sun); color: #3b2a00; font-weight: 800; font-size: .8rem; padding: .2rem .6rem; border-radius: 99px; text-align: center; }
h1 { margin: 0 0 .35rem; font-size: 1.9rem; color: var(--teal); line-height: 1.1; }
h1 small { display: block; font-size: .95rem; color: var(--coral2); margin-top: .15rem; }
.intro { margin: 0 0 .6rem; font-size: .95rem; line-height: 1.4; }
.opts { display: flex; flex-direction: column; gap: .4rem; }
.opt { display: flex; align-items: center; gap: .6rem; }
.opt > span { width: 4.8rem; font-weight: 800; font-size: .85rem; color: var(--muted); flex: none; }
.seg { display: inline-flex; flex-wrap: wrap; gap: .25rem; background: var(--teal3); padding: .2rem; border-radius: .7rem; }
.seg button { border: 0; background: transparent; padding: .3rem .7rem; border-radius: .55rem; font-weight: 700; font-size: .88rem; color: var(--teal); }
.seg button.on { background: var(--teal); color: #fff; }
.best { margin: .5rem 0 0; font-weight: 700; color: var(--teal2); font-size: .9rem; min-height: 1em; }
.small { font-size: .88rem; margin: 0 0 .3rem; }
.muted { color: var(--muted); }
.btns { display: flex; gap: .6rem; justify-content: center; align-items: center; flex-wrap: wrap; padding: .7rem 1rem .95rem; }
.btns.sticky { flex: none; border-top: 2px dashed var(--line); background: var(--paper); }
.keys { font-size: .8rem; color: var(--muted); }
.keychips { display: flex; flex-wrap: wrap; gap: .35rem; margin: .2rem 0 .4rem; }
.keychips i { font-style: normal; min-width: 2.2rem; text-align: center; padding: .3rem .5rem; border-radius: .5rem; background: #fff; border: 2px solid #c9bea0;
  border-bottom-width: 4px; font-weight: 800; font-size: 1.05rem; }
.keychips i em { display: block; font-style: normal; font-size: .62rem; color: var(--bad); }

/* result */
.rtop { display: flex; align-items: center; gap: 1rem; }
.bignum b { font-size: 4rem; line-height: 1; color: var(--teal); font-variant-numeric: tabular-nums; display: block; }
.bignum span { font-weight: 800; color: var(--muted); font-size: .85rem; }
.rbadge { margin-left: auto; text-align: right; }
.level { background: var(--sun); color: #3b2a00; font-weight: 900; padding: .35rem .8rem; border-radius: .7rem; font-size: 1.05rem; display: inline-block; }
.newbest { margin-top: .35rem; color: var(--coral2); font-weight: 900; animation: hover 1s ease-in-out infinite; }
.rstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem; margin: .6rem 0; }
.rstats div { background: #fff; border: 2px solid var(--line); border-radius: .7rem; padding: .25rem .4rem; text-align: center; }
.rstats b { display: block; font-size: 1.2rem; font-variant-numeric: tabular-nums; }
.rstats span { font-size: .68rem; color: var(--muted); font-weight: 700; }
.pct { margin-top: .2rem; }
.pbar { position: relative; height: .9rem; border-radius: 99px; background: linear-gradient(90deg, #f6d9a8, #ffe9a6 40%, #bfe8cf); border: 2px solid var(--line); overflow: visible; }
.pbar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; background: var(--teal2); opacity: .85; width: 0; transition: width .8s ease-out; }
.pbar em { position: absolute; top: -.35rem; bottom: -.35rem; width: 3px; background: var(--ink); border-radius: 2px; }
#pTxt { margin: .35rem 0 0; font-size: .82rem; line-height: 1.35; }
.rbox { background: #fff; border: 2px solid var(--line); border-radius: .9rem; padding: .5rem .6rem .6rem; }
.rbox h3 { margin: 0 0 .4rem; font-size: .95rem; color: var(--teal); }
.rbox h3 small { color: var(--muted); font-weight: 600; }
.heat { display: flex; flex-direction: column; gap: .25rem; align-items: center; }
.heat .r { display: flex; gap: .22rem; width: 100%; justify-content: center; }
.heat .r:nth-child(2) { padding-left: .7rem; }
.heat .r:nth-child(3) { padding-left: 1.6rem; }
.heat i { font-style: normal; flex: 0 1 2.05rem; min-width: 0; height: 2.05rem; display: flex; align-items: center; justify-content: center; border-radius: .4rem;
  background: #f1ede2; border: 1.5px solid #d8cfb8; border-bottom-width: 3px; font-weight: 800; font-size: .9rem; text-transform: uppercase; }
.heat .leg { display: flex; gap: .6rem; font-size: .7rem; color: var(--muted); margin-top: .3rem; align-items: center; }
.heat .leg b { display: inline-block; width: .8rem; height: .8rem; border-radius: .2rem; vertical-align: middle; margin-right: .2rem; }
.note { font-size: .82rem; color: var(--muted); margin: .5rem 0 0; line-height: 1.35; }

/* treino mode tweaks */
body.treino .ghoststat { display: none; }

/* compact: short frames (store page 794x447, 640x360) */
@media (max-height: 560px) {
  :root { --hh: 2.4rem; }
  #brand { font-size: .95rem; }
  #brand img { width: 1.5rem; }
  .ico { width: 1.8rem; height: 1.8rem; }
  #main { gap: .4rem; padding: .45rem .8rem .5rem; }
  .stat { padding: .15rem .5rem; min-width: 4.4rem; }
  .stat b { font-size: 1.2rem; }
  .gauge { width: 7.6rem; height: 4.5rem; }
  .gnum b { font-size: 1.35rem; }
  #box { --fs: 1.5rem; --pad: .5rem; padding: var(--pad) .9rem; }
  #tin { font-size: 1.25rem; padding: .3rem .8rem; }
  .pscroll { padding: .7rem 1rem .3rem; }
  .pcol.art { width: 8rem; }
  .mascot { width: 7rem; }
  h1 { font-size: 1.5rem; }
  .intro { font-size: .85rem; margin-bottom: .4rem; }
  .btns { padding: .45rem .8rem .6rem; }
  .btn.big { font-size: 1.2rem; padding: .45rem 2rem; }
  .bignum b { font-size: 3rem; }
  .heat i { flex-basis: 1.75rem; height: 1.75rem; }
}
@media (max-height: 420px) {
  .pcol.art { display: none; }
  #tip { display: none; }
  .stat span, .gnum span { font-size: .62rem; }
  #box { --fs: 1.35rem; }
  .gauge { width: 6.6rem; height: 3.9rem; }
  .rstats { margin: .35rem 0; }
}
@media (max-width: 600px), (max-width: 700px) and (min-height: 421px) {
  .pscroll { flex-direction: column; gap: .7rem; }
}
@media (max-width: 700px) and (max-height: 420px) {
  .pscroll { gap: .7rem; padding: .5rem .7rem .2rem; }
  .bignum b { font-size: 2.4rem; }
  .rstats { grid-template-columns: repeat(2, 1fr); gap: .25rem; }
  .rstats b { font-size: 1rem; }
  .heat i { flex-basis: 1.45rem; height: 1.55rem; font-size: .75rem; }
  .heat .r { gap: .14rem; }
  .heat .r:nth-child(2) { padding-left: .5rem; } .heat .r:nth-child(3) { padding-left: 1rem; }
  #pTxt, .note { font-size: .74rem; }
}
/* narrow screens / phones */
@media (max-width: 700px) {
  #brand span { display: none; }
  #tabs { margin-left: 0; }
  #tools { margin-left: auto; }
  .pcol.art { display: none; }
  #hud { gap: .3rem; }
  .stat { min-width: 0; flex: 1; padding: .2rem .3rem; }
  #hRestart { padding: .4rem .5rem; }
  .hide-xs { display: none !important; }
  .opt { flex-wrap: wrap; gap: .25rem; }
  .opt > span { width: auto; }
}
@media (max-width: 460px) {
  #tabs button { padding: .3rem .6rem; font-size: .85rem; }
  .gauge { width: 7rem; height: 4.2rem; }
  #box { --fs: 1.45rem; --pad: .5rem; padding: var(--pad) .7rem; }
  .rstats { grid-template-columns: repeat(2, 1fr); }
  .bignum b { font-size: 3.2rem; }
  .heat i { flex-basis: 1.75rem; height: 1.9rem; font-size: .8rem; }
  .heat .r { gap: .15rem; }
  .heat .r:nth-child(2) { padding-left: .5rem; }
  .heat .r:nth-child(3) { padding-left: 1rem; }
  .ghoststat b { font-size: 1.1rem; }
  .gnum b { font-size: 1.2rem; }
  .gnum { bottom: 0; }
}
#mute{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M3 9v6h4l5 5V4L7 9H3z'/%3E%3Cpath d='M16 8a5 5 0 0 1 0 8' stroke='white' stroke-width='2' fill='none'/%3E%3C/svg%3E")}
#mute.off{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M3 9v6h4l5 5V4L7 9H3z'/%3E%3Cpath d='M16 9l5 6M21 9l-5 6' stroke='%23ff8a8a' stroke-width='2'/%3E%3C/svg%3E")}
#music{background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M9 18V5l11-2v13' stroke='white' stroke-width='2' fill='none'/%3E%3Ccircle cx='6' cy='18' r='3'/%3E%3Ccircle cx='17' cy='16' r='3'/%3E%3C/svg%3E")}
#music.off{opacity:.45}
