/* =====================================================
   養車成本計算器 v2 — Design System
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Noto+Sans+TC:wght@300;400;500;600;700;900&display=swap');

/* ── Design Tokens ── */
:root {
    /* Brand Palette */
    --brand-primary: #6C63FF;
    --brand-secondary: #48CFAD;
    --brand-accent: #FF6B6B;
    --brand-gold: #FFD166;

    /* Backgrounds */
    --bg: #0D1117;
    --bg-surface: #161B24;
    --bg-card: #1C2333;
    --bg-input: #242C3B;
    --bg-hover: #2A3347;

    /* Text */
    --text-primary: #E6EDF3;
    --text-secondary: #8B949E;
    --text-muted: #484F58;
    --text-on-brand: #FFFFFF;

    /* Borders */
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(108, 99, 255, 0.5);
    --border-focus: rgba(108, 99, 255, 0.8);

    /* Semantic Colors */
    --green: #3FB950;
    --red: #F85149;
    --yellow: #D29922;
    --blue: #58A6FF;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 30px rgba(108, 99, 255, 0.25);

    /* Radius */
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 24px;

    /* Transitions */
    --t: 0.2s ease;
    --t-slow: 0.4s ease;

    /* Mode colors */
    --ice-color: #FF9F43;
    --ev-color: #48CFAD;
    --rental-color: #58A6FF;
    --sub-color: #C77DFF;
    --uber-color: #FFD166;
}

/* Light Theme */
[data-theme="light"] {
    --bg: #F6F8FA;
    --bg-surface: #FFFFFF;
    --bg-card: #FFFFFF;
    --bg-input: #F0F3F8;
    --bg-hover: #E8ECF4;

    --text-primary: #0D1117;
    --text-secondary: #57606A;
    --text-muted: #9BA3AD;

    --border: rgba(0, 0, 0, 0.1);
    --border-hover: rgba(108, 99, 255, 0.4);
    --border-focus: rgba(108, 99, 255, 0.7);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.15);
    --shadow-glow: 0 0 30px rgba(108, 99, 255, 0.15);
}

/* ── Reset & Base ── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', 'Noto Sans TC', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 14px;
    min-height: 100vh;
    transition: background var(--t-slow), color var(--t-slow);
}

/* ── Layout ── */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ── Theme Toggle ── */
.theme-toggle {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--t);
    backdrop-filter: blur(8px);
}

.theme-toggle:hover {
    border-color: var(--brand-primary);
    color: var(--text-primary);
}

/* ── Hero ── */
.hero {
    position: relative;
    padding: 56px 0 40px;
    text-align: center;
    overflow: hidden;
}

.hero-bg {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(108, 99, 255, 0.15) 0%, transparent 70%);
    pointer-events: none;
}

.hero h1 {
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #FFFFFF 0%, var(--brand-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
}

[data-theme="light"] .hero h1 {
    background: linear-gradient(135deg, #1A1A2E 0%, var(--brand-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero .subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.hero .icon {
    -webkit-text-fill-color: initial;
}

/* ── Step Navigator ── */
.step-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin: 32px 0 28px;
    padding: 16px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
}

.step-item {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: default;
    opacity: 0.4;
    transition: opacity var(--t);
}

.step-item.active {
    opacity: 1;
}

.step-item.done {
    opacity: 0.7;
}

.step-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    transition: all var(--t);
}

.step-item.active .step-circle {
    background: var(--brand-primary);
    border-color: var(--brand-primary);
    color: #fff;
    box-shadow: 0 0 16px rgba(108, 99, 255, 0.5);
}

.step-item.done .step-circle {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.step-item.done .step-circle::before {
    content: '✓';
}

.step-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.step-item.active .step-label {
    color: var(--text-primary);
}

.step-connector {
    flex: 1;
    height: 2px;
    background: var(--border);
    margin: 0 16px;
    min-width: 40px;
    max-width: 80px;
}

/* ── Step Sections ── */
.step-section {
    display: none;
    animation: fadeIn 0.35s ease;
}

.step-section.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Glow Card (Step 1) ── */
.glow-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: 36px;
    box-shadow: var(--shadow-md), var(--shadow-glow);
}

.step-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.step-desc {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

/* ── Selector Groups ── */
.selector-group {
    margin-bottom: 32px;
}

.selector-label {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 14px;
}

/* ── Mode Cards (主方案, ICE/EV) ── */
.mode-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.mode-card {
    position: relative;
    cursor: pointer;
}

.mode-card input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.mode-card-inner {
    padding: 20px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--r-lg);
    text-align: center;
    transition: all var(--t);
}

.mode-card:hover .mode-card-inner {
    border-color: var(--border-hover);
    background: var(--bg-hover);
}

.mode-card input:checked~.mode-card-inner {
    border-color: var(--brand-primary);
    background: rgba(108, 99, 255, 0.1);
    box-shadow: 0 0 0 1px var(--brand-primary);
}

.mode-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.mode-name {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 4px;
}

.mode-desc {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ── Compare Cards (第二方案) ── */
.compare-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.compare-card {
    position: relative;
    cursor: pointer;
}

.compare-card input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.compare-card-inner {
    padding: 16px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--r-md);
    text-align: center;
    transition: all var(--t);
}

.compare-card:hover .compare-card-inner {
    border-color: var(--border-hover);
}

.compare-card input:checked~.compare-card-inner {
    border-color: var(--brand-secondary);
    background: rgba(72, 207, 173, 0.07);
}

.compare-icon {
    font-size: 1.6rem;
    margin-bottom: 6px;
}

.compare-name {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 2px;
}

.compare-desc {
    font-size: 11px;
    color: var(--text-secondary);
}

.check-mark {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--brand-secondary);
    color: #fff;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: scale(0.5);
    transition: all var(--t);
}

.compare-card input:checked~.check-mark {
    opacity: 1;
    transform: scale(1);
}

/* ── Cards (表單 section) ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    margin-bottom: 16px;
    overflow: hidden;
    transition: box-shadow var(--t);
}

.card:hover {
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    cursor: pointer;
    user-select: none;
    transition: background var(--t);
}

.card-header:hover {
    background: var(--bg-hover);
}

.card-header h2 {
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-icon {
    font-size: 11px;
    color: var(--text-muted);
    transition: transform var(--t);
}

.card.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.card-body {
    display: none;
    padding: 4px 20px 20px;
    border-top: 1px solid var(--border);
}

.card-body.open {
    display: block;
}

/* ── Mode Block Headers ── */
.mode-block {
    margin-bottom: 8px;
}

.mode-block-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--ice-color);
    padding: 12px 4px 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}

.compare-title {
    color: var(--brand-secondary);
}

/* ── Form Fields ── */
.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding-top: 16px;
}

@media (max-width: 640px) {
    .grid-3 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 400px) {
    .grid-3 {
        grid-template-columns: 1fr;
    }
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.2px;
}

.input-wrap {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--bg-input);
    overflow: hidden;
    transition: border-color var(--t), box-shadow var(--t);
}

.input-wrap:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.12);
}

input[type="number"] {
    flex: 1;
    padding: 8px 10px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    min-width: 0;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.unit {
    padding: 0 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.03);
    border-left: 1px solid var(--border);
    white-space: nowrap;
    line-height: 36px;
}

.hint {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* ── Uber Preview ── */
.uber-preview {
    margin-top: 16px;
    padding: 12px 16px;
    background: rgba(255, 209, 102, 0.07);
    border: 1px solid rgba(255, 209, 102, 0.2);
    border-radius: var(--r-sm);
    font-size: 13px;
    color: var(--text-secondary);
}

.uber-preview strong {
    color: var(--uber-color);
    font-weight: 700;
}

/* ── Custom Items ── */
.custom-item {
    display: grid;
    grid-template-columns: 1fr auto auto auto auto auto;
    gap: 10px;
    align-items: end;
    padding: 12px;
    background: var(--bg-input);
    border-radius: var(--r-sm);
    margin-bottom: 10px;
}

.custom-item label {
    font-size: 11px;
}

.custom-item .remove-btn {
    padding: 8px 10px;
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid rgba(248, 81, 73, 0.3);
    border-radius: var(--r-sm);
    color: var(--red);
    cursor: pointer;
    font-size: 13px;
    transition: all var(--t);
    align-self: flex-end;
}

.custom-item .remove-btn:hover {
    background: rgba(248, 81, 73, 0.2);
}

/* ── Buttons ── */
.action-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    padding: 24px 0;
    flex-wrap: wrap;
}

.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 28px;
    background: linear-gradient(135deg, var(--brand-primary), #8B82FF);
    color: #fff;
    border: none;
    border-radius: var(--r-md);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--t);
    box-shadow: 0 4px 16px rgba(108, 99, 255, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(108, 99, 255, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    padding: 8px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--t);
}

.btn-secondary:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.btn-ghost {
    padding: 10px 20px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--t);
}

.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ── Decision Banner ── */
.decision-banner {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 20px 24px;
    background: linear-gradient(135deg, rgba(72, 207, 173, 0.1), rgba(108, 99, 255, 0.08));
    border: 1px solid rgba(72, 207, 173, 0.3);
    border-radius: var(--r-lg);
    margin-bottom: 28px;
    animation: fadeIn 0.5s ease;
}

.decision-icon {
    font-size: 1.6rem;
    flex-shrink: 0;
}

.decision-text {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
}

.decision-text strong {
    color: var(--brand-secondary);
}

/* ── Compare Cards (結果摘要) ── */
.compare-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: transform var(--t), box-shadow var(--t);
}

.result-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.result-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--card-color, var(--brand-primary));
}

.result-card .rc-badge {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.07);
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--card-color, var(--brand-primary));
    margin-bottom: 12px;
}

.result-card .rc-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.result-card .rc-value {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.result-card .rc-sub {
    font-size: 11px;
    color: var(--text-secondary);
}

.result-card .rc-monthly {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.result-card .rc-tags {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
}

.result-card .rc-tag {
    font-size: 11px;
    color: var(--text-secondary);
}

.best-badge {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 2px 8px;
    background: var(--green);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 999px;
}

/* ── Charts ── */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (max-width: 640px) {
    .charts-row {
        grid-template-columns: 1fr;
    }
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 20px;
}

.chart-card h3 {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-secondary);
}

.chart-wrap {
    position: relative;
    height: 240px;
}

/* ── Per KM Bar ── */
.per-km-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    margin-bottom: 20px;
}

.per-km-label {
    font-size: 13px;
    font-weight: 600;
}

.per-km-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.per-km-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--brand-gold);
}

/* ── Table ── */
.table-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 20px;
    margin-bottom: 24px;
}

.table-section h3 {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 16px;
}

.table-scroll {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

th {
    text-align: right;
    padding: 8px 10px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th:first-child {
    text-align: center;
}

td {
    text-align: right;
    padding: 7px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-secondary);
}

td:first-child {
    text-align: center;
    font-weight: 700;
    color: var(--text-primary);
}

tr:hover td {
    background: var(--bg-hover);
}

tr.sweet-spot td {
    color: var(--green) !important;
    font-weight: 700;
}

tr.sweet-spot td:first-child::after {
    content: ' 🎯';
}

/* ── Footer ── */
.footer {
    text-align: center;
    padding: 32px 20px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: 40px;
}