:root {
    --ivory: #F2F3F0;
    --ebony: #1A1C20;
    --cobalt: #2B44C7;
    --cobalt-soft: #DDE2F8;
    --gold: #C9860A;
    --gold-soft: #F6E3BC;
    --claret: #B3323C;
    --claret-soft: #F3DBDD;
    --mist: #82868D;
    --line: #D8DAD5;
    --display: "Futura", "Avenir Next Condensed", "Avenir Next", sans-serif;
    --body: "Avenir Next", "Avenir", -apple-system, "Segoe UI", sans-serif;
    --mono: ui-monospace, "SF Mono", "Menlo", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    background: var(--ivory);
    color: var(--ebony);
    font-family: var(--body);
    font-size: 15px;
    line-height: 1.5;
}

.masthead {
    border-bottom: 3px solid var(--ebony);
    padding: 56px 24px 32px;
}

.masthead-inner, .controls-inner, .result-bar, main, .attribution {
    max-width: 980px;
    margin-left: auto;
    margin-right: auto;
}

.eyebrow {
    font-family: var(--display);
    text-transform: uppercase;
    letter-spacing: 0.32em;
    font-size: 12px;
    color: var(--cobalt);
    margin-bottom: 10px;
}

h1 {
    font-family: var(--display);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: clamp(40px, 7vw, 76px);
    line-height: 1;
}

.subtitle {
    margin-top: 14px;
    max-width: 560px;
    color: #45484e;
}

.controls {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--ivory);
    border-bottom: 1px solid var(--ebony);
    padding: 18px 24px 0;
    box-shadow: 0 6px 18px -14px rgba(26, 28, 32, 0.5);
}

.controls-inner {
    display: flex;
    gap: 36px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.piano {
    position: relative;
    width: 322px;
    height: 96px;
    user-select: none;
}

.key {
    position: absolute;
    top: 0;
    border: 1px solid var(--ebony);
    cursor: pointer;
    transition: background 0.12s, box-shadow 0.12s;
    font-family: var(--body);
    font-size: 10px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 4px;
}

.key.white {
    width: 46px;
    height: 96px;
    background: #FBFBF9;
    border-radius: 0 0 4px 4px;
    color: var(--mist);
}

.key.black {
    width: 28px;
    height: 58px;
    background: var(--ebony);
    border-radius: 0 0 3px 3px;
    z-index: 2;
    color: rgba(255, 255, 255, 0.55);
}

.key.include { background: var(--cobalt); color: #fff; border-color: var(--cobalt); }
.key.black.include { box-shadow: inset 0 0 0 2px var(--ivory); background: var(--cobalt); }
.key.exclude { background: var(--claret); color: #fff; border-color: var(--claret); }
.key.black.exclude { box-shadow: inset 0 0 0 2px var(--ivory); background: var(--claret); }
.key.exclude::before { content: "✕"; position: absolute; top: 6px; left: 50%; transform: translateX(-50%); font-size: 11px; }

.key.sounding, .key.include.sounding, .key.exclude.sounding {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--ebony);
    box-shadow: 0 0 14px rgba(201, 134, 10, 0.7);
}

.key:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 2px; z-index: 3; }

.piano-hint {
    margin-top: 8px;
    font-size: 11.5px;
    color: var(--mist);
}
.hint-include { color: var(--cobalt); font-weight: 600; }
.hint-exclude { color: var(--claret); font-weight: 600; }

.filter-block {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.filter-row {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.root-label {
    font-family: var(--display);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

select#root {
    font-family: var(--mono);
    font-size: 14px;
    padding: 7px 8px;
    border: 1px solid var(--ebony);
    border-radius: 4px;
    background: #FBFBF9;
    color: var(--ebony);
}

input[type="search"] {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px;
    font-family: var(--body);
    font-size: 14px;
    border: 1px solid var(--ebony);
    border-radius: 4px;
    background: #FBFBF9;
    color: var(--ebony);
}

input[type="search"]:focus, select#root:focus {
    outline: 2px solid var(--cobalt);
    outline-offset: 1px;
}

.named-toggle {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13.5px;
    cursor: pointer;
    white-space: nowrap;
}

.named-toggle input { accent-color: var(--cobalt); width: 15px; height: 15px; }

.tones-label {
    font-family: var(--display);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 12px;
}

.tone-chips { display: flex; gap: 5px; flex-wrap: wrap; }

.chip {
    font-family: var(--body);
    font-size: 12.5px;
    min-width: 30px;
    padding: 4px 0;
    text-align: center;
    border: 1px solid var(--ebony);
    border-radius: 999px;
    background: transparent;
    color: var(--ebony);
    cursor: pointer;
    transition: background 0.1s;
}

.chip:hover { background: var(--cobalt-soft); }
.chip.on { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
.chip:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }

.clear-btn {
    font-family: var(--body);
    font-size: 12.5px;
    border: none;
    background: none;
    color: var(--claret);
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.result-bar {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 12px 0 10px;
    font-family: var(--display);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 12.5px;
}

#count strong { color: var(--cobalt); }

.playing-now {
    color: var(--gold);
    font-size: 11.5px;
    letter-spacing: 0.1em;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 55%;
}

main { padding: 8px 24px 60px; }

.scale-list { list-style: none; }

.scale-row {
    display: grid;
    grid-template-columns: 132px 172px 1fr auto 44px;
    gap: 18px;
    align-items: center;
    padding: 11px 10px;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
    transition: background 0.1s;
}

.scale-row:hover { background: #E9EBE6; }

.scale-row.playing { background: var(--gold-soft); }

.glyph {
    display: flex;
    gap: 2px;
    align-items: flex-end;
    height: 30px;
}

.cell {
    width: 9px;
    border-radius: 1.5px;
    background: transparent;
    border: 1px solid var(--line);
    height: 30px;
    transition: background 0.1s;
}

.cell.blackpos { height: 20px; border-color: #C3C5C0; background: #E4E6E1; }
.cell.in { background: var(--ebony); border-color: var(--ebony); }
.cell.in.rootpos { background: var(--cobalt); border-color: var(--cobalt); }
.cell.sounding { background: var(--gold); border-color: var(--gold); box-shadow: 0 0 8px rgba(201, 134, 10, 0.8); }

.steps {
    font-family: var(--body);
    font-size: 13.5px;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.names { min-width: 0; }

.name-primary {
    font-weight: 600;
    font-size: 15px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.name-rest {
    display: block;
    font-size: 12.5px;
    color: var(--mist);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unnamed { color: var(--mist); font-style: italic; font-weight: 400; }

.meta {
    font-family: var(--body);
    font-size: 11.5px;
    color: var(--mist);
    text-align: right;
    white-space: nowrap;
}

.play-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1.5px solid var(--ebony);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s;
}

.play-btn svg { width: 13px; height: 13px; fill: var(--ebony); margin-left: 2px; }
.play-btn:hover { background: var(--ebony); }
.play-btn:hover svg { fill: var(--ivory); }
.scale-row.playing .play-btn { background: var(--gold); border-color: var(--gold); }
.scale-row.playing .play-btn svg { fill: var(--ebony); }
.play-btn:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 2px; }

.empty-state {
    padding: 60px 0;
    text-align: center;
    color: var(--mist);
    font-size: 16px;
}

.attribution {
    padding: 14px 24px 0;
    font-size: 12.5px;
    color: var(--mist);
}

.attribution a { color: var(--cobalt); }

@media (max-width: 760px) {
    .masthead { padding: 36px 16px 24px; }
    .controls { padding: 14px 16px 0; }
    .attribution { padding: 12px 16px 0; }
    main { padding: 8px 12px 60px; }
    .scale-row {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "names play"
            "glyph play"
            "steps meta";
        gap: 6px 12px;
    }
    .glyph { grid-area: glyph; }
    .steps { grid-area: steps; }
    .names { grid-area: names; }
    .meta { grid-area: meta; text-align: left; align-self: center; }
    .play-btn { grid-area: play; align-self: center; }
    .playing-now { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
    html { scroll-behavior: auto; }
}
