:root {
    --bg: #fafbfc;
    --panel: #ffffff;
    --fg: #1d2330;
    --muted: #6b7385;
    --border: #dde1e8;
    --accent: #2f6fdb;
    --accent-bg: #e6eefc;
    --wave-bg: #0f1626;
    --wave-line: #8fd8ff;
    --wave-axis: #2a3550;
    --wave-loop: rgba(255, 170, 60, 0.18);
    --z0: #4f8ef7; --z1: #2bb673; --z2: #f29d38; --z3: #c25de0; --z4: #e8556d; --z5: #17a2b8;
    --key-white: #ffffff; --key-black: #2b2f38;
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171d; --panel: #1b1f27; --fg: #e3e6ec; --muted: #8e96a8;
        --border: #2e3440; --accent: #7aa7ff; --accent-bg: #23314d;
        --key-white: #d9dde5; --key-black: #10131a;
    }
}
* { box-sizing: border-box; }
body {
    margin: 0; height: 100vh; display: grid;
    grid-template: "head head" auto "side main" 1fr / 300px 1fr;
    background: var(--bg); color: var(--fg);
}
body.drop { outline: 3px dashed var(--accent); outline-offset: -6px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header {
    grid-area: head; display: flex; align-items: center; gap: 16px;
    padding: 8px 16px; border-bottom: 1px solid var(--border); background: var(--panel);
}
header h1 { margin: 0; font-size: 18px; }
header h1 a { color: var(--fg); }
.file { cursor: pointer; padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; }
.file input { display: none; }
#status { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#side {
    grid-area: side; display: flex; flex-direction: column; min-height: 0;
    border-right: 1px solid var(--border); background: var(--panel);
}
#tabs { display: flex; }
#tabs button {
    flex: 1; padding: 8px 4px; border: 0; border-bottom: 2px solid transparent;
    background: none; color: var(--muted); cursor: pointer; font: inherit; font-size: 12px;
}
#tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
#filter {
    margin: 8px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg); color: var(--fg); font: inherit;
}
#list { list-style: none; margin: 0; padding: 0 0 16px; overflow-y: auto; flex: 1; }
#list li.heading {
    position: sticky; top: 0; padding: 4px 12px; font-size: 11px; font-weight: 600;
    text-transform: uppercase; color: var(--muted); background: var(--panel);
    border-bottom: 1px solid var(--border);
}
#list a {
    display: block; padding: 3px 12px; color: var(--fg);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#list a:hover { background: var(--accent-bg); text-decoration: none; }
#list a.current { background: var(--accent); color: #fff; }

main { grid-area: main; overflow-y: auto; padding: 16px 24px 48px; min-width: 0; }
main h2 { margin: 0 0 4px; font-size: 22px; }
main h3 { margin: 24px 0 8px; font-size: 14px; }
.kind { margin: 0; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.meta, .muted { color: var(--muted); }
.error { color: #e8556d; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

table { border-collapse: collapse; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 12px; }
table.zones { width: 100%; }
table.zones tr.global { background: var(--accent-bg); }
table.props th { width: 140px; }

dl.gens { display: grid; grid-template-columns: max-content 1fr; gap: 1px 12px; margin: 0; }
dl.gens dt { color: var(--muted); font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
dl.gens dd { margin: 0; }
details.mods { margin-top: 6px; }
details.mods summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.mods table { margin-top: 4px; font-size: 12px; }

ul.inline { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
ul.inline li a {
    display: inline-block; padding: 2px 8px; border: 1px solid var(--border); border-radius: 12px;
}

.buttons { margin: 12px 0; display: flex; gap: 8px; }
.buttons button {
    padding: 6px 14px; border: 1px solid var(--border); border-radius: 6px;
    background: var(--panel); color: var(--fg); font: inherit; cursor: pointer;
}
.buttons button:hover { border-color: var(--accent); }

canvas.wave { display: block; width: 100%; height: 180px; border-radius: 6px; }
canvas.seam { height: 140px; }

.keymap { margin-bottom: 8px; }
.km-rows { position: relative; }
.km-rows .octave { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--border); }
.km-row { position: relative; height: 22px; }
.km-zone {
    position: absolute; top: 2px; bottom: 2px; min-width: 3px; border-radius: 3px;
    color: #fff; font-size: 11px; line-height: 18px; padding: 0 4px;
    white-space: nowrap; overflow: visible; opacity: .88;
}
.km-zone span { text-shadow: 0 0 3px rgba(0,0,0,.6); }
.km-zone:hover { opacity: 1; outline: 2px solid var(--fg); text-decoration: none; z-index: 1; }
.km-zone.vel-split { background-image: repeating-linear-gradient(45deg, transparent 0 6px, rgba(255,255,255,.25) 6px 9px); }
.zone-0 { background-color: var(--z0); } .zone-1 { background-color: var(--z1); } .zone-2 { background-color: var(--z2); }
.zone-3 { background-color: var(--z3); } .zone-4 { background-color: var(--z4); } .zone-5 { background-color: var(--z5); }
svg.keyboard { display: block; width: 100%; height: 26px; }
svg.keyboard .key-white { fill: var(--key-white); stroke: var(--border); stroke-width: .05; }
svg.keyboard .key-black { fill: var(--key-black); }
.km-labels { position: relative; height: 14px; font-size: 10px; color: var(--muted); }
.km-labels span { position: absolute; }

@media (max-width: 720px) {
    body { grid-template: "head" auto "side" 40vh "main" 1fr / 1fr; }
    #side { border-right: 0; border-bottom: 1px solid var(--border); }
    main { padding: 12px 16px 32px; }
}
