/* Pin & Wiring Highlights */
.sim-pin-snap {
    box-shadow: 0 0 12px 2px rgba(255, 255, 255, 0.8), 0 0 4px 1px #fff;
    transform: scale(1.3);
    border-color: #fff !important;
    z-index: 2000;
}

.sim-pin-active {
    box-shadow: 0 0 8px 1px rgba(255, 255, 0, 0.6);
    background: #ffff00 !important;
}

.sim-pin:hover {
    box-shadow: 0 0 6px 1px rgba(255, 255, 255, 0.4);
    cursor: crosshair;
}

.sim-active-wire-preview {
    stroke-dasharray: 5, 5;
    animation: dash linear 1s infinite;
}

@keyframes dash {
    to { stroke-dashoffset: -10; }
}

/* ======= CSS reset and variable definitions ======= */
:root {
    /* Pro Dark Mode Base (Slate/Zinc hybrid) */
    --bg-darker: #09090b;
    /* Background Deep */
    --bg-dark: #121217;
    /* Secondary/Modal Background */
    --bg-panel: #18181b;
    /* Active Panel/Card Background */
    --bg-hover: #27272a;
    /* Hover State */
    --bg-glass: rgba(18, 18, 23, 0.75);
    /* Sophisticated Glass */

    /* Semantic Text Hierarchy */
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --text-bright: #ffffff;
    --text-code: #dcdcaa;
    --text-main: var(--text-primary);
    --text-main1: var(--text-primary);

    /* Pro Accents (Vibrant yet Refined) */
    --accent-primary: #3b82f6;
    /* Blue 500 */
    --accent-hover: #60a5fa;
    /* Blue 400 */
    --accent-success: #10b981;
    /* Emerald 500 */
    --accent-success-hover: #34d399;
    /* Emerald 400 */
    --accent-warning: #f59e0b;
    /* Amber 500 */
    --accent-warning-hover: #fbbf24;
    /* Amber 400 */
    --accent-danger: #ef4444;
    /* Red 500 */
    --accent-danger-hover: #f87171;
    /* Red 400 */

    /* Advanced Decorative Elements */
    --border-color: #27272a;
    --border-bright: #3f3f46;
    --border-glow: rgba(59, 130, 246, 0.5);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

    /* Typography */
    --font-main: 'Inter', system-ui, -apple-system, sans-serif;
    --font-display: 'Outfit', 'Inter', sans-serif;
    --font-code: 'JetBrains Mono', 'Consolas', monospace;

    --toolbar-height: 56px;
}

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

body.dark-theme {
    background-color: var(--bg-darker);
    color: var(--text-main);
    font-family: var(--font-main);
    height: 100vh;
    overflow: hidden;
}

/* ======= Layout structure ======= */
#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ======= Premium Toolbar ======= */
#top-toolbar {
    min-height: 50px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    z-index: 100;
    color: var(--text-bright);
}

.logo {
    font-size: 1.25rem;
    font-weight: 800;
    background: linear-gradient(90deg, #58a6ff, #a371f7);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 12px;
    letter-spacing: 0.5px;
    margin-right: 20px;
}

.logo i {
    -webkit-text-fill-color: #58a6ff;
    filter: drop-shadow(0 0 8px var(--border-glow));
}

.toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.toolbar-actions>* {
    flex-shrink: 0;
}

.divider {
    width: 1px;
    height: 24px;
    background: linear-gradient(to bottom, transparent, var(--border-color), transparent);
    margin: 0 6px;
}

/* Main Content Dual Pane */
#main-content {
    display: flex;
    flex: 1;
    min-height: 0;
    /* Prevents flex children from pushing bounds */
}

#blockly-container {
    flex: 1;
    min-width: 300px;
    position: relative;
    background-color: #ffffff; /* White background behind the transparent workspace */
}

#blocklyDiv {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Blockly Toolbox Styling for Light Mode */
.blocklyTreeLabel {
    color: #1e293b !important;
    font-family: var(--font-main) !important;
}

.blocklyToolboxDiv {
    background-color: #ffffff !important;
    border-right: 1px solid #e2e8f0 !important;
}

/* Resizers */
.resizer {
    background-color: var(--border-color);
    transition: background-color 0.2s;
}

#resizer-vertical {
    width: 5px;
    cursor: col-resize;
}

#resizer-horizontal {
    height: 5px;
    cursor: row-resize;
}

.resizer:hover,
.resizer:active {
    background-color: var(--accent-primary);
}

/* Right Panel (Code + Serial) */
#right-panel {
    width: 25%;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-panel);
}

#code-viewer-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 200px;
    background-color: var(--bg-code);
}

.panel-header {
    background-color: var(--bg-dark);
    padding: 10px 15px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: #eee;
}

#code-output {
    flex: 1;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    font-family: var(--font-code);
    font-size: 14px;
    line-height: 1.5;
    background-color: var(--bg-code);
}

#code-output code {
    background: transparent !important;
    padding: 15px;
    display: block;
    overflow-x: auto;
    white-space: pre;
}

/* Custom IDE Scrollbars for the right panel */
#right-panel ::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

#right-panel ::-webkit-scrollbar-corner {
    background: var(--bg-panel);
}

#right-panel ::-webkit-scrollbar-track {
    background: var(--bg-panel);
}

#right-panel ::-webkit-scrollbar-thumb {
    background: #424242;
    border-radius: 5px;
    border: 2px solid var(--bg-panel);
}

#right-panel ::-webkit-scrollbar-thumb:hover {
    background: #4f4f4f;
}

/* Tabs */
.panel-tabs {
    display: flex;
    background-color: var(--bg-dark);
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 10px 20px;
    cursor: pointer;
    font-family: var(--font-main);
    font-weight: 500;
}

.tab-btn.active {
    color: var(--text-main1);
    border-bottom: 2px solid var(--accent-primary);
}

/* Bottom Panel Views */
#bottom-panel-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.tab-content {
    display: none;
    flex: 1;
    flex-direction: column;
}

.tab-content.active {
    display: flex;
}

/* Serial Monitor View */
.serial-toolbar {
    padding: 8px 15px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

#serial-output {
    flex: 1;
    background-color: var(--bg-dark, #121217);
    color: #0f0;
    font-family: var(--font-code);
    padding: 4px;
    box-sizing: border-box;
    overflow: hidden;
    min-height: 0;
    width: 100%;
    height: 100%;
    position: relative;
}

#serial-output .xterm {
    height: 100% !important;
    width: 100% !important;
}

#serial-output .xterm-viewport {
    height: 100% !important;
    width: 100% !important;
    background-color: transparent !important;
}

#serial-output .xterm-screen {
    width: 100% !important;
}

.serial-input-wrapper {
    display: flex;
    align-items: center;
    padding: 8px 15px;
    background-color: var(--bg-code);
    border-top: 1px dashed var(--border-color);
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.2);
    z-index: 10;
    flex-shrink: 0;
}

.serial-input-wrapper i {
    color: var(--accent-primary) !important;
}

#serial-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main1);
    padding: 8px 12px;
    font-family: var(--font-code);
    font-size: 14px;
    outline: none;
}

#serial-input:focus {
    outline: none;
    box-shadow: none;
}

#btn-send-serial {
    background: transparent;
    color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-main);
    font-weight: 600;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

#btn-send-serial:hover {
    background: rgba(88, 166, 255, 0.1);
    transform: translateY(-1px);
}

/* Simulator View */
.simulator-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 1.2rem;
    background-color: var(--bg-darker);
}

.simulator-placeholder i {
    font-size: 3rem;
    margin-bottom: 10px;
    color: var(--border-color);
}

#wokwi-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background-color: white;
    /* Embedded simulators usually need white background */
}

/* ======= Button & Input Styles ======= */
.btn {
    background-color: var(--bg-hover);
    color: var(--text-bright);
    border: 1px solid var(--border-color);
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn:hover {
    background-color: #3e3e42;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

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

.btn:disabled,
.btn:disabled:hover,
.btn:disabled:active {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
    box-shadow: none !important;
    transform: none !important;
}

.btn.primary {
    background: linear-gradient(145deg, var(--accent-primary), #005a9e);
    border: none;
    color: white;
}

.btn.primary:hover {
    background: linear-gradient(145deg, var(--accent-hover), var(--accent-primary));
}

.btn.success {
    background: linear-gradient(145deg, var(--accent-success), #388e3c);
    border: none;
    color: white;
}

.btn.success:hover {
    background: linear-gradient(145deg, #66bb6a, var(--accent-success));
}

.btn.warning {
    background: linear-gradient(145deg, var(--accent-warning), #f57c00);
    border: none;
    color: white;
}

.btn.warning:hover {
    background: linear-gradient(145deg, #ffa726, var(--accent-warning));
}

.btn.outline {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.15));
    color: var(--text-bright);
    border-radius: 6px;
    transition: all 0.2s ease;
}

.btn.outline:hover {
    border-color: var(--accent-primary, #3b82f6);
    color: #ffffff;
    background-color: var(--bg-hover, rgba(255, 255, 255, 0.1));
}

.btn.small {
    padding: 5px 10px;
    font-size: 0.76rem;
    font-weight: 600;
    gap: 6px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.icon-btn:hover {
    color: var(--text-main);
}

.board-dropdown {
    background-color: var(--bg-hover);
    color: var(--text-bright);
    border: 1px solid var(--border-color);
    padding: 5px 10px;
    border-radius: 4px;
    font-family: var(--font-main);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease-in-out;
    appearance: none;
    -moz-appearance: none;
    -webkit-appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg fill="%23c9d1d9" viewBox="0 0 24 24" width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 6px center;
    padding-right: 24px;
    height: 28px;
}

.board-dropdown:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-panel);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 4px 8px rgba(0, 0, 0, 0.3);
}

.board-dropdown:focus {
    outline: none;
    border-color: var(--accent-hover);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.3);
}

/* ======= Simulator Styling ======= */
.simulator-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: rgba(15, 17, 26, 0.85);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: 1.5vh 2vw;
}

.simulator-container {
    display: flex;
    flex-direction: column;
    width: 96vw;
    max-width: 96vw;
    height: 96vh;
    max-height: 96vh;
    background: var(--bg-panel);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.simulator-toolbar {
    padding: 12px 24px;
    background: rgba(30, 34, 49, 0.8);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.simulator-toolbar-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.simulator-toolbar-actions {
    margin-left: auto;
    display: flex;
    gap: 10px;
}

.simulator-main {
    display: flex;
}

.simulator-placeholder i {
    font-size: 3rem;
    margin-bottom: 10px;
    color: var(--border-color);
}

#wokwi-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background-color: white;
    /* Embedded simulators usually need white background */
}

/* ======= Button & Input Styles ======= */
.btn {
    background-color: var(--bg-hover);
    color: var(--text-bright);
    border: 1px solid var(--border-color);
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-family: var(--font-main);
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.btn:hover {
    background-color: #3e3e42;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

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

.btn.primary {
    background: linear-gradient(145deg, var(--accent-primary), #005a9e);
    border: none;
    color: white;
}

.btn.primary:hover {
    background: linear-gradient(145deg, var(--accent-hover), var(--accent-primary));
}

.btn.success {
    background: linear-gradient(145deg, var(--accent-success), #388e3c);
    border: none;
    color: white;
}

.btn.success:hover {
    background: linear-gradient(145deg, #66bb6a, var(--accent-success));
}

.btn.warning {
    background: linear-gradient(145deg, var(--accent-warning), #f57c00);
    border: none;
    color: white;
}

.btn.warning:hover {
    background: linear-gradient(145deg, #ffa726, var(--accent-warning));
}

.btn.outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-bright);
}

.btn.outline:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background-color: rgba(88, 166, 255, 0.05);
}

.btn.small {
    padding: 4px 8px;
    font-size: 0.70rem;
    gap: 4px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.icon-btn:hover {
    color: var(--text-main);
}

.board-dropdown {
    background-color: var(--bg-hover);
    color: var(--text-bright);
    border: 1px solid var(--border-color);
    padding: 5px 10px;
    border-radius: 4px;
    font-family: var(--font-main);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease-in-out;
    appearance: none;
    -moz-appearance: none;
    -webkit-appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg fill="%23c9d1d9" viewBox="0 0 24 24" width="16" height="16" xmlns="http://www.w3.org/2000/svg"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 6px center;
    padding-right: 24px;
    height: 28px;
}

.board-dropdown:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-panel);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1), 0 4px 8px rgba(0, 0, 0, 0.3);
}

.board-dropdown:focus {
    outline: none;
    border-color: var(--accent-hover);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.3);
}

/* ======= Simulator Styling ======= */
.simulator-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: rgba(15, 17, 26, 0.85);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: 1.5vh 2vw;
}

.simulator-container {
    display: flex;
    flex-direction: column;
    width: 96vw;
    max-width: 96vw;
    height: 96vh;
    max-height: 96vh;
    background: var(--bg-panel);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.simulator-toolbar {
    position: relative;
    z-index: 100;
    padding: 10px 18px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.simulator-toolbar-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-bright);
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--font-display);
}

.simulator-toolbar-actions {
    margin-left: auto;
    display: flex;
    gap: 10px;
}

.simulator-main {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.sim-sidebar {
    width: 140px;
    min-width: 140px;
    max-width: 140px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-x: hidden;
    box-sizing: border-box;
}

.sim-sidebar-header {
    padding: 8px 10px;
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.sim-search-container {
    padding: 6px;
    position: relative;
    border-bottom: 1px solid var(--border-color);
}

.sim-search-container .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 9px;
}

#sim-component-search {
    width: 100%;
    background: var(--bg-hover);
    border: 1px solid var(--border-bright);
    border-radius: 5px;
    padding: 4px 6px 4px 22px;
    color: var(--text-primary);
    font-size: 10px;
    font-family: var(--font-main);
    transition: all 0.2s ease;
    box-sizing: border-box;
}

#sim-component-search:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: var(--bg-panel);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.sim-components-list {
    padding: 6px 5px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    align-content: start;
    box-sizing: border-box;
}

.sim-components-list::-webkit-scrollbar {
    width: 4px;
}

.sim-components-list::-webkit-scrollbar-track {
    background: transparent;
}

.sim-components-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}

.sim-components-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.sim-category-header {
    font-size: 9px;
    font-weight: 700;
    color: #38bdf8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 2px 2px 2px;
    margin-bottom: 2px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sim-component-library-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 6px 4px;
    text-align: center;
    cursor: grab;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    user-select: none;
    font-size: 0.65rem;
    font-weight: 500;
    line-height: 1.15;
    color: #cbd5e1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 100%;
}

.sim-component-library-item:hover {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.5);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.35);
    color: #ffffff;
}

.sim-comp-symbol-icon {
    width: 24px;
    height: 20px;
    color: #38bdf8;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 0 5px rgba(56, 189, 248, 0.35));
    transition: transform 0.15s ease, filter 0.15s ease;
}

.sim-component-library-item:hover .sim-comp-symbol-icon {
    transform: scale(1.1);
    filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.65));
}

.sim-comp-name {
    display: block;
    word-break: break-word;
    white-space: normal;
    text-align: center;
}

.sim-canvas-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sim-canvas-area {
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: #646464;
}

.sim-canvas {
    width: 3000px;
    height: 3000px;
    position: relative;
    background-image:
        radial-gradient(circle, rgba(255, 255, 255, 0.5) 1.5px, transparent 1px);
    background-size: 32px 32px;
    will-change: transform;
    transform-style: preserve-3d;
    backface-visibility: hidden;
    contain: layout style;
}

/* Firefox Performance & Hardware Rendering Fixes */
@-moz-document url-prefix() {
    .sim-canvas {
        background-image: radial-gradient(circle, rgba(255, 255, 255, 0.4) 1px, transparent 1px) !important;
        background-attachment: local !important;
    }
    .sim-wire {
        filter: none !important;
    }
    .sim-component-instance {
        filter: none !important;
    }
}

.sim-wires-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 60;
}

.sim-active-wire-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

.sim-component-instance {
    position: absolute;
    cursor: grab;
    user-select: none;
    transition: box-shadow 0.2s, transform 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    border-radius: 4px;
    z-index: 10;
}




.sim-pin {
    width: 6px;
    height: 6px;
    background-color: #222;
    border: 1.5px solid #bdc3c7;
    border-radius: 50%;
    position: absolute;
    cursor: crosshair;
    z-index: 100;
    transition: all 0.2s ease;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
}

/* Invisible 22x22px magnetic hitbox around the 6x6px physical pin */
.sim-pin::before {
    content: '';
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    border-radius: 50%;
    /* border: 1px solid rgba(255,0,0,0.5); /* uncomment for debugging hitbox */
}

.sim-pin:hover, .sim-pin.sim-pin-snap {
    transform: scale(1.6);
    background-color: var(--accent-primary);
    border-color: #fff;
    box-shadow: 0 0 10px 2px var(--accent-primary);
}

.sim-pin.connected {
    background: #4caf50;
}

.sim-pin.active {
    background: var(--accent-primary);
    box-shadow: 0 0 15px var(--accent-primary);
}

.sim-pin-label {
    position: absolute;
    font-size: 8px;
    color: rgba(255, 255, 255, 0.7);
    pointer-events: auto;
    user-select: none;
    cursor: crosshair;
    z-index: 101;
    white-space: nowrap;
    transition: color 0.2s ease;
}

.sim-pin-label.vertical {
    writing-mode: vertical-rl;
    text-orientation: sideways;
    transform: rotate(180deg);
    transform-origin: left top;
}

.sim-pin-label.align-bottom {
    text-align: right;
    /* Inside vertical-rl, left/right aligns top/bottom */
}

.sim-pin-label:hover {
    color: var(--accent-primary);
}

.sim-wire {
    fill: none;
    stroke: #007bff;
    stroke-width: 3;
    stroke-linecap: round;
    cursor: pointer;
    pointer-events: auto;
    transition: stroke 0.2s, stroke-width 0.2s;
}

@keyframes wire-dash {
    to {
        stroke-dashoffset: -10;
    }
}

/* Professional Trash Bin */
.sim-trash-bin {
    position: absolute;
    bottom: 30px;
    left: 30px;
    width: 60px;
    height: 70px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    opacity: 1;
    z-index: 1000;
    cursor: default;
}

.sim-trash-lid {
    width: 40px;
    height: 8px;
    background: #e74c3c;
    border-radius: 4px 4px 2px 2px;
    margin-bottom: 2px;
    transition: transform 0.3s ease;
    transform-origin: left bottom;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.sim-trash-body {
    width: 36px;
    height: 40px;
    background: #c0392b;
    border-radius: 2px 2px 6px 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.8);
    font-size: 18px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
}

.sim-trash-bin.sim-trash-active {
    transform: scale(1.2);
}

.sim-trash-bin.sim-trash-active .sim-trash-lid {
    transform: rotate(-45deg) translateY(-10px);
}

.sim-trash-bin.sim-trash-active .sim-trash-body {
    background: #ff4757;
    box-shadow: 0 0 20px rgba(255, 71, 87, 0.5);
}

/* Simulator Zoom Controls */
.sim-zoom-controls {
    position: absolute;
    bottom: 120px;
    left: 40px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
    pointer-events: auto;
}

.sim-zoom-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-bright);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.sim-zoom-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: scale(1.1);
}

.sim-zoom-btn:active {
    transform: scale(0.95);
}

.sim-zoom-btn i {
    font-size: 14px;
}

/* Animations */
@keyframes pinSnap {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.8);
    }

    100% {
        transform: scale(1.6);
    }
}

.sim-pin-snap {
    animation: pinSnap 0.3s ease-out forwards;
}

/* Responsive Overrides */
@media (max-width: 1024px) {
    .sim-sidebar {
        width: 200px;
    }
}

@media (max-width: 768px) {
    .simulator-container {
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .sim-sidebar {
        display: none;
    }
}

/* ======= Code Loading & Dropdowns ======= */
.sim-dropdown {
    position: relative;
    display: inline-block;
}

.sim-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: rgba(24, 27, 34, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    min-width: 190px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.08);
    z-index: 2500;
    /* Ensure it stays on top of the property editor (2100) and modal content */
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 6px;
    overflow: hidden;
    animation: simDropdownFade 0.18s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes simDropdownFade {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.sim-dropdown-menu.show {
    display: block;
}

.dropdown-item {
    width: 100%;
    padding: 8px 12px;
    text-align: left;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--text-bright, #ffffff);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s ease, color 0.15s ease;
    box-sizing: border-box;
}

.dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.dropdown-item:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.dropdown-item i {
    width: 16px;
    text-align: center;
    font-size: 0.9rem;
}

/* ======= Code Paste Modal ======= */
.sim-code-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1100;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.sim-code-container {
    width: 90%;
    max-width: 800px;
    height: 80%;
    background: var(--bg-panel);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.sim-code-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: #eee;
}

.sim-code-body {
    flex: 1;
    padding: 0;
    background: #000;
}

#sim-code-input {
    width: 100%;
    height: 100%;
    background: #1e1e1e;
    color: #d4d4d4;
    border: none;
    padding: 20px;
    font-family: var(--font-code);
    font-size: 14px;
    resize: none;
    outline: none;
}

.sim-code-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

/* ======= Compilation Overlay ======= */
.sim-compile-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(13, 17, 23, 0.9);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.sim-compile-content {
    text-align: center;
    color: white;
    max-width: 80%;
}

.sim-compile-content i {
    font-size: 40px;
    color: var(--accent-primary);
    margin-bottom: 20px;
}

#sim-compile-status {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 15px;
}


.sim-compile-log {
    background: black;
    color: #ccc;
    font-family: var(--font-code);
    font-size: 12px;
    padding: 15px;
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    text-align: left;
    white-space: pre-wrap;
    border: 1px solid #333;
}

/* ======= Dropdown Menu ======= */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    min-width: 220px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    padding: 8px;
    overflow: hidden;
    animation: fadeInDown 0.2s ease-out;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown.active .dropdown-menu {
    display: block;
}

.dropdown-menu button {
    width: 100%;
    padding: 10px 14px;
    text-align: left;
    background: none;
    border: none;
    color: var(--text-bright);
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
}

.dropdown-menu button i {
    width: 16px;
    text-align: center;
    color: var(--accent-primary);
}

.dropdown-menu button:hover {
    background: var(--bg-hover);
    color: var(--accent-hover);
}

/* ======= Simulator Serial Monitor (Floating & Draggable Modal) ======= */
.sim-serial-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1200;
    pointer-events: none; /* Allows user to see and click/edit all circuit components behind! */
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

.sim-serial-modal-container {
    position: fixed;
    top: 72px;
    left: 170px;
    right: auto;
    width: 460px;
    min-width: 320px;
    max-width: calc(100vw - 40px);
    height: 380px;
    min-height: 200px;
    max-height: calc(100vh - 80px);
    resize: both; /* Native browser resize support */
    background: rgba(24, 27, 38, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: 0 16px 45px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.08);
    overflow: hidden;
    pointer-events: auto; /* Modal itself captures mouse/keyboard events */
    z-index: 1210;
    transition: box-shadow 0.2s ease;
}

.sim-serial-modal-container.is-dragging,
.sim-serial-modal-container.is-resizing {
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.85), 0 0 0 2px var(--accent-primary, #3b82f6);
    opacity: 0.98;
}

.sim-serial-resizer {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 18px;
    height: 18px;
    cursor: nwse-resize;
    z-index: 30;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 3px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.sim-serial-resizer::after {
    content: '';
    width: 8px;
    height: 8px;
    border-right: 2px solid rgba(255, 255, 255, 0.45);
    border-bottom: 2px solid rgba(255, 255, 255, 0.45);
    display: block;
    margin-right: 2px;
    margin-bottom: 2px;
    transition: border-color 0.15s ease;
}

.sim-serial-resizer:hover::after,
.sim-serial-modal-container.is-resizing .sim-serial-resizer::after {
    border-right-color: var(--accent-primary, #3b82f6);
    border-bottom-color: var(--accent-primary, #3b82f6);
}

.sim-serial-container {
    width: 220px;
    min-width: 0;
    height: 100%;
    background: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
    transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.15s ease;
}

.sim-serial-container.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    border-left: none !important;
    opacity: 0;
    pointer-events: none;
}

.sim-serial-resizer {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: ew-resize;
    z-index: 50;
    background: transparent;
    transition: background 0.15s ease;
}

.sim-serial-resizer:hover,
.sim-serial-resizer.resizing {
    background: var(--accent-primary, #3b82f6);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.sim-terminal-floating-btn {
    position: absolute;
    right: 12px;
    top: 12px;
    z-index: 40;
    background: rgba(30, 34, 49, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text-bright, #ffffff);
    border: 1px solid var(--border-bright, rgba(255, 255, 255, 0.2));
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    transition: all 0.2s ease;
}

.sim-terminal-floating-btn:hover {
    background: var(--accent-primary, #3b82f6);
    border-color: #3b82f6;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.sim-serial-header {
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted, #a1a1aa);
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

.sim-serial-header:active,
.sim-serial-modal-container.is-dragging .sim-serial-header {
    cursor: grabbing;
}

.sim-serial-output {
    flex: 1;
    background: #000000;
    overflow: hidden;
    padding: 4px;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sim-serial-output .xterm {
    height: 100% !important;
    width: 100% !important;
    padding: 4px;
}

.sim-serial-output .xterm-viewport {
    height: 100% !important;
}

.sim-serial-input-wrapper {
    display: flex;
    align-items: center;
    padding: 6px 22px 6px 8px;
    gap: 6px;
    background: rgba(0, 0, 0, 0.25);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
}

.sim-serial-input-wrapper input {
    flex: 1;
    min-width: 0;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 8px;
    color: var(--text-bright);
    font-size: 0.8rem;
    outline: none;
    transition: border-color 0.2s;
}

.sim-serial-input-wrapper input:focus {
    border-color: var(--accent-primary, #3b82f6);
}

.sim-serial-input-wrapper button {
    background: var(--accent-primary, #3b82f6);
    border: none;
    border-radius: 6px;
    width: 30px;
    min-width: 30px;
    height: 30px;
    flex-shrink: 0;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background-color 0.2s, transform 0.1s;
}

.sim-serial-input-wrapper button:hover {
    background: #2563eb;
    transform: scale(1.04);
}

.sim-serial-input-wrapper button:active {
    transform: scale(0.96);
}

.btn.tiny {
    padding: 2px 6px;
    font-size: 0.75rem;
}

/* Property Editor */
.sim-property-editor {
    position: fixed;
    z-index: 2100;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-bright);
    border-radius: 16px;
    width: 240px;
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    font-family: var(--font-main);
    overflow: hidden;
    animation: simPanelAppear 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes simPanelAppear {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.sim-prop-header {
    background: rgba(255, 255, 255, 0.03);
    padding: 12px 16px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.sim-prop-close {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 14px;
}

.sim-prop-close:hover {
    color: #ff3b30;
}

.sim-prop-body {
    padding: 12px;
}

.sim-prop-row {
    margin-bottom: 10px;
}

.sim-prop-row:last-child {
    margin-bottom: 0;
}

.sim-prop-row label {
    display: block;
    font-size: 10px;
    color: #888;
    margin-bottom: 4px;
}

.sim-prop-row input,
.sim-prop-row select {
    width: 100%;
    background: #2d2d2d;
    border: 1px solid #444;
    border-radius: 4px;
    color: #eee;
    padding: 6px 8px;
    font-size: 12px;
    outline: none;
}

.sim-prop-row input:focus,
.sim-prop-row select:focus {
    border-color: var(--accent-primary);
}

.sim-prop-row input[type="color"] {
    height: 30px;
    padding: 2px;
}

/* Simulation State Interaction Gating */
#sim-components-canvas.sim-stopped .sim-interactive-btn,
#sim-components-canvas.sim-stopped .sim-interactive-switch,
#sim-components-canvas.sim-stopped .sim-interactive-dip-switch,
#sim-components-canvas.sim-stopped .sim-battery-9v svg > g[id$="-switch"],
#sim-components-canvas.sim-stopped .sim-power-supply-module svg > g[id$="-power-btn"],
#sim-components-canvas.sim-stopped .sim-multimeter-mode-select {
    pointer-events: auto !important;
    cursor: not-allowed !important;
    opacity: 0.85;
    filter: grayscale(0.15) contrast(0.9);
}

/* Component Rotation Interaction System */
.sim-rotation-handle {
    position: absolute;
    width: 28px;
    height: 28px;
    background: #3b82f6;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.4);
    z-index: 1005;
    font-size: 13px;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.2s, box-shadow 0.2s;
    border: 2px solid white;
}
.sim-rotation-handle:hover {
    background: #2563eb;
    transform: scale(1.2) rotate(45deg);
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.6);
}
.sim-rotation-handle:active {
    transform: scale(0.95);
}
.sim-rotation-handle i {
    pointer-events: none;
}

/* Capacitance Input + Dropdown specific layout */
.capacitance-container {
    display: flex;
    flex: 1;
    gap: 6px;
}

.capacitance-container input {
    flex: 1;
    min-width: 0;
}

.capacitance-container select {
    width: 75px;
    flex: none;
}

/* Voltage Input + Dropdown specific layout */
.voltage-container {
    display: flex;
    flex: 1;
    gap: 6px;
}

.voltage-container input {
    flex: 1;
    min-width: 0;
}

.voltage-container select {
    width: 75px;
    flex: none;
}

/* Resistance Input + Dropdown specific layout */
.resistance-container {
    display: flex;
    flex: 1;
    gap: 6px;
}

.resistance-container input {
    flex: 1;
    min-width: 0;
}

.resistance-container select {
    width: 75px;
    flex: none;
}

/* Help button inside property editor header */
.sim-prop-help {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    padding: 0;
}

.sim-prop-help:hover {
    color: var(--accent-primary);
}

/* ==========================================================================
   STEMAura - Kids & Student Friendly Blockly Styling Overrides
   ========================================================================== */

/* Modern Rounded Font for Blockly Blocks */
.blocklyText, .blocklyFlyoutLabelText {
    font-family: 'Outfit', 'Inter', 'Segoe UI', sans-serif !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    letter-spacing: 0.3px !important;
}

/* Kids Friendly Toolbox Styling */
.blocklyToolboxDiv {
    background-color: #f1f5f9 !important; /* Light-grey sidebar to separate from the white workspace */
    border-right: 1.5px solid #cbd5e1 !important; /* Slightly more defined border */
    padding: 12px 6px !important;
    width: 140px !important;
}

/* Rounded, Pill-shaped Category Row Items (similar to Scratch) */
.blocklyTreeRow {
    border-radius: 20px !important; /* Scratch-like capsule buttons */
    margin: 6px 8px !important;
    padding: 10px 14px !important;
    border: 1px solid transparent !important;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    cursor: pointer !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05) !important;
}

/* Rounded Category Tree Hover States */
.blocklyTreeRow:hover {
    background-color: rgba(0, 0, 0, 0.04) !important;
    transform: scale(1.03) translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1) !important;
}

/* Selected Category Row styling */
.blocklyTreeSelectedRow {
    background-color: rgba(0, 0, 0, 0.06) !important;
    border-color: rgba(0, 0, 0, 0.1) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.8) !important;
    transform: scale(1.03);
}

/* Style the text label inside categories to be bold and readable */
.blocklyTreeLabel {
    color: #1e293b !important;
    font-family: 'Outfit', 'Inter', sans-serif !important;
    font-weight: 700 !important;
    font-size: 12px !important;
    letter-spacing: 0.5px !important;
}

/* Toolbox Icons Margin Adjustment */
.blocklyTreeIcon {
    margin-right: 8px !important;
    transform: scale(1.15) !important;
}

/* High Contrast Rounded Flyout Palette */
.blocklyFlyout {
    filter: drop-shadow(6px 0 16px rgba(0, 0, 0, 0.08)) !important;
}

.blocklyFlyoutBackground {
    fill: rgba(226, 232, 240, 0.95) !important; /* Distinct light grey-slate background */
    fill-opacity: 0.95 !important;
}

/* Soft 3D Shadow under Blocks inside Workspace */
.blocklyDraggable {
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.15)) !important;
}

/* CSS transform transition removed to fix dragging coordinate drift and latency */

/* Input Fields inside Blocks (Dropdowns, numbers, text inputs) */
.blocklyHtmlInput {
    font-family: 'Outfit', 'Inter', sans-serif !important;
    font-weight: 700 !important;
    border-radius: 8px !important;
    border: 2px solid var(--accent-primary, #3b82f6) !important;
    padding: 4px 8px !important;
}

.blocklyDropdownText {
    font-weight: 800 !important;
}

/* Scrollbars inside Blockly Workspace */
.blocklyScrollbarHandle {
    fill: #475569 !important;
    rx: 8px !important; /* Rounded scrollbar handles */
    ry: 8px !important;
    transition: fill 0.2s ease !important;
}

.blocklyScrollbarHandle:hover {
    fill: #334155 !important;
}

/* Ultrasonic, PIR, Gas, Temperature, IR & LDR Obstacles / Controls: 
   ONLY visible after selecting the component WHILE simulator is actively running! Otherwise it is hidden. */
.sim-ultrasonic-obstacle-layer,
.sim-pir-obstacle-layer,
.sim-gas-obstacle-layer,
.sim-temp-obstacle-layer,
.sim-ir-obstacle-layer,
.sim-ldr-obstacle-layer,
.sim-component-instance:not(.sim-component-selected) .sim-ultrasonic-obstacle-layer,
.sim-component-instance:not(.sim-component-selected) .sim-pir-obstacle-layer,
.sim-component-instance:not(.sim-component-selected) .sim-gas-obstacle-layer,
.sim-component-instance:not(.sim-component-selected) .sim-temp-obstacle-layer,
.sim-component-instance:not(.sim-component-selected) .sim-ir-obstacle-layer,
.sim-component-instance:not(.sim-component-selected) .sim-ldr-obstacle-layer {
    display: none !important;
}

body.sim-running .sim-component-instance.sim-component-selected .sim-ultrasonic-obstacle-layer,
body.sim-running .sim-component-instance.sim-component-selected .sim-pir-obstacle-layer,
body.sim-running .sim-component-instance.sim-component-selected .sim-gas-obstacle-layer,
body.sim-running .sim-component-instance.sim-component-selected .sim-temp-obstacle-layer,
body.sim-running .sim-component-instance.sim-component-selected .sim-ir-obstacle-layer,
body.sim-running .sim-component-instance.sim-component-selected .sim-ldr-obstacle-layer,
.simulator-modal.sim-running .sim-component-instance.sim-component-selected .sim-ultrasonic-obstacle-layer,
.simulator-modal.sim-running .sim-component-instance.sim-component-selected .sim-pir-obstacle-layer,
.simulator-modal.sim-running .sim-component-instance.sim-component-selected .sim-gas-obstacle-layer,
.simulator-modal.sim-running .sim-component-instance.sim-component-selected .sim-temp-obstacle-layer,
.simulator-modal.sim-running .sim-component-instance.sim-component-selected .sim-ir-obstacle-layer,
.simulator-modal.sim-running .sim-component-instance.sim-component-selected .sim-ldr-obstacle-layer,
#sim-components-canvas.sim-running .sim-component-instance.sim-component-selected .sim-ultrasonic-obstacle-layer,
#sim-components-canvas.sim-running .sim-component-instance.sim-component-selected .sim-pir-obstacle-layer,
#sim-components-canvas.sim-running .sim-component-instance.sim-component-selected .sim-gas-obstacle-layer,
#sim-components-canvas.sim-running .sim-component-instance.sim-component-selected .sim-temp-obstacle-layer,
#sim-components-canvas.sim-running .sim-component-instance.sim-component-selected .sim-ir-obstacle-layer,
#sim-components-canvas.sim-running .sim-component-instance.sim-component-selected .sim-ldr-obstacle-layer {
    display: block !important;
}

/* Realistic Slow Gas Cloud Rotation */
@keyframes simGasCloudRotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.sim-gas-cloud-rotator {
    transform-origin: 0px 0px;
    animation: simGasCloudRotate 32s linear infinite;
    pointer-events: none;
}

/* ======= Simulator Window Light Theme ======= */
.simulator-modal.sim-light-mode .simulator-container {
    background: #ffffff;
    border-color: #cbd5e1;
    color: #0f172a;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.simulator-modal.sim-light-mode .simulator-toolbar {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.simulator-modal.sim-light-mode .simulator-toolbar-title {
    color: #0f172a;
}

.simulator-modal.sim-light-mode .simulator-toolbar .btn.outline {
    background: #ffffff;
    border-color: #cbd5e1;
    color: #334155;
}

.simulator-modal.sim-light-mode .simulator-toolbar .btn.outline:hover {
    background: #f1f5f9;
    color: #0f172a;
    border-color: #94a3b8;
}

.simulator-modal.sim-light-mode .sim-dropdown-menu {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
}

.simulator-modal.sim-light-mode .sim-dropdown-menu .dropdown-item {
    color: #334155;
}

.simulator-modal.sim-light-mode .sim-dropdown-menu .dropdown-item:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.simulator-modal.sim-light-mode .sim-sidebar {
    background: #f8fafc;
    border-right: 1px solid #e2e8f0;
}

.simulator-modal.sim-light-mode .sim-sidebar-header {
    background: #f1f5f9;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
}

.simulator-modal.sim-light-mode .sim-search-container {
    border-bottom: 1px solid #e2e8f0;
}

.simulator-modal.sim-light-mode #sim-component-search {
    background: #ffffff;
    border-color: #cbd5e1;
    color: #0f172a;
}

.simulator-modal.sim-light-mode .sim-category-header {
    color: #0284c7;
    border-bottom: 1px solid #e2e8f0;
}

.simulator-modal.sim-light-mode .sim-component-library-item {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    color: #334155;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.simulator-modal.sim-light-mode .sim-component-library-item:hover {
    background: #e0f2fe;
    border-color: #38bdf8;
    color: #0369a1;
}

.simulator-modal.sim-light-mode .sim-canvas-area {
    background-color: #f1f5f9;
}

.simulator-modal.sim-light-mode .sim-canvas {
    background-image: radial-gradient(circle, rgba(148, 163, 184, 0.6) 1.5px, transparent 1px);
}