:root {
    color-scheme: dark;
    --bg: #1a1a1a;
    --neon: #00ffcc;
    --neon-soft: rgba(0, 255, 204, 0.35);
    --panel: rgba(0, 0, 0, 0.5);
    --panel-strong: rgba(0, 0, 0, 0.8);
    --text-muted: #888;
    --danger: #ff5c5c;
}

body {
    margin: 0;
    overflow: hidden;
    background-color: var(--bg);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: white;
    user-select: none;
    -webkit-user-select: none;
}

#canvas-container {
    width: 100vw;
    height: 100vh;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    touch-action: none;
}

#canvas-container canvas {
    touch-action: none;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.top-bar {
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.85), transparent);
    pointer-events: auto;
}

.title-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

h1 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--neon);
    text-shadow: 0 0 10px rgba(0, 255, 204, 0.5);
}

.subtitle {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    color: rgba(0, 255, 204, 0.7);
}

.stats {
    display: flex;
    gap: 10px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 10px;
    background: var(--panel);
    border: 1px solid var(--neon-soft);
    border-radius: 10px;
    min-width: 64px;
}

.stat-label {
    font-size: 0.55rem;
    letter-spacing: 0.15em;
    color: rgba(0, 255, 204, 0.7);
}

.stat-value {
    font-size: 0.9rem;
    font-weight: 600;
}

.stat-value.over-limit {
    color: var(--danger);
}

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    backdrop-filter: blur(5px);
    font-weight: bold;
    transition: all 0.2s;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn:active:not(:disabled) {
    background: rgba(0, 255, 204, 0.3);
    border-color: var(--neon);
    transform: scale(0.95);
}

.btn.active {
    background: rgba(0, 255, 204, 0.6);
    color: #000;
    border-color: var(--neon);
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.5);
}

.controls-area {
    padding: 20px;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-bottom: 40px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent);
}

#message-box {
    margin-bottom: 12px;
    color: #ccc;
    font-size: 0.9rem;
    text-align: center;
    min-height: 20px;
    text-shadow: 1px 1px 2px black;
    background: var(--panel);
    padding: 6px 12px;
    border-radius: 10px;
}

.control-hint {
    margin-top: 10px;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

.legend {
    margin-top: 10px;
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    justify-content: center;
    font-size: 0.7rem;
    color: #aaa;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend-item::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 6px currentColor;
}

.legend-core {
    color: #ff3366;
}

.legend-data {
    color: #3366ff;
}

.legend-firewall {
    color: #444;
}

.legend-exit {
    color: #00ff00;
}

.d-pad {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(2, 50px);
    gap: 10px;
    pointer-events: auto;
}

.axis-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.axis-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.control-btn {
    width: 50px;
    height: 40px;
    background: rgba(30, 30, 30, 0.8);
    border: 1px solid #444;
    border-radius: 8px;
    color: white;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin: 2px 0;
    transition: background 0.2s;
}

.control-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.control-btn:not(:disabled):active {
    background: var(--neon);
    color: black;
}

#loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    color: var(--neon);
    font-size: 1.5rem;
    transition: opacity 0.5s;
}

#victory-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
}

#victory-modal.show {
    opacity: 1;
    pointer-events: auto;
}

.victory-content {
    text-align: center;
    transform: scale(0.8);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#victory-modal.show .victory-content {
    transform: scale(1);
}

.victory-title {
    font-size: 3rem;
    color: var(--neon);
    margin-bottom: 10px;
    text-shadow: 0 0 20px var(--neon);
}

.victory-desc {
    font-size: 1.2rem;
    color: white;
    margin-bottom: 30px;
}

.restart-btn {
    padding: 15px 40px;
    font-size: 1.2rem;
    background: var(--neon);
    color: black;
    border: none;
    border-radius: 30px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.5);
}

/* Modal Generic */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 60;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
    backdrop-filter: blur(10px);
}

.modal.show {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: rgba(20, 20, 20, 0.8);
    border: 1px solid var(--neon);
    padding: 30px;
    border-radius: 20px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 30px rgba(0, 255, 204, 0.2);
    transform: translateY(20px);
    transition: transform 0.4s;
}

.modal.show .modal-content {
    transform: translateY(0);
}

.modal-header {
    margin-bottom: 25px;
}

.modal-title {
    font-size: 1.8rem;
    color: var(--neon);
    font-weight: bold;
    letter-spacing: 0.1em;
}

.modal-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 0.2em;
}

.instructions {
    text-align: left;
    margin-bottom: 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.inst-item {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.inst-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
}

.inst-text {
    font-size: 0.95rem;
    line-height: 1.4;
    color: #ddd;
}

.inst-text strong {
    color: var(--neon);
}

.start-btn {
    padding: 15px 40px;
    font-size: 1.1rem;
    background: var(--neon);
    color: black;
    border: none;
    border-radius: 10px;
    font-weight: bold;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: all 0.2s;
}

.start-btn:hover {
    box-shadow: 0 0 20px var(--neon);
    transform: scale(1.05);
}

@media (max-width: 720px) {
    .top-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .title-group {
        align-items: center;
    }

    .stats {
        justify-content: center;
    }

    .actions {
        justify-content: center;
    }

    .d-pad,
    .control-hint {
        display: none;
    }

    .controls-area {
        padding-bottom: 20px;
    }
}