:root {
    --bg: #111113;
    --surface: #161618;
    --pad: #1c1c20;
    --pad-inner: #151518;
    --line: #232327;
    --border: #2c2c32;
    --rim: #34343b;
    --text: #f2efe8;
    --text-soft: #b8b4ab;
    --muted: #9b988f;
    --note: #8d8a82;
    --accent: #ff5b2e;
    --accent-hover: #ff8a66;
    --ok: #5fd08a;
    --brass-rim: #5c4b2b;
    --brass-a: #3b3222;
    --brass-b: #2c261b;
    --mono: 'JetBrains Mono', ui-monospace, monospace;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Archivo', system-ui, sans-serif;
    overflow: hidden;
}

button, select, input {
    font: inherit;
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

.app {
    height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr auto;
}

/* Header */
.topbar {
    height: 72px;
    padding: 0 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.logo {
    color: var(--accent);
    flex-shrink: 0;
}

.midi-selector {
    display: flex;
    align-items: center;
    gap: 16px;
}

.midi-selector label {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.midi-selector select {
    height: 44px;
    width: 260px;
    padding: 0 14px;
    background: #18181b;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.chip {
    height: 32px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 13px;
    color: #cfcbc2;
    white-space: nowrap;
}

.chip::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #55535a;
}

.chip.on::before {
    background: var(--ok);
}

/* Stage */
.stage-area {
    min-height: 0;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.hint {
    font-family: var(--mono);
    font-size: 12px;
    letter-spacing: 0.06em;
    color: var(--muted);
}

/* Palco 960x600: as peças se posicionam em % a partir de --x, --y, --r */
.stage {
    position: relative;
    width: min(960px, 100%, (100dvh - 260px) * 1.6);
    aspect-ratio: 960 / 600;
}

.rug {
    position: absolute;
    left: calc(150 / 9.6 * 1%);
    top: calc(20 / 6 * 1%);
    width: calc(660 / 9.6 * 1%);
    height: calc(560 / 6 * 1%);
    border-radius: 50%;
    border: 1px dashed var(--line);
}

.drum-part {
    --ring: 9px;
    --rest: var(--rim);
    position: absolute;
    left: calc((var(--x) - var(--r)) / 9.6 * 1%);
    top: calc((var(--y) - var(--r)) / 6 * 1%);
    width: calc(var(--r) / 4.8 * 1%);
    aspect-ratio: 1;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    background: var(--pad);
    border: 2px solid var(--rest);
    box-shadow:
        inset 0 0 0 var(--ring) var(--pad-inner),
        inset 0 0 0 calc(var(--ring) + 1px) #2a2a30;
    transition: box-shadow 0.15s ease-out, border-color 0.15s ease-out;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.drum-part.cymbal {
    --rest: var(--brass-rim);
    background: repeating-radial-gradient(circle at center, var(--brass-a) 0 2px, var(--brass-b) 2px 6px);
}

.drum-part.kick {
    --ring: 16px;
}

.pad-name {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.pad-note {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--note);
}

.drum-part.active {
    border-color: var(--accent);
    box-shadow:
        inset 0 0 0 var(--ring) var(--pad-inner),
        inset 0 0 0 calc(var(--ring) + 1px) #2a2a30,
        0 0 0 8px rgb(255 91 46 / 0.2),
        0 0 56px rgb(255 91 46 / 0.35);
    transition: none;
}

.drum-part.active .pad-name {
    color: var(--accent);
}

/* Transport */
.transport {
    height: 112px;
    padding: 0 32px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: center;
    background: var(--surface);
    border-top: 1px solid var(--line);
}

.transport-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.record-btn {
    display: flex;
    align-items: center;
    gap: 16px;
    background: none;
    border: none;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}

.record-ring {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 2px solid #3a3a42;
    background: var(--pad);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s;
}

.record-btn:hover .record-ring {
    border-color: var(--accent);
}

.record-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    transition: all 0.15s ease-out;
}

.record-btn.recording .record-icon {
    width: 20px;
    height: 20px;
    border-radius: 4px;
}

#recording-status {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
}

.transport:has(.recording) #recording-status {
    color: var(--accent);
}

.transport:has(.recording) #recording-status::before {
    content: '● ';
}

.transport-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

#recording-time {
    font-family: var(--mono);
    font-size: 44px;
    font-weight: 500;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

.tempo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.field {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.field input,
.field select,
.metronome-btn {
    height: 32px;
    background: var(--pad);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: var(--mono);
    font-size: 13px;
}

.field input {
    width: 60px;
    padding: 0 8px;
    font-variant-numeric: tabular-nums;
}

.field select {
    padding: 0 6px;
    cursor: pointer;
}

.metronome-btn {
    width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    cursor: pointer;
}

.metronome-btn[aria-pressed="true"] {
    color: var(--accent);
    border-color: var(--accent);
}

.field input:disabled,
.field select:disabled,
.metronome-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.transport-right {
    display: flex;
    justify-content: flex-end;
}

.download-btn {
    height: 48px;
    padding: 0 22px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
    background: var(--accent);
    border: 1px solid var(--accent);
    color: var(--bg);
    cursor: pointer;
}

.download-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.download-btn:disabled {
    background: var(--pad);
    border-color: var(--border);
    color: #6b6964;
    cursor: not-allowed;
}

/* Start Overlay */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    padding: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.overlay-content {
    max-width: 600px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.overlay h1 {
    font-size: clamp(44px, 7vw, 80px);
    line-height: 0.95;
    font-weight: 800;
    letter-spacing: -0.035em;
}

.overlay p {
    font-size: 19px;
    line-height: 1.5;
    color: var(--text-soft);
}

.overlay-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.primary-btn {
    height: 56px;
    padding: 0 32px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: none;
    border-radius: 14px;
    background: var(--accent);
    color: var(--bg);
    font-size: 17px;
    font-weight: 700;
    cursor: pointer;
}

.primary-btn:hover {
    background: var(--accent-hover);
}

.primary-btn[aria-busy="true"] {
    opacity: 0.6;
    cursor: progress;
}

.facts {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 32px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}

/* Celular: a bateria vira um grid de pads */
@media (max-width: 640px) {
    .topbar {
        height: auto;
        padding: 20px 20px 0;
        flex-direction: column;
        align-items: stretch;
    }

    .midi-selector {
        flex-wrap: wrap;
        gap: 8px 12px;
    }

    .midi-selector label {
        width: 100%;
    }

    .midi-selector select {
        flex: 1;
        width: auto;
        min-width: 0;
    }

    .stage-area {
        padding: 20px;
        justify-content: stretch;
    }

    .hint,
    .rug {
        display: none;
    }

    .stage {
        width: 100%;
        flex: 1;
        aspect-ratio: auto;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-auto-rows: 1fr;
        gap: 10px;
    }

    .drum-part {
        position: static;
        width: auto;
        aspect-ratio: auto;
        min-height: 72px;
        border-radius: 18px;
        border-width: 1px;
        padding: 14px 16px;
        flex-direction: column-reverse;
        align-items: flex-start;
        justify-content: space-between;
        box-shadow: none;
    }

    .drum-part.cymbal {
        background: #1d1a14;
    }

    .drum-part.active {
        box-shadow: 0 0 0 6px rgb(255 91 46 / 0.18);
    }

    .pad-name {
        font-size: 15px;
        letter-spacing: 0;
        text-transform: none;
    }

    .transport {
        height: auto;
        padding: 16px 20px 28px;
        grid-template-columns: auto 1fr auto;
        gap: 12px;
    }

    #recording-status {
        display: none;
    }

    /* Controles de tempo ganham uma linha própria abaixo do relógio */
    .transport-center {
        display: contents;
    }

    #recording-time {
        justify-self: center;
    }

    .tempo {
        grid-column: 1 / -1;
        grid-row: 2;
        justify-content: center;
    }

    /* Mantém o nome acessível do botão de gravar */
    #record-text {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }

    .record-ring {
        width: 60px;
        height: 60px;
    }

    #recording-time {
        font-size: 34px;
    }

    .download-btn {
        padding: 0 14px;
        font-size: 14px;
    }
}
