:root {
    --bg-color: #f4f1ea;
    /* Soft paper color */
    --panel-bg: #fffdf9;
    --border-color: #2c3e50;
    /* Charcoal ink */
    --text-primary: #2c3e50;
    --text-secondary: #5d6d7e;

    /* Highlight aesthetics */
    --accent-blue: #3b82f6;
    --accent-green: #10b981;
    --accent-red: #e74c3c;
    --accent-gold: #f59e0b;
    --accent-highlight: #fff9c4;

    --font-main: 'Patrick Hand', cursive;
    --font-mono: 'JetBrains Mono', monospace;
    --font-ui: 'Outfit', sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    line-height: 1.6;
    overflow-x: hidden;
    background-image: url("data:image/svg+xml,%3Csvg width='200' height='200' viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.6' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23noise)' opacity='0.05'/%3E%3C/svg%3E");
    min-height: 100vh;
}

.app-container {
    max-width: 1350px;
    margin: 0 auto;
    padding: 20px;
}

.sketch-panel {
    background: var(--panel-bg);
    border: 3px solid var(--border-color);
    box-shadow: 6px 6px 0 rgba(44, 62, 80, 0.15);
    padding: 24px;
    border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
    margin-bottom: 20px;
}

.sketch-note {
    background: var(--accent-highlight);
    border: 2px solid #d4c454;
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.1);
    transform: rotate(-1deg);
    border-radius: 2px 5px 2px 5px;
    padding: 16px;
}

header {
    text-align: center;
    position: relative;
    padding-top: 20px;
}

#state-readout {
    position: absolute;
    right: 20px;
    top: 15px;
    min-width: 200px;
    font-size: 0.95rem;
    transform: rotate(2deg);
    padding: 16px 20px;
    text-align: left;
    z-index: 10;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    padding-left: 20px;
    display: inline-block;
    border-bottom: 3px solid var(--border-color);
    border-radius: 10px 50px 10px 50px;
    padding-bottom: 2px;
}

header p {
    color: var(--text-secondary);
    font-size: 1.2rem;
    margin-bottom: 15px;
}


/* Mode Toggle */
.mode-toggle {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

.mode-btn {
    font-family: var(--font-main);
    font-size: 1.2rem;
    padding: 8px 24px;
    background: transparent;
    border: 2px solid var(--border-color);
    border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.mode-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.mode-btn.active {
    background: var(--border-color);
    color: var(--panel-bg);
    transform: scale(1.05);
    box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.2);
}

main {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 30px;
}

/* === DRIVING SIMULATION (DARK MODE PRESERVED) === */
.visualizer-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.dark-wrapper {
    background-color: #0d0f14;
    border: 3px solid var(--border-color);
    box-shadow: 6px 6px 0 rgba(44, 62, 80, 0.3);
    border-radius: 24px;
    overflow: hidden;
    position: relative;
}

.canvas-container {
    width: 100%;
    aspect-ratio: 16 / 10;
}

#mhc-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.overlay {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    z-index: 10;
}

.feedback-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.6);
    padding: 6px 14px;
    border-radius: 100px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
}

.feedback-indicator .label {
    font-size: 0.75rem;
    font-family: var(--font-mono);
    letter-spacing: 0.1em;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-red);
    box-shadow: 0 0 10px var(--accent-red);
    transition: all 0.3s ease;
}

.dot.active {
    background: var(--accent-green);
    box-shadow: 0 0 10px var(--accent-green);
}

.steering-hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 16px;
    border-radius: 12px;
    font-family: var(--font-ui);
    font-size: 0.85rem;
    color: #94a3b8;
}

.steering-hint span {
    color: white;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
}

#tracing-viz-container {
    width: 100%;
    aspect-ratio: 16 / 5;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

#tracing-canvas {
    width: 100%;
    height: 100%;
    display: block;
    transition: filter 0.6s ease, opacity 0.6s ease;
}

#tracing-viz-container.blurred #tracing-canvas {
    filter: blur(8px);
    opacity: 0.15;
}

#tracing-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.2);
    z-index: 5;
    transition: opacity 0.4s ease;
}

#tracing-overlay span {
    font-size: 0.8rem;
    font-family: var(--font-mono);
    color: #94a3b8;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

#tracing-overlay.hidden,
.hidden {
    opacity: 0;
    pointer-events: none;
    display: none !important;
}

#instruction-flash {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-2deg);
    font-size: 3rem;
    font-weight: bold;
    color: var(--accent-red);
    text-shadow: 2px 2px 0px white, -2px -2px 0px white, 2px -2px 0px white, -2px 2px 0px white;
    z-index: 100;
    font-family: var(--font-main);
    letter-spacing: 4px;
    text-align: center;
    pointer-events: none;
    animation: flashPulse 0.5s infinite alternate;
}

@keyframes flashPulse {
    from {
        transform: translate(-50%, -50%) rotate(-2deg) scale(1);
    }

    to {
        transform: translate(-50%, -50%) rotate(-2deg) scale(1.1);
    }
}

/* === PROGRESS BAR === */
#trial-progress-bar {
    position: absolute;
    bottom: 0px;
    left: 0;
    width: 100%;
    height: 8px;
    background: rgba(0, 0, 0, 0.5);
    z-index: 20;
    display: block !important;
    /* Overriding .hidden if testing */
}

#trial-progress-bar.hidden {
    display: none !important;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6);
    transition: width 0.1s linear;
}


/* === CONTROLS & MATRIX === */
.controls-section {
    display: flex;
    flex-direction: column;
}

.tabbed-container {
    display: flex;
    flex-direction: column;
    margin-top: 15px;
}

.tab-header {
    display: flex;
    gap: 0px;
    z-index: 2;
    position: relative;
    padding: 0;
    margin-bottom: -3px;
    /* Pull content up to meet tabs */
}

.tab-btn {
    font-family: var(--font-main);
    font-size: 1.2rem;
    padding: 8px 30px;
    background: #e9eaee;
    border: 3px solid var(--border-color);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    position: relative;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
}

.tab-btn:first-child {
    border-top-left-radius: 15px;
}

.tab-btn:last-child {
    border-top-right-radius: 15px;
    margin-left: -3px;
}

.tab-btn.active {
    background: var(--panel-bg);
    color: var(--text-primary);
    z-index: 10;
    padding-top: 10px;
    margin-top: -2px;
    border-bottom: none;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    right: 0;
    height: 6px;
    background: var(--panel-bg);
    z-index: 11;
}

.tab-content {
    margin-top: 0 !important;
}

.tab-content.sketch-panel {
    border-radius: 0 15px 15px 15px;
    /* Flatten top left for tabs */
    margin-top: 0;
}

/* 3D Matrix Cube */
.matrix-panel h3 {
    text-align: center;
    font-size: 1.5rem;
}

.cube-container {
    perspective: none;
    width: 100%;
    position: relative;
    margin-bottom: 0px;
}

.cube-viewport {
    position: relative;
    width: 100%;
    max-width: 500px;
    aspect-ratio: 5 / 3;
    margin: 0 auto;
}

.cube-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.svg-edge {
    stroke: var(--text-secondary);
    stroke-width: 3;
    stroke-linecap: round;
    opacity: 0.25;
}

.hidden-edge {
    stroke-dasharray: 6 6;
    opacity: 0.15;
}

.svg-axis {
    stroke: var(--text-secondary);
    stroke-width: 2;
    stroke-dasharray: 4 4;
}

.svg-axis-label {
    fill: var(--text-secondary);
    font-family: var(--font-main);
    font-size: 1.2rem;
    font-weight: bold;
}

/* Nodes */
.cube-node {
    position: absolute;
    width: 28px;
    height: 28px;
    background: var(--panel-bg);
    border: 3px solid var(--text-secondary);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.15);
}

.cube-node span {
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--text-secondary);
}

.cube-node:hover {
    outline: 4px solid var(--accent-gold);
    background: var(--accent-highlight);
    z-index: 10;
}

.cube-node.active {
    background: var(--accent-red);
    color: white;
    border-color: #c0392b;
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.6);
}

.cube-node.active span {
    color: white;
}

/* Scenario Card */
.scenario-card h4 {
    font-size: 1.4rem;
    margin-bottom: 10px;
    font-weight: 700;
}

.scenario-card p {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.scenario-badge {
    position: absolute;
    top: -10px;
    left: 15px;
    background: var(--border-color);
    color: white;
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-family: var(--font-mono);
}

.scenario-meta {
    display: flex;
    gap: 10px;
}

.mt-2 {
    margin-top: 10px;
}

.mt-4 {
    margin-top: 20px;
}

.mb-4 {
    margin-bottom: 20px;
}

.tag {
    padding: 4px 10px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid currentColor;
}

.tag.success {
    color: #27ae60;
    background: rgba(39, 174, 96, 0.1);
}

.tag.danger {
    color: #e74c3c;
    background: rgba(231, 76, 60, 0.1);
}

.tag.info {
    color: #2980b9;
    background: rgba(41, 128, 185, 0.1);
}

/* Controls UI */
.slider-wrapper label,
.switch-wrapper label {
    font-size: 1.2rem;
    font-weight: bold;
    display: block;
}

.slider-desc {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    margin: 10px 0;
    background: transparent;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    cursor: pointer;
    background: var(--border-color);
    border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
    /* sketch */
}

input[type=range]::-webkit-slider-thumb {
    height: 24px;
    width: 14px;
    border-radius: 4px;
    background: var(--accent-red);
    border: 2px solid var(--border-color);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    margin-top: -8px;
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
}

/* Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
    border: 2px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    top: 1px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    border: 2px solid var(--border-color);
}

input:checked+.slider {
    background-color: var(--accent-green);
}

input:checked+.slider:before {
    transform: translateX(21px);
}

/* Sketchy Button */
.sketch-btn {
    background: transparent;
    color: var(--border-color);
    border: 2px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
    font-family: var(--font-main);
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    transition: all 0.2s;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.15);
}

.sketch-btn:hover {
    background: var(--border-color);
    color: white;
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.2);
}

.sketch-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.1);
}

/* Questionnaire Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(244, 241, 234, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--panel-bg);
    max-width: 500px;
    width: 90%;
}

.modal-content h2 {
    text-align: center;
    margin-bottom: 10px;
    font-size: 2rem;
}

.question-block {
    margin-top: 20px;
}

.question {
    font-size: 1.2rem;
    margin-bottom: 10px;
}

.likert-scale {
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
}

.likert-scale label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.modal-footer {
    margin-top: 30px;
}

/* === RESPONSIVE MEDIA QUERIES === */
@media (max-width: 900px) {
    main {
        grid-template-columns: 1fr;
    }

    #state-readout {
        position: relative;
        right: auto;
        top: auto;
        margin: 20px auto 0;
        transform: rotate(0deg);
        max-width: 300px;
    }

    .mode-toggle {
        flex-direction: column;
        align-items: stretch;
    }

    .tab-header {
        padding-left: 0;
    }

    .tab-btn {
        flex: 1;
        padding: 8px 10px;
        font-size: 1.1rem;
    }

    .tab-content.sketch-panel {
        border-top-right-radius: 0;
    }

    .cube-node {
        transform: translate(-50%, -50%) scale(0.85);
    }

    header h1 {
        font-size: 2rem;
    }

    #instruction-flash {
        font-size: 2rem;
        width: 100%;
    }

    .steering-hint {
        display: none;
    }
}