:root {
  color-scheme: dark;
  --bg: #12110f;
  --raise: #1c1916;
  --sink: #0c0b0a;
  --line: #3a342c;
  --ink: #f6f1e8;
  --muted: #c4b8a8;
  --faint: #8f8476;
  --accent: #e4a04a;
  --accent-ink: #1c1308;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Segoe UI", "Avenir Next", "Trebuchet MS", sans-serif;
  --mono: Consolas, "Cascadia Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background:
    radial-gradient(880px 380px at 0% -8%, rgba(228, 160, 74, 0.09), transparent 55%),
    var(--bg);
  font: 16px/1.45 var(--sans);
}
body:not(.gate) {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button, .as-button {
  background: #2a261f;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  color: var(--ink);
  text-decoration: none;
}
button.primary, a.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 650;
}
button:hover, .as-button:hover { border-color: #8a6a32; }
button.primary:hover, a.primary:hover { filter: brightness(1.06); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea {
  background: var(--sink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}
input[type="range"] {
  accent-color: var(--accent);
  padding: 0;
  background: transparent;
  border: 0;
}
label { display: grid; gap: 0.28rem; color: var(--muted); font-size: 0.82rem; }
a { color: var(--accent); }
.hint, .count, .root-line, .meta-line, .aliases, .artist, .who { color: var(--muted); }
.hint, .count, .root-line, .aliases { font-size: 0.82rem; }
.who { margin: 0; font-size: 0.78rem; color: var(--faint); }

.brand {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  font-weight: 680;
  letter-spacing: 0.01em;
}
.mark {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: inset 0 -6px 0 rgba(28, 19, 8, 0.35);
}

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.gate-card {
  width: min(26rem, 100%);
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.4rem;
  box-shadow: var(--shadow);
}
.gate-card h1 {
  margin: 0.35rem 0 0.2rem;
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.lede { margin: 0 0 1rem; color: var(--muted); }
.gate-card form { display: grid; gap: 0.65rem; }
.gate-card button { min-height: 44px; }

.banner {
  margin: 0.55rem 0.9rem 0;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: #3a2a18;
  color: #f6e2c4;
}
.status {
  min-height: 1.1rem;
  margin: 0.2rem 0.9rem;
  color: var(--faint);
  font-size: 0.85rem;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 17, 15, 0.94);
  position: sticky;
  top: 0;
  z-index: 5;
}
.metro, .top-actions, .row, .transport, .speeds, .loop-row, .pitch-row, .now-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}
.metro { flex: 1; }
.top-actions { margin-left: auto; }
.bpm-label { display: flex; align-items: center; gap: 0.35rem; }
.bpm-label input { width: 4.6rem; }
#metro-range { width: min(180px, 28vw); }
.pips { display: flex; gap: 0.35rem; align-items: center; min-width: 4.5rem; min-height: 1rem; }
.pip {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 99px;
  background: #3a342c;
}
.pip.accent { width: 0.62rem; height: 0.62rem; }
.pip.on { background: var(--accent); }

.shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr) minmax(230px, 300px);
  gap: 0.75rem;
  padding: 0.55rem 0.9rem 0.85rem;
}
.library, .stage, .tools { min-height: 0; }
.library {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: hidden;
}
.lib-head { display: flex; gap: 0.4rem; }
.lib-head input { flex: 1; min-width: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chip {
  border-radius: 999px;
  padding: 0.22rem 0.65rem;
  background: transparent;
  color: var(--muted);
}
.chip.on {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.classic-row { display: flex; flex-wrap: wrap; gap: 0.35rem 0.75rem; }
.classic-row a { font-size: 0.86rem; }
.count, .root-line { margin: 0; }
.root-line {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-list { flex: 1; overflow: auto; min-height: 0; padding-right: 0.15rem; }
.file {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  display: block;
}
.file:hover { background: #26221c; }
.file[aria-current="true"] {
  background: #2a241c;
  box-shadow: inset 3px 0 0 var(--accent);
}
.file b { display: block; font-weight: 650; }
.file .sub { display: block; color: var(--muted); font-size: 0.86rem; }
.tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.28rem; }
.tag {
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  color: var(--muted);
}
.empty-note { color: var(--muted); margin: 0.4rem 0.2rem; }

.stage { overflow: auto; padding-right: 0.2rem; }
.empty h2, .now h2, .tools h2, .file-card h3, dialog h2 {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.empty h2 { margin: 0.2rem 0 0.35rem; font-size: 2rem; }
.now h2 { margin: 0; font-size: 1.8rem; }
.kicker {
  margin: 0;
  color: var(--accent);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.artist, .meta-line, .aliases { margin: 0.15rem 0 0; }
.now {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 0.8rem;
}
.now-controls { align-items: end; }
.now-controls a, a.primary {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0.4rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  text-decoration: none;
}
a.primary { border-color: transparent; }
.cards { display: grid; gap: 0.55rem; margin-top: 1rem; }
.cards a {
  display: block;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--raise);
  color: inherit;
  text-decoration: none;
}
.cards a:hover { border-color: var(--accent); }
.cards a strong { display: block; }
.cards a span { color: var(--muted); font-size: 0.88rem; }
.sheet-picker { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: end; margin: 0 0 0.7rem; }
.sheet-picker label { min-width: min(100%, 16rem); }

.viewer-grid { display: grid; gap: 0.8rem; }
.viewer-grid.has-sheet { grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr); }
video, .sheet-image { width: 100%; border-radius: 10px; background: #000; }
video { max-height: 72vh; }
.sheet-image { background: #f4efe6; height: auto; }
.sheet-frame {
  width: 100%;
  min-height: 70vh;
  border: 0;
  border-radius: 10px;
  background: #f4efe6;
}
.sheet-text {
  margin: 0;
  white-space: pre-wrap;
  font-family: var(--mono);
  background: var(--sink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  line-height: 1.45;
  max-height: 75vh;
  overflow: auto;
}
.file-card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--raise);
}
.file-card h3 { margin: 0 0 0.35rem; }

.player { display: grid; gap: 0.45rem; }
.timeline { position: relative; height: 1.6rem; display: flex; align-items: center; }
.loop-region {
  position: absolute;
  height: 0.45rem;
  border-radius: 99px;
  background: rgba(228, 160, 74, 0.35);
  pointer-events: none;
}
.timeline input[type="range"] { width: 100%; position: relative; z-index: 1; }
.time-row { display: flex; justify-content: space-between; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.85rem; }
.transport button, #metro-toggle, #session-start, #session-save { min-height: 44px; }
.icon { width: 1rem; height: 1rem; display: block; }
.vol { display: flex; align-items: center; gap: 0.4rem; min-width: 9rem; }
.vol input { flex: 1; }
.speed.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.pitch-row input[type="range"] { width: min(220px, 50vw); }

.tools { display: flex; flex-direction: column; gap: 0.7rem; overflow: auto; }
.card {
  background: var(--raise);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
  display: grid;
  gap: 0.55rem;
}
.tools h2 { margin: 0; font-size: 1.25rem; }
.timer {
  margin: 0;
  font-family: var(--serif);
  font-size: 2.6rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1;
}
.log-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.65rem; }
.log-list li { border-top: 1px solid var(--line); padding-top: 0.55rem; }
.log-list .when { color: var(--faint); font-size: 0.78rem; }
.log-list p { margin: 0.15rem 0; }
.log-empty { color: var(--muted); border: 0 !important; padding: 0 !important; }

dialog {
  background: var(--raise);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.1rem 1.2rem 1rem;
  width: min(24rem, calc(100% - 2rem));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog ul { padding-left: 1.1rem; }
dialog li { margin: 0.25rem 0; }
kbd {
  font-family: var(--mono);
  font-size: 0.85em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0.02rem 0.35rem;
}

@media (max-width: 980px) {
  body:not(.gate) { height: auto; overflow: auto; }
  .brand-block, .metro { flex: 1 1 100%; }
  .top-actions { margin-left: 0; }
  .shell { display: flex; flex-direction: column; height: auto; }
  .library { overflow: visible; }
  .file-list { max-height: 46vh; flex: none; }
  .viewer-grid.has-sheet { grid-template-columns: 1fr; }
  .stage, .tools { overflow: visible; }
  .now h2 { font-size: 1.55rem; overflow-wrap: anywhere; }
  body.has-track .file-list { max-height: 8.5rem; }
  .timeline { order: 1; }
  .time-row { order: 2; }
  .transport { order: 3; }
  .loop-row { order: 4; scroll-margin-top: 4.5rem; scroll-margin-bottom: 1rem; }
  .speeds { order: 5; }
  .pitch-row { order: 6; }
  .player .hint { order: 7; }
}
@media (prefers-reduced-motion: reduce) {
  .pip.on { transform: none; }
}
