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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Header */
.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 28px;
}

.back-link {
    color: #888;
    text-decoration: none;
    font-size: 0.9rem;
    display: block;
    margin-bottom: 6px;
    transition: color 0.2s;
}
.back-link:hover { color: #f7931e; }

h1 {
    font-size: 2.2rem;
    background: linear-gradient(90deg, #ff6b35, #f7931e);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
}

/* Keep the emoji as a normal colour glyph; background-clip:text would clip a
   colour emoji into a solid orange block. */
h1 .logo-emoji {
    -webkit-text-fill-color: initial;
    background: none;
}

.subtitle {
    color: #888;
    font-size: 0.95rem;
}

/* Unit toggle */
.unit-toggle {
    display: inline-flex;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    padding: 3px;
    flex: none;
}

.unit-btn {
    border: none;
    background: none;
    color: #aaa;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.unit-btn:hover { color: #fff; }

.unit-btn.active {
    background: linear-gradient(90deg, #ff6b35, #f7931e);
    color: #fff;
}

/* Panels */
.panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.panel {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 22px;
}

.panel h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: #f7931e;
    margin-bottom: 16px;
    letter-spacing: 0.02em;
}

/* Form elements */
.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #2a2a45;
    border-radius: 8px;
    background: #1a1a2e;
    color: #fff;
    font-size: 0.95rem;
    transition: border-color 0.2s;
    appearance: none;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #f7931e;
}

.form-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23888' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.field-hint {
    font-size: 0.75rem;
    color: #777;
    margin-top: 5px;
    line-height: 1.35;
}

/* Inline help "?" icon with hover/focus tooltip (e.g. drafting benchmarks) */
.help-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    margin-left: 6px;
    border-radius: 50%;
    background: #2a2a45;
    color: #bbb;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1;
    cursor: help;
    vertical-align: middle;
    text-transform: none;
    letter-spacing: 0;
}

.help-icon:hover,
.help-icon:focus {
    background: #f7931e;
    color: #1a1a2e;
    outline: none;
}

.help-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: 220px;
    padding: 10px 12px;
    border: 1px solid #2a2a45;
    border-radius: 8px;
    background: #12121f;
    color: #ccc;
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.4;
    text-transform: none;
    letter-spacing: 0;
    text-align: left;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s;
    z-index: 10;
}

.help-tooltip strong {
    color: #f7931e;
}

.help-icon:hover .help-tooltip,
.help-icon:focus .help-tooltip {
    opacity: 1;
    visibility: visible;
}

/* Inline checkbox row (e.g. "Include lead-in") */
.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-check input[type="checkbox"] {
    width: 18px;
    height: 18px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 0;
    background: none;
    appearance: auto;
    -webkit-appearance: checkbox;
    accent-color: #f7931e;
    cursor: pointer;
    flex: none;
}

.form-check label {
    margin-bottom: 0;
    text-transform: none;
    letter-spacing: normal;
    font-size: 0.9rem;
    color: #ddd;
    cursor: pointer;
}

/* Stat pills */
.route-stats {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
}

/* Lap counter */
.lap-counter {
    display: flex;
    align-items: center;
    gap: 12px;
}

.lap-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid rgba(247,147,30,0.4);
    border-radius: 6px;
    background: rgba(247,147,30,0.12);
    color: #f7931e;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lap-btn:hover:not(:disabled) {
    background: rgba(247,147,30,0.25);
}

.lap-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.lap-count {
    min-width: 28px;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 700;
    color: #f7931e;
}

.bike-stats {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
}

/* Bike config summary (Total weight + Total CdA bias) */
.bike-summary {
    background: rgba(0,0,0,0.25);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 4px 14px;
    margin-top: 12px;
}

.bike-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

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

.bike-summary-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #aaa;
}

.bike-summary-value {
    font-family: monospace;
    font-weight: 700;
    font-size: 1.05rem;
}

.bike-summary-value.weight { color: #81c784; }
.bike-summary-value.cda { color: #4fc3f7; }

.stat-pill {
    background: rgba(247,147,30,0.1);
    border: 1px solid rgba(247,147,30,0.25);
    border-radius: 6px;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 70px;
}

.stat-label {
    font-size: 0.68rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-label.no-uppercase {
    text-transform: none;
}

.stat-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: #f7931e;
    margin-top: 2px;
}

/* W/kg display */
.wpkg-display {
    font-size: 0.9rem;
    color: #4fc3f7;
    font-weight: 600;
    text-align: right;
    margin-top: -6px;
}

/* Plan bar */
.simulate-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 28px;
}

.btn-simulate {
    padding: 14px 36px;
    background: linear-gradient(90deg, #ff6b35, #f7931e);
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    letter-spacing: 0.02em;
}

.btn-simulate:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-simulate:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-simulate.loading {
    opacity: 0.7;
    cursor: wait;
}

.simulate-hint {
    font-size: 0.85rem;
    color: #666;
}

/* Results */
.results-section {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    padding: 24px;
}

.results-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.results-header h2 {
    font-size: 1.2rem;
    color: #fff;
}

.btn-export-plan {
    margin-left: auto;
    padding: 8px 14px;
    border: 1px solid rgba(247,147,30,0.7);
    border-radius: 6px;
    background: rgba(247,147,30,0.12);
    color: #f7931e;
    cursor: pointer;
    font-weight: 600;
}

.btn-export-plan:hover { background: rgba(247,147,30,0.24); }

/* Summary cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.summary-card {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    padding: 18px 14px;
    text-align: center;
}

.summary-card.highlight {
    background: rgba(247,147,30,0.1);
    border-color: rgba(247,147,30,0.3);
}

.card-icon {
    font-size: 1.4rem;
    margin-bottom: 8px;
}

.card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 4px;
}

.summary-card.highlight .card-value {
    color: #f7931e;
}

.card-label {
    font-size: 0.75rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Chart */
.surface-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    color: #ccc;
    font-size: 0.8rem;
    margin-bottom: 10px;
}

.surface-legend > span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.surface-swatch {
    width: 14px;
    height: 3px;
}

.chart-container {
    position: relative;
    height: 320px;
    margin-bottom: 28px;
}

/* Route map (lead-in + route) */
.map-section {
    margin-bottom: 28px;
}
.map-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.map-header h3 {
    font-size: 1.1rem;
    color: #ddd;
}
.map-legend {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    font-size: 0.82rem;
    color: #aaa;
}
.map-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.map-legend .swatch {
    width: 14px;
    height: 3px;
    border-radius: 2px;
    display: inline-block;
}
.swatch-leadin { background: #f7931e; }
.swatch-route  { background: #35d0ff; }
.map-container {
    position: relative;
    height: 460px;
    background: #10162b;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
    overflow: hidden;
}
.map-container canvas {
    width: 100%;
    height: 100%;
    display: block;
}
.map-hint {
    font-size: 0.82rem;
    color: #777;
    margin-top: 8px;
}

/* Bucket / divider controls */
.bucket-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.bucket-hint {
    font-size: 0.85rem;
    color: #888;
    flex: 1 1 240px;
}

.bucket-hint.active {
    color: #f7931e;
}

.bucket-slider-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    color: #ccc;
    white-space: nowrap;
}

.bucket-slider-wrap label {
    font-weight: 600;
}

.bucket-slider-wrap #bucketCount {
    color: #f7931e;
    font-weight: 700;
}

#bucketSlider {
    width: 180px;
    accent-color: #f7931e;
    cursor: pointer;
}

#bucketSlider:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Pacing table */
.table-wrap h3 {
    font-size: 1.05rem;
    color: #f7931e;
    margin-bottom: 12px;
}

.pacing-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.pacing-table th,
.pacing-table td {
    padding: 8px 12px;
    text-align: right;
    border-bottom: 1px solid rgba(255,255,255,0.07);
}

.pacing-table th:first-child,
.pacing-table td:first-child {
    text-align: left;
}

.pacing-table thead th {
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.72rem;
    font-weight: 700;
    border-bottom: 2px solid rgba(255,255,255,0.15);
}

.pacing-table tbody tr:hover {
    background: rgba(247,147,30,0.06);
}

.pacing-table td.power {
    font-weight: 700;
    color: #f7931e;
}

.grade-up { color: #ff7043; }
.grade-down { color: #4fc3f7; }

/* Error toast */
.error-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #c62828;
    color: #fff;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    z-index: 999;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
