/* =========================================================
   GLOBAL SETTINGS
========================================================= */

* {
    box-sizing: border-box;
}

:root {
    --background: #202124;
    --panel: #2c2d30;
    --panel-dark: #27282b;

    --control: #3a3c40;
    --control-hover: #4b4e53;
    --control-active: #565a60;

    --canvas: #f4f4f4;
    --grid-line: #d6d6d6;

    --border: #5c5f66;
    --border-light: #777b82;

    --text: #ffffff;
    --muted: #cccccc;

    --accent: #4da3ff;
    --accent-dark: #336b9e;

    --fault: #ffb000;
    --delete: #e04444;
    --success: #258b46;
    --warning: #a56a1f;

    --grid-size: 25px;
}

html,
body {
    width: 100%;
    min-height: 100vh;

    margin: 0;
    padding: 0;

    color: var(--text);
    background: var(--background);

    font-family: Arial, Helvetica, sans-serif;
}

body {
    overflow-x: hidden;
}

button,
input {
    font: inherit;
}

button,
#component_search,
.dropdown-button {
    min-height: 40px;

    color: var(--text);
    background: var(--control);

    border: 1px solid var(--border);
    border-radius: 10px;

    transition:
        background 120ms ease,
        border-color 120ms ease,
        opacity 120ms ease;
}

button {
    padding: 8px 12px;
    cursor: pointer;
}

button:hover:not(:disabled) {
    background: var(--control-hover);
    border-color: var(--border-light);
}

button:active:not(:disabled) {
    background: var(--control-active);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}


/* =========================================================
   MAIN TOOLBAR
========================================================= */

#toolbar {
    position: relative;
    z-index: 100;

    display: flex;
    flex-wrap: wrap;
    align-items: center;

    gap: 8px;

    padding: 12px;

    background: var(--panel);
    border-bottom: 1px solid var(--border);
}

.toolbar-control {
    display: flex;
    align-items: center;

    gap: 7px;

    white-space: nowrap;
}

.toolbar-control input[type="color"] {
    width: 44px;
    height: 36px;

    padding: 2px;

    background: var(--control);

    border: 1px solid var(--border);
    border-radius: 9px;

    cursor: pointer;
}


/* =========================================================
   COMPONENT SEARCH
========================================================= */

.search-wrapper {
    position: relative;
    z-index: 3000;

    flex: 1;

    min-width: 260px;
}

#component_search {
    width: 100%;

    padding: 9px 12px;

    outline: none;
}

#component_search:focus {
    border-color: var(--accent);

    box-shadow:
        0 0 0 2px rgba(77, 163, 255, 0.18);
}

#component_search::placeholder {
    color: var(--muted);
}


/* =========================================================
   SEARCH RESULTS DROPDOWN
========================================================= */

#search_results {
    position: absolute;

    top: calc(100% + 5px);
    left: 0;
    right: 0;

    z-index: 5000;

    display: none;

    max-height: 320px;

    overflow-x: hidden;
    overflow-y: auto;

    overscroll-behavior: contain;

    background: var(--control);

    border: 1px solid var(--border);
    border-radius: 10px;

    box-shadow:
        0 12px 30px rgba(0, 0, 0, 0.4);

    scrollbar-width: thin;
    scrollbar-color:
        var(--control-hover)
        var(--control);
}


/* Firefox search result scrollbar */

#search_results {
    scrollbar-width: thin;

    scrollbar-color:
        var(--control-hover)
        var(--control);
}


/* Chrome, Edge and Safari search result scrollbar */

#search_results::-webkit-scrollbar {
    width: 11px;
}

#search_results::-webkit-scrollbar-track {
    margin-top: 6px;
    margin-bottom: 6px;

    background: var(--control);

    border-radius: 999px;
}

#search_results::-webkit-scrollbar-thumb {
    min-height: 40px;

    background: var(--control-hover);

    border: 3px solid var(--control);
    border-radius: 999px;
}

#search_results::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

#search_results::-webkit-scrollbar-thumb:active {
    background: #79bbff;
}


/* Individual search result */

.search-result {
    display: flex;
    align-items: center;

    gap: 12px;

    width: 100%;
    min-height: 66px;

    padding: 10px;

    color: var(--text);
    background: var(--control);

    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;

    text-align: left;
}

.search-result:first-child {
    border-radius: 9px 9px 0 0;
}

.search-result:last-child {
    border-bottom: 0;
    border-radius: 0 0 9px 9px;
}

.search-result:only-child {
    border-radius: 9px;
}

.search-result:hover {
    background: var(--control-hover);
}

.search-result:focus-visible {
    position: relative;
    z-index: 1;

    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.search-symbol-box {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 90px;
    height: 46px;

    flex: 0 0 90px;

    overflow: hidden;

    background: #ffffff;

    border: 1px solid #777777;
    border-radius: 7px;
}

.search-result img {
    display: block;

    width: 80px;
    height: 38px;

    object-fit: contain;

    filter: none;
}


/* =========================================================
   CUSTOM DROPDOWN MENUS
========================================================= */

.custom-dropdown {
    position: relative;
    z-index: 2500;
}

.dropdown-button {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 14px;

    min-width: 160px;

    padding: 8px 11px;
}

.dropdown-menu {
    position: absolute;

    top: calc(100% + 5px);
    left: 0;

    z-index: 5000;

    display: none;

    min-width: 100%;

    overflow: hidden;

    background: var(--control);

    border: 1px solid var(--border);
    border-radius: 10px;

    box-shadow:
        0 12px 30px rgba(0, 0, 0, 0.4);
}

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

.dropdown-menu button {
    display: block;

    width: 100%;
    min-height: 40px;

    padding: 9px 12px;

    color: var(--text);
    background: var(--control);

    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;

    text-align: left;
    white-space: nowrap;
}

.dropdown-menu button:first-child {
    border-radius: 9px 9px 0 0;
}

.dropdown-menu button:last-child {
    border-bottom: 0;
    border-radius: 0 0 9px 9px;
}

.dropdown-menu button:only-child {
    border-radius: 9px;
}

.dropdown-menu button:hover {
    background: var(--control-hover);
}


/* =========================================================
   TOOLBAR BUTTON COLORS
========================================================= */

#zoom_display {
    min-width: 55px;

    color: var(--muted);

    text-align: center;
}

#run_button {
    background: var(--success);
}

#run_button:hover:not(:disabled) {
    background: #2fa655;
}

#stop_button {
    background: var(--warning);
}

#stop_button:hover:not(:disabled) {
    background: #bd7b29;
}

#clear_button {
    background: #9f3434;
}

#clear_button:hover:not(:disabled) {
    background: #bc4141;
}

#cancel_wire_button {
    background: #8b5e22;
}

#cancel_wire_button:hover:not(:disabled) {
    background: #a8732b;
}


/* =========================================================
   STATUS BAR
========================================================= */

#status_message {
    min-height: 42px;

    padding: 11px 14px;

    color: var(--muted);
    background: var(--panel-dark);

    border-bottom: 1px solid var(--border);
}


/* =========================================================
   MAIN WORKSPACE
========================================================= */

#workspace {
    display: grid;

    grid-template-columns:
        minmax(0, 1fr)
        290px;

    gap: 14px;

    padding: 14px;
}


/* =========================================================
   CANVAS VIEWPORT
========================================================= */

#canvas_viewport {
    position: relative;

    width: 100%;
    height: 72vh;
    min-height: 540px;

    overflow: hidden;

    background: #151619;

    border: 2px solid var(--border);
    border-radius: 12px;

    cursor: default;
}

#canvas_viewport.panning {
    cursor: grabbing;
}

#canvas_transform {
    position: absolute;

    top: 0;
    left: 0;

    width: 8000px;
    height: 6000px;

    transform-origin: top left;

    will-change: transform;
}


/* =========================================================
   WIRING CANVAS
========================================================= */

#wiring_canvas {
    position: relative;

    width: 8000px;
    height: 6000px;

    overflow: hidden;

    background-color: var(--canvas);

    background-image:
        linear-gradient(
            var(--grid-line) 1px,
            transparent 1px
        ),
        linear-gradient(
            90deg,
            var(--grid-line) 1px,
            transparent 1px
        );

    background-size:
        var(--grid-size)
        var(--grid-size);

    border-radius: 12px;
}

#wire_layer,
#component_layer {
    position: absolute;

    inset: 0;

    width: 100%;
    height: 100%;
}

#wire_layer {
    z-index: 1;

    overflow: visible;
}

#component_layer {
    z-index: 2;

    pointer-events: none;
}


/* =========================================================
   COMPONENT PLACEMENT PREVIEW
========================================================= */

#component_preview {
    position: absolute;

    z-index: 3;

    display: none;

    width: 100px;
    height: 50px;

    opacity: 0.5;

    transform:
        translate(-50%, -50%);

    transform-origin: center;

    pointer-events: none;
}

#component_preview img {
    display: block;

    width: 90px;
    height: 40px;

    margin: 5px;

    object-fit: contain;
}


/* =========================================================
   PLACED COMPONENTS
========================================================= */

.placed-component {
    position: absolute;

    width: 100px;
    height: 50px;

    transform:
        translate(-50%, -50%);

    pointer-events: auto;

    user-select: none;

    cursor: grab;
}

.placed-component.locked {
    cursor: default;
}

.placed-component.dragging {
    z-index: 20;

    opacity: 0.72;

    cursor: grabbing;
}

.component-rotation {
    position: absolute;

    inset: 0;

    transform-origin: center;

    transition:
        transform 160ms ease;
}

.component-body {
    position: absolute;

    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 2px solid transparent;
    border-radius: 7px;

    transition:
        border-color 120ms ease,
        background 120ms ease;
}

.component-body img {
    display: block;

    width: 90px;
    height: 40px;

    object-fit: contain;

    pointer-events: none;

    transition:
        filter 200ms ease,
        opacity 200ms ease;
}

.component-label {
    position: absolute;

    top: 52px;
    left: 50%;

    max-width: 180px;

    color: #000000;

    font-size: 12px;
    font-weight: 600;

    text-align: center;
    white-space: nowrap;

    transform:
        translateX(-50%);

    pointer-events: none;
}

.placed-component.selected .component-body {
    background:
        rgba(77, 163, 255, 0.12);

    border-color: var(--accent);

    box-shadow:
        0 0 0 2px
        rgba(77, 163, 255, 0.12);
}

.placed-component.faulty .component-body {
    background:
        rgba(255, 176, 0, 0.18);

    border-color: var(--fault);

    box-shadow:
        0 0 8px
        rgba(255, 176, 0, 0.45);
}

.placed-component.destroyed .component-body {
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

.placed-component.led-off .component-body img {
    opacity: 0.45;

    filter: none;
}

.placed-component.led-powered .component-body img {
    opacity:
        var(--led-brightness, 1);

    filter:
        drop-shadow(
            0 0
            calc(
                4px *
                var(--led-glow-strength, 1)
            )
            var(--led-glow, #ff0000)
        )
        drop-shadow(
            0 0
            calc(
                12px *
                var(--led-glow-strength, 1)
            )
            var(--led-glow, #ff0000)
        )
        drop-shadow(
            0 0
            calc(
                24px *
                var(--led-glow-strength, 1)
            )
            var(--led-glow, #ff0000)
        );
}


/* =========================================================
   COMPONENT TERMINALS
========================================================= */

.terminal {
    position: absolute;

    top: 50%;

    z-index: 10;

    width: 16px;
    height: 16px;
    min-height: 0;

    padding: 0;

    background: #1d1d1d;

    border: 2px solid #ffffff;
    border-radius: 50%;

    transform:
        translateY(-50%);

    cursor: crosshair;

    transition:
        background 100ms ease,
        border-color 100ms ease,
        transform 100ms ease,
        box-shadow 100ms ease;
}

.terminal-left {
    left: -8px;
}

.terminal-right {
    right: -8px;
}

.terminal:hover {
    background: var(--accent);

    border-color: #ffffff;

    box-shadow:
        0 0 8px
        rgba(77, 163, 255, 0.9);
}

.terminal.wire-start {
    background: var(--accent);

    border-color: #ffffff;

    box-shadow:
        0 0 0 3px
        rgba(77, 163, 255, 0.3),
        0 0 10px
        rgba(77, 163, 255, 0.9);
}


/* =========================================================
   WIRES
========================================================= */

.wire-group {
    pointer-events: stroke;
}

.wire-base {
    fill: none;

    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;

    pointer-events: stroke;

    cursor: pointer;

    transition:
        stroke-width 100ms ease,
        opacity 100ms ease;
}

.wire-flow {
    display: none;

    fill: none;

    stroke:
        rgba(255, 255, 255, 0.95);

    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;

    stroke-dasharray: 12 12;

    pointer-events: none;
}

.wire-group.running .wire-flow {
    display: block;

    animation:
        current-forward
        var(--flow-speed, 1s)
        linear
        infinite;
}

.wire-group.running.reverse .wire-flow {
    animation-name:
        current-reverse;
}

.wire-group.dragging {
    opacity: 0.35;
}

.wire-group.delete-hover .wire-base {
    stroke: var(--delete) !important;

    stroke-width: 9;
}

@keyframes current-forward {
    from {
        stroke-dashoffset: 24;
    }

    to {
        stroke-dashoffset: 0;
    }
}

@keyframes current-reverse {
    from {
        stroke-dashoffset: 0;
    }

    to {
        stroke-dashoffset: 24;
    }
}


/* =========================================================
   WIRE PLACEMENT PREVIEW
========================================================= */

#wire_preview {
    fill: none;

    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;

    stroke-dasharray: 10 7;

    opacity: 0.45;

    pointer-events: none;

    animation:
        preview-wire-movement
        0.8s
        linear
        infinite;
}

@keyframes preview-wire-movement {
    from {
        stroke-dashoffset: 17;
    }

    to {
        stroke-dashoffset: 0;
    }
}


/* =========================================================
   PROPERTY PANEL
========================================================= */

#property_panel,
#fault_panel {
    background: var(--panel);

    border: 2px solid var(--border);
    border-radius: 12px;
}

#property_panel {
    align-self: start;

    padding: 15px;
}

#property_panel h2,
#fault_panel h2 {
    margin-top: 0;
}

#property_panel label {
    display: block;

    margin-bottom: 14px;

    color: var(--muted);
}

#property_panel input {
    width: 100%;

    margin-top: 5px;
    padding: 8px;

    color: var(--text);
    background: var(--control);

    border: 1px solid var(--border);
    border-radius: 8px;

    outline: none;
}

#property_panel input:focus {
    border-color: var(--accent);

    box-shadow:
        0 0 0 2px
        rgba(77, 163, 255, 0.15);
}

#property_panel input[type="color"] {
    height: 42px;

    padding: 3px;

    cursor: pointer;
}

#save_properties_button {
    width: 100%;

    background: var(--accent-dark);
}

#save_properties_button:hover:not(:disabled) {
    background: #417fb8;
}


/* =========================================================
   FAULT PANEL
========================================================= */

#fault_panel {
    margin:
        0
        14px
        14px;

    padding: 16px;
}

#fault_summary {
    color: var(--muted);
}

#fault_list {
    margin-bottom: 0;
}

#fault_list li {
    margin: 7px 0;

    color: #ffca66;
}

#fault_list li.no-faults {
    color: #72dd8b;
}


/* =========================================================
   LIVE SIMULATION TOOLTIP
========================================================= */

#live_tooltip {
    position: fixed;

    z-index: 10000;

    min-width: 190px;

    padding: 10px 12px;

    color: var(--text);

    background:
        rgba(24, 25, 28, 0.96);

    border: 1px solid #777777;
    border-radius: 9px;

    box-shadow:
        0 8px 22px
        rgba(0, 0, 0, 0.4);

    font-size: 13px;
    line-height: 1.45;

    pointer-events: none;
}

#live_tooltip strong {
    display: block;

    margin-bottom: 5px;

    color: #ffffff;
}

.live-value {
    color: #7ec8ff;
}

.live-warning {
    color: #ffbe55;
}

.live-good {
    color: #76df8c;
}


/* =========================================================
   RESPONSIVE LAYOUT
========================================================= */

@media (max-width: 1100px) {
    #toolbar {
        align-items: stretch;
    }

    .search-wrapper {
        flex-basis: 100%;
    }
}

@media (max-width: 950px) {
    #workspace {
        grid-template-columns: 1fr;
    }

    #property_panel {
        order: -1;
    }

    #canvas_viewport {
        height: 68vh;
    }
}

@media (max-width: 600px) {
    #toolbar {
        padding: 8px;
    }

    .search-wrapper {
        min-width: 100%;
    }

    .custom-dropdown,
    .dropdown-button {
        width: 100%;
    }

    .dropdown-menu {
        width: 100%;
    }

    #workspace {
        padding: 8px;
    }

    #canvas_viewport {
        min-height: 460px;
    }
    
}

/* =========================================================
   FUSE COMPONENT
========================================================= */

.fuse-svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.fuse-link,
.fuse-break-left,
.fuse-break-right,
.fuse-body,
.fuse-cap,
.fuse-spark {
    transition:
        opacity 160ms ease,
        stroke 160ms ease,
        fill 160ms ease,
        filter 160ms ease,
        transform 160ms ease;
}

.fuse-break-left,
.fuse-break-right,
.fuse-spark {
    opacity: 0;
}

.placed-component.fuse-powered .fuse-link {
    stroke: #222222;
}

.placed-component.fuse-heating .fuse-body {
    fill: rgba(255, 221, 145, 0.82);
    stroke: #d98200;
    filter:
        drop-shadow(0 0 5px rgba(255, 145, 0, 0.75));
}

.placed-component.fuse-heating .fuse-link {
    stroke: #ff6a00;
    animation:
        fuse-heat-pulse 420ms ease-in-out infinite alternate;
}

.placed-component.fuse-heating .fuse-cap {
    fill: #ffd08a;
}

.placed-component.fuse-blown .fuse-link {
    opacity: 0;
}

.placed-component.fuse-blown .fuse-break-left,
.placed-component.fuse-blown .fuse-break-right {
    opacity: 1;
    stroke: #7c1f1f;
}

.placed-component.fuse-blown .fuse-body {
    fill: rgba(235, 235, 235, 0.82);
    stroke: #cc3333;
}

.placed-component.fuse-blown .fuse-cap {
    fill: #c9c9c9;
}

.placed-component.fuse-blown .fuse-spark {
    opacity: 1;
    animation:
        fuse-spark-pop 320ms ease-out 1 forwards;
}

.placed-component.fuse-blown .fuse-spark-two {
    animation-delay: 70ms;
}

@keyframes fuse-heat-pulse {
    from {
        filter:
            drop-shadow(0 0 1px rgba(255, 80, 0, 0.35));
    }

    to {
        filter:
            drop-shadow(0 0 8px rgba(255, 80, 0, 0.98));
    }
}

@keyframes fuse-spark-pop {
    0% {
        opacity: 0;
        transform: scale(0.4);
    }

    45% {
        opacity: 1;
        transform: scale(1.6);
    }

    100% {
        opacity: 0;
        transform: scale(0.2);
    }
}


/* =========================================================
   DESKTOP + IPHONE TOOLBAR AND TOUCH SUPPORT
========================================================= */

html {
    -webkit-text-size-adjust: 100%;
}

body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

#toolbar {
    padding-top: max(12px, env(safe-area-inset-top));
}

.search-wrapper {
    flex: 0 0 320px;
    width: 320px;
    min-width: 320px;
    max-width: 320px;
}

.toolbar-menu {
    min-width: 210px;
    padding: 7px;
}

.dropdown-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 48px;
    padding: 8px 10px;
    color: var(--text);
    white-space: nowrap;
}

.dropdown-control input[type="color"] {
    width: 54px;
    height: 38px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--control);
}

.dropdown-zoom-row {
    display: grid;
    grid-template-columns: 48px 1fr 48px;
    align-items: center;
    gap: 7px;
    padding: 7px 0;
}

.dropdown-zoom-row button {
    min-width: 48px;
    min-height: 46px;
}

#zoom_display {
    min-width: 70px;
    text-align: center;
}

#canvas_viewport,
#wiring_canvas {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.placed-component.led-heating .component-body {
    background:
        rgba(
            255,
            112,
            0,
            calc(0.10 + var(--led-heat-level, 0) * 0.28)
        );
    border-color: rgba(255, 105, 0, 0.9);
    box-shadow:
        0 0 calc(5px + var(--led-heat-level, 0) * 16px)
        rgba(255, 92, 0, 0.85);
}

.placed-component.led-heating .component-body img {
    animation:
        led-heat-pulse
        var(--led-heat-duration, 0.55s)
        ease-in-out
        infinite
        alternate;
}

.placed-component.led-blown .component-body {
    background: rgba(70, 22, 14, 0.28);
    border-color: #8c2417;
}

.placed-component.led-blown .component-body img {
    opacity: 0.18 !important;
    filter:
        grayscale(1)
        brightness(0.32)
        contrast(1.5) !important;
}

/* Broken internal conductor, similar to the blown fuse link. */
.placed-component.led-blown .component-body::before,
.placed-component.led-blown .component-body::after {
    content: "";
    position: absolute;
    z-index: 25;
    top: 50%;
    width: 24px;
    height: 3px;
    background: #6f1712;
    border-radius: 999px;
    pointer-events: none;
}

.placed-component.led-blown .component-body::before {
    left: 24px;
    transform: translateY(-50%) rotate(-20deg);
}

.placed-component.led-blown .component-body::after {
    right: 24px;
    transform: translateY(-50%) rotate(20deg);
}

.placed-component.led-blown::after {
    content: "";
    position: absolute;
    z-index: 30;
    left: 50%;
    top: 50%;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ff9a1f;
    box-shadow:
        0 0 6px #ff6a00,
        0 0 14px #ff2f00;
    transform: translate(-50%, -50%);
    animation: led-break-pop 320ms ease-out 1 forwards;
    pointer-events: none;
}

@keyframes led-heat-pulse {
    from {
        filter:
            saturate(1.05)
            brightness(1.05)
            drop-shadow(0 0 3px rgba(255, 92, 0, 0.45));
    }

    to {
        filter:
            saturate(1.5)
            brightness(1.35)
            drop-shadow(0 0 13px rgba(255, 70, 0, 1));
    }
}

@keyframes led-break-pop {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.3);
    }

    45% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.8);
    }

    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.2);
    }
}

@media (pointer: coarse) {
    button,
    .dropdown-button,
    #component_search {
        min-height: 48px;
    }

    .terminal {
        width: 24px;
        height: 24px;
        border-width: 3px;
    }

    .terminal-left { left: -12px; }
    .terminal-right { right: -12px; }

    .search-result {
        min-height: 74px;
    }
}

@media (max-width: 600px) {
    #toolbar {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        padding: max(8px, env(safe-area-inset-top)) 8px 8px;
    }

    .search-wrapper {
        grid-column: 1 / -1;
        width: 300px;
        min-width: 300px;
        max-width: calc(100vw - 16px);
        justify-self: start;
    }

    .custom-dropdown,
    .dropdown-button {
        width: 100%;
        min-width: 0;
    }

    .dropdown-menu {
        position: fixed;
        left: 8px;
        right: 8px;
        top: auto;
        bottom: max(8px, env(safe-area-inset-bottom));
        width: auto;
        max-height: 62vh;
        overflow-y: auto;
        border-radius: 14px;
    }

    #workspace {
        display: flex;
        flex-direction: column;
        padding: 8px;
    }

    #canvas_viewport {
        order: 1;
        height: 64vh;
        min-height: 420px;
    }

    #property_panel {
        order: 2;
        width: 100%;
    }

    #status_message {
        font-size: 14px;
    }
}

/* =========================================================
   LED CURRENT HEAT / BREAK — FUSE-STYLE
========================================================= */

.led-svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.led-link,
.led-break-left,
.led-break-right,
.led-diode-body,
.led-cathode,
.led-lead,
.led-ray,
.led-spark {
    transition:
        opacity 180ms ease,
        stroke 180ms ease,
        fill 180ms ease,
        filter 180ms ease;
}

.led-break-left,
.led-break-right,
.led-spark {
    opacity: 0;
}

.placed-component.led-powered .led-diode-body {
    fill: color-mix(in srgb, var(--led-glow, #ff0000) 22%, white);
    filter:
        drop-shadow(
            0 0 calc(3px * var(--led-glow-strength, 1))
            var(--led-glow, #ff0000)
        );
}

.placed-component.led-powered .led-ray {
    stroke: var(--led-glow, #ff0000);
    fill: var(--led-glow, #ff0000);
    opacity: var(--led-brightness, 1);
}

.placed-component.led-heating .component-body {
    background: transparent;
    border-color: #d98200;
    box-shadow: 0 0 7px rgba(255, 120, 0, 0.42);
}

.placed-component.led-heating .led-link {
    stroke: #ff6a00;
    animation:
        led-link-heat
        var(--led-heat-duration, 0.7s)
        ease-in-out
        infinite alternate;
}

.placed-component.led-heating .led-diode-body {
    fill: rgba(255, 205, 125, 0.72);
    stroke: #d98200;
}

.placed-component.led-blown .component-body {
    background: transparent;
    border-color: #cc3333;
    animation: none;
}

.placed-component.led-blown .led-link {
    opacity: 0;
}

.placed-component.led-blown .led-break-left,
.placed-component.led-blown .led-break-right {
    opacity: 1;
    stroke: #7c1f1f;
}

.placed-component.led-blown .led-diode-body {
    fill: rgba(225, 225, 225, 0.9);
    stroke: #8c2c24;
    filter: none;
}

.placed-component.led-blown .led-ray {
    opacity: 0.15;
    fill: #555;
    stroke: #555;
}

.placed-component.led-blown .led-spark {
    opacity: 1;
    animation: led-spark-pop 300ms ease-out 1 forwards;
}

.placed-component.led-blown .led-spark-two {
    animation-delay: 55ms;
}

/* Disable the previous smoke and drawn-on broken-line effects. */
.placed-component.led-blown::after,
.placed-component.led-blown .component-body::before,
.placed-component.led-blown .component-body::after,
.placed-component.led-burnt::after {
    content: none !important;
    display: none !important;
}

@keyframes led-link-heat {
    from {
        stroke: #d98200;
        filter: drop-shadow(0 0 1px rgba(255, 90, 0, 0.35));
    }

    to {
        stroke: #ff2f00;
        filter: drop-shadow(0 0 7px rgba(255, 70, 0, 0.95));
    }
}

@keyframes led-spark-pop {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }

    45% {
        opacity: 1;
        transform: scale(1.7);
    }

    100% {
        opacity: 0;
        transform: scale(0.2);
    }
}
