/* Dark glass + neon theme. Every colour has a literal fallback before the var(). */
:root {
    color-scheme: dark;
    --bg-0: #05060f;
    --bg-1: #0b0f24;
    --glass: rgba(18, 24, 52, 0.55);
    --glass-solid: #121834;
    --glass-strong: rgba(24, 32, 68, 0.72);
    --glass-border: rgba(120, 160, 255, 0.18);
    --text: #e6ecff;
    --text-dim: #9aa6c8;
    --text-faint: #6b7699;
    --cyan: #00f0ff;
    --magenta: #ff2bd6;
    --violet: #8a5cff;
    --lime: #3dffa8;
    --amber: #ffc53d;
    --red: #ff4d6d;
    --radius: 14px;
    --radius-sm: 9px;
    --glow-cyan: 0 0 0 1px rgba(0, 240, 255, 0.55), 0 0 18px rgba(0, 240, 255, 0.35);
    --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
    font-family: var(--font);
    color: #e6ecff;
    color: var(--text);
    background-color: #05060f;
    background-color: var(--bg-0);
    background-image:
        radial-gradient(1200px 600px at 10% -10%, rgba(138, 92, 255, 0.28), transparent 60%),
        radial-gradient(900px 500px at 110% 10%, rgba(0, 240, 255, 0.18), transparent 60%),
        radial-gradient(800px 600px at 50% 120%, rgba(255, 43, 214, 0.16), transparent 60%),
        linear-gradient(180deg, #05060f 0%, #0b0f24 100%);
    background-attachment: fixed;
    min-height: 100vh;
    padding: 32px 16px;
    line-height: 1.45;
    overflow-x: hidden;
}

/* Subtle grid overlay */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(120, 160, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(120, 160, 255, 0.05) 1px, transparent 1px);
    background-size: 40px 40px;
    -webkit-mask-image: linear-gradient(180deg, #000 0%, transparent 80%);
    mask-image: linear-gradient(180deg, #000 0%, transparent 80%);
    z-index: -1;
}

.container, .panel {
    position: relative;
    width: 100%;
    max-width: 680px;
    margin: 0 auto;
    padding: 36px;
    border-radius: 14px;
    border-radius: var(--radius);
    background: #121834;
    background: var(--glass-solid);
    border: 1px solid rgba(120, 160, 255, 0.18);
    border: 1px solid var(--glass-border);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .container, .panel, .modal-content {
        background: var(--glass);
        -webkit-backdrop-filter: blur(22px) saturate(140%);
        backdrop-filter: blur(22px) saturate(140%);
    }
}

/* Neon edge on top of the card */
.container::before, .panel::before {
    content: "";
    position: absolute;
    left: 24px; right: 24px; top: -1px;
    height: 2px;
    border-radius: 2px;
    background: linear-gradient(90deg, transparent, var(--cyan), var(--magenta), transparent);
    box-shadow: 0 0 14px rgba(0, 240, 255, 0.6);
}

.panel { margin-top: 24px; padding: 24px 36px; }

h1 {
    margin-bottom: 28px;
    font-size: clamp(22px, 5vw, 30px);
    font-weight: 800;
    letter-spacing: 0.5px;
    text-align: center;
    color: #00f0ff;
    background: linear-gradient(90deg, #00f0ff, #8a5cff 50%, #ff2bd6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 12px rgba(0, 240, 255, 0.35));
}

.form-section { margin-bottom: 28px; }

.form-section h2, .panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #00f0ff;
    color: var(--cyan);
    text-shadow: 0 0 10px rgba(0, 240, 255, 0.5);
}

.form-section h2::after {
    content: "";
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, rgba(0, 240, 255, 0.45), transparent);
}

.form-group { margin-bottom: 18px; min-width: 0; }

label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 500;
    color: #9aa6c8;
    color: var(--text-dim);
}

input, select, textarea {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 11px 13px;
    font: inherit;
    font-size: 16px; /* prevents iOS zoom on focus */
    color: #e6ecff;
    color: var(--text);
    background: rgba(5, 8, 22, 0.6);
    border: 1px solid rgba(120, 160, 255, 0.22);
    border-radius: 9px;
    border-radius: var(--radius-sm);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

@media (min-width: 600px) { input, select, textarea { font-size: 14px; } }

input::placeholder { color: #6b7699; color: var(--text-faint); opacity: 1; }

select {
    padding-right: 34px;
    background-image: linear-gradient(45deg, transparent 50%, #00f0ff 50%), linear-gradient(135deg, #00f0ff 50%, transparent 50%);
    background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
}

select option { background: #0b0f24; color: #e6ecff; }

input[type="date"], input[type="time"] { min-height: 44px; }
input::-webkit-calendar-picker-indicator { filter: invert(1) hue-rotate(160deg); opacity: 0.8; cursor: pointer; }

input[type="file"] { padding: 9px; cursor: pointer; color: var(--text-dim); }
input[type="file"]::file-selector-button {
    margin-right: 12px;
    padding: 7px 14px;
    font: inherit;
    font-size: 13px;
    color: #00f0ff;
    background: rgba(0, 240, 255, 0.08);
    border: 1px solid rgba(0, 240, 255, 0.45);
    border-radius: 7px;
    cursor: pointer;
}

input:hover, select:hover, textarea:hover { border-color: rgba(0, 240, 255, 0.4); }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #00f0ff;
    background: rgba(5, 8, 22, 0.8);
    box-shadow: 0 0 0 1px rgba(0, 240, 255, 0.55), 0 0 18px rgba(0, 240, 255, 0.35);
}

input:user-invalid:not(:focus) { border-color: rgba(255, 77, 109, 0.7); }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
    gap: 14px;
}

.radio-group { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }

.radio-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 9px 16px;
    font-size: 14px;
    color: #e6ecff;
    color: var(--text);
    background: rgba(5, 8, 22, 0.45);
    border: 1px solid rgba(120, 160, 255, 0.2);
    border-radius: 999px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    user-select: none;
}

.radio-group label:hover { border-color: rgba(0, 240, 255, 0.5); }

.radio-group input[type="radio"] {
    width: 16px;
    height: 16px;
    padding: 0;
    flex: none;
    border: 2px solid #6b7699;
    border-radius: 50%;
    background: transparent;
    cursor: pointer;
}

.radio-group input[type="radio"]:checked {
    border-color: #00f0ff;
    background: radial-gradient(circle, #00f0ff 45%, transparent 50%);
    box-shadow: 0 0 10px rgba(0, 240, 255, 0.7);
}

.radio-group label:has(input:checked) {
    border-color: #00f0ff;
    background: rgba(0, 240, 255, 0.08);
    box-shadow: 0 0 16px rgba(0, 240, 255, 0.2);
}

.conditional { display: none; }
.conditional.show { display: block; }

.hint, .splits-hint {
    margin-bottom: 14px;
    font-size: 13px;
    line-height: 1.55;
    color: #9aa6c8;
    color: var(--text-dim);
    overflow-wrap: anywhere;
}

.gpx-preview { display: none; margin-top: 10px; font-size: 13px; color: #3dffa8; text-shadow: 0 0 8px rgba(61, 255, 168, 0.5); }

/* Splits table */
.splits-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid rgba(120, 160, 255, 0.14);
    border-radius: 9px;
    background: rgba(5, 8, 22, 0.35);
}

.splits-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.splits-table th {
    padding: 9px 6px;
    text-align: left;
    white-space: nowrap;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #ff2bd6;
    color: var(--magenta);
    text-shadow: 0 0 8px rgba(255, 43, 214, 0.45);
    border-bottom: 1px solid rgba(255, 43, 214, 0.25);
}

.splits-table td { padding: 5px; border-bottom: 1px solid rgba(120, 160, 255, 0.08); }
.splits-table tbody tr:hover { background: rgba(0, 240, 255, 0.04); }

.splits-table input { min-width: 64px; padding: 7px 6px; font-size: 13px; }

.splits-table .split-index, .splits-table .split-pace {
    white-space: nowrap;
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    color: #9aa6c8;
    color: var(--text-dim);
}

.splits-table .col-cadence, .splits-table .col-power { display: none; }
.splits-table.show-cadence .col-cadence, .splits-table.show-power .col-power { display: table-cell; }

.splits-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.splits-total { margin-top: 12px; font-size: 13px; font-family: var(--mono); color: #3dffa8; }
.splits-total.mismatch { color: #ff4d6d; text-shadow: 0 0 8px rgba(255, 77, 109, 0.5); }

/* Buttons */
button {
    flex: 1;
    padding: 12px 22px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.4px;
    color: #e6ecff;
    color: var(--text);
    background: rgba(5, 8, 22, 0.5);
    border: 1px solid rgba(120, 160, 255, 0.28);
    border-radius: 9px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s, background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

button:hover { border-color: #00f0ff; box-shadow: 0 0 16px rgba(0, 240, 255, 0.3); }
button:active { transform: translateY(1px); }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
    outline: 2px solid #00f0ff;
    outline-offset: 2px;
}
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-block { display: block; width: 100%; margin-top: 10px; }

.btn-split { flex: 0 1 auto; padding: 8px 14px; font-size: 13px; }

.btn-split-clear, .btn-remove-split { color: #ff4d6d; }
.btn-split-clear { margin-left: auto; border-color: rgba(255, 77, 109, 0.35); }
.btn-split-clear:hover { border-color: #ff4d6d; box-shadow: 0 0 16px rgba(255, 77, 109, 0.35); }

.btn-remove-split {
    flex: none;
    padding: 4px 9px;
    font-size: 16px;
    line-height: 1;
    background: none;
    border: none;
}
.btn-remove-split:hover { box-shadow: none; text-shadow: 0 0 8px #ff4d6d; }

.button-group { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }
.button-group > button { min-width: 160px; }

.btn-verify { color: #00f0ff; border-color: rgba(0, 240, 255, 0.45); }

.btn-save, .btn-neon {
    color: #05060f;
    background: #00f0ff;
    background: linear-gradient(90deg, #00f0ff, #8a5cff 55%, #ff2bd6);
    border: none;
    box-shadow: 0 0 18px rgba(138, 92, 255, 0.45);
    text-shadow: none;
}
.btn-save:hover, .btn-neon:hover {
    transform: translateY(-2px);
    box-shadow: 0 0 26px rgba(0, 240, 255, 0.55), 0 0 40px rgba(255, 43, 214, 0.35);
}
.btn-neon { flex: 0 1 auto; }

/* Alerts */
.alert {
    display: none;
    margin-bottom: 18px;
    padding: 14px 16px;
    font-size: 14px;
    border-radius: 9px;
    border: 1px solid;
    overflow-wrap: anywhere;
}
.alert.error   { display: block; color: #ff9aae; background: rgba(255, 77, 109, 0.1);  border-color: rgba(255, 77, 109, 0.5);  box-shadow: 0 0 18px rgba(255, 77, 109, 0.15); }
.alert.warning { display: block; color: #ffe08a; background: rgba(255, 197, 61, 0.1); border-color: rgba(255, 197, 61, 0.5); box-shadow: 0 0 18px rgba(255, 197, 61, 0.12); }
.alert.success { display: block; color: #9dffd2; background: rgba(61, 255, 168, 0.1); border-color: rgba(61, 255, 168, 0.5); box-shadow: 0 0 18px rgba(61, 255, 168, 0.15); }
.alert ul, .alert ol { margin: 8px 0 0 20px; }
.alert li { margin-bottom: 4px; }
.alert strong { color: inherit; }

/* Device picker */
.device-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); gap: 10px; }

.device-button {
    flex: none;
    min-width: 0;
    padding: 11px 12px;
    text-align: left;
    font-size: 13px;
    font-weight: 400;
    background: rgba(5, 8, 22, 0.5);
    border: 1px solid rgba(120, 160, 255, 0.2);
}
.device-button:hover { border-color: rgba(0, 240, 255, 0.6); }
.device-button.selected {
    border-color: #00f0ff;
    background: rgba(0, 240, 255, 0.1);
    box-shadow: 0 0 0 1px rgba(0, 240, 255, 0.55), 0 0 20px rgba(0, 240, 255, 0.3);
}
.device-name { margin-bottom: 3px; font-weight: 600; color: #e6ecff; overflow-wrap: anywhere; }
.device-category { font-size: 11px; line-height: 1.35; color: #a98bff; overflow-wrap: anywhere; }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(2, 3, 10, 0.75);
}
.modal-content {
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 28px;
    background: #121834;
    border: 1px solid rgba(0, 240, 255, 0.3);
    border-radius: 14px;
    box-shadow: 0 0 40px rgba(0, 240, 255, 0.15), 0 30px 80px rgba(0, 0, 0, 0.6);
}
.modal-content h2 { margin-bottom: 18px; font-size: 18px; color: #00f0ff; text-shadow: 0 0 10px rgba(0, 240, 255, 0.5); }
.modal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: 10px; }

/* Loading */
.loading { display: none; margin-top: 18px; text-align: center; color: #00f0ff; }
.spinner {
    display: inline-block;
    width: 26px;
    height: 26px;
    border: 3px solid rgba(0, 240, 255, 0.15);
    border-top-color: #00f0ff;
    border-right-color: #ff2bd6;
    border-radius: 50%;
    box-shadow: 0 0 14px rgba(0, 240, 255, 0.45);
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Collapsible panel */
details.panel > summary {
    list-style: none;
    cursor: pointer;
    font-weight: 600;
    color: #e6ecff;
    display: flex;
    align-items: center;
    gap: 10px;
}
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 2px solid #00f0ff;
    border-bottom: 2px solid #00f0ff;
    transform: rotate(-45deg);
    transition: transform 0.2s;
    flex: none;
}
details.panel[open] > summary::before { transform: rotate(45deg); }
details.panel[open] > summary { margin-bottom: 18px; }

.panel-divider { height: 1px; margin: 22px 0; border: 0; background: linear-gradient(90deg, transparent, rgba(255, 43, 214, 0.5), transparent); }
.panel-title { margin-top: 4px; color: #ff2bd6; text-shadow: 0 0 10px rgba(255, 43, 214, 0.5); }
.inline-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.msg { font-size: 13px; color: #9aa6c8; overflow-wrap: anywhere; }

.app-version { margin: 20px 0 0; text-align: center; font-size: 12px; font-family: var(--mono); letter-spacing: 1px; color: #6b7699; }

a { color: #00f0ff; }

@media (max-width: 560px) {
    body { padding: 16px 12px; }
    .container, .panel { padding: 22px 16px; }
    .button-group > button { min-width: 0; flex-basis: 100%; }
    .btn-split-clear { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition: none !important; }
}
.msg-error { color: #ff4d6d; text-shadow: 0 0 8px rgba(255, 77, 109, 0.4); }
.pace-impossible { color: #ff4d6d; font-weight: 700; text-shadow: 0 0 8px rgba(255, 77, 109, 0.6); }

/* Watch presets */
.preset-row { display: flex; gap: 8px; margin-bottom: 12px; align-items: stretch; }
.preset-row select { flex: 1; min-width: 0; }
.preset-row .btn-split { margin-left: 0; }
