:root {
    --bg: #f4f3f1;
    --surface: #ffffff;
    --surface-hover: #fafaf9;
    --border: #e2e0dc;
    --border-light: #edebe8;
    --text: #1a1a1a;
    --text-secondary: #6b6966;
    --text-tertiary: #9e9b96;
    --accent: #c44b1a;
    --accent-soft: rgba(196, 75, 26, 0.08);
    --accent-medium: rgba(196, 75, 26, 0.15);
    --engaged: #c44b1a;
    --disengaged: #b8b5b0;
    --mono: 'DM Mono', 'SF Mono', monospace;
    --sans: 'Instrument Sans', system-ui, sans-serif;
    --radius: 6px;
    --radius-lg: 10px;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--sans);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

#canvas-container {
    position: fixed;
    inset: 0;
    z-index: 0;
}

canvas { display: block; }

/* ── Top Bar ────────────────────────────────────────── */

#topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 20;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: rgba(255,255,255,0.82);
    backdrop-filter: blur(12px) saturate(1.4);
    border-bottom: 1px solid var(--border-light);
}

.logo { display: flex; align-items: center; gap: 10px; }

.logo-mark {
    font-family: var(--mono);
    font-weight: 500;
    font-size: 15px;
    letter-spacing: 0.08em;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 2px 8px;
    border-radius: 4px;
}

.logo-text {
    font-weight: 600;
    font-size: 14px;
    letter-spacing: -0.01em;
}

.topbar-right { display: flex; gap: 8px; }

.tag {
    font-family: var(--mono);
    font-size: 11px;
    font-weight: 400;
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 3px 10px;
    border-radius: 20px;
    letter-spacing: 0.02em;
}

.tag-muted { color: var(--text-tertiary); border-color: var(--border-light); }

/* ── Gear Strip (vertical) ──────────────────────────── */

#gear-strip {
    position: fixed;
    top: 60px;
    left: 16px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 4px;
    background: rgba(255,255,255,0.88);
    backdrop-filter: blur(12px) saturate(1.4);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

.gear-divider {
    width: 24px;
    height: 1px;
    background: var(--border);
    margin: 2px 0;
}

.gear-btn {
    width: 36px;
    height: 32px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

.gear-btn:hover {
    background: var(--accent-soft);
    color: var(--text);
}

.gear-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 1px 4px rgba(196, 75, 26, 0.3);
}

/* ── Ratio Bar ──────────────────────────────────────── */

#ratio-bar {
    position: fixed;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 6px 18px;
    background: rgba(255,255,255,0.75);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-light);
    border-radius: 8px;
}

.ratio-item { display: flex; flex-direction: column; align-items: center; }
.ratio-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-tertiary); font-family: var(--mono); }
.ratio-value { font-family: var(--mono); font-size: 14px; font-weight: 500; color: var(--text); }
.ratio-sep { width: 1px; height: 28px; background: var(--border-light); }

/* ── Torque Path Panel (left) ───────────────────────── */

#torque-panel {
    position: fixed;
    top: 60px;
    left: 68px;
    bottom: 50px;
    width: 260px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    overflow-x: hidden;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(14px) saturate(1.4);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}

#torque-panel::-webkit-scrollbar { width: 0; }

.tp-step {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 0;
    font-size: 12px;
    line-height: 1.45;
    color: var(--text-secondary);
}

.tp-step + .tp-step {
    border-top: 1px solid var(--border-light);
}

.tp-badge {
    flex-shrink: 0;
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.03em;
    margin-top: 1px;
}

.tp-badge.engaged {
    background: var(--accent-soft);
    color: var(--accent);
    border: 1px solid var(--accent-medium);
}

.tp-badge.open {
    background: var(--surface);
    color: var(--text-tertiary);
    border: 1px solid var(--border-light);
}

.tp-text { flex: 1; }

.tp-name {
    font-weight: 600;
    color: var(--text);
    font-size: 11px;
}

.tp-desc {
    font-family: var(--mono);
    font-size: 10px;
    color: var(--text-tertiary);
    margin-top: 1px;
}

.tp-path {
    margin-top: 10px;
    padding: 8px 10px;
    background: var(--accent-soft);
    border: 1px solid var(--accent-medium);
    border-radius: var(--radius);
    font-family: var(--mono);
    font-size: 10px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.tp-path-label {
    font-family: var(--sans);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent);
    margin-bottom: 3px;
}

/* ── Side Panel ─────────────────────────────────────── */

#panel {
    position: fixed;
    top: 60px;
    right: 16px;
    bottom: 50px;
    width: 240px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    overflow-x: hidden;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(14px) saturate(1.4);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}

#panel::-webkit-scrollbar { width: 0; }

.panel-section {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
}

.panel-section:last-child { border-bottom: none; }

.panel-section h3 {
    font-family: var(--mono);
    font-size: 10px;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-tertiary);
    margin-bottom: 10px;
}

/* Element cards */
#elements-grid { display: flex; flex-direction: column; gap: 4px; }

.el-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    transition: all 0.25s ease;
    cursor: default;
}

.el-card.engaged {
    background: var(--accent-soft);
    border-color: var(--accent-medium);
}

.el-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--disengaged);
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.el-card.engaged .el-indicator {
    background: var(--engaged);
    box-shadow: 0 0 8px rgba(196, 75, 26, 0.4);
}

.el-info { display: flex; flex-direction: column; }
.el-name { font-size: 12px; font-weight: 600; line-height: 1.3; }
.el-desc { font-size: 10px; color: var(--text-tertiary); font-family: var(--mono); }

/* Toggle rows */
.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 3px 0;
    font-size: 12px;
    color: var(--text-secondary);
}
.toggle-row.sub-toggle {
    padding-left: 18px;
    font-size: 11px;
}

.toggle {
    position: relative;
    width: 32px;
    height: 18px;
    flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }

.toggle-track {
    position: absolute;
    inset: 0;
    background: var(--disengaged);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 14px; height: 14px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(14px); }

/* Sliders */
.slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.slider-row input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(196,75,26,0.3);
}

.slider-val {
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-tertiary);
    min-width: 32px;
    text-align: right;
}

/* ── Keyboard Hint ──────────────────────────────────── */

#hint {
    position: fixed;
    bottom: 14px;
    right: 16px;
    z-index: 20;
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-tertiary);
    background: rgba(255,255,255,0.7);
    backdrop-filter: blur(8px);
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid var(--border-light);
    white-space: nowrap;
}

kbd {
    display: inline-block;
    font-family: var(--mono);
    font-size: 11px;
    padding: 0 5px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    box-shadow: 0 1px 0 var(--border);
    line-height: 1.6;
}

/* ── Animations ─────────────────────────────────────── */

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

#topbar { animation: fadeInUp 0.4s ease both; }
#gear-strip { animation: fadeInUp 0.4s ease 0.05s both; }
#ratio-bar { animation: fadeInUp 0.4s ease 0.1s both; }
#torque-panel { animation: fadeInUp 0.4s ease 0.12s both; }
#panel { animation: fadeInUp 0.4s ease 0.15s both; }
#hint { animation: fadeInUp 0.4s ease 0.25s both; }
