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

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-panel: rgba(18, 18, 28, 0.85);
    --bg-control: rgba(22, 22, 35, 0.9);
    --border-color: rgba(100, 120, 150, 0.15);
    --border-glow: rgba(0, 229, 255, 0.2);
    --text-primary: #e8eaf0;
    --text-secondary: #8892a4;
    --text-muted: #556677;
    --accent: #00e5ff;
    --accent-dim: rgba(0, 229, 255, 0.15);
    --warning: #ffb74d;
    --danger: #ff6b6b;
    --success: #69f0ae;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --radius: 12px;
    --radius-sm: 8px;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

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

.back-button {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.back-button:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.03);
}

/* ===== Main ===== */
main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ===== Viz Container ===== */
.viz-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.viz-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
}

.panel-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.phasor-formula {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent);
    opacity: 0.7;
}

.status-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--accent-dim);
    color: var(--accent);
    transition: all 0.3s ease;
}

.status-badge.reverse {
    background: rgba(255, 107, 107, 0.15);
    color: var(--danger);
}

.status-badge.frozen {
    background: rgba(255, 183, 77, 0.15);
    color: var(--warning);
}

.status-badge.stopped {
    background: rgba(85, 102, 119, 0.2);
    color: var(--text-secondary);
}

/* ===== SVG Wrapper ===== */
.svg-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    flex: 1;
    min-height: 0;
}

.svg-wrapper svg {
    width: 100%;
    max-width: 300px;
    height: auto;
    aspect-ratio: 1;
}

/* ===== Wheel & Phasor Info ===== */
.wheel-info,
.phasor-info {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-top: 1px solid var(--border-color);
}

.info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 8px;
    gap: 4px;
}

.info-item:not(:last-child) {
    border-right: 1px solid var(--border-color);
}

.info-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    text-align: center;
}

.info-value {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* ===== Controls ===== */
.controls-container {
    background: var(--bg-control);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 20px 24px;
    display: flex;
    align-items: flex-end;
    gap: 24px;
}

.control-group {
    flex: 1;
    display: flex;
    gap: 24px;
}

.slider-control {
    flex: 1;
    min-width: 0;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}

.slider-header label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.slider-value {
    font-family: var(--font-mono);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--accent);
    min-width: 3ch;
    text-align: right;
}

/* ===== Range Slider ===== */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: #1e1e2e;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0, 229, 255, 0.4);
    transition: box-shadow 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    box-shadow: 0 0 14px rgba(0, 229, 255, 0.6);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 8px rgba(0, 229, 255, 0.4);
}

.slider-range {
    display: flex;
    justify-content: space-between;
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 4px;
    font-family: var(--font-mono);
}

/* ===== Buttons ===== */
.button-group {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

.action-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border: 1px solid var(--border-glow);
    border-radius: var(--radius-sm);
    background: var(--accent-dim);
    color: var(--accent);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.action-button:hover {
    background: rgba(0, 229, 255, 0.25);
    border-color: rgba(0, 229, 255, 0.4);
    box-shadow: 0 0 16px rgba(0, 229, 255, 0.15);
}

.action-button.active {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}

.action-button.secondary {
    background: rgba(85, 102, 119, 0.15);
    border-color: rgba(85, 102, 119, 0.3);
    color: var(--text-secondary);
}

.action-button.secondary:hover {
    background: rgba(85, 102, 119, 0.25);
    color: var(--text-primary);
}

/* ===== Info Panel ===== */
.info-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 14px 20px;
}

.info-content {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.info-icon {
    font-size: 1rem;
    color: var(--accent);
    flex-shrink: 0;
    margin-top: 1px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
}

.info-icon.warn {
    color: var(--warning);
    background: rgba(255, 183, 77, 0.15);
}

.info-icon.danger {
    color: var(--danger);
    background: rgba(255, 107, 107, 0.15);
}

.info-content p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.info-content p strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* ===== Spoke Styling ===== */
.spoke {
    stroke: #8899aa;
    stroke-width: 3;
    stroke-linecap: round;
    transition: stroke 0.1s ease;
}

.spoke-tip {
    fill: #aabbcc;
}

.spoke.highlight {
    stroke: var(--accent);
    stroke-width: 4;
    filter: url(#glowFilter);
}

/* ===== Freeze Frame Markers ===== */
.sample-marker {
    fill: var(--warning);
    opacity: 0.8;
}

.sample-line {
    stroke: var(--warning);
    stroke-width: 1.5;
    opacity: 0.3;
    stroke-dasharray: 3,3;
}

/* ===== Phasor Trail ===== */
.trail-dot {
    fill: var(--accent);
    opacity: 0.3;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    header {
        padding: 12px 16px;
    }

    header h1 {
        font-size: 1rem;
    }

    .subtitle {
        display: none;
    }

    main {
        padding: 16px;
        gap: 14px;
    }

    .viz-container {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .svg-wrapper {
        padding: 16px;
    }

    .svg-wrapper svg {
        max-width: 260px;
    }

    .controls-container {
        flex-direction: column;
        align-items: stretch;
        padding: 16px;
        gap: 16px;
    }

    .control-group {
        flex-direction: column;
        gap: 16px;
    }

    .button-group {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .action-button {
        justify-content: center;
    }

    .wheel-info,
    .phasor-info {
        grid-template-columns: repeat(3, 1fr);
    }

    .info-value {
        font-size: 0.78rem;
    }
}

@media (max-width: 400px) {
    .back-button span,
    .back-button {
        font-size: 0;
        padding: 8px;
    }
    
    .back-button svg {
        width: 20px;
        height: 20px;
    }

    .svg-wrapper svg {
        max-width: 220px;
    }
}

/* ===== Animation for badge ===== */
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.3); }
    50% { box-shadow: 0 0 8px 2px rgba(255, 107, 107, 0.2); }
}

.status-badge.reverse {
    animation: pulse-glow 2s ease-in-out infinite;
}
