/* Zapper games — everything Note Zapper and Key Signature Zapper share.
   Namespaced zp-. Each game's own sheet holds only what is unique to it.

   The whole stage wears the arena: .night (default) is an arcade cabinet,
   .day follows the site theme with a white playfield for bright rooms. */

body { display: block; padding: 0; margin: 0; }

.zp-page { max-width: 940px; margin: 0 auto; padding: 24px 20px 48px; }
.zp-head { text-align: center; margin-bottom: 16px; }
.zp-head h1 { font-size: 34px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 6px; color: var(--text, #0f172a); }
.zp-head p { color: var(--text-light, #64748b); font-size: 15.5px; margin: 0; }

/* position: relative is required by zap-fx.js; .zp-faux-fs below must be able to beat it */
.zp-stage { position: relative; border-radius: 18px; padding: 14px 20px 20px; background: var(--s-bg); color: var(--s-ink);
    border: 1px solid var(--s-line); box-shadow: var(--shadow, 0 1px 3px rgba(0,0,0,.1)); }
.zp-stage.night { --s-bg: #0b1226; --s-panel: #121c39; --s-line: #26355f; --s-ink: #f1f5f9; --s-dim: #a9b7d6;
    --s-key: #18244a; --s-key-line: #3a4d84; --s-accent: #2dd4bf; --s-on: #05231f; --good: #5eead4; --bad: #fda4af;
    --ink: #f8fafc; --lines: #64769c; --cell: #2a3a66;
    --field: radial-gradient(1.5px 1.5px at 18% 22%, #ffffff66, transparent), radial-gradient(1.5px 1.5px at 63% 14%, #ffffff55, transparent),
        radial-gradient(1.5px 1.5px at 84% 78%, #ffffff55, transparent), radial-gradient(1px 1px at 38% 84%, #ffffff66, transparent),
        radial-gradient(1px 1px at 93% 30%, #ffffff55, transparent), radial-gradient(ellipse at 50% 45%, #22346a 0%, #152148 55%, #0f1936 100%); }
.zp-stage.day { --s-bg: var(--card, #fff); --s-panel: var(--bg, #f8fafc); --s-line: var(--border, #e2e8f0); --s-ink: var(--text, #0f172a);
    --s-dim: var(--text-light, #64748b); --s-key: var(--bg, #f8fafc); --s-key-line: var(--border, #cbd5e1); --s-accent: #0f766e; --s-on: #fff;
    --good: #0f766e; --bad: #b91c1c; --ink: #111827; --lines: #999; --cell: var(--border, #e2e8f0); --field: #fff; }
body.dark-mode .zp-stage.day { --s-accent: #5eead4; --s-on: #05231f; --good: #5eead4; --bad: #fda4af; }

/* Named here so ♯ and ♭ fall back to the same tight glyphs everywhere */
.zp-stage, .zp-stage button { font-family: Inter, system-ui, -apple-system, sans-serif; }
.zp-stage button:focus-visible { outline: 3px solid var(--s-accent); outline-offset: 2px; }

/* Top bar: what's being played, and the three things you may want any time */
.zp-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 36px; margin-bottom: 10px; }
.zp-now { font-size: 13px; font-weight: 600; color: var(--s-dim); }
.zp-icons { display: flex; gap: 6px; margin-left: auto; }
.zp-icons button { min-height: 36px; padding: 0 11px; border-radius: 9px; border: 1px solid var(--s-line); background: var(--s-panel);
    color: var(--s-dim); font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.zp-icons button:hover { color: var(--s-ink); border-color: var(--s-dim); }

/* ---- Lobby ---- */
.zp-lobby { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 18px; align-items: stretch; }
.zp-panel { background: var(--s-panel); border: 1px solid var(--s-line); border-radius: 14px; padding: 14px 16px 16px; }
.zp-panel h2 { margin: 0 0 10px; font-size: 15px; font-weight: 800; color: var(--s-ink); }

/* How to play: smaller and framed, so it can't be mistaken for the game itself */
.zp-demo { position: relative; cursor: pointer; }
.zp-demo .zp-field { border-radius: 10px; }
.zp-demo-keys { display: flex; justify-content: center; gap: 6px; margin: 12px 0 14px; }
.zp-demo-keys span { position: relative; flex: 0 1 44px; min-width: 0; padding: 6px 0; border-radius: 8px; text-align: center; font-size: 15px; font-weight: 800;
    border: 1px solid var(--s-key-line); background: var(--s-key); color: var(--s-dim); }
.zp-demo-keys span.press { background: var(--s-accent); border-color: var(--s-accent); color: var(--s-on); transform: translateY(2px); }
.zp-demo-keys span.press::after { content: '👆'; position: absolute; left: 50%; top: 68%; font-size: 24px; transform: translateX(-30%); z-index: 2; }
.zp-lock { position: absolute; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; border: 2px solid #f59e0b; opacity: 0; pointer-events: none;
    box-shadow: 0 0 0 4px rgba(245,158,11,.22); }
.zp-lock.on { opacity: 1; }
.zp-steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 0; padding: 0; list-style: none; counter-reset: s; }
.zp-steps li { counter-increment: s; padding: 8px 9px; border-radius: 9px; border: 1px solid var(--s-line); font-size: 13px; line-height: 1.35; font-weight: 600;
    color: var(--s-dim); transition: background .2s, color .2s, border-color .2s; }
.zp-steps li::before { content: counter(s); display: inline-flex; align-items: center; justify-content: center; width: 19px; height: 19px; margin-right: 6px;
    border-radius: 50%; background: var(--s-line); color: var(--s-ink); font-size: 11.5px; font-weight: 800; }
.zp-steps li.on { color: var(--s-ink); border-color: var(--s-accent); background: color-mix(in srgb, var(--s-accent) 16%, transparent); }
.zp-steps li.on::before { background: var(--s-accent); color: var(--s-on); }

/* Modes + Start */
.zp-go { display: flex; flex-direction: column; gap: 8px; }
.zp-mode { display: block; width: 100%; text-align: left; padding: 10px 14px; border-radius: 12px; cursor: pointer;
    border: 2px solid var(--s-key-line); background: var(--s-key); color: var(--s-ink); }
.zp-mode b { display: block; font-size: 16px; font-weight: 800; }
.zp-mode span { display: block; font-size: 13px; line-height: 1.35; color: var(--s-dim); margin-top: 1px; }
.zp-mode:hover { border-color: var(--s-dim); }
.zp-mode.active { border-color: var(--s-accent); background: color-mix(in srgb, var(--s-accent) 16%, var(--s-key)); }
.zp-start { margin-top: auto; min-height: 60px; border: 0; border-radius: 14px; cursor: pointer; font-size: 21px; font-weight: 800; color: #05231f;
    background: linear-gradient(135deg, #5eead4, #14b8a6); box-shadow: 0 6px 22px rgba(20,184,166,.4); }
.zp-start:hover { filter: brightness(1.06); }

/* Options console */
.zp-opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 18px; margin-top: 14px; }
.zp-opt > span { display: block; font-size: 13px; font-weight: 700; color: var(--s-dim); margin-bottom: 5px; }
.zp-seg { display: flex; gap: 4px; padding: 4px; border-radius: 11px; background: var(--s-bg); border: 1px solid var(--s-line); }
.zp-seg button { flex: 1 1 auto; min-height: 38px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; color: var(--s-dim);
    font-size: 14px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.zp-seg button:hover:not(:disabled) { color: var(--s-ink); background: var(--s-key); }
.zp-seg button.active { background: var(--s-accent); color: var(--s-on); }
.zp-opt.locked { opacity: .55; }
.zp-opt.locked button { cursor: not-allowed; }
.zp-lock-note { grid-column: 1 / -1; margin: 0; font-size: 13px; color: var(--s-dim); }
.zp-teach { text-align: center; font-size: 13.5px; line-height: 1.6; color: var(--text-light, #64748b); max-width: 640px; margin: 14px auto 0; }

/* ---- Play ---- */
.zp-hud { display: flex; justify-content: center; gap: 10px 26px; flex-wrap: wrap; font-weight: 800; font-size: 17px; margin-bottom: 8px; }
.zp-hud .l { font-size: 12px; font-weight: 700; color: var(--s-dim); display: block; text-align: center; }
.zp-hud > div { text-align: center; min-width: 64px; }
.zp-timer { font-variant-numeric: tabular-nums; color: var(--good); }
.zp-timer.danger { color: var(--bad); }
.zp-cells { display: inline-flex; gap: 3px; height: 20px; align-items: center; }
.zp-cells i { width: 11px; height: 16px; border-radius: 3px; background: var(--cell); transition: background .15s; }
/* Levelling up refills from a dim charge, never from empty */
.zp-cells.charged i { background: color-mix(in srgb, var(--zap) 35%, var(--cell)); }
.zp-cells i.on, .zp-cells.charged i.on { background: var(--zap, #14b8a6); }

.zp-field { position: relative; border: 1px solid var(--s-line); border-radius: 14px; overflow: hidden; background: var(--field); }
/* VexFlow hard-codes its colours as attributes; CSS beats them. */
.zp-field svg { display: block; }
.zp-field svg [stroke="#999999"] { stroke: var(--lines); }
.zp-field svg rect { fill: var(--lines); }

.zp-feedback { text-align: center; min-height: 34px; font-size: 22px; font-weight: 800; margin: 8px 0 4px; }
.zp-feedback.good { color: var(--good); }
.zp-feedback.bad { color: var(--bad); }

.zp-key { font-weight: 800; border-radius: 14px; border: 2px solid var(--s-key-line); background: var(--s-key); color: var(--s-ink);
    cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
@media (hover: hover) { .zp-key:hover { border-color: var(--s-accent); color: var(--s-accent); } }
.zp-key:active { transform: scale(.96); }
.zp-key.zapped, .zp-demo-keys span.zapped { background: var(--zap, #14b8a6); border-color: var(--zap, #14b8a6); color: #fff; }
.zp-key.fizzled { border-color: #dc2626; color: var(--bad); }

.zp-hint { text-align: center; font-size: 13px; color: var(--s-dim); margin: 10px 0 0; }
.zp-actions { display: flex; justify-content: center; margin-top: 12px; }
.zp-small { font-weight: 700; font-size: 13.5px; padding: 10px 20px; border-radius: 10px; border: 1px solid var(--s-key-line); background: transparent; color: var(--s-dim); cursor: pointer; }
.zp-small:hover { color: var(--s-ink); border-color: var(--s-dim); }

/* ---- Results (takes the How-to-play panel's place) ---- */
.zp-over { text-align: center; display: flex; flex-direction: column; justify-content: center; }
.zp-over h2 { font-size: 18px; }
.zp-over-score { font-size: 72px; font-weight: 800; line-height: 1; color: var(--good); }
.zp-over-sub { color: var(--s-dim); font-weight: 600; margin: 4px 0 16px; }
.zp-over-stats { display: flex; justify-content: center; gap: 28px; color: var(--s-dim); font-weight: 600; font-size: 14px; }
.zp-over-stats b { color: var(--s-ink); font-size: 22px; display: block; }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: no-preference) {
    .zp-start { animation: zp-pulse 2.2s ease-in-out infinite; }
    .zp-key.zapped, .zp-demo-keys span.zapped { animation: zp-fire .45s ease-out; }
    .zp-key.fizzled { animation: zp-shake .32s linear; }
    .zp-field.shake { animation: zp-shake .4s linear; }
    .zp-field.nudge { animation: zp-nudge .18s ease-out; }
    .zp-cells.full i { animation: zp-hum .7s ease-in-out infinite alternate; }
    .zp-lock.on { animation: zp-aim .7s ease-in-out infinite alternate; }
}
@keyframes zp-pulse { 50% { box-shadow: 0 8px 34px rgba(20,184,166,.65); } }
@keyframes zp-fire { 0% { transform: scale(.94); } 30% { transform: translateY(4px) scale(1.04); box-shadow: 0 0 0 6px color-mix(in srgb, var(--zap, #14b8a6) 30%, transparent); } }
@keyframes zp-shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@keyframes zp-nudge { 50% { transform: translateY(-3px); } }
@keyframes zp-hum { to { filter: brightness(1.35); } }
@keyframes zp-aim { to { transform: scale(.8); } }

/* ---- Fullscreen. .zp-faux-fs is the iPhone fallback (no element.requestFullscreen). ---- */
.zp-stage:fullscreen { display: flex; flex-direction: column; border-radius: 0; padding: 2vh 4vw; overflow: auto; }
.zp-faux-fs { position: fixed; inset: 0; z-index: 9999; margin: 0; border-radius: 0; display: flex; flex-direction: column; overflow: auto; padding: 2vh 4vw; }
body.zp-faux-fs-lock { overflow: hidden; }
/* Centre with auto-margin spacers, NOT justify-content: a centred flex column pushes overflow
   past the start edge, where overflow:auto cannot scroll to it. */
.zp-stage:fullscreen::before, .zp-stage:fullscreen::after, .zp-faux-fs::before, .zp-faux-fs::after { content: ''; flex: 0 0 auto; margin: auto 0; }
.zp-stage:fullscreen .zp-hud, .zp-faux-fs .zp-hud { font-size: 22px; gap: 8px 36px; }
.zp-stage:fullscreen .zp-feedback, .zp-faux-fs .zp-feedback { font-size: 28px; min-height: 42px; }
.zp-stage:fullscreen .zp-lobby, .zp-stage:fullscreen .zp-opts, .zp-faux-fs .zp-lobby, .zp-faux-fs .zp-opts { width: 100%; max-width: 1100px; margin-left: auto; margin-right: auto; }

#leaderboard { margin-top: 26px; }
.zp-info { margin-top: 30px; color: var(--text-light, #64748b); font-size: 15px; line-height: 1.7; }
.zp-info h2 { font-size: 21px; font-weight: 800; color: var(--text, #0f172a); margin: 24px 0 8px; }
.zp-info a { color: var(--primary, #0d9488); font-weight: 700; text-decoration: none; }
.zp-info a:hover { text-decoration: underline; }

@media (max-width: 720px) {
    .zp-lobby { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .zp-go { order: -1; }
    .zp-lobby.over .zp-go { order: 0; }
}
@media (max-width: 560px) {
    .zp-page { padding: 18px 12px 40px; }
    .zp-head h1 { font-size: 28px; }
    .zp-stage { padding: 10px 10px 14px; }
    .zp-icons .zp-ic { display: none; }
    .zp-icons button { min-width: 42px; padding: 0 9px; }
    .zp-mode { padding: 9px 12px; }
    .zp-steps li { padding: 7px; font-size: 12.5px; }
    .zp-steps li::before { display: flex; margin: 0 0 4px; }
    .zp-opts { grid-template-columns: minmax(0, 1fr); gap: 10px; }
    .zp-seg button { padding: 0 6px; font-size: 13.5px; }
    .zp-hud { gap: 8px 16px; }
}
