:root {
    --bg-dark: #020617;
    --panel-bg: rgba(15, 23, 42, 0.7);
    --border-glow: rgba(6, 182, 212, 0.2);
    --primary: #06b6d4;
    --secondary: #10b981;
    --accent: #f59e0b;
    --danger: #ef4444;
    --text-main: #f8fafc;
    --text-dim: #94a3b8;
    --card-bg: rgba(30, 41, 59, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

#phet-stage {
    position: absolute;
    top: 0;
    left: 0;
    width: 1280px;
    height: 720px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: transparent;
    transform-origin: top left;
}

html {
    background: #020617;
}

body.flowchart-page {
    font-family: 'Inter', sans-serif;
    background: transparent;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

#bgCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background: radial-gradient(circle at 50% 50%, #0f172a 0%, #020617 100%);
}

/* Nav Styles */
nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: rgba(2, 6, 23, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
    width: 100%;
    z-index: 1000;
}

.nav-center {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chapter-label { color: var(--text-dim); font-size: 0.9rem; }
.exp-label { font-weight: 700; color: var(--primary); }
.divider { color: rgba(255, 255, 255, 0.2); }

.btn-back {
    text-decoration: none;
    color: var(--text-dim);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    transition: all 0.2s;
}

.btn-back:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.08);
}

/* App Layout */
main {
    flex: 1;
    min-height: 0;
    width: 100%;
    overflow: hidden;
}

.sim-container {
    display: grid;
    grid-template-columns: 280px 1fr 300px;
    height: 100%;
}

.sidebar {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 20px;
    overflow-y: auto;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 10px; }

.debug-panel {
    border-right: none;
    border-left: 1px solid rgba(255, 255, 255, 0.05);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.panel-header i { color: var(--primary); }

/* Palette Items */
.category-label {
    text-transform: uppercase;
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--text-dim);
    letter-spacing: 1px;
    margin: 15px 0 10px 0;
}

.flow-item {
    cursor: grab;
    margin-bottom: 12px;
    transition: transform 0.2s;
}

.flow-item:active { cursor: grabbing; }
.flow-item:hover { transform: scale(1.02); }

.preview {
    padding: 12px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-dim);
}

.f-start-end { border-radius: 25px; border-color: #f43f5e; color: #f43f5e; }
.f-process { border-color: var(--primary); color: var(--primary); }
.f-decision { transform: perspective(100px) rotateX(10deg); border-color: var(--accent); color: var(--accent); }
.f-io { transform: skew(-15deg); border-color: var(--secondary); color: var(--secondary); }
.f-note { border-style: dashed; }

/* AI Box */
.ai-box {
    margin-top: auto;
    padding: 15px;
    background: rgba(6, 182, 212, 0.05);
    border: 1px solid rgba(6, 182, 212, 0.1);
    border-radius: 16px;
}

#ai-input {
    width: 100%;
    height: 80px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    color: var(--text-main);
    padding: 10px;
    font-size: 0.8rem;
    resize: none;
    margin: 10px 0;
}

.btn-primary-glow {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: none;
    background: var(--primary);
    color: white;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(6, 182, 212, 0.4);
    transition: all 0.2s;
}

/* Workspace */
.workspace {
    position: relative;
    overflow: hidden;
    background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 30px 30px;
}

#transform-layer {
    position: absolute;
    width: 1px;
    height: 1px;
    top: 0;
    left: 0;
    transform-origin: 0 0;
}

.connection-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.block-layer {
    position: absolute;
    inset: 0;
}

/* Blocks in Workspace */
.flow-block {
    position: absolute;
    min-width: 120px;
    padding: 15px;
    text-align: center;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    border: 2px solid var(--primary);
    border-radius: 8px;
    cursor: grab;
    user-select: none;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    z-index: 10;
}

.flow-block:active { cursor: grabbing; }

.flow-block.active-exec {
    border-color: var(--secondary) !important;
    box-shadow: 0 0 25px rgba(16, 185, 129, 0.4);
    transform: scale(1.05);
    z-index: 100;
}

.flow-block.active-exec .label-editor {
    color: var(--secondary);
}
.flow-block.type-decision { 
    clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
    min-width: 150px;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-color: var(--accent);
}
.flow-block.type-io { transform: skew(-15deg); border-color: var(--secondary); }
.flow-block.type-io .content { transform: skew(15deg); }

.flow-block .label-editor {
    outline: none;
    font-size: 0.9rem;
    font-weight: 600;
    color: white;
}

/* Block Pins */
.block-pin {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--bg-dark);
    border: 2px solid var(--text-dim);
    border-radius: 50%;
    cursor: crosshair;
    transition: all 0.2s;
}

.block-pin:hover {
    background: var(--primary);
    border-color: var(--text-main);
    transform: scale(1.3);
}

.pin-top { top: -6px; left: 50%; transform: translateX(-50%); }
.pin-bottom { bottom: -6px; left: 50%; transform: translateX(-50%); }
.pin-left { left: -6px; top: 50%; transform: translateY(-50%); }
.pin-right { right: -6px; top: 50%; transform: translateY(-50%); }

/* Simulation Toolbar */
.sim-toolbar {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px 25px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    gap: 20px;
    backdrop-filter: blur(20px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.sim-toolbar button {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.sim-toolbar button:hover { color: var(--primary); transform: scale(1.1); }
#sim-play { color: var(--secondary); font-size: 1.5rem; }
#sim-stop { color: var(--danger); }

.speed-control {
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    padding-left: 20px;
}

.speed-control span { font-size: 0.75rem; color: var(--text-dim); font-weight: 700; text-transform: uppercase; }

/* Debug Panel Elements */
.panel-section {
    display: flex;
    flex-direction: column;
    height: 40%;
}

.console {
    flex-grow: 1;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 12px;
    padding: 15px;
    font-family: 'Space Grotesk', monospace;
    font-size: 0.8rem;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.log-entry { margin-bottom: 8px; color: #e2e8f0; }
.log-entry.system { color: var(--primary); font-weight: 700; }
.log-entry.process { color: var(--secondary); }

.var-table {
    flex-grow: 1;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    padding: 15px;
}

.empty-vars {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.8rem;
    padding-top: 20px;
}

/* Utilities */
.zoom-controls {
    position: absolute;
    right: 20px;
    bottom: 30px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.zoom-controls button {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--panel-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    cursor: pointer;
    backdrop-filter: blur(10px);
}

.actions { gap: 10px; padding-top: 20px; }
.btn-outline, .btn-danger-outline {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-dim);
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
}

.btn-danger-outline { color: var(--danger); border-color: rgba(239, 68, 68, 0.2); }
.btn-danger-outline:hover { background: rgba(239, 68, 68, 0.05); }

/* Wires */
.wire {
    fill: none;
    stroke: var(--text-dim);
    stroke-width: 3;
    transition: stroke 0.3s;
}

.wire.active {
    stroke: var(--primary);
    stroke-dasharray: 8;
    animation: flowLines 1s infinite linear;
}

.workspace-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: rgba(255, 255, 255, 0.1);
    font-size: 1.5rem;
    font-weight: 700;
    pointer-events: none;
    z-index: 0;
}

.workspace-hint span {
    font-size: 0.9rem;
    font-weight: 400;
    opacity: 0.5;
}

