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

:root {
    --neon: #00d9ff;
    --neon-soft: #55eaff;
    --bg: #020812;
    --panel: rgba(2, 13, 25, 0.82);
    --text: #e8fbff;
    --muted: #86aab5;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: "Orbitron", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    background:
        linear-gradient(rgba(0, 217, 255, .025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 217, 255, .025) 1px, transparent 1px);
    background-size: 45px 45px;
    mask-image: linear-gradient(to bottom, black, transparent 90%);
}

#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #040f1e;
    transition: opacity .45s ease, visibility .45s ease;
}

#loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: min(320px, 80vw);
}

.loading-eyebrow {
    font-size: 10px;
    letter-spacing: 3px;
    color: var(--neon);
    margin-bottom: 26px;
}

.loading-ring {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 3px solid rgba(0, 217, 255, .18);
    border-top-color: var(--neon);
    box-shadow: 0 0 18px rgba(0, 217, 255, .25);
    animation: loading-spin 1s linear infinite;
    margin-bottom: 22px;
}

@keyframes loading-spin {
    to { transform: rotate(360deg); }
}

.loading-title {
    font-size: 13px;
    letter-spacing: 3px;
    color: #fff;
    text-shadow: 0 0 10px rgba(0, 217, 255, .45);
    margin-bottom: 16px;
}

.loading-bar-track {
    width: 100%;
    height: 4px;
    background: rgba(0, 217, 255, .12);
    border: 1px solid rgba(0, 217, 255, .3);
    overflow: hidden;
    margin-bottom: 10px;
}

.loading-bar-fill {
    width: 0%;
    height: 100%;
    background: var(--neon);
    box-shadow: 0 0 10px var(--neon);
    transition: width .2s ease;
}

.loading-bar-fill.indeterminate {
    width: 40% !important;
    animation: loading-indeterminate 1.1s ease-in-out infinite;
}

@keyframes loading-indeterminate {
    0% { margin-left: -40%; }
    100% { margin-left: 100%; }
}

.loading-percent {
    font-size: 11px;
    letter-spacing: 2px;
    color: var(--muted);
}

#loading-screen.error .loading-ring {
    animation: none;
    border-top-color: #ff5c5c;
    border-color: rgba(255, 92, 92, .25);
    box-shadow: 0 0 18px rgba(255, 92, 92, .3);
}

#loading-screen.error .loading-title,
#loading-screen.error .loading-percent {
    color: #ff8080;
}

#canvas-container {
    position: absolute;
    inset: 0;
    z-index: 1;
}

#ui-overlay {
    position: absolute;
    top: 28px;
    left: 30px;
    z-index: 10;
    width: min(390px, calc(100vw - 60px));
    padding: 22px 24px;
    background: linear-gradient(135deg, rgba(2, 15, 28, .92), rgba(2, 8, 17, .72));
    border: 1px solid rgba(0, 217, 255, .42);
    border-left: 3px solid var(--neon);
    box-shadow: 0 0 30px rgba(0, 217, 255, .09), inset 0 0 25px rgba(0, 217, 255, .025);
    backdrop-filter: blur(12px);
    clip-path: polygon(0 0, 96% 0, 100% 22%, 100% 100%, 0 100%);
}

.eyebrow, .panel-kicker, #status, #controls-hint {
    font-size: 10px;
    letter-spacing: 2px;
}

.eyebrow {
    color: var(--neon);
    margin-bottom: 9px;
}

#ui-overlay h1 {
    font-size: clamp(27px, 4vw, 42px);
    line-height: 1;
    letter-spacing: 5px;
    color: #fff;
    text-shadow: 0 0 12px rgba(0, 217, 255, .55);
    margin-bottom: 12px;
}

#ui-overlay p {
    color: var(--muted);
    font-family: Arial, sans-serif;
    font-size: 13px;
    line-height: 1.5;
    letter-spacing: .3px;
    margin-bottom: 16px;
}

#specs-btn {
    display: inline-block;
    padding: 9px 16px;
    background: rgba(0, 217, 255, .1);
    border: 1px solid rgba(0, 217, 255, .5);
    color: var(--neon-soft);
    font-family: "Orbitron", Arial, sans-serif;
    font-size: 11px;
    letter-spacing: 1.5px;
    cursor: pointer;
    transition: background .15s ease, box-shadow .15s ease;
}

#specs-btn:hover {
    background: rgba(0, 217, 255, .2);
    box-shadow: 0 0 14px rgba(0, 217, 255, .3);
}

#status {
    position: absolute;
    top: 30px;
    right: 30px;
    z-index: 10;
    padding: 11px 14px;
    border: 1px solid rgba(0, 217, 255, .35);
    background: rgba(2, 13, 25, .72);
    color: var(--neon-soft);
    backdrop-filter: blur(10px);
}

.status-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 8px;
    border-radius: 50%;
    background: var(--neon);
    box-shadow: 0 0 10px var(--neon);
}

#info-panel {
    position: absolute;
    left: 50%;
    bottom: 34px;
    transform: translateX(-50%);
    z-index: 10;
    width: min(520px, calc(100vw - 40px));
    padding: 19px 24px 21px;
    background: var(--panel);
    border: 1px solid rgba(0, 217, 255, .38);
    box-shadow: 0 0 35px rgba(0, 217, 255, .08), inset 0 0 20px rgba(0, 217, 255, .025);
    backdrop-filter: blur(15px);
    text-align: center;
}

.panel-line {
    width: 70px;
    height: 2px;
    margin: -19px auto 15px;
    background: var(--neon);
    box-shadow: 0 0 12px var(--neon);
}

.panel-kicker {
    color: var(--neon);
    margin-bottom: 8px;
}

#info-panel h2 {
    font-size: 17px;
    letter-spacing: 1px;
    color: #fff;
    margin-bottom: 8px;
}

#info-panel p {
    color: #9dbcc5;
    font-family: Arial, sans-serif;
    font-size: 13px;
    line-height: 1.45;
}

#controls-hint {
    position: absolute;
    right: 30px;
    bottom: 30px;
    z-index: 10;
    color: #607f89;
}

#controls-hint span {
    color: var(--neon-soft);
}

#credit-tag {
    position: absolute;
    left: 30px;
    bottom: 30px;
    z-index: 10;
    font-family: Arial, sans-serif;
    font-size: 10.5px;
    letter-spacing: .3px;
    color: #4c6672;
    max-width: min(340px, calc(100vw - 60px));
    line-height: 1.4;
}

#popup-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(1, 6, 14, .72);
    backdrop-filter: blur(6px);
    transition: opacity .25s ease;
}

#popup-backdrop.hidden {
    opacity: 0;
    pointer-events: none;
}

#piece-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 30;
    width: min(920px, 92vw);
    height: min(680px, 86vh);
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, rgba(2, 15, 28, .96), rgba(2, 8, 17, .9));
    border: 1px solid rgba(0, 217, 255, .42);
    box-shadow: 0 0 60px rgba(0, 217, 255, .18), inset 0 0 25px rgba(0, 217, 255, .03);
    backdrop-filter: blur(14px);
    clip-path: polygon(0 0, 98% 0, 100% 4%, 100% 100%, 0 100%);
    transition: opacity .25s ease, transform .25s ease;
    transform: translate(-50%, -50%);
}

#piece-popup.hidden {
    opacity: 0;
    transform: translate(-50%, -50%) scale(.96);
    pointer-events: none;
}

#popup-close {
    position: absolute;
    top: 14px;
    right: 18px;
    z-index: 5;
    width: 30px;
    height: 30px;
    background: rgba(2, 13, 25, .7);
    border: 1px solid rgba(0, 217, 255, .45);
    color: var(--neon-soft);
    font-family: "Orbitron", Arial, sans-serif;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

#popup-close:hover {
    background: rgba(0, 217, 255, .18);
    box-shadow: 0 0 10px rgba(0, 217, 255, .35);
}

#popup-canvas-container {
    flex: 1 1 auto;
    min-height: 280px;
    position: relative;
}

#popup-canvas-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#popup-info-panel {
    flex: 0 0 auto;
    margin: 0 20px 20px;
    padding: 16px 20px;
    border: 1px solid var(--neon);
    background: rgba(2, 13, 25, .65);
    box-shadow: 0 0 18px rgba(0, 217, 255, .15), inset 0 0 12px rgba(0, 217, 255, .04);
    text-align: center;
}

.popup-kicker {
    font-size: 10px;
    letter-spacing: 2px;
    color: var(--neon);
    margin-bottom: 7px;
}

#popup-info-panel h2 {
    font-size: 17px;
    letter-spacing: .5px;
    color: #fff;
    margin-bottom: 6px;
}

#popup-info-panel p {
    color: #9dbcc5;
    font-family: Arial, sans-serif;
    font-size: 13px;
    line-height: 1.45;
}

#hover-tooltip {
    position: fixed;
    z-index: 40;
    padding: 6px 12px;
    background: rgba(2, 13, 25, .88);
    border: 1px solid rgba(0, 217, 255, .55);
    color: var(--neon-soft);
    font-size: 11px;
    letter-spacing: 1px;
    white-space: nowrap;
    box-shadow: 0 0 14px rgba(0, 217, 255, .25);
    backdrop-filter: blur(8px);
    transform: translate(14px, 14px);
    transition: opacity .12s ease;
}

#hover-tooltip.hidden {
    opacity: 0;
    pointer-events: none;
}

#specs-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(1, 6, 14, .72);
    backdrop-filter: blur(6px);
    transition: opacity .25s ease;
}

#specs-backdrop.hidden {
    opacity: 0;
    pointer-events: none;
}

#specs-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 30;
    width: min(560px, 92vw);
    max-height: 86vh;
    overflow-y: auto;
    padding: 30px 32px 26px;
    background: linear-gradient(135deg, rgba(2, 15, 28, .96), rgba(2, 8, 17, .9));
    border: 1px solid rgba(0, 217, 255, .42);
    box-shadow: 0 0 60px rgba(0, 217, 255, .18), inset 0 0 25px rgba(0, 217, 255, .03);
    backdrop-filter: blur(14px);
    clip-path: polygon(0 0, 98% 0, 100% 3%, 100% 100%, 0 100%);
    transition: opacity .25s ease, transform .25s ease;
    transform: translate(-50%, -50%);
}

#specs-modal.hidden {
    opacity: 0;
    transform: translate(-50%, -50%) scale(.96);
    pointer-events: none;
}

.specs-header {
    margin-bottom: 22px;
}

.specs-header h2 {
    font-size: 20px;
    letter-spacing: 2px;
    color: #fff;
    text-shadow: 0 0 12px rgba(0, 217, 255, .5);
}

.specs-table {
    display: flex;
    flex-direction: column;
}

.specs-row {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(0, 217, 255, .18);
}

.specs-row:last-child {
    border-bottom: none;
}

.specs-label {
    font-family: Arial, sans-serif;
    font-size: 12.5px;
    letter-spacing: .3px;
    color: var(--muted);
    flex: 1 1 auto;
}

.specs-value {
    font-family: "Orbitron", Arial, sans-serif;
    font-size: 13px;
    letter-spacing: .5px;
    color: var(--neon-soft);
    text-align: right;
    flex: 0 0 auto;
}

#specs-close {
    position: absolute;
    top: 14px;
    right: 18px;
    z-index: 5;
    width: 30px;
    height: 30px;
    background: rgba(2, 13, 25, .7);
    border: 1px solid rgba(0, 217, 255, .45);
    color: var(--neon-soft);
    font-family: "Orbitron", Arial, sans-serif;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

#specs-close:hover {
    background: rgba(0, 217, 255, .18);
    box-shadow: 0 0 10px rgba(0, 217, 255, .35);
}

@media (max-width: 650px) {
    #ui-overlay {
        top: 16px;
        left: 16px;
        width: calc(100vw - 32px);
    }

    #status {
        top: auto;
        right: 16px;
        bottom: 16px;
    }

    #controls-hint {
        display: none;
    }

    #credit-tag {
        display: none;
    }

    #info-panel {
        bottom: 16px;
        width: calc(100vw - 32px);
    }

    #piece-popup {
        width: 94vw;
        height: 80vh;
    }
}
