:root {
    --bg-color: #f4f1ea;
    --panel-bg: #fffdf9;
    --border-color: #2c3e50;
    --text-primary: #2c3e50;
    --text-secondary: #5d6d7e;
    --accent-blue: #3b82f6;
    --accent-green: #10b981;
    --accent-red: #e74c3c;
    --accent-gold: #f59e0b;
    --accent-highlight: #fff9c4;
    --dark-surface: #0d1017;
    --dark-panel: rgba(12, 16, 24, 0.72);
    --dark-border: rgba(255, 255, 255, 0.14);
    --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;
    min-height: 100vh;
    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");
}

.app-container {
    max-width: 1400px;
    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 {
    position: relative;
    text-align: center;
    padding-top: 20px;
}

.header h1 {
    font-size: 2.7rem;
    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;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.18rem;
    max-width: 760px;
    margin: 0 auto;
}

#state-readout {
    position: absolute;
    right: 20px;
    top: 16px;
    min-width: 220px;
    transform: rotate(2deg);
    text-align: left;
    z-index: 10;
}

.readout-title {
    display: block;
    margin-bottom: 12px;
    font-size: 1.1rem;
    border-bottom: 2px dashed #d4c454;
    padding-bottom: 5px;
}

.readout-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 16px;
}

main {
    display: grid;
    grid-template-columns: 1.2fr 0.95fr;
    gap: 28px;
}

.visualizer-section {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

.glass-dark {
    background:
        radial-gradient(circle at top left, rgba(59, 130, 246, 0.16), transparent 28%),
        radial-gradient(circle at top right, rgba(245, 158, 11, 0.12), transparent 24%),
        linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.015)),
        var(--dark-surface);
    backdrop-filter: blur(18px);
}

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

#lane-canvas,
#controller-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.overlay {
    position: absolute;
    inset: 18px 18px auto 18px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    z-index: 10;
    pointer-events: none;
}

.overlay-pills {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.feedback-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.58);
    border: 1px solid rgba(255, 255, 255, 0.16);
    color: white;
    border-radius: 999px;
    padding: 7px 14px;
}

.label {
    font-size: 0.74rem;
    letter-spacing: 0.12em;
    font-family: var(--font-mono);
    color: #93a4bf;
}

.pill-value {
    font-size: 0.78rem;
    font-family: var(--font-ui);
    font-weight: 600;
    letter-spacing: 0.03em;
}

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

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

.bottom-overlay {
    position: absolute;
    inset: auto 18px 18px 18px;
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 12px;
    z-index: 10;
    pointer-events: none;
}

.steering-hint,
.status-prompt {
    background: rgba(0, 0, 0, 0.58);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    padding: 8px 14px;
    color: #c7d3e3;
    font-family: var(--font-ui);
    font-size: 0.85rem;
}

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

.status-prompt {
    max-width: 360px;
    text-align: right;
}

.controller-panel {
    min-height: 300px;
    padding: 18px;
}

.controller-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 16px;
    margin-bottom: 16px;
}

.controller-header h3 {
    color: white;
    font-family: var(--font-ui);
    font-size: 1.15rem;
}

.controller-header p {
    color: #9db0c8;
    font-family: var(--font-ui);
    font-size: 0.9rem;
    max-width: 420px;
}

.controller-metrics {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.metric-chip {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 10px 12px;
    min-width: 112px;
}

.metric-chip span {
    display: block;
    color: #8fa2bb;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    font-family: var(--font-mono);
    text-transform: uppercase;
}

.metric-chip strong {
    color: white;
    font-family: var(--font-ui);
    font-size: 1rem;
}

.theory-toggle {
    align-self: center;
    font-family: var(--font-ui);
    font-size: 0.84rem;
    letter-spacing: 0.04em;
    padding: 10px 14px;
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    cursor: pointer;
}

.theory-toggle.active {
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(96, 165, 250, 0.45);
    color: #dbeafe;
}

.belief-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 16px;
    margin-bottom: 14px;
}

.pid-grid {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.pid-row {
    display: grid;
    grid-template-columns: 92px 1fr 78px;
    align-items: center;
    gap: 10px;
}

.pid-label {
    color: #d4deec;
    font-family: var(--font-ui);
    font-size: 0.82rem;
}

.belief-row {
    display: grid;
    grid-template-columns: 84px 1fr 44px;
    align-items: center;
    gap: 10px;
}

.belief-label,
.belief-value {
    color: #d4deec;
    font-family: var(--font-ui);
    font-size: 0.82rem;
}

.belief-bar {
    height: 12px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    overflow: hidden;
}

.belief-fill {
    height: 100%;
    width: 25%;
    border-radius: inherit;
    transition: width 0.18s ease;
}

.stay-left {
    background: linear-gradient(90deg, #60a5fa, #93c5fd);
}

.stay-right {
    background: linear-gradient(90deg, #34d399, #6ee7b7);
}

.change-left {
    background: linear-gradient(90deg, #f59e0b, #fcd34d);
}

.change-right {
    background: linear-gradient(90deg, #fb7185, #fda4af);
}

.pid-p {
    background: linear-gradient(90deg, #2563eb, #60a5fa);
}

.pid-i {
    background: linear-gradient(90deg, #7c3aed, #c4b5fd);
}

.pid-d {
    background: linear-gradient(90deg, #d97706, #fcd34d);
}

.pid-goal {
    background: linear-gradient(90deg, #1d4ed8, #38bdf8);
}

#controller-canvas {
    height: 180px;
    border-radius: 18px;
    background: rgba(4, 8, 13, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

#controller-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(2, 6, 12, 0.68);
    color: #9db0c8;
    font-family: var(--font-mono);
    font-size: 0.84rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    transition: opacity 0.3s ease;
    z-index: 20;
}

#controller-panel.blurred #controller-canvas,
#controller-panel.blurred .belief-grid,
#controller-panel.blurred .pid-grid,
#controller-panel.blurred .controller-header {
    filter: blur(7px);
    opacity: 0.18;
}

.schematic-legend {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    color: #c9d6e7;
    font-family: var(--font-ui);
    font-size: 0.78rem;
}

.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 6px;
}

.legend-dot.sensing {
    background: #fbbf24;
}

.legend-dot.inference {
    background: #60a5fa;
}

.legend-dot.action {
    background: #a78bfa;
}

.schematic-modal {
    position: fixed;
    inset: 0;
    z-index: 120;
}

.schematic-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(3, 6, 12, 0.72);
    backdrop-filter: blur(8px);
}

.schematic-dialog {
    position: absolute;
    inset: 4vh 4vw;
    border-radius: 34px;
    border: 3px solid rgba(44, 62, 80, 0.65);
    padding: 22px;
    box-shadow: 0 20px 70px rgba(0, 0, 0, 0.4);
    overflow: auto;
}

.schematic-modal-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: start;
    margin-bottom: 16px;
}

.schematic-modal-header h2 {
    color: white;
    font-family: var(--font-ui);
    font-size: 1.65rem;
    margin-bottom: 6px;
}

.schematic-modal-header p {
    color: #a6bad4;
    font-family: var(--font-ui);
    font-size: 1rem;
}

.schematic-modal-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.schematic-close {
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.07);
    color: #e5edf8;
    cursor: pointer;
    font-family: var(--font-ui);
}

.schematic-layout {
    display: grid;
    grid-template-columns: minmax(720px, 1.5fr) minmax(320px, 0.72fr);
    gap: 18px;
    align-items: start;
}

.schematic-main {
    min-width: 0;
}

.schematic-svg-wrap {
    border-radius: 22px;
    background: rgba(255, 248, 238, 0.96);
    border: 1px solid rgba(44, 62, 80, 0.16);
    overflow: hidden;
}

.schematic-svg-wrap.large {
    min-height: 580px;
}

.schematic-svg {
    display: block;
    width: 100%;
    height: auto;
    color: #111827;
}

.schematic-svg.interactive {
    cursor: default;
}

.schematic-shell,
.system-boundary,
.user-model-boundary,
.env-shell,
.env-inner {
    fill: none;
    stroke: #111827;
}

.schematic-shell {
    stroke-width: 2;
}

.system-boundary {
    fill: #f8efe3;
    stroke-width: 3;
}

.user-model-boundary {
    fill: #f8f7f3;
    stroke-width: 2.2;
}

.env-shell,
.env-inner {
    stroke-width: 1.5;
}

.schematic-title,
.schematic-side-label,
.schematic-node-title,
.schematic-subtitle {
    fill: #111827;
    font-family: Georgia, 'Times New Roman', serif;
}

.schematic-title {
    font-size: 24px;
    font-weight: 700;
}

.schematic-title.right {
    font-weight: 500;
}

.schematic-subtitle {
    font-size: 16px;
}

.schematic-side-label {
    font-size: 18px;
}

.schematic-caption,
.schematic-node-sub,
.schematic-mini-label {
    fill: #334155;
    font-family: var(--font-ui);
}

.schematic-caption {
    font-size: 11px;
}

.schematic-node-title {
    font-size: 18px;
}

.schematic-node-sub {
    font-size: 13px;
}

.schematic-node-sub.small {
    font-size: 11px;
}

.schematic-mini-label {
    font-size: 10px;
}

.schematic-user-ring,
.mini-dashed {
    fill: none;
    stroke: #111827;
    stroke-width: 1.2;
    stroke-dasharray: 3 4;
}

.port {
    stroke: #475569;
    stroke-width: 1;
}

.port.sensing {
    fill: #f6b55f;
}

.port.action {
    fill: #9ea7ff;
}

.schematic-zone {
    cursor: pointer;
}

.schematic-zone:hover .schematic-node,
.schematic-zone:hover .schematic-mini-node,
.schematic-zone:hover .schematic-user-ring {
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.18));
}

.schematic-node,
.schematic-mini-node {
    fill: #f8f7f3;
    stroke: #475569;
    stroke-width: 1.4;
    transition: fill 0.2s ease, stroke 0.2s ease, filter 0.2s ease;
}

.schematic-node.active,
.schematic-mini-node.active {
    fill: #eef6ff;
    stroke: #3b82f6;
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.18));
}

.schematic-node.action-active,
.schematic-mini-node.action-active {
    fill: #f4efff;
    stroke: #8b5cf6;
}

.schematic-node.warning-active,
.schematic-mini-node.warning-active {
    fill: #fff7e8;
    stroke: #f59e0b;
}

.environment-node {
    fill: #f7f3ea;
}

.schematic-flow,
.schematic-link {
    fill: none;
    stroke-width: 2;
    color: #64748b;
    stroke: currentColor;
    opacity: 0.8;
    transition: color 0.2s ease, opacity 0.2s ease, stroke-width 0.2s ease;
}

.schematic-flow.sensing,
.schematic-link.sensing {
    color: #f59e0b;
}

.schematic-flow.inference,
.schematic-link.inference {
    color: #3b82f6;
}

.schematic-flow.action,
.schematic-link.action {
    color: #8b5cf6;
}

.schematic-flow.active,
.schematic-link.active {
    opacity: 1;
    stroke-width: 3;
}

.schematic-sidebar {
    display: grid;
    gap: 14px;
}

.schematic-focus-card,
.schematic-live-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 22px;
    padding: 16px 18px;
}

.focus-kicker {
    display: block;
    color: #8fb4ff;
    font-family: var(--font-ui);
    margin-bottom: 6px;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.schematic-focus-card h3,
.schematic-live-card h4 {
    color: #eef4fb;
    font-family: var(--font-ui);
    margin-bottom: 8px;
}

.schematic-focus-card p,
.schematic-live-card p {
    color: #a5b7cd;
    font-family: var(--font-ui);
    font-size: 0.88rem;
}

.mini-meter-row,
.distribution-row {
    display: grid;
    grid-template-columns: 88px 1fr 52px;
    gap: 10px;
    align-items: center;
    margin-top: 10px;
    color: #d6e0ee;
    font-family: var(--font-ui);
    font-size: 0.84rem;
}

.mini-meter {
    height: 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.mini-fill {
    height: 100%;
    width: 0%;
    border-radius: inherit;
    transition: width 0.18s ease;
}

.mini-fill.sensing {
    background: linear-gradient(90deg, #f59e0b, #fcd34d);
}

.mini-fill.inference {
    background: linear-gradient(90deg, #60a5fa, #93c5fd);
}

.mini-fill.action {
    background: linear-gradient(90deg, #8b5cf6, #c4b5fd);
}

.policy-chip-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.policy-chip {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 12px;
}

.policy-chip span {
    display: block;
    color: #93a8c4;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.policy-chip strong {
    color: #eef4fb;
    font-family: var(--font-ui);
    font-size: 1rem;
}

.policy-chip strong:empty::after {
    content: "-";
    color: #94a3b8;
}

.hidden {
    display: none !important;
}

.controls-section {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.panel-desc,
.slider-desc,
.toggle-card p,
.scenario-card p,
.rationale-panel p {
    font-family: var(--font-ui);
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.mode-toggle,
.scenario-selector {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.mode-btn,
.scenario-btn,
.primary-btn {
    font-family: var(--font-main);
    font-size: 1.18rem;
    padding: 10px 18px;
    background: transparent;
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
    border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.mode-btn:hover,
.scenario-btn:hover,
.primary-btn:hover {
    transform: translate(-2px, -2px);
    box-shadow: 4px 4px 0 rgba(44, 62, 80, 0.12);
}

.mode-btn.active,
.scenario-btn.active,
.primary-btn {
    background: var(--border-color);
    color: var(--panel-bg);
}

.scenario-card {
    margin-top: 18px;
}

.scenario-badge {
    display: inline-block;
    margin-bottom: 8px;
    padding: 4px 10px;
    background: rgba(44, 62, 80, 0.12);
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.74rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.controls-panel h3,
.rationale-panel h3,
.controls-section h3 {
    font-size: 1.6rem;
}

.slider-wrapper {
    margin-top: 16px;
}

.slider-wrapper label {
    display: block;
    font-size: 1.15rem;
}

.slider-desc {
    margin-bottom: 8px;
}

input[type=range] {
    -webkit-appearance: none;
    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);
}

/* Firefox support (partial) */
input[type=range]::-moz-range-track {
    width: 100%;
    height: 8px;
    background: var(--border-color);
    border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
}

input[type=range]::-moz-range-thumb {
    height: 22px;
    width: 12px;
    background: var(--accent-red);
    border: 2px solid var(--border-color);
    border-radius: 4px;
}


.toggle-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 18px;
}

.toggle-card {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border: 2px dashed rgba(44, 62, 80, 0.2);
    border-radius: 24px;
    padding: 14px 16px;
}

.toggle-title {
    display: block;
    font-size: 1.05rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
    flex-shrink: 0;
}

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

.slider.round {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #cbd5e1;
    transition: .4s;
    border-radius: 34px;
    border: 2px solid var(--border-color);
}

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

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

.switch input:checked+.slider.round:before {
    transform: translateX(22px);
}


.control-actions {
    margin-top: 18px;
}

.tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.tag.info {
    background: rgba(59, 130, 246, 0.12);
    color: var(--accent-blue);
}

.tag.success {
    background: rgba(16, 185, 129, 0.14);
    color: #047857;
}

.tag.warning {
    background: rgba(245, 158, 11, 0.14);
    color: #b45309;
}

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

@media (max-width: 1180px) {
    main {
        grid-template-columns: 1fr;
    }

    #state-readout {
        position: static;
        margin: 18px auto 0;
        transform: rotate(-1deg);
        max-width: 420px;
    }
}

@media (max-width: 760px) {
    .app-container {
        padding: 14px;
    }

    .header h1 {
        font-size: 2.05rem;
        padding-left: 10px;
    }

    .overlay,
    .bottom-overlay {
        inset-inline: 10px;
    }

    .bottom-overlay {
        flex-direction: column;
        align-items: stretch;
    }

    .status-prompt {
        max-width: none;
        text-align: left;
    }

    .controller-header,
    .toggle-grid {
        grid-template-columns: 1fr;
        display: grid;
    }

    .belief-grid {
        grid-template-columns: 1fr;
    }

    .toggle-card {
        flex-direction: column;
    }
}

@media (max-width: 980px) {
    .desktop-only {
        display: none !important;
    }
}
