:root {
  --paper: #fbfaf8;
  --surface: #ffffff;
  --fg: #1b1a18;
  --muted: #6d6b66;
  --line: #e3ded6;
  --accent: #2f6f5e;
  --accent-fg: #ffffff;
  --warn: #b4552d;
  --radius: 10px;
  --tap: 2.75rem;              /* 44px: the smallest comfortable touch target */
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16171a;
    --surface: #1e2024;
    --fg: #e9e7e2;
    --muted: #9b9890;
    --line: #2f3238;
    --accent: #7fc0ac;
    --accent-fg: #10231e;
    --warn: #e0885f;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  height: 100dvh;                       /* dvh: iOS Safari's toolbar collapses */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--paper);
  color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------- header ---------- */

header {
  flex: none;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: .5rem .7rem;
  padding-top: max(.5rem, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: .45rem;
}

.bar { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; }
.bar.grow > select { flex: 1 1 8rem; min-width: 0; }
.spacer { flex: 1 1 auto; }

select, input, button {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 .55rem;
  min-height: var(--tap);
  touch-action: manipulation;           /* no 300ms double-tap delay */
}

select { max-width: 100%; }

button {
  cursor: pointer;
  min-width: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  white-space: nowrap;
}

button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
button.icon { font-size: 1.1rem; padding: 0 .4rem; }

/* ---------- tempo ---------- */

.tempo { display: flex; align-items: center; gap: .25rem; }
.tempo input { width: 4.2rem; text-align: center; padding: 0 .2rem; }
.tempo .unit { color: var(--muted); font-size: .8rem; }

/* ---------- drawer of secondary controls ---------- */

details.drawer { border-top: 1px solid var(--line); padding-top: .45rem; }
details.drawer > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .85rem;
  min-height: 1.6rem;
  display: flex;
  align-items: center;
}
details.drawer[open] > summary { margin-bottom: .5rem; }
.groups { display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-start; }

fieldset {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .1rem .55rem .45rem;
  display: flex;
  flex-wrap: wrap;
  gap: .55rem;
  align-items: center;
}
legend { padding: 0 .3rem; font-size: .75rem; color: var(--muted); }

fieldset label {
  display: flex;
  align-items: center;
  gap: .3rem;
  min-height: 1.9rem;
  white-space: nowrap;
}
fieldset input[type=checkbox], fieldset input[type=radio] { min-height: 0; width: 1.05rem; height: 1.05rem; }

#status { color: var(--muted); font-size: .82rem; min-height: 1.1rem; }
#status.saved { color: var(--accent); }

/* ---------- score + lyrics ---------- */

main { flex: 1; min-height: 0; display: flex; position: relative; }

#viewport {
  flex: 1;
  min-width: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: .6rem;
  padding-bottom: max(.6rem, env(safe-area-inset-bottom));
}

/* alphaTab draws black on white; keep the score on paper in both themes. */
#score { background: #fff; color: #000; border-radius: 6px; }
.at-cursor-bar { background: #c8e0ff; opacity: .45; }
.at-cursor-beat { background: #2f6f5e; width: 3px; }
.at-highlight * { fill: #2f6f5e; stroke: #2f6f5e; }

/* Narrow screens: the panel covers the score instead of removing it from the
   layout — alphaTab measures its container, and a display:none parent makes it
   re-render at zero width after a rotation. */
#lyrics {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: .9rem 1rem max(.9rem, env(safe-area-inset-bottom));
  background: var(--surface);
  border-left: 1px solid var(--line);
}

#lyrics h2 { margin: 0 0 .1rem; font-size: 1.05rem; }
#lyrics .sub { margin: 0 0 1rem; color: var(--muted); font-size: .9rem; }
#lyrics .line { margin-bottom: .6rem; }
#lyrics .line .it { display: block; }
#lyrics .line .tr { display: block; color: var(--muted); font-size: .9rem; }
#lyrics .free { margin-top: 1.2rem; padding-top: .8rem; border-top: 1px solid var(--line); white-space: pre-line; }
#lyrics .free h3 { margin: 0 0 .3rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
#lyrics .note { margin-top: 1.2rem; font-size: .78rem; color: var(--muted); }

body.lyrics-open #lyrics { display: block; }

@media (min-width: 900px) {
  #lyrics { position: static; }
  body.lyrics-open #lyrics { flex: 0 0 clamp(260px, 30vw, 380px); }
}

/* ---------- install / help dialog ---------- */

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--fg);
  max-width: min(34rem, 92vw);
  padding: 1.1rem 1.2rem;
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h2 { margin: 0 0 .6rem; font-size: 1.05rem; }
dialog h3 { margin: 1rem 0 .2rem; font-size: .9rem; }
dialog p, dialog li { color: var(--muted); }
dialog ol { margin: .2rem 0; padding-left: 1.1rem; }
dialog .close { margin-top: 1rem; }
