/* ============================================================
   GAME 1 — INDUSTRIAL AUTOMATION CONTROL BOARD
   Theme + Navigation + Drag/Drop + Wire Connection Styling
   ============================================================ */

/* ============================================================
   GLOBAL THEME VARIABLES
   ============================================================ */

:root {
    --text-color: #1f2933;
    --muted-text: #5f6c7b;

    --bg-light: #fdfaf6;
    --page-surface: #ffffff;
    --footer-bg: #f8f9fa;

    --box-shadow: rgba(0, 0, 0, 0.12);
    --soft-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
    --panel-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);

    --nav-bg: #626e7a;
    --nav-hover-bg: #1f2933;
    --nav-link-color: #ffffff;

    --panel-bg: #1f2933;
    --panel-bg-soft: #2f3b47;
    --panel-text: #ffffff;
    --panel-border: rgba(255, 255, 255, 0.12);

    --panel-button-bg: #3d4a57;
    --panel-button-hover-bg: #4d5c6a;
    --panel-button-active-bg: #5d6d7d;

    --drop-bg: #f4f4f4;
    --drop-border: #263238;
    --drop-label: #777777;

    --control-bg: #263238;
    --control-hover-bg: #3a4752;
    --control-active-bg: #007bff;

    --legend-bg: rgba(0, 0, 0, 0.055);
    --legend-border: rgba(0, 0, 0, 0.1);

    --item-border: #1f2933;
    --terminal-bg: #ffffff;
    --terminal-border: #111111;
    --terminal-selected: #ffd700;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --transition-fast: 0.18s ease;
    --transition-med: 0.3s ease;

    --wrapper-shadow: 10px 80px 80px rgba(0, 0, 0, 0.45);
}

html[data-theme="dark"] {
    --text-color: #ffd700;
    --muted-text: #d7c76a;

    --bg-light: #1e1e1e;
    --page-surface: #242424;
    --footer-bg: #121212;

    --box-shadow: rgba(0, 0, 0, 0.45);
    --soft-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
    --panel-shadow: 0 8px 18px rgba(0, 0, 0, 0.55);

    --nav-bg: #333333;
    --nav-hover-bg: #000000;
    --nav-link-color: #ffffff;

    --panel-bg: #121212;
    --panel-bg-soft: #202020;
    --panel-text: #ffd700;
    --panel-border: rgba(255, 215, 0, 0.25);

    --panel-button-bg: #2c2c2c;
    --panel-button-hover-bg: #3a3a3a;
    --panel-button-active-bg: #444444;

    --drop-bg: #2c2c2c;
    --drop-border: #ffd700;
    --drop-label: #ffd700;

    --control-bg: #2c2c2c;
    --control-hover-bg: #444444;
    --control-active-bg: #005fcc;

    --legend-bg: rgba(255, 255, 255, 0.08);
    --legend-border: rgba(255, 215, 0, 0.22);

    --item-border: #000000;
    --terminal-bg: #ffd700;
    --terminal-border: #111111;
    --terminal-selected: #ffffff;

    --wrapper-shadow: 10px 80px 80px rgba(0, 0, 0, 0.85);
}

/* ============================================================
   GLOBAL RESET + BASE PAGE STYLING
   ============================================================ */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

html {
    min-height: 100%;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    background: radial-gradient(circle at top left, rgba(0, 123, 255, 0.08), transparent 32rem), var(--bg-light);
    color: var(--text-color);
    text-align: center;
    transition:
        background-color var(--transition-med),
        color var(--transition-med);
}

.wrapper {
    position: relative;
    width: min(100%, 1180px);
    min-height: 100vh;
    margin: 0 auto;
    padding: 1rem;
    background-color: var(--bg-light);
    box-shadow: var(--wrapper-shadow);
}

ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

h1 {
    margin: 1.25em 0 0.35em;
    text-align: center;
    font-size: clamp(2rem, 4vw, 3rem);
    letter-spacing: 0.02em;
}

h3 {
    margin: 0 0 1.25rem;
    text-align: center;
    color: var(--muted-text);
    font-size: clamp(1.05rem, 2vw, 1.35rem);
    font-weight: 600;
}

button,
select {
    font-family: inherit;
}

button {
    touch-action: none;
}

/* ============================================================
   HEADER + NAVIGATION THEME
   Supports:
   1. <header><ul>...</ul></header>
   2. <nav class="nav"><ul>...</ul></nav>
   ============================================================ */

header {
    position: relative;
    width: 100%;
    padding: 0.75rem 1.25rem;
    background-color: var(--page-surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 2px 10px var(--box-shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    z-index: 1000;
}

header ul,
.nav ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.25rem;
}

header li,
.nav li {
    margin: 0;
}

header a,
.nav a {
    display: block;
    padding: 0.875em 1em;
    color: var(--nav-link-color);
    background-color: var(--nav-bg);
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 1rem;
    transition:
        background-color var(--transition-fast),
        color var(--transition-fast),
        transform var(--transition-fast);
}

header a:hover,
.nav a:hover {
    background-color: var(--nav-hover-bg);
    color: #ffffff;
    text-decoration: none;
    transform: translateY(-1px);
}

.drag-item-content {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.drag-item-thumb-wrap {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;

    display: flex;
    align-items: center;
    justify-content: center;

    background-color: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    overflow: hidden;
}

.drag-item-thumb {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.drag-item-text {
    flex: 1;
    text-align: left;
}

.placed-item,
.drag-preview {
    position: absolute;
    width: 150px;
    height: 90px;
    border: 2px solid var(--item-border);
    border-radius: var(--radius-md);
    background-color: #ffffff;
    overflow: visible;
    user-select: none;
    touch-action: none;
    box-shadow: 0 6px 14px var(--box-shadow);
}

.placed-item-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-weight: 800;
    font-size: 0.85rem;
    text-align: center;
    color: #111111;
}

html[data-theme="dark"] .placed-item,
html[data-theme="dark"] .drag-preview {
    background-color: #2c2c2c;
}

.placed-item-visual {
    width: 100%;
    height: 58px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.35rem 0 0.35rem;
    overflow: hidden;
}

.placed-item-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    pointer-events: none;
}

.placed-item-label {
    width: 100%;
    min-height: 28px;
    padding: 0.2rem 0.4rem 0.35rem;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 800;
    line-height: 1.1;
    color: #111111;
    pointer-events: none;
}

html[data-theme="dark"] .placed-item-label {
    color: #ffd700;
}

@media (min-width: 48em) {
    .menu-icon {
        display: none;
    }

    .nav {
        position: static;
        display: flex !important;
        flex-direction: row;
        justify-content: center;
        padding: 0;
        background-color: transparent;
        box-shadow: none;
    }

    .nav ul {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .nav li {
        margin: 0;
    }
}

/* ============================================================
   LOGO + THEME TOGGLE SUPPORT
   Safe even if Game 1 does not currently use these elements.
   ============================================================ */

.theme-toggle {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
}

.logo-container {
    display: flex;
    justify-content: center;
    align-items: center;
}

.logo-container img {
    width: 3em;
    height: 3em;
    border-radius: 50%;
    object-fit: cover;
    transition:
        transform 0.4s ease,
        box-shadow 0.4s ease,
        opacity 0.3s ease;
}

#dark-logo,
#light-logo,
.nav-dark-logo,
.nav-light-logo {
    display: none;
    opacity: 0;
}

html[data-theme="light"] #light-logo,
html[data-theme="light"] .nav-light-logo {
    display: inline-block;
    opacity: 1;
    filter: drop-shadow(0 0 4px rgba(181, 183, 187, 0.5));
}

html[data-theme="dark"] #dark-logo,
html[data-theme="dark"] .nav-dark-logo {
    display: inline-block;
    opacity: 1;
    filter: drop-shadow(0 0 4px rgba(255, 215, 0, 0.5));
}

@keyframes glowPulse {
    0% {
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    }

    50% {
        box-shadow: 0 0 40px rgba(255, 215, 0, 1);
    }

    100% {
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.8);
    }
}

@keyframes glowPulseW {
    0% {
        box-shadow: 0 0 20px rgba(192, 192, 192, 0.8);
    }

    50% {
        box-shadow: 0 0 40px rgba(173, 216, 230, 1);
    }

    100% {
        box-shadow: 0 0 20px rgba(192, 192, 192, 0.8);
    }
}

html[data-theme="dark"] .logo-container img:hover {
    animation: glowPulse 1.2s infinite ease-in-out;
    transform: scale(1.05);
}

html[data-theme="light"] .logo-container img:hover {
    animation: glowPulseW 1.2s infinite ease-in-out;
    transform: scale(1.05);
}
/* ============================================================
   MAIN GAME LAYOUT
   ============================================================ */

.game-layout {
    display: grid;
    grid-template-columns: 240px minmax(0, 800px);
    gap: 1.25rem;
    align-items: start;
    justify-content: center;
    margin-top: 1.5rem;
}

/* ============================================================
   LEFT PARTS MENU PANEL
   ============================================================ */

.drag-menu {
    width: 100%;
    max-width: 240px;
    padding: 1rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent), var(--panel-bg);
    color: var(--panel-text);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--panel-shadow);
}

.drag-menu h4 {
    margin: 0 0 1rem;
    padding-bottom: 0.75rem;
    text-align: center;
    border-bottom: 1px solid var(--panel-border);
    font-size: 1.1rem;
    letter-spacing: 0.04em;
}

.parts-menu-tree {
    max-height: 560px;
    overflow-y: auto;
    padding-right: 0.35rem;
    text-align: left;
    scrollbar-width: thin;
}

.parts-menu-tree::-webkit-scrollbar {
    width: 8px;
}

.parts-menu-tree::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 999px;
}

.parts-menu-tree::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.28);
    border-radius: 999px;
}

.parts-category {
    margin-bottom: 0.45rem;
}

.parts-category summary {
    padding: 0.6rem 0.7rem;
    background-color: var(--panel-bg-soft);
    color: var(--panel-text);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    user-select: none;
    font-size: 0.92rem;
    font-weight: 700;
    transition:
        background-color var(--transition-fast),
        transform var(--transition-fast);
}

.parts-category summary:hover {
    background-color: var(--panel-button-hover-bg);
    transform: translateX(2px);
}

.parts-category[open] > summary {
    background-color: var(--panel-button-active-bg);
}

.parts-children {
    margin-top: 0.45rem;
    margin-left: 0.65rem;
    padding-left: 0.65rem;
    border-left: 2px solid rgba(255, 255, 255, 0.25);
}

.drag-item {
    display: block;
    width: 100%;
    margin-bottom: 0.55rem;
    padding: 0.7rem 0.75rem;
    background-color: var(--panel-button-bg);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-sm);
    cursor: grab;
    text-align: left;
    font-size: 0.9rem;
    font-weight: 700;
    touch-action: none;
    user-select: none;
    transition:
        background-color var(--transition-fast),
        transform var(--transition-fast),
        box-shadow var(--transition-fast);
}

.drag-item:hover {
    background-color: var(--panel-button-hover-bg);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.18);
}

.drag-item:active {
    cursor: grabbing;
    background-color: var(--panel-button-active-bg);
    transform: translateY(0);
}

/* ============================================================
   GAME BOARD PANEL
   ============================================================ */

.game-board {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    width: min(800px, 100%);
}

/* ============================================================
   PART PROPERTIES PANEL
   ============================================================ */

.part-properties-panel {
    display: none;
    padding: 0.95rem;
    background-color: var(--page-surface);
    color: var(--text-color);
    border: 1px solid var(--legend-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 12px var(--box-shadow);
    text-align: left;
}

.part-properties-panel.panel-visible {
    display: block;
}

.properties-header h4 {
    margin: 0 0 0.35rem;
    font-size: 1rem;
}

.properties-header p {
    margin: 0 0 0.85rem;
    color: var(--muted-text);
    font-size: 0.9rem;
    line-height: 1.35;
}

.properties-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.part-properties-panel label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-weight: 800;
    font-size: 0.9rem;
}

.part-properties-panel input,
.part-properties-panel select,
.part-properties-panel textarea {
    width: 100%;
    padding: 0.65rem 0.7rem;
    border: 1px solid var(--legend-border);
    border-radius: var(--radius-sm);
    background-color: #ffffff;
    color: #111111;
    font: inherit;
}

html[data-theme="dark"] .part-properties-panel input,
html[data-theme="dark"] .part-properties-panel select,
html[data-theme="dark"] .part-properties-panel textarea {
    background-color: #2c2c2c;
    color: #ffd700;
    border-color: rgba(255, 215, 0, 0.25);
}

.properties-notes-label textarea {
    min-height: 70px;
    resize: vertical;
}

.properties-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-top: 0.85rem;
}

.placed-item.part-selected {
    outline: 4px solid #0d6efd;
    box-shadow:
        0 0 0 4px rgba(13, 110, 253, 0.18),
        0 0 18px rgba(13, 110, 253, 0.65);
}

.placed-item-label {
    white-space: pre-line;
}

/* ============================================================
   CONNECTION CONTROLS
   ============================================================ */

.connection-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    justify-content: flex-start;
    align-items: center;
    padding: 0.85rem;
    background-color: var(--page-surface);
    border: 1px solid var(--legend-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 12px var(--box-shadow);
}

.connection-btn,
.wire-select {
    min-height: 42px;
    padding: 0.65rem 0.9rem;
    background-color: var(--control-bg);
    color: #ffffff;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 700;
    touch-action: none;
    user-select: none;
    transition:
        background-color var(--transition-fast),
        transform var(--transition-fast),
        box-shadow var(--transition-fast);
}

.connection-btn:hover,
.wire-select:hover {
    background-color: var(--control-hover-bg);
    transform: translateY(-1px);
}

.connection-btn.active {
    background-color: var(--control-active-bg);
    color: #ffffff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

.wire-select {
    max-width: 230px;
}

.wire-label {
    color: var(--text-color);
    font-weight: 800;
}

/* ============================================================
   SAVE / LOAD / CLEAR BOARD BUTTON STYLING
   ============================================================ */

.save-btn {
    background-color: #0d6efd;
}

.save-btn:hover {
    background-color: #0b5ed7;
}

.load-btn {
    background-color: #6f42c1;
}

.load-btn:hover {
    background-color: #5e35a8;
}

.clear-board-btn {
    background-color: #6c757d;
}

.clear-board-btn:hover {
    background-color: #5c636a;
}

/* ============================================================
   SNAP-TO-GRID MODE STYLING
   ============================================================ */

.snap-btn.active,
.snap-btn.snap-active {
    background-color: #198754;
    color: #ffffff;
    box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.25);
}

.drop-zone.snap-mode {
    box-shadow:
        var(--soft-shadow),
        inset 0 0 0 2px rgba(25, 135, 84, 0.25);
}

/* ============================================================
   DELETE MODE STYLING
   ============================================================ */

.delete-btn.active,
.delete-btn.delete-active {
    background-color: #dc3545;
    color: #ffffff;
    box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.25);
}

.drop-zone.delete-mode {
    border-color: #dc3545;
    box-shadow:
        var(--soft-shadow),
        0 0 0 4px rgba(220, 53, 69, 0.18);
}

.drop-zone.delete-mode .placed-item {
    cursor: not-allowed;
}

.drop-zone.delete-mode .placed-item:hover {
    outline: 4px solid rgba(220, 53, 69, 0.85);
    box-shadow:
        0 0 0 4px rgba(220, 53, 69, 0.18),
        0 0 18px rgba(220, 53, 69, 0.65);
}

.drop-zone.delete-mode .connection-terminal {
    cursor: not-allowed;
}

.drop-zone.delete-mode .connection-terminal:hover {
    background-color: #dc3545;
    border-color: #ffffff;
    box-shadow: 0 0 12px rgba(220, 53, 69, 0.95);
}

/* ============================================================
   WIRE LEGEND
   ============================================================ */

.wire-legend {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
    gap: 0.45rem 0.9rem;
    padding: 0.85rem;
    background-color: var(--legend-bg);
    color: var(--text-color);
    border: 1px solid var(--legend-border);
    border-radius: var(--radius-lg);
    text-align: left;
    box-shadow: 0 4px 12px var(--box-shadow);
}

.wire-legend h4 {
    grid-column: 1 / -1;
    margin: 0 0 0.35rem;
    text-align: left;
    font-size: 1rem;
}

.wire-legend div {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.9rem;
    font-weight: 700;
}

.legend-line {
    display: inline-block;
    width: 36px;
    height: 5px;
    margin-right: 0.25rem;
    border-radius: 999px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.wire-power {
    background-color: #d32f2f;
}

.wire-common {
    background-color: #111111;
}

.wire-signal {
    background-color: #1976d2;
}

.wire-safety {
    background-color: #fbc02d;
}

.wire-network {
    background-color: #388e3c;
    background-image: repeating-linear-gradient(
        90deg,
        transparent 0,
        transparent 8px,
        rgba(255, 255, 255, 0.75) 8px,
        rgba(255, 255, 255, 0.75) 12px
    );
}

.wire-analog {
    background-color: #8e24aa;
}

.wire-ac-control {
    background-color: #f57c00;
}

.wire-pneumatic {
    background-color: #777777;
    background-image: repeating-linear-gradient(
        90deg,
        transparent 0,
        transparent 10px,
        rgba(255, 255, 255, 0.8) 10px,
        rgba(255, 255, 255, 0.8) 16px
    );
}

.wire-hydraulic {
    background-color: #004d80;
}

/* ============================================================
   DROP ZONE + CANVAS WIRE LAYER
   ============================================================ */
/* ============================================================
   ZOOMABLE BOARD WORLD
   dropZone = viewport
   boardScrollArea = scrollable size holder
   boardWorld = scaled CAD board
   ============================================================ */

.drop-zone {
    position: relative;
    width: 800px;
    height: 500px;
    max-width: 100%;

    background-color: var(--drop-bg);
    border: 3px solid var(--drop-border);
    border-radius: var(--radius-lg);

    overflow: auto;
    touch-action: none;

    box-shadow: var(--soft-shadow);
}

.board-scroll-area {
    position: relative;
    width: 800px;
    height: 500px;
}

.board-world {
    position: absolute;
    left: 0;
    top: 0;

    width: 800px;
    height: 500px;

    transform-origin: 0 0;
}

#canvas1 {
    position: absolute;
    left: 0;
    top: 0;

    display: block;
    width: 800px;
    height: 500px;

    background-color: var(--drop-bg);
    pointer-events: none;
}

/* ============================================================
   DROPPED PARTS + DRAG PREVIEW
   Must match game_1.js CONFIG.itemWidth / CONFIG.itemHeight
   ============================================================ */

.placed-item,
.drag-preview {
    position: absolute;
    width: 150px;
    height: 90px;

    border: 2px solid var(--item-border);
    border-radius: var(--radius-md);

    background-color: #ffffff;
    color: #111111;

    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;

    cursor: grab;
    font-size: 0.95rem;
    font-weight: 800;
    text-align: center;

    user-select: none;
    touch-action: none;
    z-index: 10;

    overflow: visible;
    box-shadow: 0 6px 14px var(--box-shadow);
}

html[data-theme="dark"] .placed-item,
html[data-theme="dark"] .drag-preview {
    background-color: #2c2c2c;
    color: #ffd700;
}

.drag-preview {
    position: fixed;
    pointer-events: none;
    opacity: 0.75;
    z-index: 9999;
}

.placed-item-visual {
    width: 100%;
    height: 58px;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 0.35rem 0.35rem 0;
    overflow: hidden;
}

.placed-item-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
    pointer-events: none;
}

.placed-item-fallback {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    height: 100%;

    padding: 0.25rem;

    font-weight: 800;
    font-size: 0.85rem;
    text-align: center;
    color: inherit;
}

.placed-item-label {
    width: 100%;
    min-height: 28px;

    padding: 0.2rem 0.4rem 0.35rem;

    text-align: center;
    font-size: 0.8rem;
    font-weight: 800;
    line-height: 1.1;

    color: inherit;
    white-space: pre-line;
    pointer-events: none;
}

/* ============================================================
   PART CATEGORY COLORS
   Used by menu buttons, dropped parts, and drag preview.
   ============================================================ */

.part-generic {
    background-color: #555555;
}

.sensor-part {
    background-color: #2f80ed;
}

.motor-part {
    background-color: #9b51e0;
}

.control-part {
    background-color: #27ae60;
}

.safety-part {
    background-color: #eb5757;
}

.pneumatic-part {
    background-color: #f2994a;
}

.hydraulic-part {
    background-color: #56ccf2;
    color: #102027;
}

.electrical-part {
    background-color: #f2c94c;
    color: #111111;
}

/* Backward-compatible old test classes */
.motor {
    background-color: #2f80ed;
}

.sensor {
    background-color: #27ae60;
}

.valve {
    background-color: #eb5757;
}

.gear {
    background-color: #9b51e0;
}

/* ============================================================
   CONNECTION TERMINALS
   ============================================================ */

.connection-terminal {
    position: absolute;
    width: 14px;
    height: 14px;
    background-color: var(--terminal-bg);
    border: 3px solid var(--terminal-border);
    border-radius: 50%;
    cursor: crosshair;
    touch-action: none;
    z-index: 20;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
    transition:
        transform var(--transition-fast),
        box-shadow var(--transition-fast),
        background-color var(--transition-fast);
}

.connection-terminal:hover {
    transform: translate(-50%, -50%) scale(1.25);
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.95);
}

.connection-terminal.terminal-selected {
    background-color: var(--terminal-selected);
    border-color: #111111;
    box-shadow: 0 0 14px rgba(255, 215, 0, 1);
}

.placed-item.connection-selected {
    outline: 4px solid #ffd700;
    box-shadow:
        0 0 0 4px rgba(255, 215, 0, 0.25),
        0 0 18px rgba(255, 215, 0, 0.9);
}

/* ============================================================
   DARK MODE REFINEMENTS
   ============================================================ */

html[data-theme="dark"] .parts-category summary {
    background-color: #2c2c2c;
    color: #ffd700;
}

html[data-theme="dark"] .parts-category summary:hover,
html[data-theme="dark"] .parts-category[open] > summary {
    background-color: #444444;
}

html[data-theme="dark"] .connection-btn,
html[data-theme="dark"] .wire-select {
    color: #ffd700;
    border-color: rgba(255, 215, 0, 0.22);
}

html[data-theme="dark"] .connection-btn.active {
    color: #ffffff;
}

/* ============================================================
   FOOTER THEME SUPPORT
   ============================================================ */

footer {
    margin-top: 2rem;
    padding: 1rem 0;
    background-color: var(--footer-bg);
    color: var(--text-color);
    border-radius: var(--radius-lg);
    text-align: center;
    font-size: 0.875rem;
}

/* ============================================================
   RESPONSIVE GAME LAYOUT
   ============================================================ */

@media (max-width: 1100px) {
    .wrapper {
        width: 100%;
        max-width: 100%;
    }

    .game-layout {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .drag-menu,
    .game-board {
        width: min(800px, 100%);
        max-width: 100%;
    }

    .parts-menu-tree {
        max-height: 340px;
    }
}

@media (max-width: 700px) {
    .wrapper {
        padding: 0.75rem;
    }

    .wire-label-input {
        width: 100%;
        max-width: none;
    }

    header ul,
    .nav ul {
        flex-direction: column;
        width: 100%;
    }

    header a,
    .nav a {
        width: 100%;
    }

    .connection-controls {
        align-items: stretch;
    }

    .connection-btn,
    .wire-select,
    .wire-label {
        width: 100%;
    }

    .wire-select {
        max-width: none;
    }

    .wire-legend {
        grid-template-columns: 1fr;
    }

    .drop-zone,
    #canvas1 {
        width: 100%;
    }

    /* ============================================================
   WIRE LABEL INPUT
   ============================================================ */

    .wire-label-input {
        min-height: 42px;
        max-width: 260px;
        padding: 0.65rem 0.9rem;
        background-color: #ffffff;
        color: #111111;
        border: 1px solid var(--legend-border);
        border-radius: var(--radius-sm);
        font: inherit;
        font-weight: 700;
    }

    html[data-theme="dark"] .wire-label-input {
        background-color: #2c2c2c;
        color: #ffd700;
        border-color: rgba(255, 215, 0, 0.25);
    }

    /* ============================================================
   WIRE PROPERTIES PANEL
   ============================================================ */

    .wire-properties-panel {
        display: none;
        padding: 0.95rem;
        background-color: var(--page-surface);
        color: var(--text-color);
        border: 1px solid var(--legend-border);
        border-radius: var(--radius-lg);
        box-shadow: 0 4px 12px var(--box-shadow);
        text-align: left;
    }

    .wire-properties-panel.panel-visible {
        display: block;
    }

    .wire-properties-panel input,
    .wire-properties-panel select {
        width: 100%;
        padding: 0.65rem 0.7rem;
        border: 1px solid var(--legend-border);
        border-radius: var(--radius-sm);
        background-color: #ffffff;
        color: #111111;
        font: inherit;
    }

    html[data-theme="dark"] .wire-properties-panel input,
    html[data-theme="dark"] .wire-properties-panel select {
        background-color: #2c2c2c;
        color: #ffd700;
        border-color: rgba(255, 215, 0, 0.25);
    }

    /* ============================================================
   PROPERTY PANEL VISIBILITY CONTROL
   Both panels are hidden until a part or wire is selected.
   ============================================================ */

    .part-properties-panel,
    .wire-properties-panel {
        display: none;
    }

    .part-properties-panel.panel-visible,
    .wire-properties-panel.panel-visible {
        display: block;
    }

    /* Keep terminal dots clickable above the part label */
    .connection-terminal {
        z-index: 30;
    }

    .placed-item-label {
        pointer-events: none;
    }
}
/* ============================================================
   PROPERTY PANEL VISIBILITY CONTROL
   Both panels are hidden until an item or wire is selected.
   ============================================================ */

.part-properties-panel,
.wire-properties-panel {
    display: none;
}

.part-properties-panel.panel-visible,
.wire-properties-panel.panel-visible {
    display: block;
}

/* ============================================================
   SPLASH SCREEN
   Dark-to-light logo transition before showing main interface.
   ============================================================ */

.splash-screen {
    position: fixed;
    inset: 0;
    z-index: 99999;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.25rem;

    background-color: #050505;
    cursor: pointer;
    overflow: hidden;

    animation: splashBackgroundShift 4s ease-in-out forwards;
    transition:
        opacity 0.65s ease,
        visibility 0.65s ease;
}

.splash-screen::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at center, rgba(255, 215, 0, 0.16), transparent 32rem),
        radial-gradient(circle at bottom right, rgba(255, 255, 255, 0.18), transparent 28rem);
    opacity: 0.9;
    pointer-events: none;
}

.splash-screen.splash-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.splash-logo-frame {
    position: relative;
    width: min(58vw, 390px);
    aspect-ratio: 1 / 1;
    z-index: 1;

    border-radius: 50%;
    overflow: hidden;

    display: flex;
    align-items: center;
    justify-content: center;

    border: 4px solid rgba(255, 215, 0, 0.75);
    box-shadow:
        0 0 24px rgba(255, 215, 0, 0.45),
        0 0 60px rgba(255, 215, 0, 0.25);
}

.splash-logo {
    position: absolute;
    inset: 0;

    width: 100%;
    height: 100%;
    object-fit: cover;

    border-radius: 50%;

    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none;
}

.splash-logo-dark {
    opacity: 1;
    filter: drop-shadow(0 0 22px rgba(255, 215, 0, 0.65)) drop-shadow(0 0 48px rgba(255, 215, 0, 0.35));
    animation: splashDarkLogoFade 4s ease-in-out forwards;
}

.splash-logo-light {
    opacity: 0;
    filter: drop-shadow(0 0 18px rgba(0, 0, 0, 0.28)) drop-shadow(0 0 36px rgba(255, 255, 255, 0.55));
    animation: splashLightLogoFade 4s ease-in-out forwards;
}

.splash-tap-text {
    position: relative;
    z-index: 1;
    margin: 0;
    padding: 0.55rem 0.9rem;

    color: #1f2933;
    background-color: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 999px;

    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.04em;

    opacity: 0;
    animation: splashTapTextFade 4s ease-in-out forwards;
}

body.splash-active {
    overflow: hidden;
}

.splash-screen .splash-logo-frame {
    animation: splashFrameShift 4s ease-in-out forwards;
}

@keyframes splashFrameShift {
    0% {
        border-color: rgba(255, 215, 0, 0.85);
        box-shadow:
            0 0 24px rgba(255, 215, 0, 0.5),
            0 0 60px rgba(255, 215, 0, 0.28);
    }

    55% {
        border-color: rgba(255, 215, 0, 0.7);
    }

    100% {
        border-color: rgba(120, 120, 120, 0.55);
        box-shadow:
            0 0 22px rgba(0, 0, 0, 0.18),
            0 0 55px rgba(255, 255, 255, 0.45);
    }
}

@keyframes splashBackgroundShift {
    0% {
        background-color: #050505;
    }

    45% {
        background-color: #0e0d08;
    }

    68% {
        background-color: #c8c2a8;
    }

    100% {
        background-color: #fdfaf6;
    }
}

@keyframes splashDarkLogoFade {
    0% {
        opacity: 1;
        transform: scale(0.94);
    }

    38% {
        opacity: 1;
        transform: scale(1);
    }

    58% {
        opacity: 0;
        transform: scale(1.04);
    }

    100% {
        opacity: 0;
        transform: scale(1.04);
    }
}

@keyframes splashLightLogoFade {
    0% {
        opacity: 0;
        transform: scale(0.94);
    }

    42% {
        opacity: 0;
        transform: scale(0.97);
    }

    68% {
        opacity: 1;
        transform: scale(1);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes splashTapTextFade {
    0%,
    55% {
        opacity: 0;
        transform: translateY(8px);
    }

    75%,
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 700px) {
    .splash-logo-frame {
        width: min(78vw, 320px);
    }

    .splash-tap-text {
        font-size: 0.85rem;
    }
}

/* ============================================================
   IMAGE PART DRAG FIX
   Prevents child image/text elements from stealing pointer events.
   ============================================================ */

.drag-item-content,
.drag-item-thumb-wrap,
.drag-item-thumb,
.drag-item-text,
.placed-item-visual,
.placed-item-image,
.placed-item-fallback,
.placed-item-label {
    pointer-events: none;
}

/* ============================================================
   DROPPED PART PLACEHOLDER ICON
   Used until actual part images are added.
   ============================================================ */

.placed-item-fallback {
    font-size: 1.6rem;
    opacity: 0.75;
}
