:root {
    color-scheme: light;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #eef2f7;
    color: #152033;
    --bg: #eef2f7;
    --panel: #ffffff;
    --panel-soft: #f7f9fc;
    --text: #152033;
    --muted: #657186;
    --border: #d7deea;
    --border-strong: #b7c1d1;
    --blue: #1463ff;
    --blue-dark: #0f4fd2;
    --green: #16834a;
    --red: #a92323;
    --amber: #73581c;
    --shadow: 0 18px 50px rgba(23, 32, 51, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 320px;
    background:
        radial-gradient(circle at top left, rgba(20, 99, 255, 0.1), transparent 34rem),
        linear-gradient(180deg, #f8fbff 0%, var(--bg) 48%, #e7edf5 100%);
}

button,
input,
select {
    font: inherit;
}

button {
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: linear-gradient(180deg, #ffffff 0%, #f1f4f9 100%);
    color: var(--text);
    min-height: 40px;
    padding: 0 16px;
    cursor: pointer;
    font-weight: 700;
    box-shadow: 0 1px 2px rgba(23, 32, 51, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.9);
    transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

button:hover {
    background: linear-gradient(180deg, #ffffff 0%, #e8edf5 100%);
    border-color: #8d99ad;
    box-shadow: 0 3px 8px rgba(23, 32, 51, 0.13), inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

button:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(23, 32, 51, 0.12), inset 0 2px 4px rgba(23, 32, 51, 0.08);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid rgba(20, 99, 255, 0.24);
    outline-offset: 2px;
}

.primary {
    background: linear-gradient(180deg, #2f7dff 0%, var(--blue-dark) 100%);
    border-color: var(--blue-dark);
    color: #ffffff;
    min-width: 112px;
    box-shadow: 0 4px 12px rgba(20, 99, 255, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.primary:hover {
    background: linear-gradient(180deg, #458cff 0%, #0f4ed2 100%);
    border-color: #0f4ed2;
}

.primary.playing {
    background: linear-gradient(180deg, #2f7dff 0%, var(--blue-dark) 100%);
    border-color: var(--blue-dark);
    box-shadow: 0 4px 12px rgba(20, 99, 255, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.24);
}

.app {
    width: min(1180px, calc(100vw - 28px));
    margin: 28px auto;
    display: grid;
    gap: 18px;
}

.panel {
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 20px;
}

.header,
.section-title,
.controls,
.section-actions,
.playback-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

h1,
h2,
p {
    margin: 0;
}

h1 {
    font-size: clamp(28px, 3vw, 32px);
    font-weight: 750;
    line-height: 1.15;
    letter-spacing: 0;
}

h2 {
    font-size: 19px;
    font-weight: 750;
    line-height: 1.2;
}

p {
    color: var(--muted);
    font-size: 15px;
    margin-top: 8px;
    max-width: 62ch;
}

.scope-block {
    margin: 0 0 12px;
}

canvas {
    display: block;
    width: 100%;
    height: clamp(210px, 30vw, 320px);
    border: 1px solid #222f43;
    border-radius: 8px;
    background: #111827;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 12px 28px rgba(17, 24, 39, 0.14);
}

.controls {
    margin: 0 0 4px;
}

.section-actions {
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.section-title {
    gap: 18px;
}

.playback-toolbar {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    justify-content: stretch;
    margin-top: 18px;
    padding: 12px;
}

.playback-status {
    align-items: center;
    align-self: center;
    background: #eef2f7;
    border: 1px solid #dbe2ec;
    border-radius: 999px;
    color: #526071;
    display: inline-flex;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    padding: 6px 10px;
}

.playback-status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: #8b98a9;
}

.playback-status.playing {
    background: #eaf8f0;
    border-color: #bde7cc;
    color: #17633a;
}

.playback-status.playing::before {
    background: var(--green);
}

.master-gain-control {
    align-items: center;
    display: grid;
    gap: 8px;
    grid-template-columns: auto minmax(160px, 260px) 44px;
    justify-self: end;
    min-width: 0;
    width: auto;
}

.master-gain-control>span:last-child {
    color: #526071;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.preview-zoom-control {
    min-width: 0;
    width: 100%;
}

.preview-zoom-control .control-heading>span:last-child {
    font-size: 12px;
    font-weight: 400;
}

label {
    display: grid;
    gap: 5px;
    color: #3d4960;
    font-size: 13px;
    font-weight: 500;
}

.control-heading {
    align-items: baseline;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    line-height: 1.2;
}

.control-heading>span:last-child {
    color: #8390a3;
    font-weight: 500;
    white-space: nowrap;
}

.controls label {
    min-width: min(260px, 100%);
}

input[type="range"] {
    appearance: none;
    background: transparent;
    width: 100%;
    min-height: 22px;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 999px;
    background: #d4dbe6;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    margin-top: -5px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    background: var(--blue);
    box-shadow: 0 1px 4px rgba(23, 32, 51, 0.22);
}

input[type="range"]::-moz-range-track {
    height: 6px;
    border: 0;
    border-radius: 999px;
    background: #d4dbe6;
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border: 2px solid #ffffff;
    border-radius: 50%;
    background: var(--blue);
    box-shadow: 0 1px 4px rgba(23, 32, 51, 0.22);
}

input[type="number"] {
    min-height: 34px;
    border: 1px solid #d9e0ea;
    border-radius: 7px;
    padding: 0 8px;
    width: 68px;
    background: #ffffff;
    color: var(--text);
}

.range-with-number {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) auto auto;
    gap: 7px;
    align-items: center;
}

.range-with-number .unit {
    color: #657186;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.gain-control .range-with-number {
    grid-template-columns: minmax(120px, 1fr) auto;
}

.gain-number,
.phase-number {
    width: 64px;
}

.noise-cutoff-number {
    width: 82px;
}

select {
    min-height: 34px;
    border: 1px solid var(--border-strong);
    border-radius: 7px;
    background: #ffffff;
    color: var(--text);
    padding: 0 28px 0 10px;
}

.signals {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}

.signal {
    border: 1px solid #e3e8f0;
    border-left-color: var(--signal-color, var(--border));
    border-left-width: 3px;
    border-radius: 10px;
    background: #fbfcfe;
    padding: 9px 12px;
    display: grid;
    grid-template-columns: 28px 62px 150px 260px 220px 180px 96px;
    align-items: center;
    gap: 8px 10px;
    box-shadow: 0 1px 2px rgba(23, 32, 51, 0.04);
    transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
    position: relative;
}

.signal:hover,
.signal.highlighted {
    background: #ffffff;
    border-color: var(--signal-color, var(--blue));
    box-shadow: 0 5px 18px rgba(23, 32, 51, 0.06);
}

.signal.disabled {
    background: #f6f8fb;
    border-color: #e5eaf2;
    border-left-color: #aab4c2;
    box-shadow: none;
}

.signal.disabled label:not(.enable-control),
.signal.disabled .wave-params,
.signal.disabled .noise-params {
    color: #4d5a70;
}

.signal.disabled input:not(.enabled),
.signal.disabled select {
    opacity: 0.42;
}

.signal.disabled input[type="range"]:not(.enabled) {
    opacity: 0.5;
}

.signal.disabled input[type="range"]:not(.enabled)::-webkit-slider-runnable-track {
    background: #c5ceda;
}

.signal.disabled input[type="range"]:not(.enabled)::-webkit-slider-thumb {
    background: #8793a4;
}

.signal.disabled input[type="range"]:not(.enabled)::-moz-range-track {
    background: #c5ceda;
}

.signal.disabled input[type="range"]:not(.enabled)::-moz-range-thumb {
    background: #8793a4;
}

.signal.disabled .signal-color-dot,
.signal.disabled .toggle-track {
    opacity: 0.48;
}

.signal.disabled .remove {
    opacity: 1;
}

.wave-params {
    display: contents;
}

.wave-params .frequency-control {
    grid-column: 4;
}

.wave-params .gain-control {
    grid-column: 5;
}

.wave-params .phase-control {
    grid-column: 6;
}

.noise-params {
    display: none;
}

.signal.noise .wave-params {
    display: none;
}

.signal.noise .noise-params {
    display: contents;
}

.noise-params .gain-control {
    grid-column: 4;
}

.noise-params label:nth-child(2) {
    grid-column: 5;
}

.noise-params label:nth-child(3) {
    grid-column: 6;
}

.wave-params>label,
.noise-params>label {
    gap: 10px;
    align-items: end;
}

.wave-type-control select {
    min-width: 112px;
    width: 100%;
}

.color-control {
    align-items: center;
    display: flex;
    justify-content: center;
}

.enable-control {
    align-items: center;
    display: flex;
    gap: 8px;
    justify-content: center;
    min-height: 40px;
    width: 62px;
    cursor: pointer;
}

.enable-control input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.signal-color-dot {
    background: var(--signal-color, var(--border-strong));
    border: 2px solid #ffffff;
    border-radius: 999px;
    box-shadow: 0 0 0 1px rgba(23, 32, 51, 0.18);
    flex: 0 0 auto;
    height: 13px;
    width: 13px;
}

.disabled-badge {
    display: none;
    color: #5d6879;
    font-size: 12px;
    font-weight: 650;
    line-height: 1;
    position: absolute;
    left: 116px;
    top: -9px;
    padding: 4px 8px;
    border: 1px solid #d3dbe7;
    border-radius: 999px;
    background: #eef2f7;
    text-transform: uppercase;
}

.signal.disabled .disabled-badge {
    display: inline-block;
}

.toggle-track {
    position: relative;
    width: 42px;
    height: 24px;
    border: 1px solid #9aa6b7;
    border-radius: 4px;
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.2) 1px, transparent 1px) 0 0 / 6px 100%,
        linear-gradient(180deg, #e4e9f1 0%, #c2cad7 100%);
    box-shadow: inset 0 1px 3px rgba(23, 32, 51, 0.26);
    transform: rotate(90deg);
    transition: background 140ms ease;
}

.toggle-track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border: 1px solid rgba(23, 32, 51, 0.22);
    border-radius: 2px;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(23, 32, 51, 0.28);
    transition: transform 140ms ease;
}

.enable-control input:checked+.toggle-track {
    border-color: #0f4fd2;
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.2) 1px, transparent 1px) 0 0 / 6px 100%,
        linear-gradient(180deg, #2f7dff 0%, #0f4fd2 100%);
}

.enable-control input:checked+.toggle-track::after {
    transform: translateX(16px);
}

.add-signal {
    align-items: center;
    display: inline-flex;
    gap: 8px;
    justify-content: center;
    min-width: 76px;
    min-height: 36px;
    padding: 0 12px;
    line-height: 1;
    background: #ffffff;
    border-color: #cbd5e1;
    color: #334155;
    box-shadow: 0 1px 2px rgba(23, 32, 51, 0.06);
}

.add-signal:hover {
    background: #f8fafc;
    border-color: #94a3b8;
    color: #152033;
}

.plus-icon {
    position: relative;
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.plus-icon::before,
.plus-icon::after {
    content: "";
    position: absolute;
    inset: 8px 2px auto;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
}

.plus-icon::after {
    transform: rotate(90deg);
}

.icon-actions {
    display: flex;
    flex-shrink: 0;
    gap: 6px;
}

.icon-btn {
    align-items: center;
    display: inline-flex;
    justify-content: center;
    min-height: 36px;
    padding: 0;
    width: 36px;
}

/* Normalize: three equal-height vertical bars */
.normalize-icon {
    position: relative;
    width: 12px;
    height: 10px;
    flex: 0 0 auto;
}

.normalize-icon::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 2px;
    height: 100%;
    background: currentColor;
    border-radius: 1px;
    box-shadow: 5px 0 0 currentColor, 10px 0 0 currentColor;
}

/* Reset: clockwise circular arrow */
.reset-settings-icon {
    position: relative;
    width: 14px;
    height: 14px;
    flex: 0 0 auto;
}

.reset-settings-icon::before {
    content: "";
    position: absolute;
    inset: 1px;
    border: 2px solid currentColor;
    border-radius: 50%;
    border-top-color: transparent;
    transform: rotate(70deg);
}

.reset-settings-icon::after {
    content: "";
    position: absolute;
    top: 1px;
    right: 1px;
    width: 0;
    height: 0;
    border-left: 5px solid currentColor;
    border-top: 3px solid transparent;
    border-bottom: 3px solid transparent;
    transform: rotate(45deg);
}

/* Download: downward arrow + floor line */
.download-icon {
    position: relative;
    width: 12px;
    height: 13px;
    flex: 0 0 auto;
}

.download-icon::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 10px;
    background: currentColor;
    clip-path: polygon(4px 0, 8px 0, 8px 5px, 12px 5px, 6px 10px, 0 5px, 4px 5px);
}

.download-icon::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
}

.settings-status {
    color: var(--muted);
    font-size: 13px;
    min-width: 88px;
    text-align: right;
}

.site-footer {
    align-items: center;
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    justify-content: center;
    padding: 12px 0 20px;
    font-size: 13px;
}

.site-footer a {
    color: var(--muted);
    text-decoration: none;
}

.site-footer a:hover {
    color: var(--text);
    text-decoration: underline;
}

.text-link {
    color: var(--blue-dark);
    font-weight: 600;
    text-decoration: none;
}

.text-link:hover {
    text-decoration: underline;
}

.text-link:focus-visible {
    border-radius: 4px;
    outline: 3px solid rgba(20, 99, 255, 0.24);
    outline-offset: 3px;
}

.footer-separator {
    color: #9aa6b7;
}

.legal-app {
    width: min(900px, calc(100vw - 28px));
}

.legal-panel {
    padding: 28px;
}

.legal-header {
    align-items: flex-start;
    margin-bottom: 18px;
}

.legal-copy {
    display: grid;
    gap: 14px;
}

.legal-copy h2 {
    font-size: 18px;
    margin-top: 10px;
}

.legal-copy p {
    margin-top: 0;
    max-width: 72ch;
}

.legal-footer {
    border-top: 1px solid var(--border);
    justify-content: flex-start;
    margin-top: 28px;
    padding-top: 16px;
}

.download-dialog {
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(23, 32, 51, 0.22);
    color: var(--text);
    padding: 0;
    width: min(360px, calc(100vw - 32px));
}

.download-dialog::backdrop {
    background: rgba(21, 32, 51, 0.34);
}

.download-dialog form {
    display: grid;
    gap: 16px;
    padding: 20px;
}

.download-dialog h2 {
    font-size: 18px;
}

.dialog-number-control {
    align-items: center;
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) auto;
}

.dialog-number-control input {
    width: 100%;
}

.dialog-number-control span {
    color: var(--muted);
    font-size: 13px;
}

.dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin: 4px 0 0;
    padding: 0;
}

.remove {
    justify-self: end;
    align-items: center;
    display: inline-flex;
    justify-content: center;
    width: 36px;
    min-height: 32px;
    padding: 0;
    background: transparent;
    border-color: #d9e0ea;
    color: #758296;
    box-shadow: none;
}

.remove:hover {
    background: #fff7f7;
    border-color: #ca8e8e;
    color: #8e2525;
    box-shadow: 0 2px 6px rgba(142, 37, 37, 0.1);
}

.trash-icon {
    position: relative;
    width: 14px;
    height: 15px;
    border: 2px solid currentColor;
    border-top: 0;
    border-radius: 0 0 3px 3px;
}

.trash-icon::before {
    content: "";
    position: absolute;
    top: -5px;
    left: -3px;
    width: 16px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
}

.trash-icon::after {
    content: "";
    position: absolute;
    top: -8px;
    left: 3px;
    width: 6px;
    height: 3px;
    border: 2px solid currentColor;
    border-bottom: 0;
    border-radius: 3px 3px 0 0;
}

.remove.confirming {
    background: #fee2e2;
    border-color: #ef4444;
    color: #b91c1c;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.14);
}

.remove.confirming:hover {
    background: #fecaca;
    border-color: #dc2626;
    color: #991b1b;
}

@media (max-width: 980px) {
    .signal {
        grid-template-columns: 28px 62px minmax(150px, 1fr) 96px;
    }

    .remove {
        grid-column: 4;
    }

    .wave-params .frequency-control {
        grid-column: 1 / 3;
    }

    .wave-params .gain-control {
        grid-column: 3;
    }

    .wave-params .phase-control {
        grid-column: 4;
    }

    .signal.noise .noise-params .gain-control {
        grid-column: 1 / 3;
    }

    .signal.noise .noise-params label:nth-child(2) {
        grid-column: 3;
    }

    .signal.noise .noise-params label:nth-child(3) {
        grid-column: 4;
    }
}

@media (max-width: 640px) {
    body {
        background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 55%, #e7edf5 100%);
    }

    .app {
        width: min(100% - 20px, 520px);
        margin: 10px auto 18px;
        gap: 12px;
    }

    .panel {
        padding: 14px;
    }

    .header,
    .section-title {
        align-items: stretch;
        flex-direction: column;
    }

    .header {
        gap: 14px;
    }

    .section-title {
        gap: 12px;
    }

    .legal-panel {
        padding: 18px;
    }

    .legal-footer,
    .site-footer {
        justify-content: flex-start;
    }

    p {
        font-size: 14px;
    }

    canvas {
        height: 220px;
    }

    .scope-block {
        margin: 0 0 16px;
    }

    .primary,
    .section-actions button:not(.icon-btn) {
        width: 100%;
    }

    .icon-actions {
        grid-column: 1 / -1;
        justify-content: flex-end;
    }

    .section-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        justify-content: stretch;
        gap: 10px;
    }

    .settings-status {
        grid-column: 1 / -1;
        min-width: 100%;
        text-align: left;
    }

    .master-gain-control {
        grid-column: 1 / -1;
        width: 100%;
    }

    .playback-toolbar {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .playback-status {
        align-self: center;
        justify-self: start;
    }

    .playback-toolbar .section-actions {
        grid-column: 1 / -1;
    }

    #resetSettings,
    #normalize {
        grid-column: span 1;
    }

    .signal {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: stretch;
        gap: 9px 10px;
        padding: 12px;
    }

    .range-with-number {
        grid-template-columns: minmax(0, 1fr) auto auto;
        gap: 7px;
    }

    .gain-control .range-with-number {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .color-control,
    .enable-control,
    .disabled-badge,
    .wave-type-control,
    .wave-params .frequency-control,
    .wave-params .gain-control,
    .wave-params .phase-control,
    .signal.noise .noise-params .gain-control,
    .signal.noise .noise-params label:nth-child(2),
    .signal.noise .noise-params label:nth-child(3),
    .remove {
        grid-column: 1 / -1;
    }

    input[type="number"] {
        width: 100%;
        min-height: 32px;
    }

    .enable-control {
        align-self: center;
        justify-content: flex-start;
        justify-self: start;
    }

    .disabled-badge {
        left: 12px;
        top: -8px;
    }

    .remove {
        width: 100%;
    }

    h1 {
        font-size: 24px;
    }

    .dialog-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
}

.cookie-banner {
    background: #1e293b;
    bottom: 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.22);
    color: #cbd5e1;
    font-size: 14px;
    left: 0;
    padding: 14px 20px;
    position: fixed;
    right: 0;
    z-index: 100;
}

.cookie-banner[hidden] {
    display: none;
}

.cookie-banner-inner {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    justify-content: space-between;
    margin: 0 auto;
    max-width: 1180px;
}

.cookie-banner-inner p {
    color: #cbd5e1;
    margin: 0;
    max-width: 60ch;
}

.cookie-banner-inner a {
    color: #93c5fd;
}

.cookie-banner-inner a:hover {
    color: #bfdbfe;
}

.cookie-actions {
    display: flex;
    flex-shrink: 0;
    gap: 10px;
}

.cookie-reject {
    background: transparent;
    border-color: #475569;
    box-shadow: none;
    color: #94a3b8;
    min-height: 36px;
    padding: 0 14px;
}

.cookie-reject:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: #64748b;
    box-shadow: none;
    color: #cbd5e1;
}

.cookie-banner .primary {
    min-height: 36px;
    min-width: 90px;
    padding: 0 16px;
}

@media (max-width: 420px) {
    .section-actions {
        grid-template-columns: 1fr;
    }

    #resetSettings,
    #normalize {
        grid-column: 1;
    }
}
