:root {
    --bg: #f5f5f7;
    --bg-card: #ffffff;
    --bg-hover: #f0f0f2;
    --bg-input: #f5f5f7;
    --border: #d2d2d7;
    --border-hover: #86868b;
    --border-accent: #0071e3;
    --text: #1d1d1f;
    --text-secondary: #86868b;
    --text-muted: #a1a1a6;
    --accent: #0071e3;
    --accent-dim: #005bb5;
    --accent-glow: rgba(0, 113, 227, 0.15);
    --success: #34c759;
    --warning: #ff9500;
    --danger: #ff3b30;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', 'Noto Sans SC', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Fixed Top Bar */
.top-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 52px;
}
.brand { display: flex; align-items: center; gap: 0.5rem; flex: 1; }
.brand-text { font-size: 0.95rem; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }
.lang-switch { display: flex; gap: 0.25rem; align-items: center; }

/* Sensitivity Active State */
.sense-item.active {
    background: rgba(0, 113, 227, 0.08);
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}
.sense-item.active .sense-value { color: var(--accent); }
.lang-switch {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.lang-btn {
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    transition: all 0.15s ease;
}
.lang-btn:hover { border-color: var(--accent); color: var(--accent); }
.lang-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.rpm-indicator { display: flex; align-items: center; gap: 1.5rem; }
.rpm-main { text-align: right; }
.rpm-label { font-size: 0.6rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.rpm-value {
    font-size: 1.5rem; font-weight: 600; color: var(--accent);
    font-family: 'SF Mono', SFMono-Regular, monospace; line-height: 1.2;
    transition: all 0.3s ease;
}
.rpm-value.updating { opacity: 0.5; transform: scale(0.95); }
.status-badge {
    padding: 0.2rem 0.6rem; border-radius: 100px;
    font-size: 0.7rem; font-weight: 500; letter-spacing: 0.02em;
}
.status-high { background: rgba(52, 199, 89, 0.12); color: var(--success); }
.status-med { background: rgba(255, 149, 0, 0.12); color: var(--warning); }
.status-low { background: rgba(255, 59, 48, 0.12); color: var(--danger); }

/* Layout */
.main-layout {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 0;
    margin-top: 52px;
    min-height: calc(100vh - 52px);
}

/* Left Panel */
.inputs-panel {
    border-right: 1px solid var(--border);
    max-height: calc(100vh - 52px);
    overflow-y: auto;
    padding: 1.25rem;
    background: var(--bg);
}
.inputs-panel::-webkit-scrollbar { width: 6px; }
.inputs-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Section */
.section {
    margin-bottom: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.section:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.section-header {
    padding: 0.7rem 1rem;
    display: flex; align-items: center; gap: 0.5rem;
    cursor: pointer; user-select: none;
    font-weight: 600; font-size: 0.8rem;
}
.section-header:hover { background: var(--bg-hover); }
.section-icon {
    width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem;
    opacity: 0.7;
}
.section-title { flex: 1; }
.section-arrow {
    font-size: 0.65rem; color: var(--text-muted);
    transition: transform 0.2s ease;
}
.section.collapsed .section-arrow { transform: rotate(-90deg); }
.section.collapsed .section-body { display: none; }
.section-body { padding: 0.75rem 1rem; border-top: 1px solid var(--border); }

/* Core Section */
.section.core { border-color: rgba(0, 113, 227, 0.25); }
.section.core .section-header { color: var(--accent); }

/* Field */
.field { margin-bottom: 0.875rem; }
.field:last-child { margin-bottom: 0; }
.field-label {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 0.35rem; font-size: 0.78rem; font-weight: 500;
    color: var(--text);
}
.field-value {
    font-family: 'SF Mono', SFMono-Regular, monospace; color: var(--accent);
    font-size: 0.78rem; font-weight: 600;
    background: rgba(0, 113, 227, 0.08); padding: 0.1rem 0.4rem;
    border-radius: 4px;
}
.field-hint {
    font-size: 0.7rem; color: var(--text-muted); margin-top: 0.3rem;
    line-height: 1.4;
}

/* Inputs */
input[type="range"] {
    width: 100%; height: 4px;
    background: var(--border); border-radius: 2px;
    outline: none; -webkit-appearance: none; margin: 0.5rem 0;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; width: 18px; height: 18px;
    background: #fff; border-radius: 50%; cursor: pointer;
    box-shadow: 0 0 0 4px var(--accent-glow), 0 1px 3px rgba(0,0,0,0.15);
    border: 2px solid var(--accent);
}
input[type="number"], input[type="text"], select {
    width: 100%; padding: 0.45rem 0.6rem;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: 8px; color: var(--text);
    font-family: 'SF Mono', SFMono-Regular, monospace; font-size: 0.8rem;
    outline: none; transition: all 0.2s ease;
}
input[type="number"]:focus, input[type="text"]:focus, select:focus {
    border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow);
}
.field-row { display: grid; grid-template-columns: 1fr auto; gap: 0.4rem; }
.field-row input { width: 100%; }
.field-row select { width: auto; min-width: 100px; }

/* Presets */
.presets {
    display: flex; gap: 0.35rem; flex-wrap: wrap;
    margin-bottom: 0.75rem;
}
.preset {
    padding: 0.25rem 0.55rem;
    background: var(--bg-hover); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text-secondary);
    font-size: 0.72rem; cursor: pointer; transition: all 0.15s ease;
    white-space: nowrap;
}
.preset:hover { border-color: var(--accent); color: var(--accent); background: rgba(0,113,227,0.05); }
.preset.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

/* Quick row */
.quick-row {
    display: flex; gap: 0.4rem; margin-top: 0.4rem;
}
.quick-btn {
    flex: 1; padding: 0.4rem;
    background: var(--bg-hover); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text-secondary);
    font-size: 0.7rem; text-align: center;
    cursor: pointer; transition: all 0.15s ease;
    white-space: nowrap;
}
.quick-btn:hover { border-color: var(--accent); color: var(--accent); }
.quick-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }

/* Toggle */
.toggle-wrap {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.3rem 0;
    gap: 0.75rem;
}
.toggle-wrap > span {
    font-size: 0.75rem;
    flex: 1;
    min-width: 0;
}
.toggle-track {
    position: relative; width: 36px; height: 20px;
    background: var(--border); border-radius: 10px;
    cursor: pointer; transition: background 0.2s ease;
    flex-shrink: 0;
}
.toggle-track.on { background: var(--accent); }
.toggle-track::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 14px; height: 14px; background: white;
    border-radius: 50%; transition: transform 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.toggle-track.on::after { transform: translateX(16px); }

/* Right Panel */
.results-panel {
    background: var(--bg); padding: 1.5rem 2rem;
    overflow-y: auto; max-height: calc(100vh - 52px);
}
.results-panel::-webkit-scrollbar { width: 6px; }
.results-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* RPM Card (Trinity Model) */
.rpm-card {
    background: var(--bg-card);
    border: 1px solid var(--border); border-radius: 16px;
    padding: 1.5rem; text-align: center; margin-bottom: 1.5rem;
    position: relative; overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.rpm-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0;
    height: 2px; background: var(--accent);
}

.trinity-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}
.trinity-row.gross { font-weight: 500; }
.trinity-row.noise { color: var(--text-muted); font-style: italic; }
.trinity-divider {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 1rem 1rem 1rem;
    opacity: 0.6;
}
.trinity-value { font-family: 'SF Mono', SFMono-Regular, monospace; }

.sn-ratio-wrap {
    margin-top: 0.75rem;
    padding: 0.35rem 0.75rem;
    background: rgba(0, 113, 227, 0.05);
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.sn-label { font-size: 0.7rem; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; }
.sn-value { font-size: 0.9rem; font-weight: 700; color: var(--accent); font-family: 'SF Mono', SFMono-Regular, monospace; }

.rpm-big-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.rpm-big-value {
    font-size: 3.5rem; font-weight: 700;
    color: var(--accent);
    font-family: 'SF Mono', SFMono-Regular, monospace; line-height: 1.1;
    transition: all 0.3s ease;
    margin: 0.25rem 0;
}
.rpm-big-value.updating { opacity: 0.4; transform: scale(0.97); }
.rpm-big-unit { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.2rem; }
.rpm-stats {
    display: flex; justify-content: center; gap: 2rem;
    margin-top: 1.2rem; padding-top: 1.2rem; border-top: 1px solid var(--border);
}
.rpm-stat { text-align: center; }
.rpm-stat-value { font-size: 1rem; font-weight: 600; color: var(--text); font-family: 'SF Mono', SFMono-Regular, monospace; }
.rpm-stat-label { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.2rem; }

/* Insight Card */
.insight-card {
    background: rgba(0, 113, 227, 0.04);
    border: 1px solid rgba(0, 113, 227, 0.12);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}
.insight-icon {
    width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.85rem;
    opacity: 0.8;
    flex-shrink: 0;
    margin-top: 0.05rem;
}
.insight-content { flex: 1; }
.insight-title { font-size: 0.78rem; font-weight: 600; color: var(--accent); margin-bottom: 0.25rem; }
.insight-text { font-size: 0.78rem; color: var(--text-secondary); line-height: 1.5; }
.insight-note { margin-top: 0.4rem; font-size: 0.7rem; color: var(--text-muted); font-style: italic; }

/* Tornado Chart */
.tornado-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
    font-size: 0.75rem;
}
.tornado-label { width: 80px; text-align: right; color: var(--text-secondary); flex-shrink: 0; }
.tornado-bar-wrap {
    flex: 1;
    height: 16px;
    background: var(--bg-hover);
    border-radius: 3px;
    position: relative;
    overflow: hidden;
}
.tornado-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.5s ease;
}
.tornado-value {
    width: 50px;
    text-align: left;
    color: var(--text-secondary);
    font-family: 'SF Mono', SFMono-Regular, monospace;
    font-size: 0.7rem;
}

/* Collapsible Steps */
.steps-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding: 0.5rem 0;
}
.steps-toggle {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 0.2rem 0.5rem;
    background: var(--bg-hover);
    border-radius: 4px;
    cursor: pointer;
}
.steps-toggle:hover { color: var(--accent); }
.steps-container.collapsed .step { display: none; }

/* LOD Marker */
.lod-marker {
    position: absolute;
    top: 0; bottom: 0;
    width: 2px;
    background: var(--accent);
    z-index: 10;
    pointer-events: none;
}
.lod-marker::after {
    content: 'Current';
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.65rem;
    color: var(--accent);
    white-space: nowrap;
    background: var(--bg-card);
    padding: 0.1rem 0.4rem;
    border-radius: 3px;
    border: 1px solid var(--accent);
}

/* Steps */
.steps-title {
    font-size: 0.8rem; font-weight: 600; margin-bottom: 0.75rem;
    color: var(--text-secondary); display: flex; align-items: center; gap: 0.4rem;
}
.step {
    display: flex; gap: 0.75rem; padding: 0.75rem;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 10px; margin-bottom: 0.5rem;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.step:hover { border-color: var(--border-hover); transform: translateX(2px); }
.step-num {
    width: 20px; height: 20px; background: var(--accent);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-size: 0.65rem; font-weight: 700; flex-shrink: 0; color: #fff;
}
.step-content { flex: 1; }
.step-title { font-size: 0.78rem; font-weight: 600; margin-bottom: 0.15rem; }
.step-formula {
    font-family: 'SF Mono', SFMono-Regular, monospace; font-size: 0.7rem;
    color: var(--text-muted); background: var(--bg-hover);
    padding: 0.35rem 0.5rem; border-radius: 5px; margin-top: 0.3rem;
    overflow-x: auto;
}
.step-result {
    font-family: 'SF Mono', SFMono-Regular, monospace; font-size: 0.78rem;
    color: var(--accent); font-weight: 600; margin-top: 0.2rem;
}

/* Charts */
.viz-section { margin-top: 1.5rem; }
.viz-title { font-size: 0.8rem; font-weight: 600; margin-bottom: 0.75rem; color: var(--text-secondary); }
.chart-box {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; padding: 1.25rem; margin-bottom: 1.25rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.chart-wrap { position: relative; height: 220px; width: 100%; display: flex; justify-content: center; align-items: center; }
.chart-wrap canvas { max-height: 100% !important; }

/* Sensitivity */
.sense-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem;
    margin-top: 0.75rem;
}
.sense-item {
    text-align: center; padding: 1rem 0.75rem;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 10px; transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.sense-item:hover { transform: translateY(-2px); border-color: var(--border-hover); }
.sense-value { font-size: 1rem; font-weight: 700; font-family: 'SF Mono', SFMono-Regular, monospace; margin-bottom: 0.25rem; }
.sense-value.yes { color: var(--success); }
.sense-value.no { color: var(--danger); }
.sense-label { font-size: 0.7rem; color: var(--text-muted); line-height: 1.4; }

/* Formula */
.formula-box {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; padding: 1.25rem; margin-top: 1.5rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.formula-title { font-size: 0.8rem; font-weight: 600; margin-bottom: 0.75rem; }
.formula-code {
    font-family: 'SF Mono', SFMono-Regular, monospace; font-size: 0.72rem;
    line-height: 1.8; color: var(--text-secondary);
    background: var(--bg-hover); padding: 1rem;
    border-radius: 8px; overflow-x: auto;
}
.formula-code .var { color: var(--accent); font-weight: 600; }
.formula-code .comment { color: var(--text-muted); }

/* Table */
.info-table {
    width: 100%; border-collapse: collapse; margin-top: 0.75rem;
    font-size: 0.78rem;
}
.info-table th, .info-table td {
    padding: 0.5rem; text-align: left; border-bottom: 1px solid var(--border);
}
.info-table th {
    color: var(--text-muted); font-weight: 500; font-size: 0.7rem;
    text-transform: uppercase;
}
.info-table td { font-family: 'SF Mono', SFMono-Regular, monospace; font-size: 0.72rem; }
.info-table tr:hover td { background: var(--bg-hover); }

/* Responsive */
@media (max-width: 1024px) {
    .main-layout { grid-template-columns: 1fr; }
    .inputs-panel { max-height: none; border-right: none; }
    .results-panel { max-height: none; }
    .rpm-indicator { display: none; }
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 1.5rem 0;
    font-size: 0.7rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}
.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s ease;
    font-weight: 500;
    margin-left: 0.3rem;
}
.footer-link:hover {
    color: var(--accent);
}

/* Confidence Bar */
.conf-bar-wrap {
    margin: 1.5rem 0;
    padding: 0 1rem;
}
.conf-bar-track {
    height: 8px;
    background: #e5e5e7;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
    margin-bottom: 0.5rem;
}
.conf-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 4px;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.conf-marker {
    position: absolute;
    top: 0;
    width: 2px;
    height: 100%;
    background: rgba(255,255,255,0.8);
    z-index: 1;
}
.conf-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Enhanced Formula Typography */
.step-formula {
    font-family: 'SF Mono', SFMono-Regular, ui-monospace, monospace;
    font-size: 0.72rem;
    color: var(--text-secondary);
    background: var(--bg-hover);
    padding: 0.6rem 0.8rem;
    border-radius: 8px;
    margin-top: 0.4rem;
    border-left: 3px solid var(--accent);
    letter-spacing: -0.01em;
    line-height: 1.4;
}
.step-formula b { font-style: normal; color: var(--accent); }

/* Animations */
@keyframes slideIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}
.step { animation: slideIn 0.25s ease forwards; }
