/* Note Monster — retro medieval style */
:root {
  --bg: #1a1220;
  --wood: #3a2618;
  --wood2: #4e3420;
  --wood-dark: #24170f;
  --trim: #c9a35b;
  --trim-dark: #7a5a2b;
  --parch: #f4ecd8;
  --ink: #2b1d12;
  --gold: #ffd23f;
  --text: #f4ecd8;
  --muted: #cdb98f;
  --good: #7cff6b;
  --orange: #ff9f43;
  --red: #ff4d6d;
  --sky: #9bd3e0;
  /* Jersey 10: the clearest pixel font we tried (chosen by the teacher, Nov 2026) */
  --font: "Jersey 10", "Pixelify Sans", "Trebuchet MS", system-ui, sans-serif;
  --font-title: "Jersey 10", "Pixelify Sans", monospace;
  --font-logo: "Press Start 2P", "Jersey 10", monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 18px; letter-spacing: .02em;   /* Jersey 10 is narrow: a touch bigger reads best */
  font-synthesis: none;                       /* it has one weight: never smudge it with fake bold */
}
body { -webkit-user-select: none; user-select: none; }
#app { position: fixed; inset: 0; }
canvas { image-rendering: pixelated; }
h1, h2, h3 { margin: 0 0 .4em; font-weight: 700; }
h2 { font-size: 1.5rem; color: var(--gold); text-shadow: 2px 2px 0 #000; }
h3 { font-size: 1rem; color: var(--muted); margin-top: .8em; }
p { line-height: 1.4; }
.center { text-align: center; }
.goldtxt, .gold-text { color: var(--gold); }

/* Pixel panel border */
.modal, .btn, .pill, .icon-btn, .chip, .stage, .pu, .item, .wearing {
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 2px var(--trim-dark), 3px 3px 0 #0008;
}

/* ── Buttons ── */
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; touch-action: manipulation; }
.btn {
  min-height: 48px; padding: 8px 18px; border-radius: 4px;
  background: linear-gradient(var(--wood2), var(--wood));
  font-weight: 700; font-size: 1.1rem; color: var(--parch); text-shadow: 1px 1px 0 #000;
}
.btn:active { transform: translate(2px, 2px); box-shadow: inset 0 0 0 2px var(--trim-dark), 1px 1px 0 #0008; }
.btn:disabled { opacity: .45; }
.btn.primary {
  background: linear-gradient(#e0b24f, #b07a26); color: #2b1606; text-shadow: 1px 1px 0 #f7d98b;
  box-shadow: inset 0 0 0 2px #ffe7a3, 3px 3px 0 #0008;
}
.btn.big { font-size: 1.3rem; padding: 10px 26px; }
.btn.small { min-height: 38px; padding: 4px 12px; font-size: .95rem; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn.danger { background: linear-gradient(#7a2a2a, #4f1818); }
.icon-btn {
  position: relative; width: 46px; height: 46px; border-radius: 4px; font-size: 1.3rem;
  background: linear-gradient(var(--wood2), var(--wood));
  display: inline-flex; align-items: center; justify-content: center;
}
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 16px; }
.row.wrap { flex-wrap: wrap; justify-content: center; }
.grow { flex: 1; }
.gnote { color: var(--gold); font-weight: 900; text-shadow: 1px 1px 0 #000; }
.small { color: var(--muted); font-size: .9rem; }

/* ── Screens ── */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.loading { align-items: center; justify-content: center; font-size: 1.4rem; text-align: center; }

/* Title */
.title { align-items: center; justify-content: center; overflow: hidden; }
.title-bg { position: absolute; inset: 0; width: 100%; height: 100%; }
.title-main { position: relative; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 16px; text-align: center; margin-bottom: 20vh; }
.logo { display: flex; flex-direction: column; gap: .2em; font-family: var(--font-logo); font-size: clamp(1.8rem, 9vw, 4rem); line-height: 1; margin: 0; }
.logo span { color: var(--gold); text-shadow: 4px 4px 0 #6b3a0c, 7px 7px 0 #000; }
.logo span:last-child { color: #ff6a4d; text-shadow: 4px 4px 0 #5a1208, 7px 7px 0 #000; }
.tag { margin: 0; font-size: 1.2rem; color: #fff; text-shadow: 2px 2px 0 #000; }

/* Top bar & pills */
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px; position: relative; z-index: 2; }
.pill {
  display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 4px;
  background: linear-gradient(var(--wood2), var(--wood)); font-weight: 700; font-size: 1.15rem;
}
.gold-pill b { color: var(--gold); }
.streak-pill.cold { filter: grayscale(1); opacity: .6; }

/* Town */
.town { background: var(--sky); }
.town-canvas { flex: 1; min-height: 0; width: 100%; display: block; touch-action: none; cursor: pointer; }
.town-title { position: absolute; top: calc(74px + env(safe-area-inset-top)); left: 0; right: 0; text-align: center; pointer-events: none; z-index: 1; }
.town-title h1 { font-family: var(--font-title); font-size: clamp(1rem, 4.5vw, 1.6rem); color: var(--gold); text-shadow: 3px 3px 0 #6b3a0c, 5px 5px 0 #000; }
.town-title p { margin: 0; color: #fff; text-shadow: 2px 2px 0 #0009; font-size: .95rem; }
.travel { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; padding: 8px 8px 4px; background: var(--wood-dark); border-top: 3px solid var(--ink); }
.travel .btn { flex: 1 1 30%; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 4px 8px; }
.inventory {
  display: flex; align-items: center; gap: 6px; justify-content: center; flex-wrap: wrap;
  padding: 4px 12px 10px; background: var(--wood-dark);
}
.inv-label { color: var(--muted); font-size: .9rem; margin-right: 4px; }
.chip { padding: 4px 10px; border-radius: 4px; background: var(--wood); font-weight: 700; }
.chip.empty { opacity: .45; }

/* Area path */
.area {
  background-color: var(--sky);
  background-size: auto 100%;
  background-position: center bottom;
  background-repeat: repeat-x;
  image-rendering: pixelated;
}
.area-title { text-align: center; padding: 0 16px; }
.area-title h1 { font-family: var(--font-title); font-size: clamp(1rem, 5vw, 1.7rem); color: var(--gold); text-shadow: 3px 3px 0 #6b3a0c, 5px 5px 0 #000; margin: 4px 0; }
.area-title p { margin: 0 0 6px; color: #fff; text-shadow: 2px 2px 0 #000; }
.stage-path {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 10px 16px 24px; -webkit-overflow-scrolling: touch;
}
.stage {
  width: min(440px, 100%); display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 4px;
  background: linear-gradient(var(--wood2), var(--wood)); text-align: left; flex-shrink: 0;
}
.stage:nth-child(odd) { transform: translateX(-14px); }
.stage:nth-child(even) { transform: translateX(14px); }
.snum {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--parch); color: var(--ink); font-weight: 700; font-size: 1.2rem; border: 3px solid var(--ink);
}
.sname { flex: 1; font-weight: 700; font-size: 1.1rem; }
.sname small { display: block; color: var(--muted); font-weight: 500; font-size: .85rem; }
.sstars { color: var(--gold); font-size: 1.2rem; white-space: nowrap; }
.stage.cleared .snum { background: var(--gold); }
.stage.locked { opacity: .6; filter: grayscale(.7); }
.stage.boss { background: linear-gradient(#7a2a2a, #4f1818); }
.stage.boss .snum { background: #ff6a4d; }
.stage.open { animation: nudge 1.4s ease-in-out infinite; }
.stage.open:nth-child(odd) { --tx: -14px; } .stage.open:nth-child(even) { --tx: 14px; }
@keyframes nudge { 50% { box-shadow: inset 0 0 0 2px var(--gold), 0 0 0 3px var(--gold), 3px 3px 0 #0008; } }

/* ── Modal ── */
.modal-back {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 12px; background: rgba(10, 6, 12, .72); animation: fadeIn .15s;
}
.modal {
  width: min(540px, 100%); max-height: calc(100% - 8px); overflow-y: auto;
  background: linear-gradient(#3d2a1c, #2a1c12); border-radius: 6px; padding: 18px;
  box-shadow: inset 0 0 0 3px var(--trim), inset 0 0 0 6px var(--ink), 6px 6px 0 #000a;
  border: 3px solid var(--ink);
  animation: popIn .18s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn { from { transform: scale(.92); opacity: 0; } }
.modal .sub { color: var(--muted); margin: 0 0 8px; }
.modal .new { background: #ffd23f1f; border: 2px dashed var(--trim); border-radius: 4px; padding: 8px 12px; }
.modal .best small { color: var(--muted); }
.stars-big { color: var(--gold); font-size: 1.5rem; letter-spacing: .1em; text-shadow: 2px 2px 0 #000; }
.pus { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pu {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 4px;
  background: var(--wood); font-size: .85rem; font-weight: 700; min-height: 78px; text-align: center;
}
.pu-icon { font-size: 1.6rem; }
.pu small { color: var(--muted); }
.pu.on { background: #6b4a12; box-shadow: inset 0 0 0 2px var(--gold), 0 0 0 2px var(--gold); }
.pu:disabled { opacity: .35; }
.pu-desc { min-height: 1.4em; color: var(--gold); font-size: .95rem; margin: 6px 0 0; }

.toggle { display: flex; align-items: center; gap: 12px; padding: 10px 0; font-weight: 700; font-size: 1.1rem; }
.toggle input { width: 26px; height: 26px; accent-color: #d9a53a; }
.seg { display: flex; border: 3px solid var(--ink); border-radius: 4px; overflow: hidden; }
.segbtn { flex: 1; padding: 12px 6px; font-weight: 700; background: var(--wood); }
.segbtn.on { background: var(--gold); color: var(--ink); }

.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { text-align: left; }

/* NPC speech */
.npc-head { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 8px; }
.npc-portrait { flex: 0 0 auto; background: #0003; border-radius: 4px; }
.speech {
  flex: 1; position: relative; background: var(--parch); color: var(--ink); border-radius: 4px; padding: 8px 12px;
  border: 3px solid var(--ink); box-shadow: 3px 3px 0 #0008;
}
.speech::before { content: ''; position: absolute; left: -12px; bottom: 14px; border: 6px solid transparent; border-right-color: var(--ink); }
.speech b { color: #8a3b12; }
.speech p { margin: 4px 0 0; }
.speech .judges { margin: 4px 0; }

/* Tutorial */
.tut-head { display: flex; align-items: baseline; gap: 10px; }
.tut-step { color: var(--muted); font-size: .9rem; }
.tutorial canvas.demo { width: 100%; height: 130px; display: block; background: #120c16; border: 3px solid var(--ink); border-radius: 4px; margin: 6px 0; image-rendering: auto; }
.tutorial .listen { margin-bottom: 8px; }
.tut-body { font-size: 1.1rem; }
.tut-body p { margin: 4px 0 0; }
.judges { padding-left: 18px; line-height: 1.7; }
.j-perfect { color: #c49000; } .j-good { color: #2f9a26; } .j-early { color: #d06a00; } .j-miss { color: #c62842; }
.modal .counts .j-perfect { color: #ffe600; } .modal .counts .j-good { color: var(--good); }
.modal .counts .j-early { color: var(--orange); } .modal .counts .j-miss { color: var(--red); }

/* Shop */
.shop-body { display: flex; gap: 12px; align-items: flex-start; }
.shop-preview { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; background: #0003; border-radius: 4px; padding: 4px; }
.shop-preview canvas { margin: -40px -20px -10px; }
.shop-items { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 4px; background: var(--wood); cursor: pointer; }
.item.sel { box-shadow: inset 0 0 0 2px var(--gold), 3px 3px 0 #0008; }
.swatch { width: 22px; height: 22px; border: 2px solid var(--ink); flex: 0 0 auto; }
.iname { flex: 1; font-weight: 700; }
.wearing { padding: 4px 8px; border-radius: 4px; font-size: .85rem; background: var(--gold); color: var(--ink); font-weight: 700; }
@media (max-width: 420px) {
  .shop-body { flex-direction: column; align-items: stretch; }
  .shop-preview { align-self: center; }
}

/* Results */
.res-title { text-align: center; font-size: 1.8rem; }
.res-title.lose { color: #ff8a6a; }
.pop-stars { text-align: center; font-size: 3rem; }
.pop-stars span { color: #5a4630; display: inline-block; }
.pop-stars span.on { color: var(--gold); animation: starPop .4s backwards; text-shadow: 3px 3px 0 #000; }
@keyframes starPop { from { transform: scale(2.5) rotate(-40deg); opacity: 0; } }
.res-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; margin: 10px 0; }
.res-grid div { background: var(--wood-dark); border: 2px solid var(--ink); border-radius: 4px; padding: 8px 4px; }
.res-grid small { display: block; color: var(--muted); font-size: .8rem; }
.res-grid b { font-size: 1.35rem; }
.res-grid em { display: block; color: var(--gold); font-size: .8rem; font-style: normal; font-weight: 700; }
.counts { text-align: center; font-size: .95rem; margin: 4px 0; }
.gold-earned { text-align: center; font-size: 1.9rem; font-weight: 700; color: var(--gold); margin: 8px 0; text-shadow: 2px 2px 0 #000; }
.gold-earned small { display: block; font-size: .85rem; color: var(--muted); font-weight: 500; text-shadow: none; }
.reward { text-align: center; background: #ffd23f22; border: 2px dashed var(--gold); border-radius: 4px; padding: 10px; animation: popIn .4s .6s backwards; }
.tip { color: var(--muted); font-size: 1rem; text-align: center; }

/* Calibration */
.calib-pad {
  margin: 10px auto; width: 180px; height: 180px; border-radius: 50%;
  border: 4px solid var(--trim); background: var(--wood-dark); display: flex; align-items: center; justify-content: center; touch-action: none;
}
.calib-pad.tap { animation: padTap .15s; }
@keyframes padTap { 50% { background: #ffd23f44; } }
.calib-dot { width: 90px; height: 90px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 20px var(--gold); transform: scale(.6); }
.calib-status { text-align: center; }

.toast {
  position: fixed; left: 50%; top: calc(62px + env(safe-area-inset-top)); transform: translateX(-50%);
  background: var(--parch); color: var(--ink); border: 3px solid var(--ink); box-shadow: 3px 3px 0 #000a;
  padding: 10px 16px; border-radius: 4px; font-weight: 700; z-index: 80; animation: popIn .2s; max-width: 90vw; text-align: center;
}

/* ── Battle screen ── */
.game {
  position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg);
  touch-action: none; -webkit-touch-callout: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.hud { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: var(--wood-dark); border-bottom: 3px solid var(--ink); }
.hp { flex: 1; position: relative; height: 26px; background: #1a0d0d; border: 3px solid var(--ink); box-shadow: inset 0 0 0 2px var(--trim-dark); }
.hp-fill { position: absolute; inset: 2px; background: linear-gradient(#ff5a4d, #b3201a); transform-origin: left; transition: transform .2s; }
.hp span { position: relative; display: block; text-align: center; font-size: .9rem; font-weight: 700; line-height: 20px; text-shadow: 1px 1px 0 #000, -1px -1px 0 #000; }
.hud-right { min-width: 84px; text-align: right; }
.score { font-weight: 700; font-size: 1.3rem; color: var(--gold); text-shadow: 2px 2px 0 #000; }
.combo { font-size: .85rem; color: var(--parch); font-weight: 700; min-height: 1em; }
.combo b { color: var(--gold); }

.scene { position: relative; flex: 1 1 auto; min-height: 140px; overflow: hidden; }
canvas.lane { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.judge {
  position: absolute; left: 0; right: 0; top: 10%; text-align: center; z-index: 5;
  font-family: var(--font); font-size: clamp(1.7rem, 6.5vw, 2.8rem); font-weight: 700; opacity: 0; pointer-events: none;
  text-shadow: 3px 3px 0 #000, -1px -1px 0 #000;
}
.judge.pop { animation: judgePop .6s ease-out; }
@keyframes judgePop { 0% { transform: scale(1.5); opacity: 1; } 20% { transform: scale(1); opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }
.judge.perfect { color: #ffe600; }
.judge.good { color: var(--good); }
.judge.early, .judge.late { color: var(--orange); }
.judge.miss, .judge.rest { color: var(--red); }
.countin {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 4; text-align: center;
  font-family: var(--font-title); font-size: clamp(1.4rem, 7vw, 3rem); color: #fff; text-shadow: 4px 4px 0 #000;
  pointer-events: none; padding: 0 12px;
}
.countin:not(.show) { opacity: 0; transition: opacity .3s; }
.countin.beat { animation: countBeat .4s ease-out; }
@keyframes countBeat { from { transform: scale(1.6); } }
.countin.go { color: var(--gold); }
.countin.cracked { color: var(--gold); animation: countBeat .5s; font-size: clamp(1rem, 5vw, 2rem); }
.badges { position: absolute; left: 8px; top: 6px; display: flex; flex-wrap: wrap; gap: 6px; z-index: 5; pointer-events: none; }
.badge { padding: 3px 8px; border-radius: 4px; background: #000a; border: 2px solid var(--ink); font-size: .85rem; font-weight: 700; }

canvas.staff {
  display: block; width: 100%; height: 150px; flex: 0 0 auto; image-rendering: auto;
  background: linear-gradient(#24170f, #1a1008); border-top: 3px solid var(--ink); border-bottom: 3px solid var(--ink);
}
.tapzone { flex: 0 0 96px; display: flex; align-items: center; justify-content: center; padding: 8px 16px; background: var(--wood-dark); }
.tapbtn {
  width: min(100%, 460px); height: 76px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-title); font-size: 1.1rem; letter-spacing: .1em; color: var(--ink);
  background: linear-gradient(#f0c766, #c08a2c); border: 4px solid var(--ink);
  box-shadow: inset 0 0 0 3px #ffe7a3, 0 6px 0 #5a3a10, 0 9px 0 #000a;
  transition: transform .04s, box-shadow .04s;
}
.tapbtn.down { transform: translateY(5px); box-shadow: inset 0 0 0 3px #ffe7a3, 0 1px 0 #5a3a10, 0 3px 0 #000a; background: linear-gradient(#ffe08a, #e0a840); }

@media (max-height: 560px) {
  canvas.staff { height: 110px; }
  .tapzone { flex-basis: 64px; padding: 4px 16px; }
  .tapbtn { height: 50px; }
  .hud { padding: 3px 10px; }
}
@media (min-width: 900px) and (min-height: 700px) {
  canvas.staff { height: 180px; }
}

/* ── Victory ── */
.victory-layer {
  position: fixed; inset: 0; z-index: 90; background: #120a10f0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; overflow: hidden;
}
.victory-layer h1 { font-family: var(--font-title); font-size: clamp(1.4rem, 7vw, 3rem); color: var(--gold); text-shadow: 4px 4px 0 #6b3a0c, 7px 7px 0 #000; animation: popIn .5s; }
.victory-layer p { font-size: 1.2rem; max-width: 520px; }
.victory-layer canvas { margin: -60px 0 -20px; }
.sparks { position: absolute; left: 50%; top: 40%; }
.sparks i { position: absolute; width: 10px; height: 10px; animation: spark 1.4s ease-out forwards; }
@keyframes spark { from { transform: translate(0, 0) scale(1.5); } to { transform: translate(var(--x), var(--y)) scale(0); } }

/* ── Hero, quests, journal, story ── */
.hero-pill { flex-direction: column; align-items: flex-start; gap: 0; padding: 3px 10px; max-width: 42vw; line-height: 1.1; text-align: left; }
.hero-pill b { font-size: 1rem; color: var(--parch); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.hero-pill small { font-size: .72rem; color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
@media (max-width: 420px) {
  .topbar { gap: 5px; padding: 8px 8px 4px; }
  .topbar .pill { font-size: 1rem; padding: 4px 8px; }
  .topbar .icon-btn { width: 40px; height: 40px; font-size: 1.1rem; }
}
.btn.glow { box-shadow: inset 0 0 0 2px var(--gold), 0 0 0 2px var(--gold), 3px 3px 0 #0008; animation: nudge 1.4s ease-in-out infinite; }

.name-input {
  width: 100%; font: inherit; font-size: 1.4rem; padding: 10px 12px; margin-top: 6px; border-radius: 4px;
  background: var(--parch); color: var(--ink); border: 3px solid var(--ink); -webkit-user-select: text; user-select: text;
}
.name-input.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

.xpbar { position: relative; height: 18px; background: #1a0d0d; border: 3px solid var(--ink); border-radius: 3px; margin: 6px 0; }
.xpbar div { position: absolute; inset: 0 auto 0 0; background: linear-gradient(#7cf0ff, #2b9fd8); }
.xpbar span { position: relative; display: block; text-align: center; font-size: .8rem; line-height: 12px; font-weight: 700; text-shadow: 1px 1px 0 #000; }
.xp-line { text-align: center; font-weight: 700; color: #7cf0ff; margin: 6px 0; }
.xp-line b { color: var(--gold); }

.profile-top { display: flex; gap: 12px; align-items: center; }
.profile-top canvas { flex: 0 0 auto; margin: -36px -24px -14px -30px; }
.profile-top > div { flex: 1; min-width: 0; }
.profile-top h2 { margin: 0; overflow-wrap: anywhere; }
.title-line { margin: 2px 0; color: var(--muted); }
.title-line b { color: var(--gold); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; margin: 12px 0 4px; }
.stat-grid div { background: var(--wood-dark); border: 2px solid var(--ink); border-radius: 4px; padding: 6px 8px; }
.stat-grid small { display: block; color: var(--muted); font-size: .78rem; }
.stat-grid b { font-size: 1.15rem; }

.quest-list { display: flex; flex-direction: column; gap: 8px; }
.quest { display: flex; align-items: center; gap: 10px; padding: 8px 10px; background: var(--parch); color: var(--ink); border: 3px solid var(--ink); border-radius: 4px; box-shadow: 3px 3px 0 #0008; }
.quest.ready { box-shadow: 0 0 0 3px var(--gold), 3px 3px 0 #0008; }
.quest.claimed { opacity: .6; }
.qtext { flex: 1; min-width: 0; }
.qtext b { font-size: 1.05rem; }
.qbar { position: relative; height: 14px; background: #d8c49a; border: 2px solid var(--ink); border-radius: 3px; margin-top: 4px; }
.qbar div { position: absolute; inset: 0 auto 0 0; background: #6fbf3f; }
.qbar span { position: relative; display: block; text-align: center; font-size: .72rem; line-height: 10px; font-weight: 700; }
.qreward { text-align: center; font-weight: 700; font-size: .95rem; white-space: nowrap; }
.qreward small { color: #4a6fa5; }
.quest .gnote { text-shadow: none; color: #b07a00; }

.journal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.jcard { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px; border-radius: 4px; background: var(--wood); border: 3px solid var(--ink); box-shadow: inset 0 0 0 2px var(--trim-dark), 3px 3px 0 #0008; text-align: center; }
.jcard b { font-size: .95rem; line-height: 1.1; }
.jcard small { color: var(--muted); font-size: .75rem; }
.jcard.unknown { opacity: .55; }
.jcard.unknown span { width: 96px; height: 80px; display: flex; align-items: center; justify-content: center; font-size: 2.4rem; color: var(--muted); }
.entry-top { display: flex; gap: 12px; align-items: center; }
.entry-top canvas { flex: 0 0 auto; background: #0003; border-radius: 4px; }
.entry-top h2 { margin: 0; }
.speech.lore { margin-top: 10px; }
.speech.lore::before { display: none; }

.story .npc-head { min-height: 110px; }
.story .speech p { font-size: 1.15rem; }
.levelup canvas { display: block; margin: -50px auto -20px; }
.big-text { font-size: 1.3rem; }

/* Pause */
.pause-layer { position: absolute; inset: 0; z-index: 40; background: rgba(10, 6, 12, .75); display: flex; align-items: center; justify-content: center; padding: 16px; }
.pause-layer[hidden] { display: none; }
.pause-box { text-align: center; background: linear-gradient(#3d2a1c, #2a1c12); border: 3px solid var(--ink); box-shadow: inset 0 0 0 3px var(--trim), 6px 6px 0 #000a; border-radius: 6px; padding: 20px 24px; min-width: 260px; }
.pause-count { font-family: var(--font-title); font-size: 2.4rem; color: var(--gold); min-height: 1.2em; margin: 4px 0 10px; text-shadow: 3px 3px 0 #000; }
.pause-btns { display: flex; flex-direction: column; gap: 10px; }

/* Skill tree */
.skill-tree { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.branch { display: flex; flex-direction: column; align-items: stretch; }
.bhead { text-align: center; background: var(--wood-dark); border: 2px solid var(--ink); border-radius: 4px; padding: 6px; }
.bhead b { display: block; }
.bhead small { color: var(--muted); font-size: .75rem; }
.bicon { font-size: 1.5rem; }
.snode { background: var(--wood); border: 3px solid var(--ink); border-radius: 6px; padding: 6px; box-shadow: inset 0 0 0 2px var(--trim-dark); opacity: .7; order: 0; }
.snode.on { opacity: 1; background: #6b4a12; box-shadow: inset 0 0 0 2px var(--gold), 0 0 10px #ffd23f66; }
.snode b { display: block; color: var(--gold); }
.snode small { display: block; font-size: .78rem; color: var(--parch); min-height: 2.2em; }
.snode .qbar { background: #2b1d12; }
.snode .qbar span { color: #fff; }
.slink { width: 4px; height: 12px; background: var(--trim-dark); margin: 0 auto; }
.branch { gap: 0; }
.branch .bhead { order: 9; margin-top: 6px; }
.rhythm-report .rrow { display: grid; grid-template-columns: 130px 1fr; gap: 8px; align-items: center; margin: 4px 0; }
.rhythm-report .qbar { background: #2b1d12; }
.rhythm-report .qbar span { color: #fff; }
.skill-lock { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.shop-tabs { margin: 6px 0 10px; }
.shop-tabs .segbtn { padding: 8px 4px; font-size: .9rem; }
@media (max-width: 560px) { .skill-tree { grid-template-columns: repeat(5, 150px); } }

/* Class challenge & teacher tools */
.qbar.big { height: 26px; border-width: 3px; }
.qbar.big span { line-height: 20px; font-size: .9rem; color: #fff; text-shadow: 1px 1px 0 #000; }
.challenge .qbar, .teacher .qbar { background: #2b1d12; }
.contrib-code { font-family: var(--font-title); font-size: .85rem; background: var(--parch); color: var(--ink); padding: 10px; border: 3px solid var(--ink); border-radius: 4px; word-break: break-all; text-align: center; margin: 6px 0; -webkit-user-select: all; user-select: all; }
.board { padding-left: 24px; margin: 6px 0; }
.board li { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; border-bottom: 1px dashed var(--trim-dark); }
.board b { color: var(--gold); }
.field { display: block; margin: 6px 0; font-weight: 700; }
.field .name-input { font-size: 1.05rem; padding: 6px 10px; margin-top: 2px; }
.teacher textarea.name-input, .teacher .code-input { font-size: .9rem; resize: vertical; }
.teacher details { margin: 8px 0; }
.teacher summary { cursor: pointer; color: var(--gold); font-weight: 700; }
.code-input { font-size: 1rem !important; }
.sync-view { width: 100%; height: 90px; display: block; background: #120c16; border: 3px solid var(--ink); border-radius: 4px; margin: 6px 0; image-rendering: auto; }
.sync-slider { width: 100%; accent-color: #d9a53a; height: 30px; }

/* ── Arcade polish ── */
.screen, .game { animation: screenIn .28s ease-out; }
@keyframes screenIn { from { opacity: 0; transform: scale(1.02); } }
.loading { gap: 18px; background: radial-gradient(ellipse at center, #3a2618, var(--bg)); }
.loading .logo { font-size: clamp(1.6rem, 8vw, 3rem); }
.loadbar { width: min(320px, 70vw); height: 18px; border: 3px solid var(--ink); background: #1a0d0d; box-shadow: inset 0 0 0 2px var(--trim-dark); overflow: hidden; }
.loadbar div { height: 100%; width: 40%; background: linear-gradient(#f0c766, #c08a2c); animation: loadslide 1s ease-in-out infinite alternate; }
@keyframes loadslide { from { transform: translateX(-60%); } to { transform: translateX(210%); } }
.combo-banner {
  position: absolute; right: 6%; top: 30%; z-index: 6; text-align: center; pointer-events: none;
  font-family: var(--font-title); color: #fff; font-size: clamp(.9rem, 3.5vw, 1.4rem); text-shadow: 3px 3px 0 #000;
  animation: comboIn 1.2s ease-out forwards;
}
.combo-banner b { display: block; font-size: 2.2em; color: var(--gold); text-shadow: 4px 4px 0 #6b3a0c, 6px 6px 0 #000; }
.combo-banner small { display: block; font-size: .7em; color: #7cf0ff; margin-top: 4px; }
@keyframes comboIn { 0% { transform: scale(2.2) rotate(-8deg); opacity: 0; } 15% { transform: scale(1) rotate(-4deg); opacity: 1; } 80% { opacity: 1; } 100% { transform: translateY(-30px) rotate(-4deg); opacity: 0; } }
.title .play { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.07); } }

/* Who's playing? */
.players { align-items: center; justify-content: center; overflow: hidden; }
.players .title-bg { position: absolute; inset: 0; width: 100%; height: 100%; }
.players-main { position: relative; width: min(640px, 100%); padding: 16px; max-height: 100%; overflow-y: auto; text-align: center; }
.who { font-family: var(--font-title); font-size: clamp(1.1rem, 5vw, 1.8rem); color: var(--gold); text-shadow: 3px 3px 0 #6b3a0c, 5px 5px 0 #000; }
.player-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin: 12px 0; }
.pcard { position: relative; display: flex; flex-direction: column; align-items: center; padding: 6px 6px 10px; border-radius: 6px;
  background: linear-gradient(var(--wood2), var(--wood)); border: 3px solid var(--ink); box-shadow: inset 0 0 0 2px var(--trim-dark), 3px 3px 0 #0008; overflow: hidden; }
.pcard canvas { margin: -46px -20px -14px; pointer-events: none; }
.pcard b { font-size: 1.15rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard small { color: var(--gold); font-size: .78rem; }
.pcard.last { box-shadow: inset 0 0 0 2px var(--gold), 0 0 0 2px var(--gold), 3px 3px 0 #0008; }
.pcard:active { transform: translate(2px, 2px); }
.pcard.newp { justify-content: center; min-height: 150px; background: #2a1c12cc; border-style: dashed; }
.plus { font-size: 2.6rem; color: var(--gold); line-height: 1; }
.pdel { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 4px; background: #7a2a2a; border: 2px solid var(--ink); display: flex; align-items: center; justify-content: center; font-weight: 700; }
/* Tall phones: give the music staff more room (bigger notes are easier to read) */
@media (orientation: portrait) and (min-height: 700px) {
  canvas.staff { height: min(24vh, 230px); }
}

/* ── Cloud saves ── */
.cloud-box { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 10px 0 4px; padding: 8px; background: var(--wood-dark); border: 2px solid var(--ink); border-radius: 4px; text-align: center; }
.cloud-box small { color: var(--muted); font-size: .78rem; }
.cloud-code { font-family: var(--font-title); font-size: 1rem; color: var(--gold); letter-spacing: 1px; -webkit-user-select: all; user-select: all; }
.code-input { text-transform: uppercase; text-align: center; font-family: var(--font-title); letter-spacing: 1px; }
.code-list { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: .9rem; }
.code-list td { padding: 4px 6px; border-bottom: 1px solid #0004; }
.code-list td:last-child { font-family: var(--font-title); font-size: .8rem; color: var(--gold); text-align: right; -webkit-user-select: all; user-select: all; }

/* ── Volume sliders ── */
.vols { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 8px; }
.vol { display: grid; grid-template-columns: 9.5em 1fr 2.4em; align-items: center; gap: 8px; font-size: .95rem; }
.vol input { width: 100%; accent-color: var(--gold); min-height: 28px; }
.vol b { text-align: right; color: var(--gold); font-size: .85rem; }
/* Wild Woods (wave mode) sits at the bottom right of the travel buttons */
.travel .woods { margin-left: auto; }
.test-pill { background: #3b2a6b; color: #e6d8ff; font-weight: 700; }

/* ── In-game volume panel ── */
.mix-panel { position: absolute; top: 52px; left: 8px; z-index: 30; width: min(300px, calc(100% - 16px)); padding: 8px 10px;
  background: var(--wood-dark); border: 3px solid var(--ink); border-radius: 6px; box-shadow: 3px 3px 0 #0008; }
.mix-panel .vol { grid-template-columns: 5.5em 1fr 2.2em; }

/* ── Hero picker ── */
.hero-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.hero-card small { color: var(--muted, #cdbf9f); font-size: .74rem; line-height: 1.25; text-align: center; }
.hero-card b { margin-top: 2px; }
/* Portraits drawn into fixed boxes (any hero or monster fits) */
.hero-card canvas, .pcard[data-id] canvas { margin: 0 auto 2px !important; display: block; }

/* ── Hero hearts ── */
.hearts { display: flex; gap: 1px; font-size: 1rem; line-height: 1; white-space: nowrap; }
.hearts b { color: #ff4d6d; text-shadow: 0 2px 0 #0008; font-weight: 400; }
.hearts i { color: #ff4d6d44; font-style: normal; }
.hearts.low b { animation: heartbeat .6s infinite; }
.hearts.hit { animation: shake .35s; }
@keyframes heartbeat { 50% { transform: scale(1.3); } }
.countin.ko { color: #ff4d6d; }
@media (max-width: 520px) { .hearts { font-size: .8rem; } }

/* ── World Map ── */
.worldmap { background: radial-gradient(ellipse at 50% 0%, #f3e3b9 0%, #dcc28a 60%, #c9a865 100%); color: var(--ink); overflow-y: auto; }
.worldmap .area-title h1, .worldmap .area-title p { color: #3a2410; text-shadow: none; }
.map-road { position: relative; display: flex; flex-direction: column; gap: 14px; padding: 8px 14px 40px; max-width: 640px; margin: 0 auto; width: 100%; }
.map-road::before { content: ''; position: absolute; left: 50%; top: 0; bottom: 20px; border-left: 6px dashed #8a5a2b88; transform: translateX(-50%); }
.mnode { position: relative; display: flex; align-items: center; gap: 10px; width: min(78%, 430px); padding: 8px 12px; text-align: left;
  margin-left: calc(var(--side) * (100% - min(78%, 430px))); background: var(--parch, #f4ecd8); color: var(--ink); border: 3px solid var(--ink);
  border-radius: 10px; box-shadow: 3px 3px 0 #0006; cursor: pointer; font: inherit; }
.mnode:active { transform: translate(2px, 2px); }
.msign { flex: none; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: #2a1a0e; color: #ffd23f;
  font: 400 1.35rem "Jersey 10", "Pixelify Sans", monospace; border: 3px solid #ffd23f; }
.mtext { display: flex; flex-direction: column; min-width: 0; }
.mtext b { font-size: 1.1rem; }
.mtext small { font-size: .78rem; opacity: .8; }
.mtext em { font-style: normal; font-size: .78rem; color: #8a4b12; margin-top: 2px; }
.mnode.done .msign { background: #3d6b25; }
.mnode.locked, .mnode.soon { filter: grayscale(.85); opacity: .7; }
.mnode.fresh { box-shadow: 0 0 0 3px #ffd23f, 0 0 18px #ffd23f, 3px 3px 0 #0006; }
.mnew { position: absolute; top: -10px; right: -8px; background: #ff4d6d; color: #fff; font-weight: 800; font-size: .75rem; padding: 2px 6px; border-radius: 6px; border: 2px solid var(--ink); animation: heartbeat 1s infinite; }

/* ── Tempo levels ── */
.tempo-tabs { justify-content: center; margin: 2px auto 6px; max-width: 460px; }
.tempo-tabs .segbtn.locked { opacity: .55; }

/* ── Two-hand tap zone (Polyrhythm Peaks) ── */
.tapzone.two { display: flex; gap: 8px; }
.tapzone.two .tapbtn { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
.tapzone.two .tapbtn small { font-size: .6em; opacity: .7; }
.tapzone.two .tap-L { background: linear-gradient(#8ff0ff, #2bb3d8); box-shadow: inset 0 0 0 3px #d8fbff, 0 6px 0 #135a70, 0 8px 0 #000a; color: #06303d; }
.tapzone.two .tap-L.down { transform: translateY(5px); box-shadow: inset 0 0 0 3px #d8fbff, 0 1px 0 #135a70, 0 3px 0 #000a; }
/* Shop tabs wrap onto two rows on narrow screens so every tab (Instruments, Special) is reachable */
.shop-tabs { flex-wrap: wrap; }
.shop-tabs .segbtn { flex: 1 1 30%; min-width: 0; border-bottom: 2px solid var(--ink); }

/* Two hands: the whole screen is split down the middle (left half = blue/left hand,
   right half = gold/right hand). A faint tint and a centre line make the split easy to see. */
.hand-split { position: absolute; inset: 0; pointer-events: none; z-index: 1; display: flex; }
.hand-split span { flex: 1; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 112px;
  font-weight: 700; font-size: .8rem; letter-spacing: .08em; opacity: .55; }
.hand-split .hs-L { background: linear-gradient(90deg, rgba(94,224,255,.07), rgba(94,224,255,.02)); color: #5ee0ff;
  border-right: 2px dashed rgba(255,255,255,.28); }
.hand-split .hs-R { background: linear-gradient(270deg, rgba(255,210,63,.07), rgba(255,210,63,.02)); color: #ffd23f; }
@media (max-height: 520px) { .hand-split span { padding-bottom: 76px; } }

/* Narrow phones: keep every top-bar button on screen */
.topbar > .pill { min-width: 0; }
.topbar .hero-pill { overflow: hidden; }
.travel .new-tag { margin-left: 4px; font-weight: 400; }
@media (max-width: 420px) {
  .topbar .test-pill .tp-txt { display: none; }
  .topbar .hero-pill small, .topbar .hero-pill .title { display: none; }
  .travel .btn { font-size: .8rem; padding: 4px 4px; }
  .travel [data-go="portal"] { flex-grow: 1.4; }
}

/* "Are you sure?" pop-ups */
.confirm-box { max-width: 400px; text-align: center; }
.confirm-box .confirm-art { display: block; margin: 4px auto 6px; width: 150px; height: 100px; image-rendering: pixelated; }
.confirm-box .lore { font-style: italic; line-height: 1.45; margin: 4px 6px 10px; }
.confirm-box .row { justify-content: center; gap: 10px; flex-wrap: wrap; }

/* Cut scenes: a little stage in the village's scenery, with the words underneath */
.modal.stage-scene { width: min(640px, 96vw); max-width: none; padding: 10px; }
.stage-scene .stage-wrap { position: relative; border: 3px solid var(--ink); border-radius: 4px; overflow: hidden; cursor: pointer; background: #000; }
.stage-scene .stage-canvas { display: block; width: 100%; height: clamp(110px, 34vh, 230px); image-rendering: pixelated; }
.stage-scene .stage-talk { background: var(--parch); color: var(--ink); border: 3px solid var(--ink); border-radius: 4px;
  margin: 8px 0; padding: 8px 12px; min-height: 4.6em; box-shadow: 3px 3px 0 #000a; }
.stage-scene .stage-talk .who { display: block; color: #8a4b12; margin-bottom: 2px; font-size: 1rem; font-family: inherit; text-shadow: none; letter-spacing: 0; }
.stage-scene .stage-talk .who.hero { color: #2b6fd8; }
.stage-scene .stage-talk .who.boss { color: #b0283a; }
.stage-scene .stage-talk .words { margin: 0; line-height: 1.4; min-height: 2.8em; }
.stage-scene .row { justify-content: space-between; }
@media (max-height: 480px) { .stage-scene .stage-canvas { height: 30vh; } .stage-scene .stage-talk { min-height: 3.4em; padding: 5px 10px; } }

/* Keyboard highlight (PC): a gold outline on whatever the arrow keys have selected */
button:focus-visible, .item:focus-visible, input:focus-visible { outline: 3px solid #ffd23f; outline-offset: 2px; box-shadow: 0 0 0 5px rgba(255,210,63,.25); }
.item:focus-visible { border-radius: 3px; }
/* PC: show each town button's shortcut letter */
@media (pointer: fine) {
  [data-key]::after { content: attr(data-key); font-size: .7em; margin-left: .45em; padding: 0 .3em; border: 1px solid currentColor; border-radius: 3px; opacity: .65; }
  .icon-btn[data-key]::after { position: absolute; right: 2px; bottom: 1px; margin: 0; border: 0; font-size: .55em; }
}
