/* ============================================================
   Notespawn — engraver's atelier
   Warm ivory paper, deep ink, bronze accent; the score reads as
   a physical sheet on a desk. Display serif: Fraunces.
   ============================================================ */

:root {
  --paper: #f5f1e8;
  --panel: #fffdf7;
  --sheet: #ffffff;
  --ink: #211c14;
  --ink-soft: #3d362a;
  --muted: #7a7060;
  --line: #e3dac7;
  --line-strong: #cfc3a9;
  --accent: #96551f;
  --accent-deep: #7a4217;
  --accent-ink: #b06a2e;
  --ok: #3d6b4f;
  --warn: #92600f;
  --err: #a33a2a;
  --mast: #191510;
  --mast-ink: #f2ead9;
  --shadow: 0 1px 2px rgba(33, 28, 20, .06), 0 10px 30px rgba(33, 28, 20, .09);
  --shadow-sheet: 0 1px 3px rgba(33, 28, 20, .10), 0 14px 40px rgba(33, 28, 20, .12);
  --radius: 12px;
  --serif: "Fraunces", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #171310;
    --panel: #201b15;
    --ink: #ece4d3;
    --ink-soft: #d8cdb6;
    --muted: #9b8f7a;
    --line: #373025;
    --line-strong: #4a4133;
    --accent: #c98a45;
    --accent-deep: #b06a2e;
    --accent-ink: #c98a45;
    --ok: #7fb08f;
    --warn: #d0a04a;
    --err: #d07a63;
    --mast: #100d0a;
    --mast-ink: #f2ead9;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35);
    --shadow-sheet: 0 1px 3px rgba(0, 0, 0, .4), 0 14px 40px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Masthead: dark band with engraved staff lines ---------- */
.topbar {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 1rem 1.4rem;
  background: var(--mast);
  color: var(--mast-ink);
  overflow: hidden;
}
.topbar::before {
  /* five faint staff lines drifting across the masthead */
  content: "";
  position: absolute; inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 14px,
    rgba(242, 234, 217, .07) 14px 15px
  );
  background-position: 0 6px;
  pointer-events: none;
}
.topbar::after {
  /* a large engraved clef ghosted into the right of the band */
  content: "𝄞";
  position: absolute; right: 1.2rem; top: 50%;
  transform: translateY(-52%);
  font-size: 4.6rem; line-height: 1;
  color: rgba(242, 234, 217, .10);
  font-family: var(--serif);
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: .9rem; position: relative; }
.brand-icon {
  width: 44px; height: 44px; border-radius: 10px;
  background: rgba(242, 234, 217, .08);
  border: 1px solid rgba(242, 234, 217, .18);
  padding: 3px;
}
.topbar h1 {
  font-family: var(--serif);
  font-size: 1.5rem; margin: 0; font-weight: 600;
  letter-spacing: .01em;
}
.tagline {
  margin: .05rem 0 0; font-size: .78rem;
  color: rgba(242, 234, 217, .62);
  letter-spacing: .14em; text-transform: uppercase;
}

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: 336px 1fr; gap: 1.4rem;
  padding: 1.4rem; max-width: 1400px; margin: 0 auto;
}
/* grid items may hold wide scrollable content (the tab strip): without
   min-width:0 their intrinsic width blows the whole page out sideways */
.layout > .panel { min-width: 0; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.controls { padding: 1.25rem 1.2rem 1.1rem; position: sticky; top: 1rem; align-self: start; }
.stage { padding: 1.1rem 1.2rem 1.3rem; display: flex; flex-direction: column; }

/* ---------- Fields ---------- */
.field { margin-bottom: 1.05rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
label {
  display: block; font-weight: 600; font-size: .8rem;
  letter-spacing: .04em; margin-bottom: .35rem; color: var(--ink-soft);
}
.hint { color: var(--muted); font-size: .75rem; margin-top: .3rem; }
.hint.inline { font-weight: 400; letter-spacing: 0; }

select, input[type="number"] {
  width: 100%; padding: .55rem .65rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px; font-size: .92rem;
  background: var(--panel); color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
select:focus-visible, input[type="number"]:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  cursor: pointer; padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2396551f' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .65rem center;
}
select:hover { border-color: var(--accent); }

/* Difficulty slider */
input[type="range"] {
  width: 100%; accent-color: var(--accent);
  height: 1.2rem; cursor: pointer;
}
.pill {
  display: inline-block; min-width: 1.7rem; text-align: center;
  background: var(--accent); color: #fdf8ef; border-radius: 999px;
  padding: .08rem .55rem; font-size: .78rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.seedrow { display: flex; gap: .5rem; }
.seedrow input { flex: 1; }
input:disabled, button:disabled.ghost { opacity: .45; }
.check {
  display: flex; align-items: center; gap: .55rem; font-weight: 600;
  font-size: .88rem; margin-bottom: .9rem; cursor: pointer; user-select: none;
  color: var(--ink-soft);
}
.check input { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }

details.advanced { border-top: 1px solid var(--line); padding-top: .7rem; margin-bottom: 1.1rem; }
details.advanced summary {
  cursor: pointer; font-weight: 600; font-size: .8rem;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent-ink);
}
details.advanced summary:hover { color: var(--accent-deep); }
details.advanced[open] summary { margin-bottom: .9rem; }

/* ---------- Buttons ---------- */
button {
  font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid transparent;
  transition: background .15s ease, border-color .15s ease, color .15s ease,
              box-shadow .2s ease, transform .15s ease;
}
.primary {
  width: 100%; padding: .8rem;
  background: linear-gradient(to bottom, var(--accent), var(--accent-deep));
  color: #fdf8ef;
  font-weight: 700; font-size: .98rem; letter-spacing: .05em;
  box-shadow: var(--shadow);
  border: 1px solid var(--accent-deep);
}
.primary:hover:not(:disabled) {
  box-shadow: 0 2px 6px rgba(33, 28, 20, .18), 0 12px 32px rgba(33, 28, 20, .14);
  transform: translateY(-1px);
}
.primary:active:not(:disabled) { transform: translateY(0); }
.primary:disabled { opacity: .6; cursor: progress; }
.ghost {
  background: rgba(242, 234, 217, .07); color: inherit;
  border: 1px solid rgba(242, 234, 217, .35); padding: .45rem .8rem;
  font-size: .85rem;
}
.ghost:hover { background: rgba(242, 234, 217, .16); }
.tool {
  background: var(--panel); border: 1px solid var(--line-strong);
  padding: .5rem .75rem;
  font-size: .84rem; font-weight: 600; color: var(--ink-soft);
}
.tool:hover:not(:disabled) {
  border-color: var(--accent); color: var(--accent-deep);
  transform: translateY(-1px);
}
.tool:disabled { opacity: .4; cursor: default; }

.status { margin-top: .75rem; font-size: .82rem; min-height: 1.2rem; }
.status.ok { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.err { color: var(--err); }

/* ---------- Stage: toolbar, meta, the sheet ---------- */
.toolbar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .7rem; }
.spacer { flex: 1; }
midi-player { width: 100%; max-width: 360px; --md-sys-color-primary: var(--accent); }
midi-visualizer { display: block; margin-bottom: .6rem; }
.meta {
  font-size: .82rem; color: var(--muted); margin-bottom: .75rem; min-height: 1rem;
  font-family: var(--serif); font-style: italic;
}
.meta b { color: var(--ink); font-style: normal; }

.score {
  overflow-x: auto;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-sheet);
  padding: .6rem;
  flex: 1;
  min-height: min(52vh, 480px);
}
.score svg { max-width: 100%; height: auto; }
.score > svg, .score > .placeholder {
  animation: sheet-in .35s ease both;
}
@keyframes sheet-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .score > svg, .score > .placeholder { animation: none; }
  button, select, input { transition: none !important; }
}

.placeholder { text-align: center; color: var(--muted); padding: 3.5rem 1rem; }
.placeholder p:first-child {
  font-family: var(--serif);
  font-size: 4rem; margin: 0; line-height: 1;
  color: var(--line-strong);
}

.foot {
  text-align: center; color: var(--muted); font-size: .76rem; padding: 1.1rem;
  font-family: var(--serif); font-style: italic; letter-spacing: .02em;
}

/* ---------- Mobile / embedded ---------- */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; padding: 1rem; gap: 1rem; }
  .controls { position: static; }
  .topbar { padding: .8rem 1rem; }
  .topbar h1 { font-size: 1.25rem; }
  .topbar::after { font-size: 3.4rem; right: .6rem; }
  .stage { min-height: auto; }
  .score { min-height: 0; }
}
@media (max-width: 480px) {
  .tagline { display: none; }
  .brand-icon { width: 38px; height: 38px; }
}

/* ---------- Native app frame (sync-web stamps body.native) ----------
   A wrapped page feels like a website because the DOCUMENT scrolls: the
   header bounces away, taps flash gray, inputs zoom the page. An app has
   fixed chrome, one scrolling content region, and quiet touch. */
body.native {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
body.native .topbar {
  flex: none;
  padding-top: calc(.8rem + env(safe-area-inset-top));
}
body.native .layout {
  flex: 1; min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: calc(1.2rem + env(safe-area-inset-bottom));
}
body.native .foot, body.native .teacherpack { display: none; }
body.native button, body.native label, body.native .topbar, body.native .seg-btn,
body.native summary, body.native .meta, body.native .hint {
  -webkit-user-select: none; user-select: none;
}
body.native .piececode { -webkit-user-select: all; user-select: all; }
body.native button, body.native select { touch-action: manipulation; }
/* iOS zooms the page when a focused input is under 16px — the "lurch" */
body.native select, body.native input[type="number"], body.native input[type="text"],
body.native input[type="email"] { font-size: 16px; }

/* ---------- Native score-first flow ----------
   Two screens, not one scrolling page. Home = the settings panel alone;
   Generate opens the sheet FULL SCREEN like a PDF (controls in a compact
   strip on top, the score scrolling beneath, keys at the bottom);
   ‹ Done returns home to roll another. */
.sheetback { display: none; }
body.native .stage { display: none; }
body.native .layout { display: block; }
body.native .controls { position: static; }
/* the home screen fits without scrolling: tighter rhythm, hints dropped
   (the panel is self-explanatory; the sheet screen carries the detail) */
body.native .layout { padding: .7rem .8rem; }
body.native .controls { padding: .85rem .9rem .75rem; }
body.native .field { margin-bottom: .55rem; }
body.native .controls label { margin-bottom: .2rem; }
body.native .controls .hint { display: none; }
body.native #diffLabel { display: block; }
body.native .check { margin-bottom: .55rem; }
body.native details.advanced { padding-top: .45rem; margin-bottom: .55rem; }
body.native .primary { padding: .68rem; }
body.native.sheet-open .topbar,
body.native.sheet-open .controls { display: none; }
body.native.sheet-open .stage {
  display: flex; flex-direction: column;
  position: fixed; inset: 0; z-index: 50;
  border: none; border-radius: 0; box-shadow: none;
  padding: calc(.5rem + env(safe-area-inset-top)) .6rem
           calc(.4rem + env(safe-area-inset-bottom));
}
body.native.sheet-open .sheetback { display: inline-block; flex: none; }
body.native.sheet-open .toolbar { margin-bottom: 0; }
body.native.sheet-open .pmode { margin: .1rem 0 .35rem; }
body.native.sheet-open .pmode-label { display: none; }
body.native.sheet-open .practicebar { margin-bottom: .35rem; padding: .35rem .55rem; }
body.native.sheet-open .meta { font-size: .72rem; margin: 0 0 .35rem; }
body.native.sheet-open .score {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
body.native.sheet-open .pkbd { flex: none; margin-top: .5rem; }
/* desktop-workflow buttons have no business on a phone sheet */
body.native #printBtn, body.native #dlXml, body.native #dlMidi { display: none; }

/* ---------- Print: only the score, plain paper ---------- */
@media print {
  .topbar, .controls, .toolbar, .foot, midi-player, midi-visualizer, .meta,
  .pmode, .practicebar, .pkbd { display: none !important; }
  .layout { display: block; padding: 0; }
  .panel { border: none; }
  .stage { box-shadow: none; padding: 0; }
  .score { border: none; box-shadow: none; padding: 0; background: #fff; }
  body { background: #fff; }
}

/* ---------- teacher pack capture ---------- */
.teacherpack {
  max-width: 1200px;
  margin: 28px auto 0;
  padding: 0 20px;
}
.teacherpack-inner {
  background: var(--mast);
  color: var(--mast-ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px 28px;
  align-items: center;
  justify-content: space-between;
}
.teacherpack-copy { max-width: 560px; }
.teacherpack-copy h2 {
  font-family: var(--serif);
  font-size: 1.35rem;
  margin: 0 0 6px;
}
.teacherpack-copy p { margin: 0; opacity: .82; font-size: .92rem; line-height: 1.5; }
.teacherpack-form { display: flex; gap: 10px; flex-wrap: wrap; }
.teacherpack-form input {
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid rgba(242, 234, 217, .25);
  background: rgba(242, 234, 217, .08);
  color: var(--mast-ink);
  min-width: 230px;
  font-size: .95rem;
}
.teacherpack-form input::placeholder { color: rgba(242, 234, 217, .45); }
.teacherpack-form button {
  padding: 11px 18px;
  border-radius: 8px;
  border: none;
  background: var(--accent-ink);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: .95rem;
}
.teacherpack-form button:hover { background: var(--accent-deep); }
.teacherpack-form button:disabled { opacity: .6; cursor: default; }
.teacherpack-msg { width: 100%; margin: 4px 0 0; font-size: .92rem; }
.teacherpack-msg a { color: var(--accent-ink); font-weight: 600; }
@media print { .teacherpack { display: none !important; } }

/* the piece code: the complete recipe of what's on screen, made for copying */
.piececode { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: .82em; user-select: all; letter-spacing: .02em; }

/* ---------- practice modes ---------- */
:root {
  --p-cur: #2f6fb3;
  --p-hit: #2c7a44;
  --p-loose: #b07a1a;
  --p-miss: #b03a28;
}
@media (prefers-color-scheme: dark) {
  :root { --p-cur: #6ea8e0; --p-hit: #6fbf87; --p-loose: #d0a04a; --p-miss: #d0705c; }
}

.pmode {
  display: flex; align-items: center; gap: .7rem;
  margin: .1rem 0 .55rem; flex-wrap: wrap;
}
.pmode-label {
  font-weight: 600; font-size: .8rem; letter-spacing: .04em;
  color: var(--ink-soft);
}
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 9px; overflow: hidden; }
.seg-btn {
  border: none; border-radius: 0; background: var(--panel);
  color: var(--ink-soft); font-size: .82rem; font-weight: 600;
  padding: .42rem .8rem;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line-strong); }
.seg-btn.active { background: var(--accent); color: #fdf8ef; }
.seg-btn:hover:not(.active) { color: var(--accent-deep); }

.practicebar {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: 9px;
  background: color-mix(in srgb, var(--panel) 70%, var(--paper));
  padding: .5rem .7rem; margin-bottom: .6rem;
}
.ptempo { display: inline-flex; align-items: center; gap: .45rem; font-size: .84rem; font-weight: 600; color: var(--ink-soft); }
.ptempo input[type="range"] { width: 130px; }
.plat { display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; color: var(--muted); }
.plat input { width: 4.2rem; padding: .25rem .4rem; }
.pstat { font-size: .86rem; font-weight: 600; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* score note colours — the cursor rule sits FIRST so a note that
   resolves (hit/loose/miss) always out-ranks its "current" blue */
g.p-current * { fill: var(--p-cur) !important; stroke: var(--p-cur) !important; }
g.p-hit * { fill: var(--p-hit) !important; stroke: var(--p-hit) !important; }
g.p-loose * { fill: var(--p-loose) !important; stroke: var(--p-loose) !important; }
g.p-miss * { fill: var(--p-miss) !important; stroke: var(--p-miss) !important; }

/* on-screen keys */
.pkbd {
  position: relative; height: 118px; margin-top: .8rem;
  border-radius: 9px; overflow: hidden;
  border: 1px solid var(--line-strong);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.pkey { position: absolute; top: 0; cursor: pointer; }
.pkey.white {
  height: 100%; background: #fdfbf5;
  border-right: 1px solid #c9c0ab; z-index: 1;
  display: flex; align-items: flex-end; justify-content: center;
}
.pkey.white span { font-size: .62rem; color: #9a8f7a; padding-bottom: .2rem; pointer-events: none; }
.pkey.black { height: 62%; background: #26211a; z-index: 2; border-radius: 0 0 3px 3px; }
.pkey.white.down { background: color-mix(in srgb, var(--accent) 30%, #fdfbf5); }
.pkey.black.down { background: color-mix(in srgb, var(--accent) 55%, #26211a); }
.pkey.wrong { background: var(--p-miss) !important; }
#pMic.active { border-color: var(--accent); color: var(--accent-deep); background: color-mix(in srgb, var(--accent) 14%, var(--panel)); }

/* ---------- Notespawn Tabs (the guitar page) ---------- */
.brand-tabs { color: var(--accent-ink); font-style: italic; }
/* a piano keyboard has no place on the guitar page: input is the mic,
   a MIDI instrument, or the computer keys (which work unseen) */
body.guitar .pkbd { display: none !important; }
.pianolink {
  color: var(--mast-ink); text-decoration: none; font-size: .85rem;
  padding: .45rem .8rem; border: 1px solid rgba(242, 234, 217, .35);
  border-radius: 9px; position: relative;
}
.pianolink:hover { background: rgba(242, 234, 217, .16); }
.modehint { margin: -.2rem 0 .6rem; }
.micprivacy { margin: -.1rem 0 .6rem; font-size: .72rem; }
.micheard {
  font-size: .84rem; font-weight: 700; color: var(--ok);
  font-variant-numeric: tabular-nums;
}

.tabstrip {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--sheet); border-radius: 8px;
  box-shadow: var(--shadow-sheet);
  margin-bottom: .7rem; padding: .35rem .2rem;
}
.tabsvg { display: block; }
.tabline { stroke: #b9b09c; stroke-width: 1; }
.tabbar { stroke: #4a4133; stroke-width: 1.2; }
.tabclef { font: 700 11px var(--serif); fill: #4a4133; }
.tabstring { font: 600 9px var(--sans); fill: #9a8f7a; text-anchor: middle; }
.tabpad { fill: #ffffff; }
.tabfret {
  font: 700 11px ui-monospace, "Cascadia Mono", Consolas, monospace;
  fill: #211c14; text-anchor: middle;
}
.tabfret.tf-active { fill: #96551f; font-size: 13px; }

.challengecard {
  border: 1px solid var(--accent); border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent) 7%, var(--panel));
  padding: .9rem 1rem; margin-bottom: .7rem;
}
.cc-score { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; }
.cc-detail { color: var(--ink-soft); font-size: .88rem; margin: .25rem 0 .7rem; }
.cc-actions { display: flex; gap: .55rem; flex-wrap: wrap; align-items: center; }
.ccbtn { width: auto; padding: .5rem .9rem; font-size: .88rem; text-decoration: none; display: inline-block; }
a.ccbtn { line-height: 1.2; }
.cc-share { margin-top: .6rem; }
@media print { .tabstrip { overflow: visible; } .challengecard, .modehint, .micprivacy, .pianolink { display: none !important; } }
