:root {
    --bg: #0f1420;
    --surface: #161c2c;
    --surface-2: #1d2436;
    --surface-3: #232b40;
    --line: #2a3349;
    --line-strong: #36405b;
    --text: #e7ecf5;
    --text-mute: #99a3b8;
    --text-dim: #6b7590;
    --accent: #4a90ff;
    --danger: #ff6b6b;
    --seg-warmup: #7ee0c8;
    --seg-walking: #4cc78a;
    --seg-running: #f1c218;
    --seg-sprinting: #ff7a3d;
    --seg-cooldown: #5d9bff;
    --seg-custom: #99a3b8;

    --row-cols: 24px 22px 150px 110px 90px 156px 200px 1fr 76px;
    --row-gap: 18px;
}

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

html, body {
    margin: 0;
    padding: 0;
    background: #0a0d14;
    color: var(--text);
    font-family: 'Geist', -apple-system, system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

input, textarea {
    font-family: inherit;
    color: var(--text);
}

.editor-main {
    max-width: 1180px;
    margin: 0 auto;
    padding: 32px 24px 48px;
}

.editor-card {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
}

.card-back {
    padding: 14px 20px 0;
    font-size: 12px;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 12px;
}
.card-back a { color: var(--text-dim); }
.card-back a:hover { color: var(--text); text-decoration: none; }

.language-switcher {
    margin-left: auto;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    outline: none;
}
.language-switcher:focus { border-color: var(--accent); }

.card-title {
    padding: 4px 20px 14px;
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
}

.editor-toolbar {
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 12px;
    align-items: center;
}

#program-name {
    flex: 1;
    padding: 11px 14px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text);
    outline: none;
    transition: border-color 120ms;
}
#program-name::placeholder { color: var(--text-mute); }
#program-name:focus { border-color: var(--accent); }

.seg-toggle {
    display: inline-flex;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 2px;
}
.seg-toggle button {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    border: 0;
    background: transparent;
    color: var(--text-mute);
    border-radius: 6px;
    cursor: pointer;
    text-transform: capitalize;
}
.seg-toggle button.active {
    background: var(--accent);
    color: #fff;
}

.overview-section {
    padding: 20px 20px 8px;
}
.overview-bar {
    display: flex;
    height: 64px;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface-2);
}
.overview-bar > .ov-seg {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #0a0d14;
    font-size: 11px;
    font-weight: 600;
    overflow: hidden;
    border-right: 1px solid rgba(0,0,0,0.18);
    min-width: 0;
}
.overview-bar > .ov-seg:last-child { border-right: 0; }
.overview-bar > .ov-seg .ov-label {
    display: flex;
    align-items: center;
    gap: 5px;
    opacity: 0.85;
    white-space: nowrap;
}
.overview-bar > .ov-seg .ov-label .seg-icon-svg {
    width: 12px; height: 12px;
}
.overview-ticks {
    position: relative;
    height: 18px;
    margin-top: 4px;
}
.overview-ticks .tick {
    position: absolute;
    transform: translateX(-50%);
    font-size: 9.5px;
    color: var(--text-dim);
    font-family: 'Geist Mono', monospace;
}

.segments-section {
    padding: 8px 20px 6px;
}
.segments-header {
    display: grid;
    grid-template-columns: var(--row-cols);
    column-gap: var(--row-gap);
    padding: 6px 14px;
    font-size: 9.5px;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--text-dim);
    font-weight: 600;
    border-bottom: 1px solid var(--line);
}

.segments-area {
    display: flex;
    flex-direction: column;
}

.editor-row {
    display: grid;
    grid-template-columns: var(--row-cols);
    column-gap: var(--row-gap);
    padding: 14px 14px;
    align-items: flex-start;
    border-bottom: 1px solid var(--line);
    border-left: 3px solid transparent;
    margin-left: -3px;
    background: transparent;
    transition: background 120ms;
}
.editor-row.dragging { opacity: 0.4; }
.editor-row.drag-target { background: rgba(74,144,255,0.12); }
.editor-row.expanded {
    padding: 20px 14px;
    background: rgba(74,144,255,0.07);
    border-left-color: var(--accent);
}

.cell-top {
    display: flex;
    align-items: center;
    min-height: 34px;
}

.cell-index {
    color: var(--text-dim);
    font-size: 12px;
    font-family: 'Geist Mono', monospace;
}
.editor-row.expanded .cell-index { color: var(--accent); font-weight: 600; }

.drag-handle {
    color: var(--text-dim);
    cursor: grab;
    line-height: 0.5;
    font-size: 14px;
    letter-spacing: -2px;
    user-select: none;
}
.drag-handle:active { cursor: grabbing; }

.seg-pill-wrap {
    width: 100%;
    min-height: 34px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
}
.seg-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    border-radius: 999px;
    color: #0a0d14;
    font-weight: 600;
    font-size: 12px;
    letter-spacing: 0.2px;
    white-space: nowrap;
    width: 100%;
    justify-content: flex-start;
    border: 0;
    cursor: pointer;
    box-sizing: border-box;
}
.seg-pill .seg-pill-icon {
    width: 14px; height: 14px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.seg-pill .seg-pill-icon .material-symbols-outlined { font-size: 14px; }
.seg-pill .seg-pill-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.seg-pill .seg-pill-caret { opacity: 0.55; font-size: 9px; }

.seg-custom-controls {
    display: flex;
    gap: 4px;
    align-items: center;
}
.seg-custom-controls .custom-name {
    flex: 1;
    min-width: 0;
    padding: 5px 8px;
    background: var(--surface-3);
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 11px;
    color: var(--text);
    outline: none;
}
.seg-custom-controls .custom-name:focus { border-color: var(--accent); }
.seg-color-btn, .seg-icon-btn {
    width: 26px; height: 26px;
    border-radius: 6px;
    border: 1px solid var(--line);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    background: var(--surface-3);
    color: var(--text-dim);
    padding: 0;
}
.seg-icon-btn .material-symbols-outlined { font-size: 16px; color: var(--text); }

.full-input {
    display: flex;
    align-items: baseline;
    gap: 4px;
    width: 100%;
    padding: 7px 10px;
    background: var(--surface-3);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text);
    transition: border-color 120ms;
    box-sizing: border-box;
}
.full-input:focus-within { border-color: var(--accent); }
.full-input input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: 0;
    outline: 0;
    color: var(--text);
    font: inherit;
    font-family: 'Geist Mono', monospace;
    padding: 0;
    -moz-appearance: textfield;
}
.full-input input::-webkit-outer-spin-button,
.full-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.full-input input.text-input { font-family: inherit; }
.full-input .suffix {
    color: var(--text-dim);
    font-size: 11px;
    margin-left: auto;
    font-family: 'Geist', sans-serif;
}

.mode-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    background: var(--surface-3);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 2px;
    width: 100%;
}
.mode-toggle button {
    padding: 8px 0;
    border: 0;
    background: transparent;
    text-align: center;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    color: var(--text-mute);
    cursor: pointer;
    line-height: 1.2;
}
.mode-toggle button.active {
    background: var(--accent);
    color: #fff;
}

.value-cell {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}
.value-cell .value-sub {
    font-size: 10.5px;
    color: var(--text-dim);
    padding-left: 2px;
}

.row-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}
.icon-btn {
    width: 32px; height: 32px;
    border-radius: 8px;
    background: var(--surface-3);
    border: 1px solid var(--line);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    padding: 0;
    transition: border-color 120ms, color 120ms, background 120ms;
}
.icon-btn svg { width: 16px; height: 16px; display: block; }
.icon-btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: rgba(255,107,107,0.08); }

.add-segment-btn {
    margin-top: 12px;
    width: 100%;
    padding: 12px;
    text-align: center;
    border: 1.5px dashed var(--line-strong);
    border-radius: 10px;
    color: var(--text-mute);
    font-size: 12px;
    background: transparent;
    cursor: pointer;
    transition: border-color 120ms, color 120ms;
}
.add-segment-btn:hover { border-color: var(--accent); color: var(--text); }

.stat-cards {
    padding: 14px 20px 18px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
.stat-card {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.stat-card .stat-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-dim);
    letter-spacing: 1.2px;
    text-transform: uppercase;
}
.stat-card .stat-value {
    font-size: 22px;
    font-weight: 600;
    font-family: 'Geist Mono', monospace;
}

.editor-footer {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 14px 20px;
    border-top: 1px solid var(--line);
    background: var(--surface);
}
.footer-spacer { flex: 1; }
.btn {
    padding: 9px 14px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background: var(--surface-3);
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
}
.btn:hover { border-color: var(--accent); }
.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}
.btn-primary:hover { background: #5a9aff; }
.btn:disabled, .btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.error-banner {
    margin: 12px 20px 18px;
    padding: 10px 14px;
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.4);
    border-radius: 8px;
    color: var(--danger);
    font-size: 13px;
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 16px;
    background: var(--surface-3);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
    font-size: 13px;
    z-index: 1000;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal[hidden] { display: none; }
.modal-content {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px;
    width: min(520px, 90vw);
}
.modal-content h3 {
    margin: 0 0 12px;
    font-size: 16px;
    font-weight: 600;
}
.modal-content textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    font-family: 'Geist Mono', monospace;
    font-size: 12px;
    color: var(--text);
    outline: none;
    resize: vertical;
}
.modal-content textarea:focus { border-color: var(--accent); }
.import-error {
    color: var(--danger);
    font-size: 12px;
    margin: 8px 0;
    min-height: 16px;
}
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.popover {
    position: absolute;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    padding: 8px;
    z-index: 50;
    box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}
.preset-popover {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 160px;
}
.preset-choice {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    color: #0a0d14;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    text-align: left;
}
.preset-choice .material-symbols-outlined { font-size: 16px; }
.preset-choice.active {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
.color-popover {
    display: grid;
    grid-template-columns: repeat(7, 24px);
    gap: 6px;
    padding: 10px;
}
.color-swatch {
    width: 24px; height: 24px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.1);
    cursor: pointer;
    padding: 0;
}
.color-swatch.active { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-popover { display: flex; flex-direction: column; gap: 8px; min-width: 220px; }
.icon-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
}
.icon-choice {
    width: 32px; height: 32px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.icon-choice .material-symbols-outlined { font-size: 18px; }
.icon-choice.active { border-color: var(--accent); }
.icon-custom { display: flex; gap: 6px; }
.icon-custom input {
    flex: 1;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12px;
    color: var(--text);
    outline: none;
}
.icon-custom input:focus { border-color: var(--accent); }

@media (max-width: 920px) {
    :root {
        --row-cols: 24px 22px 130px 90px 80px 130px 1fr 0 76px;
        --row-gap: 12px;
    }
    .editor-main { padding: 16px 12px 32px; }
    .stat-cards { grid-template-columns: repeat(2, 1fr); }
    .card-title { font-size: 18px; }
}

@media (max-width: 640px) {
    .segments-header { display: none; }
    .editor-row {
        display: grid;
        grid-template-columns: auto 1fr auto;
        grid-template-areas:
            "idx pill actions"
            "drag speed incline"
            "drag mode mode"
            "drag value value";
        column-gap: 10px;
        row-gap: 8px;
        padding: 14px 10px;
    }
    .editor-row.expanded { padding: 16px 10px; }
    .editor-row > :nth-child(1) { grid-area: idx; }
    .editor-row > :nth-child(2) { grid-area: drag; }
    .editor-row > :nth-child(3) { grid-area: pill; }
    .editor-row > :nth-child(4) { grid-area: speed; }
    .editor-row > :nth-child(5) { grid-area: incline; }
    .editor-row > :nth-child(6) { grid-area: mode; }
    .editor-row > :nth-child(7) { grid-area: value; }
    .editor-row > :nth-child(8) { display: none; }
    .editor-row > :nth-child(9) { grid-area: actions; }
    .editor-toolbar { flex-wrap: wrap; }
    .editor-footer { flex-wrap: wrap; }
    .footer-spacer { display: none; }
    .stat-cards { grid-template-columns: repeat(2, 1fr); padding: 12px; }
    .stat-card { padding: 10px 12px; }
    .stat-card .stat-value { font-size: 18px; }
}
