/* Maestro - piano tiles with the classics. */
:root {
  --ink: #1b1b22; --muted: #6f6a5e; --paper: #f4f1ea; --panel: #ffffff; --line: #e2dccd;
  --gold: #c9a227; --accent: #7a5cff; --bad: #d8443c; --good: #2e9e6b;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
#keys { position: fixed; inset: 0; }
.hidden { display: none !important; }
h1, h2, h4 { margin: 0; }
h4 { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 14px 0 8px; }
.board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ------------------------------------------------------------------ in play */
/* The board has its own palette, so the HUD carries a band of the page colour behind it - that
   way the numbers stay readable whether the tiles are ivory or midnight. */
.hud { position: absolute; left: 0; right: 0; top: 0; z-index: 4; padding: calc(10px + var(--safe-t)) 14px 14px;
  pointer-events: none; text-align: center;
  background: linear-gradient(var(--paper) 80%, rgba(244, 241, 234, 0));
  text-shadow: 0 1px 2px var(--paper); }
.hud .x { pointer-events: auto; }
/* keep the readout over the board column, not spread across a wide window */
.hrow, .hud .big { width: min(100%, 520px); margin-left: auto; margin-right: auto; }
.hrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hrow .piece { font-weight: 800; font-size: 14px; }
.hrow.small { font-size: 11.5px; color: var(--muted); margin-top: 2px; font-weight: 700; }
.hud .big { font-size: 44px; font-weight: 900; letter-spacing: -.02em; line-height: 1.05; }
.hud .big i { font-style: normal; font-size: 18px; color: var(--muted); font-weight: 700; }
.x { appearance: none; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font-size: 15px; cursor: pointer; flex: none; }

/* the tap targets: four invisible columns over the board */
.pads { position: absolute; inset: 0; z-index: 3; display: grid; grid-template-columns: repeat(4, 1fr);
  width: min(100%, 520px); margin: 0 auto; }
.pad { appearance: none; background: transparent; border: 0; padding: 0; cursor: pointer; touch-action: none; }
.pad:active { background: rgba(122, 92, 255, .07); }

/* ----------------------------------------------------------------- screens */
.screen { position: absolute; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: 14px; overflow-y: auto; background: rgba(244, 241, 234, .86); backdrop-filter: blur(3px); }
.card { width: min(440px, 100%); max-height: 100%; overflow-y: auto; margin: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 20px; padding: 18px; box-shadow: 0 18px 50px rgba(30, 24, 10, .12); }
.screen.wide .card { height: 100%; display: flex; flex-direction: column; }
.card h1 { font-size: 26px; letter-spacing: -.02em; }
.card h2 { font-size: 21px; letter-spacing: -.01em; }
.card p { color: var(--muted); font-size: 13.5px; }
.kick { font-size: 11px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); }
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.fine { font-size: 11px; color: var(--muted); margin: 12px 0 0; }
.muted { color: var(--muted); font-size: 12.5px; }
.good { color: var(--good); font-weight: 800; font-size: 13px; }

.btn { display: block; width: 100%; margin: 8px 0 0; appearance: none; border: 1px solid var(--line);
  background: #fbfaf7; color: var(--ink); border-radius: 14px; padding: 13px; font: inherit; font-weight: 800;
  font-size: 15px; cursor: pointer; text-align: center; }
a.btn { box-sizing: border-box; text-align: center; text-decoration: none; }
.fine a { color: inherit; text-decoration: underline; }
.btn small { display: block; font-weight: 500; font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(#2b2b36, #16161d); color: #fff; border-color: #16161d; }
.btn.primary small { color: rgba(255, 255, 255, .7); }
.btn.ghost { background: transparent; color: var(--muted); }

/* the book */
.tally { display: flex; gap: 8px; font-size: 11.5px; color: var(--muted); margin-bottom: 10px; flex-wrap: wrap; }
.tally span { background: #faf8f3; border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; font-weight: 700; }
.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.song { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; appearance: none;
  border: 1px solid var(--line); background: #fbfaf7; border-radius: 14px; padding: 10px 12px; margin-bottom: 7px;
  font: inherit; cursor: pointer; }
.song .num { width: 22px; font-weight: 900; color: var(--muted); font-size: 13px; }
.song .txt { flex: 1; min-width: 0; }
.song .txt b { display: block; font-size: 14px; }
.song .txt small { display: block; font-size: 11px; color: var(--muted); }
.song .stars { color: var(--gold); font-size: 13px; letter-spacing: 1px; white-space: nowrap; }
.song .lock { font-size: 11px; color: var(--muted); font-weight: 700; white-space: nowrap; }
.song.locked { opacity: .55; }
.off { color: var(--line); }

.stars.big { font-size: 30px; color: var(--gold); letter-spacing: 6px; text-align: center; margin: 8px 0; }
.art { width: 100%; height: 70px; display: block; margin: 6px 0 10px; }
.stats { display: flex; gap: 7px; margin: 10px 0 4px; }
.stat { flex: 1; background: #faf8f3; border: 1px solid var(--line); border-radius: 13px; padding: 9px 4px; text-align: center; }
.stat b { display: block; font-size: 16px; }
.stat span { font-size: 10.5px; color: var(--muted); }

.result { text-align: center; }
.result.won h2 { color: var(--ink); }
.result .fail { display: inline-block; background: #fdeceb; color: var(--bad); border: 1px solid #f6cfcc;
  border-radius: 999px; padding: 5px 14px; font-weight: 800; font-size: 13px; margin: 8px 0 2px; }
.unlocked { margin: 10px 0 2px; font-size: 12.5px; font-weight: 700; color: var(--accent); }

.themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.theme { appearance: none; border: 1px solid var(--line); background: #fbfaf7; border-radius: 12px; padding: 8px 4px;
  font: inherit; font-size: 10.5px; cursor: pointer; text-transform: capitalize; color: var(--muted); }
.theme i { display: block; height: 26px; border-radius: 8px; border: 1px solid; margin-bottom: 5px; }
.theme.on { border-color: var(--accent); color: var(--ink); font-weight: 800; }
.guide p { font-size: 13.5px; color: var(--muted); margin: 0 0 11px; }
.guide b { color: var(--ink); }

@media (prefers-color-scheme: dark) {
  :root { --paper: #0e0f14; --panel: #171922; --ink: #eef1f7; --muted: #949bb0; --line: #262a38; }
  .screen { background: rgba(14, 15, 20, .86); }
  .btn { background: #1d2029; }
  .btn.primary { background: linear-gradient(#6c7cff, #3a46c8); border-color: #6c7cff; color: #fff; }
  .song, .stat, .tally span, .theme { background: #1b1e27; }
  .hud { background: linear-gradient(var(--paper) 80%, rgba(14, 15, 20, 0)); }
  .result .fail { background: #2a1416; border-color: #4a2024; }
}

/* the in-play HUD follows the board's theme (KeysDraw sets html[data-theme]): on the dark halls
   it becomes a smoked-glass band with a lit counter instead of a strip of page colour */
html[data-theme="midnight"] .hud, html[data-theme="rosewood"] .hud, html[data-theme="conservatory"] .hud {
  background: linear-gradient(rgba(6, 7, 12, .78) 55%, rgba(6, 7, 12, 0)); color: #f2f4ff; text-shadow: 0 2px 10px rgba(0, 0, 0, .6); }
html[data-theme="midnight"] .hud .big { text-shadow: 0 0 22px rgba(108, 124, 255, .75); }
html[data-theme="rosewood"] .hud .big { text-shadow: 0 0 22px rgba(224, 164, 94, .75); }
html[data-theme="conservatory"] .hud .big { text-shadow: 0 0 22px rgba(127, 214, 164, .75); }
html[data-theme="midnight"] .hud .big i, html[data-theme="rosewood"] .hud .big i, html[data-theme="conservatory"] .hud .big i,
html[data-theme="midnight"] .hrow.small, html[data-theme="rosewood"] .hrow.small, html[data-theme="conservatory"] .hrow.small { color: rgba(242, 244, 255, .66); }
html[data-theme="midnight"] .hud .x, html[data-theme="rosewood"] .hud .x, html[data-theme="conservatory"] .hud .x {
  background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .18); color: #f2f4ff; }
/* ivory is a light board whatever the phone's colour scheme, so its HUD pins its own ink */
html[data-theme="ivory"] .hud { background: linear-gradient(rgba(244, 241, 234, .92) 55%, rgba(244, 241, 234, 0)); color: #1b1b22; text-shadow: 0 1px 2px #f4f1ea; }
html[data-theme="ivory"] .hud .big { text-shadow: 0 2px 0 #fff, 0 0 18px rgba(201, 162, 39, .35); }
html[data-theme="ivory"] .hud .big i, html[data-theme="ivory"] .hrow.small { color: #6f6a5e; }
html[data-theme="ivory"] .hud .x { background: #ffffff; border-color: #e2dccd; color: #1b1b22; }
.pad:active { background: transparent; }

/* achievements */
.unlocked.deed { background: rgba(232,195,90,.18); }
.deedrow { cursor: default; }
.book .top > div:last-child { display: flex; gap: 4px; }

/* screen transitions (js/fx.js FX.watch): `translate` rather than `transform`, so elements that
   centre themselves with a transform are never disturbed */
.fx-enter > * { animation: fxEnter .24s cubic-bezier(.2, .8, .3, 1); }
@keyframes fxEnter { from { opacity: 0; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }
@media (prefers-reduced-motion: reduce) { .fx-enter > * { animation: none; } }

/* keyboard focus: a ring you can actually see, on every focusable thing (a11y pass) */
:focus-visible { outline: 3px solid #ffd24d; outline-offset: 2px; border-radius: 6px; }
canvas:focus-visible { outline-offset: -3px; }
@media (prefers-reduced-motion: no-preference) { :focus-visible { transition: outline-offset .1s; } }

/* ---------------------------------------------------------------- two on one phone
   Lanes 0-1 are the left player, 2-3 the right. The HUD carries both counts instead of the solo
   tile counter, and the result card replaces the stars - a duet is not a ranked attempt and must
   never overwrite a solo best. */
.btn.two.on { border-color: #f2c14e; background: rgba(242, 193, 78, .14); }
.hud .big.duet { display: flex; align-items: baseline; justify-content: center; gap: 10px; }
.hud .big.duet i { font-size: .42em; font-style: normal; opacity: .5; letter-spacing: .08em; }
.p1 { color: #7fd4ff; }
.p2 { color: #ffb36b; }
.duetres { margin: 10px 0 4px; text-align: center; }
.duetres > b { display: block; font-size: 19px; letter-spacing: .01em; }
.duetres small { display: block; margin-top: 6px; font-size: 11.5px; opacity: .62; }
.duetrow { display: flex; justify-content: center; gap: 26px; margin: 8px 0 2px; }
.duetrow span { font-size: 30px; font-weight: 700; line-height: 1; }
.duetrow small { display: block; margin-top: 3px; font-size: 10.5px; letter-spacing: .09em;
  text-transform: uppercase; opacity: .55; color: inherit; }

/* the challenge code: six characters somebody has to read out loud across a room */
.codebig { font-size: 38px; font-weight: 700; letter-spacing: .20em; text-indent: .20em;
  margin: 10px 0 2px; font-variant-numeric: tabular-nums; color: var(--gold); }
.codebig.small { font-size: 25px; margin: 6px 0 0; }
.vsmade { text-align: center; margin: 6px 0 12px; }
.vsmade small { display: block; margin-top: 6px; font-size: 11.5px; opacity: .62; }
.vsnote { font-size: 12.5px; letter-spacing: .06em; text-transform: uppercase; opacity: .6;
  margin: 14px 0 8px; text-align: center; }
.vsjoin { margin-top: 18px; border-top: 1px solid var(--line); }
.vsjoin small { display: block; margin-top: 8px; font-size: 11px; opacity: .5; text-align: center; }
/* This app is light parchment, not a dark theme: near-white text on a dark fill rendered as a
   grey slab with an invisible placeholder, and read as a disabled control rather than a box to
   type in. Also note `user-select` - the global reset turns selection off on everything, which
   on an input fights the player trying to correct a character. */
.codein { display: block; width: 100%; box-sizing: border-box; margin: 0 0 10px; padding: 13px 14px;
  font: 700 26px/1 inherit; letter-spacing: .18em; text-align: center; text-transform: uppercase;
  color: var(--ink); background: #fbfaf7; border: 1px solid var(--line); border-radius: 12px;
  user-select: text; -webkit-user-select: text; }
.codein:focus { outline: none; border-color: var(--gold); background: #fff; }
.codein::placeholder { color: rgba(27, 27, 34, .20); letter-spacing: .18em; font-weight: 700; }
