/* BBKS Piano Kids. A night-time music stage: song cards on a scrolling home screen,
   the game is one full-screen canvas with a slim bar on top. */
@font-face { font-family: "Grandstander"; src: url("../fonts/grandstander.ttf") format("truetype"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Lexend"; src: url("../fonts/lexend.ttf") format("truetype"); font-weight: 100 900; font-display: swap; }

:root {
  --night: #121638;
  --night-2: #1c2257;
  --panel: #232a66;
  --line: #343c84;
  --ink: #f5f3ff;
  --muted: #aeb2e0;
  --gold: #ffc94a;
  --danger: #ff6b7a;
  --ok: #5cc75a;
  --font-display: "Grandstander", "Comic Sans MS", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Lexend", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--night); color: var(--ink); font-family: var(--font-body); font-size: 15px;
  overflow: hidden; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, label:focus-within { outline: 3px solid var(--gold); outline-offset: 2px; }

/* ---------- Home ---------- */
#home {
  height: 100%; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
  padding-block: max(16px, env(safe-area-inset-top, 0px)) 40px;
  background: radial-gradient(1200px 500px at 80% -10%, #2b3480 0%, transparent 60%), var(--night);
}
.wrap { max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.topbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-mark { display: grid; grid-template-columns: repeat(7, 9px); gap: 3px; height: 40px; flex: none; }
.brand-mark i { border-radius: 0 0 4px 4px; background: var(--c); }
.brand h1 { font-family: var(--font-display); font-weight: 800; font-size: clamp(26px, 4.4vw, 42px); line-height: 1; margin: 0; letter-spacing: .5px; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.brand-text { min-width: 0; }
.top-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 999px; font-weight: 600; font-size: 15px; min-height: 48px; }
.btn-primary { background: var(--gold); color: #2a1e00; }
.btn-ghost { background: var(--panel); border: 1px solid var(--line); }
.btn-danger { background: var(--danger); color: #2b0007; }
.btn svg { width: 20px; height: 20px; flex: none; }
.toggle { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; padding: 6px 4px; border-radius: 8px; }
.toggle input { width: 20px; height: 20px; accent-color: var(--gold); }
.songs { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.song { position: relative; text-align: left; display: flex; flex-direction: column; gap: 9px; padding: 16px; border-radius: 20px; background: var(--panel); border: 1px solid var(--line); min-height: 150px; transition: transform .15s ease; }
.song:not([disabled]):active { transform: scale(.97); }
.song[disabled] { opacity: .5; cursor: not-allowed; }
.song .lvl { font-size: 12px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); }
.song .name { font-family: var(--font-display); font-weight: 800; font-size: 21px; line-height: 1.15; text-wrap: balance; }
.song .meta { font-size: 13px; color: var(--muted); }
.song .new { position: absolute; top: 12px; right: 12px; background: var(--gold); color: #2a1e00; font-size: 11px; font-weight: 700; letter-spacing: 1px; padding: 3px 8px; border-radius: 99px; text-transform: uppercase; }
.dots { display: flex; gap: 4px; flex-wrap: wrap; }
.dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: inset 0 -2px 0 rgba(0,0,0,.2); }
.stars { display: flex; gap: 2px; margin-top: auto; }
.stars svg { width: 22px; height: 22px; }
.lock { position: absolute; top: 14px; right: 14px; width: 22px; height: 22px; color: var(--muted); }
h2.section { font-family: var(--font-display); font-weight: 600; font-size: 20px; margin: 4px 0 0; color: var(--muted); letter-spacing: .3px; }
.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; color: var(--muted); font-size: 14px; line-height: 1.5; }
.how div { min-width: 0; }
.how b { display: block; color: var(--ink); font-weight: 600; margin-bottom: 2px; }

.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--night); font-weight: 600; padding: 12px 20px; border-radius: 99px; box-shadow: 0 8px 24px rgba(0,0,0,.35); z-index: 50; max-width: calc(100% - 32px); text-align: center; animation: toast-in .3s ease; }
@keyframes toast-in { from { transform: translate(-50%, 20px); opacity: 0; } }

/* ---------- Game ---------- */
#game { position: fixed; inset: 0; background: var(--night); }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.hud { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: center; gap: 10px;
  padding: 8px max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px)); padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: linear-gradient(to bottom, rgba(18,22,56,.92), rgba(18,22,56,0)); pointer-events: none; }
.hud > * { pointer-events: auto; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: rgba(35,42,102,.85); border: 1px solid var(--line); flex: none; }
.icon-btn svg { width: 20px; height: 20px; }
.hud-title { display: flex; flex-direction: column; min-width: 0; flex: 0 1 auto; }
.hud-title b { font-family: var(--font-display); font-weight: 800; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-title span { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.progress { flex: 1 1 60px; height: 8px; border-radius: 99px; background: rgba(255,255,255,.12); overflow: hidden; min-width: 40px; }
.progress i { display: block; height: 100%; width: 0; background: var(--gold); border-radius: 99px; }
.spacer { flex: 1 1 auto; }
.lives { display: flex; gap: 5px; flex: none; }
.lives i { width: 16px; height: 16px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #fff 0 12%, var(--danger) 13%); transition: transform .2s; }
.lives i.lost { background: #4a4f80; transform: scale(.75); }
.score { font-family: var(--font-display); font-weight: 800; font-size: 20px; min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; flex: none; }

.banner { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); text-align: center; pointer-events: none; display: flex; flex-direction: column; align-items: center; gap: 10px; width: max-content; max-width: calc(100% - 32px); }
.banner b { font-family: var(--font-display); font-weight: 800; font-size: clamp(26px, 6vw, 52px); text-shadow: 0 4px 0 rgba(0,0,0,.25); }
.banner span { color: var(--muted); font-size: 14px; }
.banner button { pointer-events: auto; }
.banner.pop b { animation: pop .5s ease; }
@keyframes pop { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); } }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(10,12,34,.72); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); z-index: 20; }
.card { width: min(460px, 100%); max-height: 100%; overflow-y: auto; background: var(--night-2); border: 1px solid var(--line); border-radius: 26px; padding: 24px; display: flex; flex-direction: column; gap: 16px; text-align: center; }
.card.wide { width: min(620px, 100%); text-align: left; }
.card h3 { font-family: var(--font-display); font-weight: 800; font-size: 28px; margin: 0; line-height: 1.1; text-wrap: balance; }
.card p { margin: 0; color: var(--muted); line-height: 1.5; }
.card .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.card .row .btn { flex: 1 1 140px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mode { display: flex; flex-direction: column; gap: 6px; text-align: left; padding: 14px; border-radius: 18px; background: var(--panel); border: 2px solid var(--line); }
.mode b { font-family: var(--font-display); font-size: 19px; font-weight: 800; }
.mode small { color: var(--muted); font-size: 12.5px; line-height: 1.4; }
.mode.challenge { border-color: var(--gold); }
.speeds { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.speeds button { padding: 8px 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; min-height: 38px; }
.speeds button[aria-pressed="true"] { background: var(--ink); color: var(--night); }
.big-stars { display: flex; justify-content: center; gap: 8px; }
.big-stars svg { width: 54px; height: 54px; }
.big-stars svg.on { animation: pop .5s ease both; }
.big-stars svg:nth-child(2).on { animation-delay: .15s; }
.big-stars svg:nth-child(3).on { animation-delay: .3s; }
.stat { display: flex; justify-content: center; gap: 24px; font-variant-numeric: tabular-nums; }
.stat div { display: flex; flex-direction: column; }
.stat b { font-family: var(--font-display); font-size: 26px; }
.stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.phone { width: 70px; height: 44px; border: 4px solid var(--ink); border-radius: 9px; margin: 0 auto; animation: rot 1.8s ease-in-out infinite; }
@keyframes rot { 0%, 30% { transform: rotate(-90deg); } 60%, 100% { transform: rotate(0); } }

/* ---------- Grown-ups ---------- */
.gate-q { font-family: var(--font-display); font-weight: 800; font-size: 34px; text-align: center; }
.gate-a { font-family: var(--font-display); font-size: 30px; min-height: 48px; text-align: center; border-bottom: 2px solid var(--line); letter-spacing: 4px; font-variant-numeric: tabular-nums; }
.pad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.pad button { min-height: 48px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); font-size: 20px; font-weight: 600; }
.pad .wide { grid-column: span 2; font-size: 15px; }
.err { color: var(--danger); text-align: center; min-height: 1.2em; font-size: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-sec { display: flex; flex-direction: column; gap: 10px; padding-block: 14px; border-top: 1px solid var(--line); }
.panel-sec h4 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); font-weight: 600; }
.panel-sec .line { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.panel-sec .line > span { min-width: 0; color: var(--ink); line-height: 1.45; }
.panel-sec small { color: var(--muted); line-height: 1.5; font-size: 12.5px; }
.update { background: var(--gold); color: #2a1e00; border-radius: 16px; padding: 12px 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; font-weight: 600; }
.update a { color: inherit; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
@media (max-height: 460px) {
  .card { padding: 16px; gap: 10px; }
  .card h3 { font-size: 22px; }
  .big-stars svg { width: 40px; height: 40px; }
  .song { min-height: 128px; padding: 14px; }
  .pad button { min-height: 40px; }
  .gate-q { font-size: 26px; }
}
