@font-face { font-family: Bravura; src: url(fonts/bravura.woff2) format("woff2"); }

:root {
  --plum: #561747;
  --plum-2: #7a2a66;
  --lilac: #b874b0;
  --lilac-soft: #f3e6f1;
  --ink: #241a22;
  --muted: #7a6d77;
  --bg: #efe9ee;
  --ok: #1d9a4b;
  --bad: #d12a2a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; cursor: pointer; }
input { font: inherit; }

.screen { display: none; height: 100vh; height: 100dvh; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- HOME ---------- */
#home { background: linear-gradient(135deg, var(--plum) 0%, #3b0f31 100%); align-items: center; justify-content: center; }
.home-wrap { display: flex; gap: 48px; align-items: center; padding: 32px; max-width: 1100px; }
.home-cover { height: min(78vh, 680px); border-radius: 6px; box-shadow: 0 24px 60px rgba(0,0,0,.45); }
.home-panel { color: #fff; width: 380px; display: flex; flex-direction: column; }
.brand { color: var(--lilac); letter-spacing: .5px; font-weight: 600; margin-bottom: 8px; }
.home-panel h1 { font-size: 34px; line-height: 1.15; margin: 0 0 6px; font-weight: 700; }
.home-sub { color: #e6cfe2; margin-bottom: 26px; }
.name-label { font-size: 13px; color: #e6cfe2; margin-bottom: 6px; }
.name-input { padding: 11px 14px; border-radius: 10px; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1); color: #fff; outline: none; margin-bottom: 18px; -webkit-user-select: text; user-select: text; }
.name-input::placeholder { color: rgba(255,255,255,.5); }
.name-input:focus { border-color: var(--lilac); background: rgba(255,255,255,.16); }
.progress-card { background: rgba(255,255,255,.08); border-radius: 12px; padding: 12px 14px; margin-bottom: 18px; }
.progress-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 8px; color: #e6cfe2; }
.progress-top b { color: #fff; }
.bar { height: 8px; background: rgba(255,255,255,.15); border-radius: 8px; overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--lilac); transition: width .4s; }
.big { display: block; width: 100%; padding: 14px 18px; border-radius: 12px; border: none; margin-bottom: 10px; font-size: 17px; font-weight: 600; text-align: left; background: rgba(255,255,255,.12); color: #fff; transition: transform .08s, background .15s; }
.big:hover { background: rgba(255,255,255,.2); }
.big:active { transform: scale(.98); }
.big.primary { background: #fff; color: var(--plum); }
.big.primary:hover { background: #f6eaf4; }
.big.game { background: var(--lilac); color: #fff; }
.big.game:hover { background: #c98ac1; }
.hint { font-size: 13px; color: #d9bfd4; line-height: 1.5; margin-top: 8px; }

/* ---------- TOOLBAR ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; background: var(--plum); color: #fff; flex-wrap: wrap; box-shadow: 0 2px 8px rgba(0,0,0,.2); z-index: 5; }
.tgroup { display: flex; align-items: center; gap: 4px; }
.tbtn { background: rgba(255,255,255,.1); color: #fff; border: none; border-radius: 8px; padding: 7px 10px; font-size: 15px; min-width: 36px; line-height: 1.1; white-space: nowrap; }
.tbtn:hover { background: rgba(255,255,255,.2); }
.tbtn.active { background: #fff; color: var(--plum); }
.tbtn span { font-size: 13px; font-weight: 600; }
.tbtn.big-dot { font-size: 18px; }
.tbtn.done.on { background: var(--ok); color: #fff; }
.sep { width: 1px; height: 24px; background: rgba(255,255,255,.25); margin: 0 6px; }
.swatch { width: 24px; height: 24px; border-radius: 50%; border: 2px solid rgba(255,255,255,.6); background: var(--c); padding: 0; margin: 0 2px; }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 3px var(--lilac); }
.pageinfo { font-size: 14px; padding: 0 6px; }
.pageinfo input { width: 52px; text-align: center; border-radius: 6px; border: none; padding: 5px 2px; font-weight: 700; color: var(--plum); -webkit-user-select: text; user-select: text; }

/* ---------- BOOK ---------- */
.book-body { flex: 1; display: flex; min-height: 0; }
.toc { width: 280px; background: #fff; border-right: 1px solid #e3d6e0; overflow-y: auto; display: flex; flex-direction: column; transition: margin-left .25s; }
.toc.hidden { margin-left: -280px; }
.toc-head { padding: 16px 18px 8px; font-weight: 700; color: var(--plum); font-size: 18px; }
.toc ul { list-style: none; margin: 0; padding: 0 8px 8px; }
.toc li { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.toc li:hover { background: var(--lilac-soft); }
.toc li.sub { padding-left: 26px; font-size: 13px; color: var(--muted); }
.toc li.current { background: var(--lilac-soft); color: var(--plum); font-weight: 600; }
.toc li .pg { color: var(--muted); font-size: 12px; white-space: nowrap; }
.toc li .tick { color: var(--ok); font-weight: 700; }
.toc-game { margin: auto 12px 14px; padding: 12px; border-radius: 10px; border: none; background: var(--lilac); color: #fff; font-weight: 600; }

.stage { flex: 1; overflow: auto; position: relative; padding: 24px; }
.page-wrap { position: relative; margin: 0 auto; background: #fff; box-shadow: 0 6px 24px rgba(60,20,50,.18); touch-action: none; }
.page-wrap img { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#ink { position: absolute; inset: 0; width: 100%; height: 100%; }
.text-layer { position: absolute; inset: 0; pointer-events: none; }
.tnote { position: absolute; font-family: "Chalkboard SE", "Comic Sans MS", "Marker Felt", sans-serif; font-weight: 600; line-height: 1; white-space: nowrap; transform: translate(-50%, -50%); padding: 1px 2px; border-radius: 3px; }
.mode-text .tnote { pointer-events: auto; cursor: text; }
.mode-text .tnote:hover { background: rgba(184,116,176,.15); }
.tinput { position: absolute; transform: translate(-50%, -50%); font-family: "Chalkboard SE", "Comic Sans MS", "Marker Felt", sans-serif; font-weight: 600; border: 2px solid var(--lilac); border-radius: 4px; padding: 1px 3px; outline: none; background: rgba(255,255,255,.95); min-width: 2em; text-align: center; pointer-events: auto; -webkit-user-select: text; user-select: text; }
.mode-pen #ink { cursor: crosshair; }
.mode-text #ink { cursor: text; }
.mode-eraser #ink { cursor: cell; }
.mode-hand #ink { cursor: default; pointer-events: none; }
.mode-hand .page-wrap { touch-action: auto; }

.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; font-size: 14px; z-index: 20; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- GAME ---------- */
#game { background: var(--bg); position: relative; }
.game-title { font-weight: 700; font-size: 17px; }
.seg { display: flex; background: rgba(255,255,255,.12); border-radius: 8px; padding: 2px; margin-right: 6px; }
.seg button { border: none; background: none; color: #fff; padding: 6px 11px; border-radius: 6px; font-size: 13px; font-weight: 600; }
.seg button.active { background: #fff; color: var(--plum); }
.game-body { flex: 1; overflow: auto; display: flex; flex-direction: column; align-items: center; padding: 18px 24px 24px; }
.game-stats { display: flex; gap: 12px; width: 100%; max-width: 760px; }
.game-stats > div { flex: 1; background: #fff; border-radius: 12px; padding: 10px 14px; display: flex; flex-direction: column; box-shadow: 0 2px 8px rgba(60,20,50,.06); }
.game-stats span { font-size: 12px; color: var(--muted); }
.game-stats b { font-size: 22px; color: var(--plum); }
.gbar { width: 100%; max-width: 760px; height: 6px; background: #e0d3dd; border-radius: 6px; margin: 12px 0; overflow: hidden; }
.gbar > div { height: 100%; width: 0; background: var(--lilac); transition: width .3s; }
.staff-card { width: 100%; max-width: 760px; background: #fff; border-radius: 16px; box-shadow: 0 4px 18px rgba(60,20,50,.1); padding: 8px 16px 16px; text-align: center; }
#staff { width: 100%; height: auto; max-height: 34vh; }
.gmsg { font-size: 20px; font-weight: 700; color: var(--plum); min-height: 28px; }
.gmsg.ok { color: var(--ok); }
.gmsg.bad { color: var(--bad); }
.answers { display: flex; gap: 12px; margin: 18px 0 14px; flex-wrap: wrap; justify-content: center; }
.answers button { width: 74px; height: 74px; border-radius: 50%; border: none; background: #fff; color: var(--plum); font-size: 30px; font-weight: 800; box-shadow: 0 4px 0 #d9c7d5, 0 6px 14px rgba(60,20,50,.12); transition: transform .06s, background .15s; }
.answers button:hover { background: var(--lilac-soft); }
.answers button:active { transform: translateY(3px); box-shadow: 0 1px 0 #d9c7d5; }
.answers button.ok { background: var(--ok); color: #fff; }
.answers button.bad { background: var(--bad); color: #fff; animation: shake .35s; }
.answers.locked button { pointer-events: none; }
@keyframes shake { 0%,100% { transform: translateX(0) } 25% { transform: translateX(-6px) } 75% { transform: translateX(6px) } }
.piano { width: 100%; max-width: 900px; height: auto; }
.piano-cap { font-size: 12px; color: var(--muted); margin-top: 6px; }
.gend { position: absolute; inset: 0; background: rgba(40,10,35,.55); display: none; align-items: center; justify-content: center; z-index: 10; }
.gend.show { display: flex; }
.gend-card { background: var(--plum); color: #fff; padding: 30px 36px; border-radius: 18px; width: 380px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.gend-card h2 { margin: 6px 0; }
.gend-card p { color: #e6cfe2; }
.gend-card .big { text-align: center; }
.stars { font-size: 40px; letter-spacing: 4px; }

@media (max-width: 1180px) {
  .tools .tbtn span, #bDone span { display: none; }
}

.ask { position: fixed; inset: 0; background: rgba(40,10,35,.45); display: none; align-items: center; justify-content: center; z-index: 30; }
.ask.show { display: flex; }
.ask-card { background: #fff; border-radius: 14px; padding: 22px 24px; width: 340px; max-width: 90vw; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.ask-card p { margin: 0 0 18px; font-size: 16px; font-weight: 600; color: var(--ink); }
.ask-btns { display: flex; gap: 10px; justify-content: flex-end; }
.abtn { border: none; border-radius: 9px; padding: 9px 16px; font-weight: 600; background: #eee3ec; color: var(--plum); }
.abtn.yes { background: var(--bad); color: #fff; }

/* tablets & phones */
@media (max-width: 900px) {
  .toc { position: absolute; z-index: 8; height: calc(100% - 0px); box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .book-body { position: relative; }
  .stage { padding: 10px; }
  .toolbar { justify-content: center; row-gap: 6px; }
  .toolbar::-webkit-scrollbar { display: none; }
  .tgroup { flex-shrink: 0; }
  .home-wrap { flex-direction: column; gap: 22px; padding: 22px; overflow-y: auto; max-height: 100%; }
  #home { align-items: flex-start; overflow-y: auto; }
  .home-cover { height: auto; width: min(52vw, 260px); }
  .home-panel { width: min(420px, 100%); }
  .home-panel h1 { font-size: 28px; }
  .game-bar { flex-wrap: wrap; justify-content: center; }
  .game-title { display: none; }
  .answers button { width: 58px; height: 58px; font-size: 24px; }
  .answers { gap: 8px; }
  .game-stats b { font-size: 18px; }
}
@media (max-width: 600px) {
  .toolbar { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; -webkit-overflow-scrolling: touch; }
}
@media (max-width: 500px) {
  .answers button { width: 44px; height: 44px; font-size: 20px; }
  .answers { gap: 5px; }
  .game-stats { gap: 6px; }
  .game-stats > div { padding: 8px; }
}

/* ---------- LOCK ---------- */
#lock { background: linear-gradient(135deg, var(--plum) 0%, #3b0f31 100%); align-items: center; justify-content: center; padding: 20px; }
.lock-card { width: 380px; max-width: 100%; text-align: center; color: #fff; }
.lock-icon { width: 96px; height: 96px; border-radius: 22px; margin-bottom: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.35); }
.lock-card h1 { font-size: 26px; margin: 0 0 8px; }
.lock-card p { color: #e6cfe2; margin: 0 0 18px; }
.code-input { width: 100%; padding: 14px; border-radius: 12px; border: 2px solid rgba(255,255,255,.25); background: rgba(255,255,255,.1); color: #fff; font-size: 22px; font-weight: 700; text-align: center; letter-spacing: 2px; text-transform: uppercase; outline: none; margin-bottom: 12px; -webkit-user-select: text; user-select: text; }
.code-input:focus { border-color: var(--lilac); }
.code-input::placeholder { color: rgba(255,255,255,.35); letter-spacing: 1px; font-weight: 500; }
.lock-card .big { text-align: center; }
.code-msg { min-height: 22px; color: #ffb3c1; font-weight: 600; font-size: 14px; }
.lock-foot { margin-top: 26px; font-size: 12px; color: var(--lilac); }
.who { font-size: 12px; color: #d9bfd4; margin-top: 10px; }
.who a { color: var(--lilac); cursor: pointer; text-decoration: underline; }

.wm { position: absolute; top: 1.6%; left: 0; right: 0; text-align: center; color: rgba(86,23,71,.5); font-weight: 600; letter-spacing: .5px; pointer-events: none; white-space: nowrap; }

/* ===== Piano book additions ===== */
.home-cover { height: auto; width: min(46vw, 560px); }
.wm { top: 1.2%; left: 2%; right: auto; text-align: left; }

.pbar { display: none; align-items: center; gap: 14px; padding: 8px 14px; background: #fff; border-bottom: 1px solid #e3d6e0; flex-wrap: wrap; box-shadow: 0 2px 6px rgba(60,20,50,.06); z-index: 4; }
.pbar.show { display: flex; }
.ptitle { display: flex; flex-direction: column; min-width: 150px; }
.ptitle b { color: var(--plum); font-size: 16px; }
.ptitle span { color: var(--muted); font-size: 12px; }
.metro { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mbtn { border: none; border-radius: 9px; background: var(--plum); color: #fff; padding: 8px 14px; font-weight: 700; font-size: 14px; }
.mbtn.on { background: var(--bad); }
.mini { width: 30px; height: 30px; border-radius: 50%; border: none; background: var(--lilac-soft); color: var(--plum); font-weight: 800; font-size: 16px; }
#mBpm { width: 120px; accent-color: var(--plum); }
.bpm { font-size: 13px; color: var(--muted); min-width: 64px; }
.bpm b { color: var(--plum); font-size: 16px; }
#mBeats { border: 1px solid #e3d6e0; border-radius: 8px; padding: 5px 6px; color: var(--plum); font-weight: 600; background: #fff; }
.dots { display: flex; gap: 6px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: #eadfe8; display: block; transition: transform .06s; }
.dots i.first { background: #dcc4d8; }
.dots i.hit { background: var(--lilac); transform: scale(1.25); }
.dots i.first.hit { background: var(--plum); }
.practice { display: flex; gap: 8px; margin-left: auto; }
.pbtn { border: 2px solid var(--lilac); background: #fff; color: var(--plum); border-radius: 10px; padding: 7px 12px; font-weight: 700; font-size: 14px; }
.pbtn:active { transform: scale(.97); }
.pbtn.star.on { background: #ffcf3f; border-color: #e7b200; color: #5a3b00; }
.toc li .stars-sm { color: #e7a800; }

.piano-dock { display: none; background: #2a1426; padding: 8px 12px 10px; border-top: 3px solid var(--lilac); }
.piano-dock.show { display: block; }
.dock-top { display: flex; justify-content: space-between; color: #d9bfd4; font-size: 12px; margin-bottom: 6px; gap: 10px; flex-wrap: wrap; }
.dock-top kbd { background: rgba(255,255,255,.15); border-radius: 4px; padding: 0 4px; font-family: inherit; }
.lbl { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.kb { width: 100%; height: 150px; display: block; touch-action: none; }
.kb .w { fill: #fff; stroke: #6d5a69; stroke-width: 1; }
.kb .b { fill: #1a1018; }
.kb .w.down { fill: #b874b0; }
.kb .b.down { fill: #7a2a66; }
.kb text { pointer-events: none; font-size: 13px; fill: #7a6d77; font-weight: 600; }
.kb text.mid { fill: var(--plum); }
@media (max-width: 900px) { .practice { margin-left: 0; } .kb { height: 120px; } }
.toc li.toc-sec { cursor: default; font-weight: 700; color: var(--plum); font-size: 13px; padding-top: 14px; text-transform: uppercase; letter-spacing: .5px; }
.toc li.toc-sec:hover { background: none; }
