:root {
  color-scheme: dark;
  font: 100%/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #ebf2ee;
  background: #121b19;
  --surface: #182522;
  --line: #3b5148;
  --muted: #adc2b7;
  --accent: #a2e9ba;
  --gutter: clamp(.6rem, 2vw, 1.1rem);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 300px;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}
button, input, select, textarea { font: inherit; }
button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: .42rem .8rem;
  cursor: pointer;
  font-weight: 620;
}
button:disabled { opacity: .5; cursor: default; }
button:not(:disabled):hover { filter: brightness(1.15); }
:is(button,input,select,textarea,a):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.primary { color: #102c1d; background: var(--accent); }
.quiet { color: var(--accent); background: #263830; }
.outline { color: #e4eee8; border-color: #749186; background: transparent; }
.danger { color: #ffb9ac; background: #412b28; }

.toolbar, .controls { background: var(--surface); padding-inline: var(--gutter); }
.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(8rem, 17vw, 15rem) minmax(0, 1fr);
  grid-template-areas: "identity audio actions";
  align-items: center;
  gap: .85rem;
  min-height: 52px;
  padding-top: max(.22rem, env(safe-area-inset-top));
  padding-bottom: .22rem;
  border-bottom: 1px solid var(--line);
}
.header-identity { grid-area: identity; display: flex; align-items: center; gap: .85rem; min-width: 0; }
.wordmark { display: flex; align-items: center; gap: .52rem; color: var(--accent); font-size: 1.36rem; font-weight: 550; white-space: nowrap; }
.header-actions { grid-area: actions; justify-self: end; display: grid; align-items: center; gap: .1rem .4rem; }
.header-actions button { white-space: nowrap; }
#open-score { grid-area: 1 / 1; }
#settings { grid-area: 1 / 2; width: 42px; padding: 0; display: grid; place-items: center; }
#analysis { grid-area: 2 / 1; min-height: 27px; padding-block: 0; }
#update-build { grid-column: 1 / 3; min-height: 27px; padding-block: 0; }
#score-details { display: flex; align-items: baseline; gap: .55rem; min-width: 0; border-left: 1px solid var(--line); padding-left: .85rem; }
#score-details h1, #score-meta { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#score-details h1 { font-size: 1.04rem; font-weight: 650; }
#score-meta { color: var(--muted); font-size: .875rem; }
.audio-level {
  grid-area: audio;
  width: 100%;
  align-self: center;
  color: var(--muted);
  font-size: .85rem;
}
.level-label { display: flex; align-items: baseline; justify-content: space-between; gap: .4rem; }
#audio-source { color: #ebf2ee; font-weight: 650; white-space: nowrap; }
#level-state { white-space: nowrap; }
.level-control { position: relative; height: 25px; display: flex; align-items: center; }
.level-track {
  display: block;
  width: 100%;
  margin-inline: 5px;
  height: .58rem;
  border-radius: .25rem;
  background: #31483e;
}
.level-fill { display: block; height: 100%; width: 0; border-radius: inherit; background: #dab775; }
#sound-floor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  appearance: none;
  background: transparent;
  touch-action: none;
  cursor: ew-resize;
}
#sound-floor::-webkit-slider-runnable-track { height: 18px; background: transparent; }
#sound-floor::-moz-range-track { height: 18px; background: transparent; }
#sound-floor::-webkit-slider-thumb { appearance: none; width: 10px; height: 18px; border-radius: 3px; background: #eefbf3; border: 2px solid #527163; }
#sound-floor::-moz-range-thumb { width: 6px; height: 14px; border-radius: 3px; background: #eefbf3; border: 2px solid #527163; }
.audio-level[data-state="signal"] .level-fill { background: var(--accent); }

#viewport { position: relative; overflow: auto; overscroll-behavior: contain; scrollbar-color: #607e70 #15221e; }
#welcome { display: grid; justify-items: center; align-content: center; gap: .8rem; min-height: 100%; padding: 1.8rem 1rem; text-align: center; background: radial-gradient(ellipse at center,#223c32,transparent 76%); }
#welcome h1 { margin: 0; font-size: clamp(1.35rem, 4vw, 2.2rem); font-weight: 650; }
#paper { width: 100%; margin-inline: auto; background: #fff; }
#paper.continuous { padding: 7px 0; min-height: 100%; }
.staff-system, .page { position: relative; width: 100%; background: #fff; overflow: hidden; }
.page { aspect-ratio: var(--ratio); }
.page canvas, .staff-system canvas { position: absolute; top: var(--paper-offset, 0); left: 0; width: 100%; height: var(--paper-height, 100%); display: block; }
.mark { position: absolute; border-radius: .4rem; pointer-events: none; mix-blend-mode: multiply; }
.mark.ahead { background: linear-gradient(90deg,#bcf2bf65,#bcf2bfb0 13% 86%,#bcf2bf70); }
.mark.position { background: linear-gradient(90deg,#42e87980,#42e879d0 26% 68%,#42e87970); }
.mark.start { background: #9dedaea0; }

#countdown { position: fixed; top: 44%; left: 50%; transform: translate(-50%, -50%); padding: .8rem 2rem; min-width: 9rem; text-align: center; background: #172b23eb; color: #ebfff0; border: 1px solid #8cc8a3; border-radius: 15px; pointer-events: none; }
#countdown span { display: block; font-weight: 650; color: var(--accent); }
#countdown strong { display: block; font-size: 3.8rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
#status { margin: 0; padding: .28rem var(--gutter); color: var(--muted); background: #14201d; font-size: .875rem; }
#status:empty { display: none; }
#status.error { color: #ffc1af; }

.controls {
  display: grid;
  grid-template-columns: auto auto minmax(0,1fr) auto auto auto;
  grid-template-areas: "bar live transport initial start count";
  align-items: center;
  gap: .6rem clamp(.35rem, 1vw, .8rem);
  min-height: 60px;
  padding-block: .18rem max(.18rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.bar-controls { display: contents; }
.bar-info { grid-area: bar; }
.tempo-readouts, .transport { display: flex; align-items: center; gap: clamp(.35rem, 1vw, .8rem); }
.tempo-readouts, .bar-info, .controls .metric { white-space: nowrap; }
.tempo-readouts { grid-area: live; }
.transport { grid-area: transport; justify-content: center; gap: .78rem; }
#tempo-field { grid-area: initial; }
#bar-field { grid-area: start; }
#count-field { grid-area: count; }
.round { width: 50px; height: 50px; min-height: 50px; padding: 0; border-radius: 50%; display: grid; place-items: center; }
.play, .rewind { display: block; width: 17px; height: 19px; background: currentColor; }
.play { clip-path: polygon(15% 0,100% 50%,15% 100%); }
.rewind { color: #edf5ef; clip-path: polygon(0 0,14% 0,14% 46%,100% 0,100% 100%,14% 54%,14% 100%,0 100%); }
.stop { width: 14px; height: 14px; display: block; background: currentColor; }
.metric { color: var(--accent); padding-inline: .22rem; background: transparent; border: 0; border-radius: 5px; }

dialog {
  width: min(43rem, calc(100% - 1rem));
  max-height: min(90dvh, 52rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: inherit;
  background: var(--surface);
}
dialog::backdrop { background: #081410ba; }
.panel-header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .85rem 1.1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.panel-header h2 { font-size: 1.25rem; margin: 0; }
#panel-body { padding: .9rem 1.1rem 1.1rem; }
#panel-body > :first-child { margin-top: 0; }
.panel-group + .panel-group { margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: .85rem; }
.panel-group h3 { margin: 0 0 .55rem; font-size: 1rem; color: var(--accent); }
.panel-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.panel-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: .65rem; margin-bottom: .75rem; }
.field { display: grid; gap: .25rem; font-size: .9rem; }
.field :is(input,select,textarea) { min-width: 0; width: 100%; padding: .44rem .5rem; min-height: 42px; border: 1px solid var(--line); border-radius: 6px; color: inherit; background: #121e1a; font-size: 1rem; }
.field textarea { min-height: 80px; resize: vertical; }
.subtle { color: var(--muted); font-size: .88rem; }
.library-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: .18rem .6rem; align-items: center; border-top: 1px solid var(--line); padding: .55rem 0; }
.library-row p { margin: .12rem 0; }
.library-row .row-more { grid-column: 2; justify-content: flex-end; }
.report-view { width: 100%; max-height: 55dvh; overflow: auto; background: white; }
.report-view canvas { display: block; width: 100%; height: auto; }

@media (max-width: 1000px) {
  .header-identity { display: block; }
  #score-details { border-left: 0; padding: 0 0 .16rem; }
}
@media (max-width: 620px) {
  .toolbar { grid-template: "identity actions" auto "audio audio" auto / minmax(0, 1fr) auto; gap: .2rem .5rem; }
  .audio-level { width: min(75%, 16rem); justify-self: center; }
}
@media (orientation: portrait), (max-width: 760px) {
  .controls {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    grid-template-areas: "live transport bars" "initial transport count";
    gap: 0 .55rem;
  }
  .tempo-readouts { gap: .7rem; }
  .transport { padding-inline: .06rem; }
  .bar-controls { grid-area: bars; display: flex; justify-content: flex-end; align-items: center; gap: .6rem; }
  #tempo-field { justify-self: start; }
  #count-field { justify-self: end; }
  .tempo-readouts, .bar-info, .metric { font-size: clamp(.78rem, 2.25vw, 1rem); }
}
@media (max-width: 560px) {
  .toolbar button { padding-inline: .5rem; min-height: 38px; }
  #score-details { display: block; }
  .controls { min-height: 77px; }
  .controls .metric { padding-inline: 0; }
  .controls #count-field { white-space: normal; text-align: right; line-height: 1.15; }
  .round { width: 44px; height: 44px; min-height: 44px; }
  .transport { gap: .55rem; }
  .library-row .row-more { grid-column: 1 / -1; justify-content: flex-start; }
}
@media (max-width: 440px) {
  .tempo-readouts, .bar-controls { flex-direction: column; justify-content: center; gap: .08rem; line-height: 1.18; }
  .tempo-readouts { align-items: flex-start; }
  .bar-controls { align-items: flex-end; }
  #bar-field { min-height: 18px; padding-block: 0; }
}
