@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --page: #111318;
    --surface: #f4f0e8;
    --surface-muted: #e7ded1;
    --ink: #15171c;
    --ink-soft: #5b606b;
    --panel-dark: #171b22;
    --panel-dark-2: #202631;
    --line: rgba(21, 23, 28, 0.14);
    --line-dark: rgba(255, 255, 255, 0.12);
    --teal: #23b99a;
    --blue: #2f6fed;
    --pink: #d94f7b;
    --amber: #e2a438;
    --danger: #d44747;
    --radius: 8px;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    padding: 32px;
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
        var(--page);
    background-size: 44px 44px;
    color: var(--ink);
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.app-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
}

.app-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 22px;
    color: #f8f5ee;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--amber);
    font-size: 0.74rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(2.1rem, 4vw, 4.5rem);
    line-height: 0.95;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 0;
    font-size: 1.35rem;
    line-height: 1.1;
}

h3 {
    margin-bottom: 0.8rem;
    font-size: 0.9rem;
    color: var(--ink-soft);
}

.github-button,
.download-button,
button,
.file-label,
.sample-card {
    min-height: 44px;
}

.github-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius);
    color: #f8f5ee;
    text-decoration: none;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.08);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(300px, 0.85fr) minmax(0, 1.45fr);
    gap: 18px;
    align-items: start;
}

.panel {
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.control-panel,
.output-panel {
    padding: 28px;
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.28);
}

.visualizer-panel {
    padding: 28px;
    background: var(--panel-dark);
    color: #f9f6ef;
    border: 1px solid var(--line-dark);
}

.visualizer-panel .eyebrow {
    color: var(--teal);
}

.section-heading {
    margin-bottom: 22px;
}

form {
    display: grid;
    gap: 14px;
}

input[type="file"] {
    display: none;
}

.file-label,
button,
.sample-card,
.download-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.file-label {
    width: 100%;
    padding: 0.95rem 1rem;
    background: var(--ink);
    color: #fffaf1;
}

button {
    width: 100%;
    border: 0;
    padding: 0.95rem 1rem;
    background: var(--blue);
    color: #ffffff;
}

button:disabled {
    background: #9ba1ac;
    cursor: not-allowed;
}

.file-label:hover,
button:not(:disabled):hover,
.sample-card:hover,
.download-button:hover,
.github-button:hover {
    transform: translateY(-2px);
}

.file-label:focus-visible,
button:focus-visible,
.sample-card:focus-visible,
.download-button:focus-visible,
.github-button:focus-visible,
select:focus-visible {
    outline: 3px solid rgba(35, 185, 154, 0.48);
    outline-offset: 3px;
}

#file-name {
    min-height: 22px;
    color: var(--ink-soft);
    font-size: 0.9rem;
    word-break: break-word;
}

.samples-container {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}

.samples-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.sample-card {
    padding: 0.8rem;
    border: 1px solid var(--line);
    background: #ffffff;
    color: var(--ink);
    text-align: center;
}

.sample-card:hover {
    border-color: var(--teal);
}

.sample-card[aria-disabled="true"] {
    cursor: progress;
    opacity: 0.64;
    transform: none;
}

.sample-card span {
    pointer-events: none;
}

.disclaimer {
    margin-top: 18px;
    padding: 0.9rem 1rem;
    border-left: 4px solid var(--amber);
    border-radius: 0 var(--radius) var(--radius) 0;
    background: rgba(226, 164, 56, 0.14);
}

.disclaimer p {
    margin: 0;
    color: var(--ink-soft);
    font-size: 0.9rem;
    line-height: 1.45;
}

.disclaimer strong {
    color: var(--ink);
}

.visualizer-controls {
    display: grid;
    grid-template-columns: 1fr 140px;
    gap: 12px;
    margin-bottom: 18px;
}

.visualizer-controls label {
    display: grid;
    gap: 8px;
    color: rgba(249, 246, 239, 0.78);
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
}

select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line-dark);
    border-radius: var(--radius);
    padding: 0 0.8rem;
    background: var(--panel-dark-2);
    color: #f9f6ef;
    font: inherit;
    font-weight: 700;
}

.chart-stack {
    display: grid;
    gap: 12px;
}

.chart-block {
    margin: 0;
}

canvas {
    display: block;
    width: 100%;
    border: 1px solid var(--line-dark);
    border-radius: var(--radius);
    background: #101215;
}

#waveform-canvas {
    height: 220px;
}

#envelope-canvas {
    height: 150px;
}

#harmonics-canvas {
    height: 170px;
}

figcaption {
    margin-top: 7px;
    color: rgba(249, 246, 239, 0.62);
    font-size: 0.78rem;
    font-weight: 700;
}

.formula-display {
    margin-top: 16px;
    padding: 0.85rem 1rem;
    border: 1px solid var(--line-dark);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.06);
    color: #f9f6ef;
    font-size: 0.85rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

#status-message {
    display: none;
    margin: 18px 0 0;
    padding: 0.9rem 1rem;
    border-radius: var(--radius);
    color: #f9f6ef;
    font-size: 0.95rem;
    font-weight: 700;
}

#status-message[data-type="success"] {
    background: rgba(35, 185, 154, 0.24);
    border: 1px solid rgba(35, 185, 154, 0.42);
}

#status-message[data-type="error"] {
    background: rgba(212, 71, 71, 0.24);
    border: 1px solid rgba(212, 71, 71, 0.42);
}

#loading-spinner {
    display: none;
    width: 44px;
    height: 44px;
    margin: 22px auto 0;
    border: 4px solid rgba(255, 255, 255, 0.18);
    border-top-color: var(--teal);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#results-area {
    display: none;
    margin-top: 18px;
}

audio {
    width: 100%;
    margin-bottom: 14px;
}

.download-button {
    width: fit-content;
    padding: 0.85rem 1rem;
    border: 2px solid var(--pink);
    background: #ffffff;
    color: var(--ink);
}

@media (max-width: 900px) {
    body {
        padding: 20px;
    }

    .workspace {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    body {
        padding: 14px;
    }

    .app-header {
        align-items: stretch;
        flex-direction: column;
    }

    .control-panel,
    .visualizer-panel,
    .output-panel {
        padding: 20px;
    }

    .visualizer-controls,
    .samples-grid {
        grid-template-columns: 1fr;
    }
}
