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

:root {
    --bg:      #0b0e1a;
    --surface: rgba(255,255,255,0.04);
    --border:  rgba(255,255,255,0.08);
    --border-h:rgba(255,255,255,0.18);
    --text:    #f0f4ff;
    --muted:   #5a6a8a;
    --dim:     #8899bb;
    --neon:    #39ff14;
    --neon-g:  rgba(57,255,20,0.25);
    --blue:    #0ea5e9;
    --font:    'Outfit', sans-serif;
    --glass:   blur(14px);
    --r-lg:    20px;
    --r-md:    14px;
    --r-sm:    9px;
}

html, body { height: 100%; overflow: hidden; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
}

.bg-circles {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
    background: radial-gradient(ellipse at 20% 10%, #0f1c38 0%, #0b0e1a 60%);
}

.circle {
    position: absolute;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.5;
    animation: drift 22s ease-in-out infinite;
}

.c1 { width: 500px; height: 500px; background: #1a0b42; top: -150px; left: -100px; animation-delay: 0s; }
.c2 { width: 350px; height: 350px; background: #0b2e1a; bottom: -80px; right: -60px; animation-delay: -8s; }
.c3 { width: 260px; height: 260px; background: #0a2040; top: 50%; left: 45%; animation-delay: -14s; opacity: 0.3; }

@keyframes drift {
    0%, 100% { transform: translate(0, 0); }
    33%       { transform: translate(25px, -20px); }
    66%       { transform: translate(-18px, 18px); }
}

.game-container {
    position: relative;
    z-index: 1;
    width: 98vw;
    max-width: 1180px;
    height: 96vh;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.game-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    backdrop-filter: var(--glass);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 14px 22px;
    flex-shrink: 0;
    box-shadow: 0 4px 24px rgba(0,0,0,0.35);
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px 13px;
    border-radius: var(--r-sm);
    border: 1px solid transparent;
    transition: all 0.25s;
}

.back-btn:hover {
    color: var(--text);
    background: var(--surface);
    border-color: var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 13px;
}

.brand-logo {
    width: 46px;
    height: 46px;
    background: linear-gradient(135deg, #1c5a12, #39ff14);
    border-radius: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    transform: rotate(-5deg);
    box-shadow: 0 0 20px rgba(57,255,20,0.3);
}

.brand-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.brand-name {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1;
}

.brand-badge {
    display: inline-block;
    background: var(--neon);
    color: #000;
    font-size: 0.55rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    padding: 2px 8px;
    border-radius: 20px;
    width: fit-content;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: all 0.25s;
}

.icon-btn:hover {
    color: var(--neon);
    border-color: rgba(57,255,20,0.4);
    background: rgba(57,255,20,0.06);
}

.game-layout {
    display: grid;
    grid-template-columns: 200px 1fr 200px;
    gap: 16px;
    flex: 1;
    min-height: 0;
}

.side-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
}

.stats-card {
    background: var(--surface);
    backdrop-filter: var(--glass);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 22px 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-lbl {
    font-size: 0.65rem;
    letter-spacing: 2px;
    font-weight: 700;
    color: var(--muted);
}

.stat-val {
    font-size: 2.4rem;
    font-weight: 800;
    line-height: 1;
    color: var(--text);
}

.stat-val.green {
    color: var(--neon);
    text-shadow: 0 0 16px var(--neon-g);
}

.stat-sep {
    height: 1px;
    background: var(--border);
    width: 100%;
}

.meta-card {
    background: var(--surface);
    backdrop-filter: var(--glass);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.meta-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.meta-lbl {
    font-size: 0.65rem;
    letter-spacing: 1.5px;
    font-weight: 700;
    color: var(--muted);
}

.meta-val {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--blue);
}

.keys-card {
    background: var(--surface);
    backdrop-filter: var(--glass);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    flex: 1;
    justify-content: center;
}

.d-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.dp-row {
    display: flex;
    gap: 4px;
}

.dp-key {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: var(--dim);
    font-weight: 700;
    user-select: none;
}

.keys-hint {
    font-size: 0.7rem;
    color: var(--muted);
    letter-spacing: 0.3px;
    text-align: center;
}

.canvas-section {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    backdrop-filter: var(--glass);
    border: 1px solid rgba(57,255,20,0.15);
    border-radius: var(--r-lg);
    overflow: hidden;
    box-shadow:
        0 0 0 1px rgba(57,255,20,0.04),
        0 0 50px rgba(57,255,20,0.07),
        inset 0 0 60px rgba(0,0,0,0.5);
}

#game-canvas {
    display: block;
    background: #070a0c;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(7,10,12,0.88);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: opacity 0.3s;
}

.overlay.hidden { display: none; }

.overlay-inner {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 32px 24px;
}

.ov-icon { font-size: 3.5rem; }

.overlay-inner h2 {
    font-size: 2.2rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--neon), var(--blue));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

.overlay-inner p {
    color: var(--dim);
    font-size: 0.88rem;
    max-width: 240px;
    line-height: 1.55;
}

.start-btn {
    margin-top: 6px;
    padding: 13px 38px;
    background: linear-gradient(135deg, var(--neon), #0ea5e9);
    border: none;
    border-radius: 50px;
    color: #000;
    font-family: var(--font);
    font-size: 0.875rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    cursor: pointer;
    transition: all 0.25s;
    box-shadow: 0 0 24px rgba(57,255,20,0.35);
}

.start-btn:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 0 36px rgba(57,255,20,0.5);
}

.right-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.log-card {
    flex: 1;
    background: var(--surface);
    backdrop-filter: var(--glass);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.log-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.log-title {
    font-size: 0.65rem;
    letter-spacing: 2px;
    font-weight: 700;
    color: var(--muted);
}

.live-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--neon);
    box-shadow: 0 0 8px var(--neon);
    animation: pulse-dot 1.8s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.25; }
}

.log-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.log-entry {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.78rem;
    padding: 8px 10px;
    background: rgba(255,255,255,0.025);
    border-radius: var(--r-sm);
    border: 1px solid rgba(255,255,255,0.04);
    line-height: 1.4;
}

.log-icon { flex-shrink: 0; font-size: 0.85rem; }

.log-entry.system span:last-child { color: var(--muted); }
.log-entry.info    span:last-child { color: #7dd3fc; }
.log-entry.success span:last-child { color: var(--neon); }
.log-entry.danger  span:last-child { color: #f87171; }
.log-entry.warning span:last-child { color: #fbbf24; }

.reset-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--dim);
    padding: 12px 16px;
    border-radius: var(--r-md);
    font-family: var(--font);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
    flex-shrink: 0;
}

.reset-btn:hover {
    color: var(--text);
    border-color: var(--border-h);
    background: rgba(255,255,255,0.06);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: opacity 0.3s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-bg {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(10px);
}

.modal-box {
    position: relative;
    z-index: 1;
    background: #0d1018;
    border: 1px solid var(--border);
    border-radius: 24px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 32px 80px rgba(0,0,0,0.55);
    overflow: hidden;
    transform: translateY(0);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}

.modal.hidden .modal-box { transform: translateY(14px); }

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 24px 18px;
    border-bottom: 1px solid var(--border);
}

.modal-head h3 {
    font-size: 1.15rem;
    font-weight: 700;
}

.close-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    color: var(--muted);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
}

.close-btn:hover {
    background: rgba(255,255,255,0.08);
    color: var(--text);
}

.modal-body {
    padding: 20px 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.rule {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.rule-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.rule strong {
    display: block;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
}

.rule p {
    font-size: 0.8rem;
    color: var(--dim);
    line-height: 1.45;
}

.shortcut-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    border-top: 1px solid var(--border);
    padding-top: 14px;
    margin-top: 4px;
}

.shortcut {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.78rem;
    color: var(--dim);
}

.shortcut kbd {
    background: rgba(255,255,255,0.07);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 7px;
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text);
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }

@media (max-width: 900px) {
    .game-layout {
        grid-template-columns: 160px 1fr 160px;
        gap: 10px;
    }
}

@media (max-width: 700px) {
    html, body { overflow: auto; }

    .game-container {
        height: auto;
        min-height: 100vh;
        gap: 12px;
        padding: 12px;
    }

    .game-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto;
    }

    .canvas-section {
        aspect-ratio: 1 / 1;
        height: auto;
        max-height: 90vw;
    }

    .side-panel { flex-direction: row; flex-wrap: wrap; }
    .stats-card, .meta-card, .keys-card, .log-card { flex: 1; min-width: 140px; }
    .right-panel { flex-direction: row; }
}
