:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-sunken: #fafbfc;
    --border: #e3e6ea;
    --border-strong: #d0d5db;
    --ink: #14181f;
    --ink-muted: #5b6472;
    --ink-faint: #8b95a3;
    --accent: #2f5fe0;
    --accent-hover: #2650c4;
    --accent-soft: rgba(47, 95, 224, 0.08);
    --up: #0f8a5f;
    --up-soft: rgba(15, 138, 95, 0.09);
    --down: #c8402f;
    --down-soft: rgba(200, 64, 47, 0.08);
    --edge: #c4cad2;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
    --radius: 10px;
    --radius-sm: 6px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1116;
        --surface: #161a21;
        --surface-sunken: #12161c;
        --border: #262c36;
        --border-strong: #333b47;
        --ink: #e6e9ee;
        --ink-muted: #a3adba;
        --ink-faint: #74808f;
        --accent: #6690ff;
        --accent-hover: #7ba0ff;
        --accent-soft: rgba(102, 144, 255, 0.14);
        --up: #3fbf8a;
        --up-soft: rgba(63, 191, 138, 0.14);
        --down: #f0705f;
        --down-soft: rgba(240, 112, 95, 0.13);
        --edge: #3c4553;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    }
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    min-height: 100vh;
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px 24px 64px;
}

header {
    margin-bottom: 32px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 6px;
}

header p {
    font-size: 0.95rem;
    color: var(--ink-muted);
}

.main-content {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) 2fr;
    gap: 24px;
    align-items: start;
}

.input-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    height: fit-content;
    position: sticky;
    top: 24px;
}

.input-panel h2 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 20px;
    color: var(--ink-faint);
    font-weight: 600;
}

.parameter-group {
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.parameter-group:last-of-type {
    border-bottom: none;
    padding-bottom: 0;
}

.parameter-group h3 {
    font-size: 0.9rem;
    margin-bottom: 12px;
    color: var(--ink);
    font-weight: 600;
}

.input-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.input-group {
    display: flex;
    flex-direction: column;
}

.input-group label {
    font-size: 0.825rem;
    font-weight: 450;
    color: var(--ink-muted);
    margin-bottom: 5px;
}

.input-group input,
.input-group select {
    padding: 9px 11px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.925rem;
    font-family: inherit;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
    background: var(--surface);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.calculate-btn {
    width: 100%;
    padding: 11px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.925rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.12s ease;
    margin-top: 20px;
}

.calculate-btn:hover {
    background: var(--accent-hover);
}

.calculate-btn:disabled {
    opacity: 0.65;
    cursor: default;
}

.results-panel {
    display: grid;
    gap: 24px;
}

.result-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
}

.result-card h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 8px;
    color: var(--ink-faint);
    font-weight: 600;
}

.price-display {
    font-size: 2.25rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.trees-container {
    display: grid;
    gap: 24px;
}

.tree-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px 24px;
    box-shadow: var(--shadow);
}

.tree-section h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
    color: var(--ink-faint);
    font-weight: 600;
}

.tree-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 14px;
    font-size: 0.75rem;
    color: var(--ink-muted);
}

.tree-legend span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.tree-legend span[hidden] {
    display: none;
}

.tree-legend:not(:has(span:not([hidden]))) {
    display: none;
}

.tree-legend i {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    border: 1px solid var(--border-strong);
}

.tree-legend i.above { background: var(--up-soft); border-color: var(--up); }
.tree-legend i.below { background: var(--down-soft); border-color: var(--down); }
.tree-legend i.knocked { background: var(--surface-sunken); border-style: dashed; }
.tree-legend i.exercise { background: var(--accent-soft); border-color: var(--accent); }

.tree-display {
    background: var(--surface-sunken);
    border-radius: var(--radius-sm);
    padding: 16px;
    border: 1px solid var(--border);
    min-height: 180px;
    overflow-x: auto;
    font-size: 0.85rem;
}

.tree-canvas {
    position: relative;
    margin: 0 auto;
}

.tree-canvas svg {
    position: absolute;
    inset: 0;
}

.tree-edge {
    stroke: var(--edge);
    stroke-width: 1.5;
}

.ref-line {
    stroke-width: 1;
    stroke-dasharray: 4 4;
}

.ref-line.strike {
    stroke: var(--ink-faint);
}

.ref-line.barrier {
    stroke: var(--accent);
    stroke-dasharray: 6 3;
}

.ref-label {
    fill: var(--ink-faint);
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.tree-node {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font-size: 0.8rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    z-index: 1;
}

.tree-node.above-strike {
    background: var(--up-soft);
    border-color: var(--up);
    color: var(--up);
}

.tree-node.below-strike {
    background: var(--down-soft);
    border-color: var(--down);
    color: var(--down);
}

.tree-node.knocked {
    background: var(--surface-sunken);
    border-style: dashed;
    border-color: var(--border-strong);
    color: var(--ink-faint);
}

.tree-node.exercise {
    box-shadow: 0 0 0 2px var(--accent);
    border-color: var(--accent);
}

.tree-node.root {
    border-color: var(--ink);
    border-width: 2px;
    font-weight: 600;
}

.tree-display .empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 148px;
    color: var(--ink-faint);
    font-size: 0.875rem;
}

.loading {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: -1px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .input-panel {
        position: static;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 24px 16px 48px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .input-panel,
    .result-card,
    .tree-section {
        padding: 18px;
    }

    .price-display {
        font-size: 1.875rem;
    }
}

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