:root {
  --ink: #23324a; --muted: #62708a; --blue: #2f6fb3; --blue2: #24578f; --paper: #fbfdff; --grid: #d5e4f4;
  --margin: #f08a7e; --yellow: #f6c343; --red: #e0533d; --green: #3fa564;
  --fLP: #f6a6b8; --fLR: #ffd27a; --fLM: #98dea5; --fLI: #8fcbff; --fRI: #c7aeff; --fRM: #98dea5; --fRR: #ffd27a; --fRP: #f6a6b8; --fTH: #e9e0d2;
  --u: 36px; --kh: 40px;
  font-size: clamp(11px, calc(min(2.1vh, 1.5vw) + 4px), 22px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; color: var(--ink);
  background-color: var(--paper); -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }
#bgc { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; pointer-events: none; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; z-index: 1; }
#app::before { content: ""; position: absolute; top: 0; bottom: 0; left: 2.4rem; width: 2px; background: var(--margin); opacity: .55; pointer-events: none; }

/* header */
#top { position: relative; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .3rem .7rem; background: var(--blue); color: #fff; box-shadow: 0 2px 0 var(--blue2); flex: none; }
#brand { display: flex; align-items: center; gap: .45rem; font-weight: 800; font-size: 1.05rem; letter-spacing: .01em; white-space: nowrap; }
#brand img { height: 1.7rem; width: auto; }
#tools { display: flex; gap: .35rem; align-items: center; }
.ico, .tbtn { height: 1.9rem; min-width: 1.9rem; border-radius: .6rem; border: 2px solid rgba(255,255,255,.55); background: rgba(255,255,255,.12); color: #fff; padding: 0 .45rem; display: inline-flex; align-items: center; justify-content: center; font-size: .82rem; }
.tbtn b { font-size: 1.05rem; }
.tbtn[aria-pressed="true"] { background: var(--yellow); color: var(--ink); border-color: var(--yellow); }
.ico::before { content: ""; width: 1.05rem; height: 1.05rem; background: #fff; -webkit-mask: var(--m) center/contain no-repeat; mask: var(--m) center/contain no-repeat; }
#mute { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 9v6h4l5 5V4L7 9H3zm13.5 3A4.5 4.5 0 0 0 14 8v8a4.5 4.5 0 0 0 2.5-4zM14 3.2v2.1a7 7 0 0 1 0 13.4v2.1a9 9 0 0 0 0-17.6z'/%3E%3C/svg%3E"); }
#mute.off { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 9v6h4l5 5V4L7 9H3zm18.4 3 2.3-2.3-1.4-1.4L20 10.6l-2.3-2.3-1.4 1.4 2.3 2.3-2.3 2.3 1.4 1.4 2.3-2.3 2.3 2.3 1.4-1.4z'/%3E%3C/svg%3E"); }
#music { --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3v10.6A4 4 0 1 0 14 17V7h4V3h-6z'/%3E%3C/svg%3E"); }
#music.off, #mute.off { opacity: .55; }
#music.off::after { content: ""; position: absolute; width: 1.4rem; height: 2px; background: #fff; transform: rotate(-45deg); }
#music { position: relative; }

/* play area */
#play { position: relative; z-index: 1; flex: 1; min-height: 0; display: flex; flex-direction: column; padding: .35rem .6rem .45rem 3rem; gap: .3rem; }
#hud { flex: none; display: flex; align-items: center; gap: .6rem; flex-wrap: nowrap; position: relative; padding-bottom: .35rem; }
.htitle { font-weight: 800; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.hstats { display: flex; gap: .4rem; }
.hs { background: #fff; border: 2px solid var(--grid); border-radius: .55rem; padding: .1rem .5rem; text-align: center; min-width: 3.6rem; line-height: 1.05; }
.hs b { display: block; font-size: 1rem; }
.hs span { font-size: .62rem; color: var(--muted); }
#hBar { position: absolute; left: 0; right: 0; bottom: 0; height: .25rem; border-radius: .2rem; background: var(--grid); overflow: hidden; }
#hFill { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--yellow)); transition: width .15s; }
.btn { border: none; border-radius: .8rem; background: var(--red); color: #fff; font-weight: 800; padding: .55rem 1.1rem; font-size: 1rem;
  box-shadow: 0 .22rem 0 #a83a28; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap; }
.btn:active { transform: translateY(.15rem); box-shadow: 0 .07rem 0 #a83a28; }
.btn.ghost { background: #fff; color: var(--blue2); box-shadow: 0 .22rem 0 var(--grid); border: 2px solid var(--grid); }
.btn.small { padding: .3rem .7rem; font-size: .85rem; }
.btn.big { font-size: 1.2rem; padding: .7rem 1.6rem; }

#stage { position: relative; flex: 1; min-height: 0; border-radius: 1rem; background: rgba(255,255,255,.82); border: 2px solid var(--grid); overflow: hidden; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: none; }
#stage.canvas #cv { display: block; }
#textbox { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: .3rem .8rem; }
#stage.race #textbox { top: auto; height: 40%; background: rgba(255,255,255,.92); border-top: 2px dashed var(--grid); }
#stage.rain #textbox { display: none; }
#lines { font-family: ui-monospace, "Cascadia Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace; white-space: pre; line-height: 1.35; }
.ln { display: block; }
.ln.prev { opacity: .35; }
.ln.next { opacity: .45; }
.ln span { border-radius: .15em; }
.ln .ok { color: var(--green); }
.ln .bad { color: #fff; background: var(--red); }
.ln .fix { color: #c27a00; }
.ln .cur { background: var(--yellow); box-shadow: 0 .12em 0 var(--ink); animation: blink 1s steps(2) infinite; }
.ln .cur.wrong { background: #ffb3a8; animation: shake .25s; }
.ln .sp { color: #b9c7d8; }
@keyframes blink { 50% { box-shadow: 0 .12em 0 transparent; } }
@keyframes shake { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
#banner { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%) scale(.6); font-weight: 900; font-size: 2.6rem; color: var(--blue2);
  text-shadow: 0 3px 0 #fff, 0 -2px 0 #fff, 3px 0 0 #fff, -3px 0 0 #fff; opacity: 0; pointer-events: none; transition: opacity .2s, transform .25s; white-space: nowrap; }
#banner.on { opacity: 1; transform: translate(-50%, -50%) scale(1); }

#hint { flex: none; display: flex; align-items: center; justify-content: center; gap: .6rem; font-size: .9rem; min-height: 1.6rem; text-align: center; }
#hintTxt { font-weight: 700; }
#hintTxt i { font-style: normal; padding: 0 .35rem; border-radius: .4rem; }
.hand { display: inline-flex; }
.hand svg { height: 2.1rem; width: auto; display: block; }

/* keyboard */
#kb { flex: none; align-self: center; display: flex; flex-direction: column; gap: calc(var(--u) * .09); padding: calc(var(--u) * .14); background: #eef3f9; border: 2px solid #c9d7e8; border-radius: calc(var(--u) * .3); box-shadow: 0 .25rem 0 #c9d7e8; touch-action: none; }
.kr { display: flex; gap: calc(var(--u) * .09); }
.k { position: relative; height: var(--kh); width: calc(var(--u) * var(--w, 1) - var(--u) * .09); border-radius: calc(var(--u) * .18); border: none; padding: 0;
  background: var(--fc, #fff); color: var(--ink); font-weight: 800; font-size: calc(var(--u) * .42); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 calc(var(--u) * .07) 0 rgba(35,50,74,.28); transition: transform .06s; line-height: 1; }
.k.sm { font-size: calc(var(--u) * .27); font-weight: 700; }
.k.gap { visibility: hidden; }
.k .s2 { position: absolute; top: 12%; left: 14%; font-size: calc(var(--u) * .24); opacity: .7; }
.k.dim { filter: saturate(.25) brightness(1.07); opacity: .6; }
.k.home::after { content: ""; position: absolute; bottom: 16%; width: 28%; height: 2px; border-radius: 2px; background: var(--ink); opacity: .55; }
.k.next { outline: calc(var(--u) * .08) solid var(--ink); outline-offset: 1px; transform: translateY(-2px); animation: pulse .9s ease-in-out infinite; z-index: 1; }
.k.next2 { outline: calc(var(--u) * .06) dashed var(--ink); outline-offset: 1px; }
.k.hit { transform: translateY(calc(var(--u) * .06)); box-shadow: none; }
.k.err { background: var(--red) !important; color: #fff; }
.k.on { background: var(--yellow); }
@keyframes pulse { 50% { outline-color: var(--red); } }

#toast { position: absolute; left: 50%; bottom: .4rem; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .45rem .9rem; border-radius: .7rem; font-size: .9rem; opacity: 0; pointer-events: none; transition: opacity .25s; max-width: 90%; text-align: center; z-index: 5; }
#toast.on { opacity: .95; }

/* overlays and panels */
.overlay { position: fixed; top: var(--hdr, 0px); left: 0; right: 0; bottom: 0; z-index: 10; display: none; align-items: center; justify-content: center; padding: .6rem; background: rgba(35,50,74,.35); }
.overlay.on { display: flex; }
#menu { background: rgba(251,253,255,.6); }
.panel { width: min(58rem, 100%); max-height: 100%; display: flex; flex-direction: column; background: #fff; border: 3px solid var(--ink); border-radius: 1.2rem; box-shadow: 0 .45rem 0 var(--ink); overflow: hidden; }
.pbody { flex: 1; min-height: 0; overflow: auto; display: flex; gap: 1rem; padding: .9rem 1rem .5rem; }
.pbody.col { flex-direction: column; align-items: center; }
.pleft { flex: 0 0 36%; display: flex; flex-direction: column; align-items: center; text-align: center; gap: .35rem; }
.pright { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .5rem; }
.pright > *, .pleft > * { flex-shrink: 0; }
.certrow .btn { flex: none; }
.mascot { height: 7.5rem; width: auto; filter: drop-shadow(0 .25rem 0 rgba(35,50,74,.15)); }
h1 { margin: 0; font-size: 1.55rem; line-height: 1.1; color: var(--blue2); }
h1 small { display: block; font-size: .8rem; color: var(--red); margin-top: .15rem; }
h2 { margin: 0; font-size: 1.4rem; color: var(--blue2); }
.intro { margin: 0; font-size: .86rem; line-height: 1.35; }
.keysline { margin: 0; font-size: .74rem; color: var(--muted); }
.kc { display: inline-block; min-width: 1.35em; padding: .05em .3em; margin: 0 .06em; border: 1.5px solid var(--ink); border-bottom-width: 3px; border-radius: .35em; background: #fff; font-weight: 800; color: var(--ink); font-size: .9em; text-align: center; }
.kc.f { background: var(--fLI); }
.phone { margin: 0; font-size: .78rem; background: #fff6d8; border: 2px solid var(--yellow); border-radius: .6rem; padding: .35rem .5rem; text-align: left; }
.small { margin: 0; font-size: .78rem; color: var(--muted); line-height: 1.35; }
.best { margin: 0; font-weight: 800; color: var(--blue2); font-size: .9rem; }
.tabs { display: flex; gap: .3rem; background: #eef3f9; padding: .25rem; border-radius: .8rem; }
.tabs button { flex: 1; border: none; background: transparent; border-radius: .6rem; padding: .4rem .3rem; font-weight: 800; color: var(--muted); font-size: .9rem; white-space: nowrap; }
.tabs button.on { background: var(--blue); color: #fff; }
.tab { display: none; flex-direction: column; gap: .5rem; }
.tab.on { display: flex; }
.lgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .3rem; }
.lc { position: relative; border: 2px solid var(--grid); background: #fff; border-radius: .6rem; padding: .2rem .15rem .15rem; text-align: center; line-height: 1.1; min-width: 0; }
.lc b { display: block; font-size: .95rem; }
.lc span { display: block; font-size: .66rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lc i { display: block; font-style: normal; font-size: .7rem; letter-spacing: .05em; color: #c9d2de; }
.lc i .y { color: #e9a400; }
.lc.sel { border-color: var(--blue); background: #e8f1fb; box-shadow: 0 0 0 2px var(--blue); }
.lc.done { background: #f1fbf3; }
.opt { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.opt > span { font-weight: 800; font-size: .85rem; min-width: 5.2rem; }
.seg { display: inline-flex; background: #eef3f9; border-radius: .7rem; padding: .2rem; gap: .2rem; flex-wrap: wrap; }
.seg button { border: none; background: transparent; padding: .32rem .7rem; border-radius: .55rem; font-weight: 700; font-size: .85rem; }
.seg button.on { background: var(--yellow); color: var(--ink); }
.gcards { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.gcard { text-align: left; border: 2px solid var(--grid); background: #fff; border-radius: .8rem; padding: .5rem .6rem; display: flex; flex-direction: column; gap: .2rem; }
.gcard b { font-size: 1rem; color: var(--blue2); }
.gcard span { font-size: .75rem; color: var(--muted); line-height: 1.3; }
.gcard em { font-style: normal; font-size: .75rem; font-weight: 800; color: var(--red); }
.gcard.on { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue); background: #e8f1fb; }
.pfoot { flex: none; display: flex; gap: .5rem; align-items: center; justify-content: center; flex-wrap: wrap; padding: .55rem .8rem .8rem; border-top: 2px dashed var(--grid); background: #fff; }
.keys { font-size: .75rem; color: var(--muted); }

.stars { display: flex; gap: .2rem; font-size: 2rem; line-height: 1; }
.stars span { color: #dfe5ee; text-shadow: 0 2px 0 rgba(0,0,0,.08); transform: scale(.4); transition: transform .3s cubic-bezier(.3,1.6,.5,1), color .2s; }
.stars span.y { color: #f2b400; transform: scale(1); }
.stars span.s { transform: scale(1); }
.rstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .45rem; }
.rstats div { background: #f4f8fc; border: 2px solid var(--grid); border-radius: .7rem; padding: .35rem .3rem; text-align: center; }
.rstats b { display: block; font-size: 1.35rem; color: var(--blue2); }
.rstats span { font-size: .7rem; color: var(--muted); }
.rstats div.big { grid-column: span 3; background: #fff6d8; border-color: var(--yellow); }
.rstats div.big b { font-size: 2rem; color: var(--ink); }
.certrow { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; }
.certrow label { font-size: .75rem; font-weight: 700; color: var(--muted); display: flex; flex-direction: column; gap: .15rem; flex: 1; min-width: 9rem; }
.certrow input { font: inherit; font-size: .95rem; padding: .35rem .5rem; border: 2px solid var(--grid); border-radius: .5rem; -webkit-user-select: text; user-select: text; }
.certp { width: min(46rem, 100%); }
#certImg { max-width: 100%; max-height: 62vh; border-radius: .5rem; border: 2px solid var(--grid); -webkit-touch-callout: default; -webkit-user-select: auto; user-select: auto; }

/* phones and narrow */
@media (max-width: 620px) {
  #play { padding-left: .5rem; }
  #app::before { display: none; }
  .hide-xs { display: none; }
  .hs { min-width: 2.9rem; padding: .1rem .3rem; }
  .hs span { font-size: .55rem; }
  #hExtraBox { display: none; }
  .pbody { flex-direction: column; gap: .5rem; }
  .pleft { flex: none; }
  .mascot { height: 4.5rem; }
  .rstats { grid-template-columns: repeat(2, 1fr); }
  .rstats div.big { grid-column: span 2; }
  .pleft.rl { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .htitle { font-size: .85rem; }
}
@media (max-width: 620px) and (min-height: 600px) {
  .pleft .mascot { height: 5.5rem; }
}
/* short frames (store embed 794x447, 640x360, phone landscape) */
@media (max-height: 560px) {
  :root { font-size: clamp(10px, calc(min(2.4vh, 1.4vw) + 3px), 15px); }
  #top { padding: .15rem .6rem; }
  .ico, .tbtn { height: 1.6rem; min-width: 1.6rem; }
  .pbody { padding: .55rem .8rem .35rem; gap: .8rem; }
  .mascot { height: 5rem; }
  .pfoot { padding: .4rem .6rem .55rem; }
  .btn.big { padding: .5rem 1.3rem; font-size: 1.1rem; }
  .hs { padding: 0 .4rem; }
  .hand svg { height: 1.7rem; }
  #hint { min-height: 1.3rem; font-size: .82rem; }
  .stars { font-size: 1.6rem; }
  .rstats b { font-size: 1.1rem; }
  .rstats div.big b { font-size: 1.5rem; }
}
@media (max-height: 420px) {
  .mascot { height: 3.6rem; }
  .pleft .intro { font-size: .78rem; }
  .keysline { display: none; }
  h1 { font-size: 1.25rem; }
  .lc span { display: none; }
  .hand { display: none; }
  #play { gap: .2rem; padding-top: .2rem; padding-bottom: .3rem; }
  .rstats div { padding: .15rem .2rem; }
}
@media (max-height: 420px) and (max-width: 900px) {
  .pleft .intro { display: none; }
}
