:root {
    --ink: #102338;
    --muted: #66778b;
    --paper: #f4f7fa;
    --panel: #ffffff;
    --line: #dbe3eb;
    --navy: #102b46;
    --navy-2: #183b5d;
    --cyan: #19b7c5;
    --cyan-dark: #078795;
    --amber: #f1ad3d;
    --danger: #c84b58;
    --success: #23835e;
    --shadow: 0 18px 45px rgba(21, 50, 78, .11);
    --radius: 18px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--paper);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--paper); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }

.gate-mode {
    background:
        radial-gradient(circle at 10% 10%, rgba(25, 183, 197, .22), transparent 26rem),
        radial-gradient(circle at 90% 90%, rgba(241, 173, 61, .18), transparent 28rem),
        var(--navy);
}

.gate-shell { min-height: 100vh; display: grid; place-items: center; padding: 32px 18px; }
.gate-card { width: min(100%, 560px); background: rgba(255,255,255,.98); border-radius: 28px; padding: 42px; box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.gate-card.compact { width: min(100%, 460px); }
.brand-mark { width: 64px; height: 64px; border-radius: 19px; display: grid; place-items: center; color: white; font-weight: 900; letter-spacing: -.05em; background: linear-gradient(135deg, var(--cyan), var(--cyan-dark)); box-shadow: 0 12px 24px rgba(25,183,197,.26); }
.brand-mark.small { width: 44px; height: 44px; border-radius: 13px; font-size: 14px; }
.eyebrow { margin: 0 0 5px; color: var(--cyan-dark); text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 800; }
.gate-card h1 { margin: 18px 0 8px; font-size: clamp(28px, 5vw, 42px); line-height: 1.05; letter-spacing: -.035em; }
.gate-version { color: var(--cyan-dark); font-size: .48em; font-weight: 800; letter-spacing: 0; white-space: nowrap; }
.lead { color: var(--muted); line-height: 1.6; }
.gate-form { display: grid; gap: 18px; margin-top: 28px; }
label { display: grid; gap: 8px; font-size: 13px; font-weight: 700; color: var(--ink); }
input[type="text"], input[type="password"], input[type="search"], input[type="url"], .path-preview input {
    width: 100%; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 11px; padding: 11px 13px; outline: none;
}
input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(25,183,197,.13); }
.path-preview { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 11px; background: #f7fafc; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 600; }
.path-preview input { border: 0; padding: 5px 7px; min-width: 80px; }
.path-preview input:focus { box-shadow: none; }
.field-help { color: var(--muted); font-size: 12px; line-height: 1.5; margin: -9px 0 0; }
.password-context { display: grid; gap: 4px; margin: 13px 0 1px; padding: 12px 14px; color: var(--muted); background: #f0f7f9; border-left: 4px solid var(--cyan); border-radius: 9px; font-size: 12px; line-height: 1.5; }
.password-context strong { color: var(--ink); font-size: 13px; }
.password-context span { display: block; }
.notice { border-radius: 11px; padding: 12px 14px; margin-top: 18px; font-size: 13px; }
.notice.error { background: #fff0f1; color: #9a2f3b; border: 1px solid #f3c7cc; }

.primary, .secondary, .ghost, .control, .file-button, .danger-text, .filter, .nudge-row button {
    border: 0; border-radius: 11px; padding: 10px 15px; font-weight: 750; transition: transform .15s ease, background .15s ease, color .15s ease, border-color .15s ease;
}
.primary { background: var(--cyan-dark); color: white; box-shadow: 0 8px 18px rgba(7,135,149,.18); }
.primary:hover:not(:disabled) { background: #066f7a; transform: translateY(-1px); }
.primary.full { width: 100%; padding: 13px; }
.primary.large { min-height: 48px; }
.secondary { background: #e8f5f7; color: #087782; }
.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.ghost:hover:not(:disabled) { color: var(--ink); border-color: #aab8c6; }
.danger-text { background: #fff1f2; color: var(--danger); }

.app-shell { height: 100vh; display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) auto; overflow: hidden; }
.topbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 12px 24px; color: white; background: var(--navy); }
.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-lockup h1 { margin: 0; font-size: 21px; letter-spacing: -.025em; }
.brand-version { display: inline-block; margin-left: 5px; color: #58dbe4; font-size: 12px; font-weight: 800; letter-spacing: 0; vertical-align: 2px; }
.brand-lockup p { margin: 2px 0 0; color: #a9bed0; font-size: 12px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.top-actions form { margin: 0; }
.top-actions .ghost { color: #d7e4ef; border-color: rgba(255,255,255,.2); padding: 8px 11px; }

.workspace-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 24px; background: white; border-bottom: 1px solid var(--line); }
.csv-workflow { margin: 0; padding: 8px 24px; color: var(--muted); background: #f8fafc; border-bottom: 1px solid var(--line); font-size: 11px; line-height: 1.45; text-align: right; }
.upload-zone { display: flex; align-items: center; gap: 14px; min-width: 0; }
.upload-zone > div { display: grid; min-width: 0; }
.upload-zone strong, .upload-zone span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-zone strong { font-size: 13px; }
.upload-zone span { font-size: 11px; color: var(--muted); margin-top: 3px; }
.file-button { display: inline-flex; align-items: center; background: var(--navy-2); color: white; white-space: nowrap; }
.file-button:hover { background: var(--navy); }
.file-button input { display: none; }
.save-actions { display: flex; align-items: center; gap: 10px; }
.save-state { color: var(--muted); font-size: 12px; white-space: nowrap; }
.save-state.dirty { color: #a46400; font-weight: 750; }

.main-grid { min-height: 0; display: grid; grid-template-columns: minmax(360px, 42%) 1fr; gap: 0; }
.library-panel { min-height: 0; display: flex; flex-direction: column; background: #fbfcfd; border-right: 1px solid var(--line); }
.library-head { display: grid; grid-template-columns: 1fr minmax(160px, 45%); gap: 14px; align-items: center; padding: 20px 20px 12px; }
.library-head h2 { margin: 0; font-size: 22px; }
.filters { display: flex; gap: 6px; overflow-x: auto; padding: 0 20px 13px; scrollbar-width: thin; }
.filter { padding: 7px 9px; color: var(--muted); background: white; border: 1px solid var(--line); white-space: nowrap; font-size: 11px; }
.filter span { display: inline-grid; min-width: 19px; height: 19px; padding: 0 4px; place-items: center; border-radius: 9px; background: #eef2f6; margin-left: 3px; }
.filter.active { background: var(--navy); border-color: var(--navy); color: white; }
.filter.active span { background: rgba(255,255,255,.14); }
.track-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px 18px; }
.track-item { width: 100%; display: grid; grid-template-columns: 42px 1fr auto; gap: 11px; align-items: center; border: 0; border-bottom: 1px solid #e9eef3; background: transparent; text-align: left; padding: 12px 10px; color: var(--ink); }
.track-item:hover { background: #eef7f8; }
.track-item.active { background: #e2f4f6; border-radius: 12px; border-bottom-color: transparent; }
.track-item.changed .track-index::after { content: ""; display: block; width: 6px; height: 6px; border-radius: 50%; background: var(--amber); margin: 3px auto 0; }
.track-index { color: #8a99a8; font-size: 11px; text-align: center; font-variant-numeric: tabular-nums; }
.track-main { min-width: 0; display: grid; gap: 3px; }
.track-main strong, .track-main span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-main strong { font-size: 13px; }
.track-main span { font-size: 12px; color: var(--muted); font-weight: 600; }
.track-main .track-file { display: block; min-width: 0; color: #6d7f91; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-marker { min-width: 70px; color: var(--cyan-dark); background: #e5f6f7; border-radius: 8px; padding: 5px 7px; font-size: 11px; font-weight: 800; text-align: center; font-variant-numeric: tabular-nums; }
.track-marker.empty { color: #8c9aa8; background: #eef2f5; }
.track-marker.missing { color: var(--danger); background: #fff0f1; }
.no-results { color: var(--muted); text-align: center; padding: 42px 20px; font-size: 13px; }

.editor-panel { min-width: 0; min-height: 0; overflow-y: auto; padding: 30px clamp(22px, 4vw, 56px); background: radial-gradient(circle at top right, rgba(25,183,197,.06), transparent 28rem), white; }
.editor-content { max-width: 820px; margin: 0 auto; }
.now-playing { display: grid; grid-template-columns: 50px 1fr auto; gap: 15px; align-items: center; }
.track-number { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 15px; color: white; background: var(--navy); font-weight: 850; }
.track-copy { min-width: 0; }
.track-copy h2 { margin: 0; font-size: clamp(24px, 3vw, 38px); line-height: 1.1; letter-spacing: -.035em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track-copy > p:last-child { margin: 6px 0 0; color: var(--muted); font-size: clamp(18px, 2vw, 24px); font-weight: 650; }
.file-status { padding: 7px 10px; border-radius: 9px; background: #eaf7f1; color: var(--success); font-size: 11px; font-weight: 800; white-space: nowrap; }
.file-status.missing { background: #fff0f1; color: var(--danger); }

.time-card { margin: 28px 0 12px; display: grid; grid-template-columns: 1fr 1.2fr 1fr; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.time-card > div { display: grid; justify-items: center; gap: 6px; padding: 20px 10px; background: white; }
.time-card > div + div { border-left: 1px solid var(--line); }
.time-card span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .09em; font-weight: 800; }
.time-card strong { font-size: clamp(20px, 3vw, 32px); font-variant-numeric: tabular-nums; letter-spacing: -.025em; }
.time-card .marker-display { background: var(--navy); color: white; }
.time-card .marker-display span { color: #a9c3d8; }
.time-card .marker-display strong { color: #58dbe4; }

.timeline-wrap { padding: 12px 0 16px; }
input[type="range"] { width: 100%; accent-color: var(--cyan-dark); cursor: pointer; }
.transport-row { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 10px; }
.play-button { width: 62px; height: 62px; display: grid; place-items: center; border: 0; border-radius: 50%; color: white; background: var(--cyan-dark); font-size: 23px; box-shadow: 0 12px 26px rgba(7,135,149,.26); }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 50%; background: white; color: var(--navy); font-size: 27px; line-height: 1; }
.control { background: #eef2f5; color: var(--ink); }
.control.accent { background: #e4f6f7; color: var(--cyan-dark); }

.nudge-card { margin-top: 26px; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; background: #f8fafc; }
.nudge-card p { text-align: center; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .1em; font-weight: 850; margin: 0 0 12px; }
.nudge-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.nudge-row button { background: white; border: 1px solid var(--line); color: var(--ink); padding: 9px 6px; }
.nudge-row button:hover:not(:disabled) { border-color: var(--cyan); color: var(--cyan-dark); }
.marker-section-title { margin: 24px 0 10px; color: var(--danger); text-align: center; font-size: 15px; font-weight: 900; letter-spacing: .1em; }
.marker-actions { margin-top: 20px; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.file-details { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; }
.file-details > div { min-width: 0; padding: 11px 13px; background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; }
.file-details span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.file-details code, .file-details a { display: block; color: #536172; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 11px; overflow-wrap: anywhere; }
.file-details a { color: var(--cyan-dark); text-decoration: underline; text-underline-offset: 2px; }

.statusbar { display: flex; justify-content: space-between; gap: 20px; padding: 8px 24px; color: #8ea3b5; background: var(--navy); font-size: 10px; }
dialog { width: min(92vw, 520px); border: 0; border-radius: 22px; padding: 0; box-shadow: 0 30px 90px rgba(0,0,0,.32); }
dialog::backdrop { background: rgba(8,25,42,.62); backdrop-filter: blur(4px); }
.dialog-card { display: grid; gap: 20px; padding: 26px; margin: 0; }
.dialog-head { display: flex; justify-content: space-between; align-items: start; gap: 15px; }
.dialog-head h2 { margin: 0; }
.dialog-close { width: 34px; height: 34px; border: 0; border-radius: 50%; background: #eef2f5; color: var(--muted); font-size: 22px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.shortcut-list { display: grid; grid-template-columns: 130px 1fr; gap: 9px 14px; margin: 0; }
.shortcut-list dt { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-weight: 850; color: var(--cyan-dark); }
.shortcut-list dd { margin: 0; color: var(--muted); }
.toast-stack { position: fixed; right: 18px; bottom: 28px; z-index: 100; display: grid; gap: 9px; width: min(390px, calc(100vw - 36px)); }
.toast { padding: 13px 15px; border-radius: 12px; color: white; background: var(--navy); box-shadow: var(--shadow); font-size: 13px; animation: toast-in .2s ease-out; }
.toast.error { background: #a53542; }
.toast.success { background: #217655; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 900px) {
    .app-shell { height: auto; min-height: 100vh; overflow: visible; }
    .main-grid { grid-template-columns: 1fr; grid-template-rows: minmax(330px, 44vh) auto; }
    .library-panel { border-right: 0; border-bottom: 1px solid var(--line); }
    .editor-panel { overflow: visible; }
    .workspace-toolbar { align-items: stretch; flex-direction: column; }
    .save-actions { justify-content: flex-end; }
}

@media (max-width: 620px) {
    .topbar { align-items: flex-start; padding: 12px 14px; }
    .brand-lockup p { display: none; }
    .top-actions { flex-wrap: wrap; justify-content: flex-end; }
    .top-actions .ghost { font-size: 11px; padding: 7px 8px; }
    .workspace-toolbar { padding: 12px 14px; }
    .upload-zone { align-items: flex-start; }
    .save-actions { flex-wrap: wrap; }
    .save-state { width: 100%; text-align: right; }
    .library-head { grid-template-columns: 1fr; }
    .editor-panel { padding: 24px 14px; }
    .now-playing { grid-template-columns: 44px 1fr; }
    .file-status { grid-column: 2; justify-self: start; }
    .time-card { grid-template-columns: 1fr; }
    .file-details { grid-template-columns: 1fr; }
    .time-card > div + div { border-left: 0; border-top: 1px solid var(--line); }
    .nudge-row { grid-template-columns: repeat(3, 1fr); }
    .transport-row .control { font-size: 11px; padding: 9px; }
    .gate-card { padding: 30px 22px; }
}
