/* Studio look (ADR 0013): one dark theme, colours and sizes as tokens. */

@font-face {
    font-family: 'IBM Plex Sans';
    src: url('vendor/fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2');
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Sans';
    src: url('vendor/fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2');
    font-weight: 600;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('vendor/fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2');
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: 'IBM Plex Mono';
    src: url('vendor/fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2');
    font-weight: 500;
    font-display: swap;
}

:root {
    --bg: #15171a;
    --surface: #1e2125;
    --surface2: #262a2f;
    --field: #0e1012;
    --field-fg: #e6e8eb;
    --fg: #e6e8eb;
    --dim: #8a9099;
    --accent: #f0a6c4;
    --on-accent: #15171a;
    --border: #2e3238;
    --err: #ff8080;
    --sec-a: rgba(214, 138, 170, 0.3);
    --sec-b: rgba(120, 146, 200, 0.3);
    --hatch: rgba(255, 255, 255, 0.1);
    --wave-bg: #101215;
    --wave-played: #f0a6c4;
    --wave-unplayed: #4b525c;
    --radius: 6px;
    --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --mono: 'IBM Plex Mono', ui-monospace, Menlo, Consolas, monospace;
    color-scheme: dark;
}

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

[hidden] {
    display: none !important;
}

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    background: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    padding: 24px 16px 48px;
}

.container {
    max-width: 820px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

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

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
.upload-zone:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: currentColor;
}

.icon-line {
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Header ── */
.app-header {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 14px;
}

.logo {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.logo span {
    color: var(--accent);
}

.tagline {
    color: var(--dim);
    font-size: 13px;
}

/* ── Sections ── */
.section {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.section-title {
    color: var(--dim);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.player-label {
    color: var(--fg);
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    font-size: 14px;
    margin-left: 6px;
}

#player-section,
#sections-block,
#output-block {
    display: none;
}

/* ── Upload zone ── */
.upload-zone {
    display: block;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 32px 24px;
    cursor: pointer;
    text-align: center;
}

.upload-zone:hover,
.upload-zone.drag-over {
    border-color: var(--accent);
}

.upload-zone.disabled {
    pointer-events: none;
}

.upload-zone.disabled .hint {
    opacity: 0.6;
}

.upload-zone input[type="file"] {
    display: none;
}

.upload-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 17px;
    font-weight: 600;
}

.upload-formats {
    color: var(--dim);
    font-size: 13px;
    margin-top: 6px;
}

.upload-steps {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 24px;
    margin-top: 22px;
    list-style: none;
    counter-reset: step;
    color: var(--dim);
    font-size: 13px;
}

.upload-steps li {
    counter-increment: step;
    display: flex;
    align-items: center;
    gap: 8px;
}

.upload-steps li::before {
    content: counter(step);
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--surface2);
    color: var(--fg);
    font-size: 12px;
    font-weight: 600;
}

.upload-error {
    display: none;
    color: var(--err);
    font-size: 14px;
}

/* ── Spinner ── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    border: 2px solid rgba(240, 166, 196, 0.25);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .spinner {
        animation-duration: 2.4s;
    }
}

/* ── Player ── */
.player-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.waveform-wrap {
    position: relative;
    margin-top: 20px;
    cursor: pointer;
    background: var(--wave-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

#waveform-inner {
    position: relative;
    height: 176px;
    overflow-x: auto;
}

.waveform-wrap canvas {
    display: block;
    height: 100%;
}

.waveform-time {
    position: absolute;
    top: -22px;
    right: 0;
    color: var(--dim);
    font-family: var(--mono);
    font-size: 12px;
    z-index: 2;
}

.playhead-line {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 2px;
    margin-left: -1px;
    background: var(--fg);
    pointer-events: none;
    z-index: 1;
}

.playhead-time {
    position: absolute;
    top: -22px;
    left: 0;
    transform: translateX(-50%);
    color: var(--field-fg);
    background: var(--field);
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 12px;
    white-space: nowrap;
    padding: 0 5px;
    pointer-events: none;
    z-index: 2;
}

/* ── Section lane ── */
#section-lane {
    position: relative;
    height: 30px;
    overflow: hidden;
    border-bottom: 1px solid var(--border);
}

#section-lane-content {
    position: relative;
    height: 100%;
}

.lane-block {
    position: absolute;
    top: 0;
    bottom: 0;
    background: var(--sec-a);
    color: var(--fg);
    font-size: 12px;
    font-weight: 600;
    line-height: 30px;
    padding-left: 8px;
    overflow: hidden;
    white-space: nowrap;
    cursor: pointer;
}

.lane-block.alt {
    background: var(--sec-b);
}

.lane-block:hover {
    filter: brightness(1.25);
}

.lane-block.skipped {
    background: repeating-linear-gradient(135deg, transparent 0 6px, var(--hatch) 6px 8px);
    color: var(--dim);
}

/* The handle is a wide invisible touch target around a thin visible line. */
.lane-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 28px;
    margin-left: -14px;
    cursor: col-resize;
    touch-action: none;
    z-index: 1;
}

.lane-handle::after {
    content: '';
    position: absolute;
    left: 13px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--accent);
}

.lane-handle::before {
    content: '';
    position: absolute;
    left: 9px;
    top: 9px;
    width: 10px;
    height: 12px;
    border-radius: 2px;
    background: var(--accent);
}

/* Ramp indicator in the section lane. Non-interactive: .lane-handle owns this
   x position, and two pointer targets there would fight. */
.lane-seam {
    position: absolute;
    top: 0;
    bottom: 0;
    pointer-events: none;
    opacity: 0.5;
}

.lane-seam.falling {
    background: linear-gradient(to right, var(--accent), transparent);
}

.lane-seam.rising {
    background: linear-gradient(to right, transparent, var(--accent));
}

/* ── Zoom ── */
.zoom-row {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--dim);
    font-size: 13px;
}

.zoom-row input[type='range'] {
    width: 180px;
    max-width: 50%;
    accent-color: var(--accent);
}

#zoom-value {
    font-family: var(--mono);
    font-size: 12px;
}

/* ── Buttons ── */
.player-bar-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.player-controls {
    flex-wrap: wrap;
}

.player-btn,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface2);
    color: var(--fg);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.player-btn:hover,
.btn:hover {
    border-color: var(--dim);
}

.player-btn.primary,
.btn.primary,
.btn-export {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.player-btn.primary:hover,
.btn.primary:hover,
.btn-export:hover {
    filter: brightness(1.08);
}

.btn-export:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: none;
}

#play-btn .icon-pause,
#play-btn.is-playing .icon-play {
    display: none;
}

#play-btn.is-playing .icon-pause {
    display: block;
}

/* ── Help panels ── */
.help {
    color: var(--dim);
    font-size: 13px;
}

.help summary {
    cursor: pointer;
    width: fit-content;
}

.help summary:hover {
    color: var(--fg);
}

.help ul {
    margin-top: 8px;
    padding-left: 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

kbd {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--fg);
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0 5px;
    margin-right: 4px;
}

/* ── Section table ── */
#segments-container {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow-x: auto;
}

.seg-header,
.segment-row {
    display: grid;
    grid-template-columns: 34px 64px repeat(3, minmax(100px, 1fr)) 52px;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    min-width: 520px;
}

.seg-header {
    color: var(--dim);
    font-size: 12px;
    padding-top: 8px;
    padding-bottom: 8px;
}

.segment-row:last-child {
    border-bottom: none;
}

.seg-idx {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    background: var(--sec-a);
    font-size: 13px;
    font-weight: 600;
}

.segment-row.alt .seg-idx {
    background: var(--sec-b);
}

.seg-header .seg-idx {
    background: none;
}

.seg-start,
.seg-end-static {
    color: var(--dim);
    font-family: var(--mono);
    font-size: 13px;
    white-space: nowrap;
}

.seg-field {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
}

.seg-header .seg-field,
.seg-header .seg-start {
    font-family: var(--font);
}

/* hide native number spinners; the steppers replace them */
input[type='number']::-webkit-outer-spin-button,
input[type='number']::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type='number'] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.seg-field input,
.seam-ctl input {
    width: 100%;
    min-width: 0;
    max-width: 72px;
    padding: 6px 4px;
    border: 1px solid #24282d;
    border-radius: 4px;
    background: var(--field);
    color: var(--field-fg);
    font-family: var(--mono);
    font-size: 14px;
    text-align: center;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.5);
}

.seg-field input:focus,
.seam-ctl input:focus {
    border-color: var(--accent);
    outline: none;
}

.stepper {
    flex-shrink: 0;
    width: 30px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface2);
    color: var(--fg);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

.stepper:hover {
    border-color: var(--dim);
}

.stepper:disabled {
    opacity: 0.35;
    cursor: default;
}

.segment-row.highlight {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.segment-row.skipped > :not(.seg-skip-col) {
    opacity: 0.4;
}

/* ── Skip switch ── */
.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    transition: background 0.15s;
}

.switch .slider::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--dim);
    transition: transform 0.15s, background 0.15s;
}

.switch input:checked + .slider {
    background: var(--accent);
    border-color: var(--accent);
}

.switch input:checked + .slider::before {
    transform: translateX(18px);
    background: var(--on-accent);
}

.switch input:focus-visible + .slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── Divider between two kept sections: merge + seam control ── */
.seg-merge-divider {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 6px 14px 6px 58px;
    border-bottom: 1px dashed var(--border);
    background: rgba(0, 0, 0, 0.12);
    min-width: 520px;
}

.btn-merge {
    border: 1px solid var(--border);
    border-radius: 4px;
    background: none;
    color: var(--dim);
    padding: 2px 10px;
    font-size: 12px;
    cursor: pointer;
}

.btn-merge:hover {
    color: var(--fg);
    border-color: var(--dim);
}

.seam-ctl {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
}

/* dimmed when the two section volumes match, so the ramp has nothing to do */
.seam-ctl.inactive {
    opacity: 0.45;
}

.seam-label,
.seam-unit {
    color: var(--dim);
    font-size: 12px;
}

.seam-label {
    margin-right: 4px;
}

.seam-ctl input {
    width: 52px;
    padding: 3px 4px;
    font-size: 12px;
}

.seam-ctl .stepper {
    width: 26px;
    height: 26px;
}

.seg-seam-curve {
    margin-left: 6px;
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface2);
    font-size: 12px;
}

.seg-notification {
    display: none;
    padding: 8px 12px;
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    background: var(--surface);
    font-size: 13px;
}

/* ── Output ── */
.output-row {
    display: flex;
    align-items: baseline;
    gap: 12px;
}

.output-label {
    color: var(--dim);
    font-size: 14px;
}

#predicted-duration-text {
    font-family: var(--mono);
    font-size: 20px;
    font-weight: 500;
}

.export-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px 20px;
}

.export-report-opt {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--dim);
    font-size: 14px;
    cursor: pointer;
}

.export-report-opt input {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

/* ── Status banner ── */
#status-banner {
    display: none;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-left: 3px solid var(--dim);
    border-radius: var(--radius);
    background: var(--surface);
    font-size: 14px;
}

.status-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

#status-banner a {
    color: var(--accent);
}

#status-banner.ok,
#status-banner.proc {
    border-left-color: var(--accent);
}

#status-banner.fail {
    border-left-color: var(--err);
    color: var(--err);
}

#progress-line {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--dim);
    font-size: 12px;
}

#progress-line:has(#progress-bar:not([hidden])) {
    margin-top: 10px;
}

#progress-bar {
    flex: 1;
    height: 8px;
    accent-color: var(--accent);
}

#progress-text {
    font-family: var(--mono);
    white-space: nowrap;
}

/* ── Returning-user modal: blocking overlay forcing an explicit choice ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0, 0, 0, 0.7);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-card {
    width: 100%;
    max-width: 420px;
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.modal-text {
    color: var(--dim);
    font-size: 14px;
    margin-bottom: 20px;
    word-break: break-word;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ── Phone layout ── */
@media (max-width: 600px) {
    body {
        padding-top: 16px;
    }

    .container {
        gap: 28px;
    }

    .upload-zone {
        padding: 28px 16px;
    }

    .upload-steps {
        flex-direction: column;
        align-items: flex-start;
        width: fit-content;
        margin-left: auto;
        margin-right: auto;
    }

    #waveform-inner {
        height: 150px;
    }

    .player-btn,
    .btn {
        min-height: 46px;
    }

    .player-controls {
        flex-wrap: nowrap;
        gap: 8px;
    }

    .player-controls .player-btn {
        flex: 1;
        min-width: 0;
        padding: 8px 6px;
        gap: 6px;
    }

    .btn-export {
        width: 100%;
    }

    /* Each section row becomes a card with labelled fields. */
    #segments-container {
        border: none;
        background: none;
        overflow: visible;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .seg-header {
        display: none;
    }

    .segment-row {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        min-width: 0;
        padding: 12px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--surface);
    }

    .segment-row:last-child {
        border-bottom: 1px solid var(--border);
    }

    .segment-row [data-label]::before {
        content: attr(data-label);
        display: block;
        flex-basis: 100%;
        color: var(--dim);
        font-family: var(--font);
        font-size: 12px;
    }

    .seg-start {
        display: flex;
        justify-content: flex-end;
        align-items: baseline;
        gap: 6px;
    }

    .segment-row .seg-start::before {
        flex-basis: auto;
    }

    .seg-field {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .seg-field input {
        flex: 1;
        max-width: none;
        padding: 10px 4px;
        font-size: 16px;
    }

    .stepper {
        width: 44px;
        height: 44px;
        font-size: 16px;
    }

    .seg-skip-col {
        align-content: flex-start;
    }

    .switch {
        width: 52px;
        height: 30px;
        margin-top: 7px;
    }

    .switch .slider {
        border-radius: 15px;
    }

    .switch .slider::before {
        width: 22px;
        height: 22px;
    }

    .switch input:checked + .slider::before {
        transform: translateX(22px);
    }

    .seg-merge-divider {
        min-width: 0;
        padding: 0 4px;
        border: none;
        background: none;
    }

    .seam-ctl {
        margin-left: 0;
        flex-wrap: wrap;
    }

    .seam-ctl .stepper {
        width: 36px;
        height: 36px;
    }

    .btn-merge {
        padding: 8px 14px;
    }
}

/* Very narrow phones: drop the transport icons so the three buttons fit, and
   stack section fields in one column so the numbers are not cut off. */
@media (max-width: 360px) {
    .player-controls .icon {
        display: none !important;
    }

    .segment-row {
        grid-template-columns: 1fr;
    }

    .seg-start {
        justify-content: flex-start;
    }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
