:root {
    --color-shaft: #334155;
    --color-sleeve: #dc2626;
    --color-ring: #d97706;
    --color-gear: #475569;
    --color-bg: #0b1220;
    --panel-bg: #0f1828;
    --text-main: #e6edf5;
    --text-muted: #9ca8bb;
    --border-color: #1f2c3e;
    --border-radius: 12px;
}

html, body {
    height: auto;
    min-height: 100vh;
    margin: 0;
    font-family: 'Segoe UI', sans-serif;
    background: var(--color-bg);
    color: var(--text-main);
    overflow-y: auto;
}
body {
    display: flex;
    flex-direction: column;
    padding: 20px;
    align-items: stretch;
}

header {
    background: var(--panel-bg);
    padding: 15px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 14px 30px rgba(0,0,0,0.35);
    flex-shrink: 0;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto 20px auto;
    box-sizing: border-box;
}
.header-left { display: flex; align-items: center; gap: 15px; }
.back-btn { color: var(--text-muted); font-size: 1.2rem; text-decoration: none; }
.back-btn:hover { color: #1fb6ff; }
h1 { margin: 0; font-size: 1.5rem; color: var(--text-main); }
.subtitle { color: var(--text-muted); margin: 0; font-size: 1rem; }

.content-card {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    box-sizing: border-box;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 14px 30px rgba(0,0,0,0.35);
}

.main-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-sizing: border-box;
    width: 100%;
}

.vis-column { display: flex; flex-direction: column; gap: 15px; width: 100%; }
.controls-column {
    background: var(--panel-bg);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    padding: 25px;
    display: flex;
    flex-direction: column;
    gap: 30px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    width: 100%;
    box-sizing: border-box;
}

.view-box {
    background: #0f1a2a;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    position: relative;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
}
.view-box-detail { height: clamp(320px, 45vh, 520px); }
.view-box-cross { height: clamp(220px, 35vh, 360px); }

@media (min-width: 1024px) {
    .main-layout {
        display: grid;
        grid-template-columns: 1fr 350px;
        align-items: stretch;
    }
    .controls-column {
        height: 100%;
        align-self: stretch;
    }
}

@media (max-width: 768px) {
    .view-box-detail { height: clamp(260px, 40vh, 460px); }
    .view-box-cross { height: clamp(200px, 30vh, 300px); }
}

@media (max-width: 600px) {
    body { padding: 10px; }
    header { flex-direction: column; align-items: flex-start; gap: 10px; padding: 15px; }
    .header-left { width: 100%; }
    .back-btn { margin-right: 10px; }
}

.view-label {
    position: absolute; top: 10px; left: 10px; background: rgba(15, 24, 40, 0.9);
    padding: 4px 10px; border-radius: 4px; font-weight: bold; color: var(--text-muted); z-index: 10;
    border: 1px solid var(--border-color); font-size: 0.9rem; text-transform: uppercase;
}

.canvas-container { width: 100%; height: 100%; position: relative; background: #0f1a2a; min-height: 0; }
canvas { width: 100%; height: 100%; display: block; }

.control-group label { display: flex; justify-content: space-between; font-weight: 600; color: var(--text-main); margin-bottom: 10px; font-size: 1.1rem; }
.value-display { font-family: monospace; color: #1fb6ff; }

input[type=range] { -webkit-appearance: none; width: 100%; background: transparent; }
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; height: 28px; width: 28px; border-radius: 50%; background: var(--color-sleeve);
    border: 2px solid #000; cursor: pointer; margin-top: -10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%; height: 8px; background: #1f2c3e; border-radius: 4px;
}
#slider-speed::-webkit-slider-thumb { background: #94a3b8; border-color: #000; }

.toggle-row { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; color: var(--text-muted); cursor: pointer; }

.status-panel {
    background: #111a29;
    border-left: 6px solid #1f2c3e;
    padding: 15px;
    border-radius: 4px;
}
.status-header { font-weight: bold; color: var(--text-muted); font-size: 0.9rem; text-transform: uppercase; margin-bottom: 5px; }
.status-main { font-size: 1.2rem; font-weight: 600; color: var(--text-main); margin-bottom: 5px; }
.status-desc { font-size: 0.95rem; line-height: 1.4; color: #cbd5e1; }

.legend { display: flex; gap: 15px; justify-content: center; margin-top: 5px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; color: var(--text-muted); }
.dot { width: 12px; height: 12px; border-radius: 3px; }

.phase-blocked { border-left-color: #dc2626; background: rgba(220, 38, 38, 0.15); }
.phase-engaged { border-left-color: #16a34a; background: rgba(22, 163, 74, 0.15); }
.phase-sync { border-left-color: #f59e0b; background: rgba(245, 158, 11, 0.15); }

@keyframes blink { 0% { opacity: 0.5; } 100% { opacity: 1; } }
.blink-text { animation: blink 1s infinite; color: #ef4444; }
