/* ===================================================================
   Diamond Defence — crystal / neon UI
   =================================================================== */

:root {
    --bg-0: #060912;
    --bg-1: #0a0f1c;
    --bg-2: #111a2e;
    --panel: #141d33;
    --panel-hi: #1b2742;
    --accent: #4fc3f7;
    --accent-2: #7c5cff;
    --accent-glow: rgba(79, 195, 247, 0.45);
    --gold: #ffd54f;
    --success: #66e39a;
    --danger: #ef5350;
    --warning: #ffa726;
    --text: #eaf1fb;
    --text-dim: #8a97b4;
    --border: rgba(120, 150, 200, 0.16);
    --border-hi: rgba(79, 195, 247, 0.5);
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --radius: 10px;
}

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

html, body {
    height: 100%;
    background: var(--bg-0);
    color: var(--text);
    font-family: var(--font);
    overflow: hidden;
    /* Kill pinch/double-tap zoom, rubber-band scroll and tap-highlight so the
       canvas coordinate mapping can't be thrown off and the layout stays put. */
    touch-action: none;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

a { color: var(--accent); text-decoration: none; }

.hidden { display: none !important; }

/* ── Overlay / screen system (menu, pause, game-over, modal) ── */
.overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(3, 6, 14, 0.82);
    backdrop-filter: blur(6px);
    z-index: 100;
}
#modal { z-index: 120; }   /* modal sits above the pause menu */
.overlay-box {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    width: 100%;
    max-width: 360px;
    padding: 1.8rem;
    text-align: center;
    background: linear-gradient(180deg, var(--panel-hi), var(--panel));
    border: 1px solid var(--border-hi);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}
.overlay-box h2 { font-size: 1.5rem; font-weight: 900; letter-spacing: 0.05em; margin-bottom: 0.4rem; }
.overlay-box h2.danger { color: var(--danger); text-shadow: 0 0 24px rgba(239, 83, 80, 0.5); }
.overlay-box .btn { width: 100%; }
.modal-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 0.5rem 0; font-size: 0.9rem; }
.modal-note { color: var(--text-dim); font-size: 0.82rem; line-height: 1.5; margin-top: 0.4rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--panel); color: var(--text); border: none; padding: 0.4rem 0.75rem; cursor: pointer; font-weight: 700; font-family: var(--font); }
.seg button.active { background: linear-gradient(180deg, #3bb4f5, var(--accent)); color: var(--bg-0); }
#btn-open-menu { font-size: 1.1rem; line-height: 1; padding: 0.4rem 0.6rem; }

/* account / auth / leaderboard / profile */
.account-line { color: var(--text-dim); font-size: 0.82rem; margin-top: 1rem; }
.account-line a { color: var(--accent); }
.final-extra { font-size: 0.85rem; color: var(--accent); min-height: 1em; margin: 0.2rem 0; }
.final-extra a { color: var(--accent); }

.auth-tabs, .lb-tabs { display: flex; gap: 0.4rem; margin: 0.5rem 0 0.7rem; }
.auth-tabs button, .lb-tabs button {
    flex: 1; padding: 0.45rem; cursor: pointer; font-weight: 700; font-family: var(--font);
    background: var(--panel); color: var(--text-dim);
    border: 1px solid var(--border); border-radius: 8px;
}
.auth-tabs button.active, .lb-tabs button.active {
    background: linear-gradient(180deg, #3bb4f5, var(--accent)); color: var(--bg-0); border-color: var(--accent);
}

.auth-form { display: flex; flex-direction: column; gap: 0.5rem; text-align: left; }
.auth-form input {
    padding: 0.6rem 0.7rem; font-size: 0.95rem; font-family: var(--font);
    background: rgba(0, 0, 0, 0.3); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
}
.auth-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 10px var(--accent-glow); }
.auth-error { color: var(--danger); font-size: 0.82rem; min-height: 1em; margin: 0; }

.lb-body { max-height: 320px; overflow-y: auto; }
.lb-table { width: 100%; border-collapse: collapse; text-align: left; }
.lb-table td { padding: 0.42rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.lb-rank { color: var(--text-dim); width: 2rem; font-weight: 800; }
.lb-val { text-align: right; color: var(--gold); font-weight: 800; }

.stat-list { display: flex; flex-direction: column; gap: 0.15rem; text-align: left; margin: 0.6rem 0; }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 0.7rem 0.4rem; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.stat-row span { color: var(--text-dim); }
.stat-row strong { font-size: 1.05rem; }

/* super level badge + upgradable state + hint */
.super-lv { position: absolute; top: 3px; left: 5px; font-size: 0.58rem; font-weight: 800; color: #cbb6ff; opacity: 0.85; line-height: 1; }
.super-btn.upgradable { border-color: rgba(255, 213, 79, 0.6); box-shadow: 0 0 12px rgba(255, 213, 79, 0.3); }
.super-btn.upgradable .super-lv { color: #ffd54f; opacity: 1; }
.super-hint { color: var(--text-dim); font-size: 0.62rem; margin-top: 0.45rem; text-align: center; }

/* ── Main menu ───────────────────────────────────────────────── */
.menu-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
    background:
        radial-gradient(ellipse at 50% -10%, rgba(124, 92, 255, 0.22), transparent 55%),
        radial-gradient(ellipse at 50% 110%, rgba(79, 195, 247, 0.18), transparent 55%),
        var(--bg-0);
    overflow: hidden;
}
.menu-page::before {
    /* drifting diamond grid backdrop */
    content: '';
    position: absolute;
    inset: -50%;
    background-image:
        linear-gradient(rgba(79, 195, 247, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(79, 195, 247, 0.05) 1px, transparent 1px);
    background-size: 44px 44px;
    transform: perspective(400px) rotateX(55deg);
    opacity: 0.5;
    animation: drift 24s linear infinite;
    pointer-events: none;
}
@keyframes drift { to { background-position: 0 440px; } }

.menu-container {
    position: relative;
    text-align: center;
    padding: 2.5rem 2rem;
    max-width: 440px;
    width: 100%;
}

.game-title {
    font-size: clamp(2.4rem, 8vw, 3.6rem);
    font-weight: 900;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    line-height: 1;
    background: linear-gradient(135deg, #b3e5fc 0%, var(--accent) 40%, var(--accent-2) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 22px var(--accent-glow));
    margin-bottom: 0.5rem;
}
.game-logo {
    display: block;
    width: 100%;
    max-width: 380px;
    height: auto;
    margin: 0 auto 0.75rem;
    filter: drop-shadow(0 0 28px var(--accent-glow));
    image-rendering: pixelated;
}

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.game-subtitle {
    color: var(--text-dim);
    font-size: 0.8rem;
    margin-bottom: 2.5rem;
    letter-spacing: 0.35em;
    text-transform: uppercase;
}
.menu-buttons { display: flex; flex-direction: column; gap: 0.7rem; }
.menu-footer { margin-top: 2rem; color: var(--text-dim); font-size: 0.8rem; }

/* ── Buttons (chunky, game-like) ─────────────────────────────── */
.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.85rem 1.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, var(--panel-hi), var(--panel));
    color: var(--text);
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    cursor: pointer;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
    transition: transform 0.08s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.btn:hover:not(:disabled) { border-color: var(--border-hi); box-shadow: 0 3px 0 rgba(0,0,0,0.4), 0 0 16px var(--accent-glow); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.4); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-primary { background: linear-gradient(180deg, #29a3e6, #1565c0); border-color: var(--accent); box-shadow: 0 3px 0 #0d3a66, 0 0 18px var(--accent-glow); }
.btn-primary:hover:not(:disabled) { background: linear-gradient(180deg, #3bb4f5, #1976d2); }
.btn-accent { background: linear-gradient(180deg, #2fd6a8, #00897b); border-color: var(--success); box-shadow: 0 3px 0 #075244; }
.btn-danger { background: linear-gradient(180deg, #ef5350, #b71c1c); border-color: var(--danger); box-shadow: 0 3px 0 #6e0f1e; }
.btn-secondary { background: linear-gradient(180deg, var(--panel-hi), var(--panel)); }

/* ── Game layout ─────────────────────────────────────────────── */
.game-layout { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.game-header h1 {
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
    white-space: nowrap;
}

.hud-stats { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.hud-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 62px;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    font-weight: 800;
    font-size: 1rem;
    line-height: 1.15;
}
.hud-stat .label { color: var(--text-dim); font-weight: 600; font-size: 0.6rem; letter-spacing: 0.1em; text-transform: uppercase; }
.hud-stat.money { color: var(--gold); }
.hud-stat.diamonds { color: #5ff5e2; }
.hud-stat.lives { color: var(--danger); }
.hud-stat.wave  { color: var(--accent); }
.hud-stat.score { color: var(--success); }

.header-controls { display: flex; gap: 0.35rem; align-items: center; }
.header-controls .btn { padding: 0.4rem 0.7rem; font-size: 0.8rem; }
.speed-btn.active { background: linear-gradient(180deg, #3bb4f5, var(--accent)); color: var(--bg-0); border-color: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }

.game-main { flex: 1; display: flex; overflow: hidden; min-height: 0; }

.battlefield-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 50% 50%, var(--bg-1), var(--bg-0));
    overflow: hidden;
    position: relative;
    padding: 0.5rem;
}
#game-canvas {
    display: block;
    border-radius: 8px;
    box-shadow: 0 0 0 1px var(--border), 0 12px 40px rgba(0, 0, 0, 0.6);
}

/* ── Side rails: towers (left) · abilities + waves (right) ────── */
.rail {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.7rem 0.55rem;
    background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
    overflow-y: auto;
    flex-shrink: 0;
}
.rail-left  { width: 118px; border-right: 1px solid var(--border); }
.rail-cols { display: flex; flex-direction: column; gap: 0.7rem; }
.rail-col { min-width: 0; display: flex; flex-direction: column; gap: 0.4rem; }
.rail .tower-grid, .rail .super-grid { grid-template-columns: 1fr; gap: 0.4rem; }
.rail-label { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--text-dim); }
.rail-label .hint { color: #5ff5e2; letter-spacing: 0; }
.wave-status-text { font-size: 0.75rem; color: var(--text-dim); line-height: 1.4; }
.start-wave-btn { width: 100%; }

.tower-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.tower-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0.6rem 0.25rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: linear-gradient(180deg, var(--panel-hi), var(--panel));
    color: var(--text);
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.08s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.tower-btn:hover { border-color: var(--border-hi); transform: translateY(-1px); }
.tower-btn.selected { border-color: var(--accent); box-shadow: 0 0 14px var(--accent-glow); background: linear-gradient(180deg, #234269, #17253f); }
.tower-btn.unaffordable { opacity: 0.4; }

/* diamond icon per tower type */
.tower-icon {
    width: 24px; height: 24px;
    transform: rotate(45deg);
    border-radius: 5px;
    border: 2px solid currentColor;
    box-shadow: 0 0 10px currentColor, inset 0 0 6px rgba(255,255,255,0.25);
}
/* block-themed icons: rounded squares, not diamonds */
.tower-icon { transform: none; border-radius: 4px; }
.tower-btn[data-tower="basic"]  .tower-icon { color: #b0b0b0; background: #b0b0b033; }
.tower-btn[data-tower="rapid"]  .tower-icon { color: #ff5555; background: #ff555533; }
.tower-btn[data-tower="sniper"] .tower-icon { color: #5ff5e2; background: #5ff5e233; }
.tower-btn[data-tower="cannon"] .tower-icon { color: #f5c518; background: #f5c51833; }
.tower-btn[data-tower="slow"]   .tower-icon { color: #9ad4ff; background: #9ad4ff33; }
.tower-btn[data-tower="advanced"] .tower-icon { color: #4be37a; background: #4be37a33; }
.tower-btn[data-tower="miner"] .tower-icon { color: #7ec850; background: #7ec85033; border-radius: 50%; }
.tower-cost { color: var(--gold); font-weight: 800; }

/* ── Super abilities ── */
.sidebar-section h2 .hint { color: #5ff5e2; font-weight: 600; letter-spacing: 0; text-transform: none; }
.super-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.super-btn {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    padding: 0.55rem 0.25rem;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: linear-gradient(180deg, #2a2350, #171232);
    color: var(--text);
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.08s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.super-btn:hover:not(:disabled) { border-color: #7c5cff; transform: translateY(-1px); box-shadow: 0 0 14px rgba(124, 92, 255, 0.4); }
.super-btn:disabled { cursor: not-allowed; }
.super-btn.unaffordable { opacity: 0.45; }
.super-btn.on-cooldown { opacity: 0.6; }
.super-icon { font-size: 1.2rem; line-height: 1; }
.super-cost { color: #5ff5e2; font-weight: 800; }
.super-cd {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;            /* purely visual — taps fall through to the button / "+" */
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: 900;
    color: #fff;
    background: rgba(6, 9, 18, 0.72);
    border-radius: 9px;
}
.super-up {
    position: absolute;
    top: 2px;
    right: 2px;
    z-index: 2;                      /* above the cooldown overlay so it's always tappable */
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 900;
    line-height: 1;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-dim);
    border: 1px solid var(--border);
}
.super-btn.upgradable .super-up {
    background: #ffd54f;
    color: #1a1000;
    border-color: #ffd54f;
    box-shadow: 0 0 8px rgba(255, 213, 79, 0.55);
}

/* Selected-tower panel */
#tower-panel {
    position: relative;
    padding: 0.75rem;
    margin-top: 0.3rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.28);
}
#tower-panel.hidden { display: none; }
#tower-panel h3 { font-size: 1rem; margin-bottom: 0.2rem; }
.tp-close {
    position: absolute; top: 4px; right: 6px;
    width: 24px; height: 24px;
    border: none; background: transparent;
    color: var(--text-dim); font-size: 0.95rem; cursor: pointer;
}
.tp-close:hover { color: var(--text); }
.tower-level { color: var(--accent); font-size: 0.8rem; font-weight: 700; margin-bottom: 0.6rem; }
.tower-stats {
    display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem 0.6rem;
    font-size: 0.78rem; margin-bottom: 0.8rem; color: var(--text-dim);
    padding: 0.6rem; background: rgba(0,0,0,0.25); border-radius: 8px;
}
#tower-panel .btn { width: 100%; margin-bottom: 0.45rem; font-size: 0.82rem; padding: 0.55rem; }
.max-level { color: var(--warning); font-size: 0.85rem; font-weight: 700; text-align: center; margin-bottom: 0.5rem; }

/* wave preview card */
.wave-preview-box { margin-top: 0.6rem; padding: 0.6rem; border: 1px solid var(--border); border-radius: 8px; background: rgba(0,0,0,0.25); font-size: 0.75rem; }
.wave-preview-box strong { color: var(--accent); }
.wave-preview-enemies { display: flex; flex-direction: column; gap: 0.15rem; margin: 0.4rem 0; color: var(--text-dim); }
.wave-preview-boss { color: var(--gold); font-weight: 700; }
.wave-preview-reward { color: var(--success); margin-top: 0.3rem; }

/* ── Game-over overlay ───────────────────────────────────────── */
#game-over { position: fixed; inset: 0; background: rgba(3, 6, 14, 0.85); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; z-index: 100; }
#game-over.hidden { display: none; }
.game-over-box {
    background: linear-gradient(180deg, var(--panel-hi), var(--panel));
    border: 1px solid var(--border-hi);
    border-radius: 16px;
    padding: 2.2rem;
    text-align: center;
    max-width: 380px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), 0 0 40px rgba(239, 83, 80, 0.15);
}
.game-over-box h2 { font-size: 2.2rem; font-weight: 900; letter-spacing: 0.08em; color: var(--danger); margin-bottom: 1.2rem; text-shadow: 0 0 24px rgba(239,83,80,0.5); }
.game-over-stats { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.6rem; font-size: 0.9rem; color: var(--text-dim); }
.game-over-stats strong { color: var(--text); font-size: 1.05rem; }

/* ── Toasts ──────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 0.4rem; z-index: 50; pointer-events: none; }
.toast {
    padding: 0.55rem 1.1rem;
    border-radius: 24px;
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
    backdrop-filter: blur(4px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    will-change: opacity, transform;
}
.toast-success { background: rgba(27, 94, 32, 0.85); border: 1px solid var(--success); }
.toast-error   { background: rgba(183, 28, 28, 0.85); border: 1px solid var(--danger); }
.toast-info    { background: rgba(13, 71, 161, 0.85); border: 1px solid var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* ── Mobile ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Sleeker top: no big title, one thin stats row + a compact control row */
    .game-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.25rem;
        padding: 0.3rem 0.45rem;
    }
    .game-header h1 { display: none; }
    .hud-stats { display: flex; gap: 0.25rem; width: 100%; flex-wrap: nowrap; }
    .hud-stat {
        flex: 1; min-width: 0;
        padding: 0.2rem 0.1rem;
        font-size: 0.78rem;
        border-radius: 6px;
    }
    .hud-stat .label { font-size: 0.46rem; }
    .header-controls { justify-content: center; gap: 0.3rem; }
    .header-controls .btn { padding: 0.28rem 0.5rem; font-size: 0.75rem; }

    /* One compact control column on the left, map fills the right */
    .rail-left { width: 84px; padding: 0.4rem 0.3rem; gap: 0.4rem; }
    .rail-cols { gap: 0.5rem; }
    .rail-col { gap: 0.3rem; }
    .rail-label { font-size: 0.5rem; margin-bottom: 0.05rem; }
    .super-hint, .tb-name, .super-name, .wave-status-text { display: none; }
    .tower-btn { padding: 0.35rem 0.1rem; }
    .tower-icon { width: 26px; height: 26px; }
    .super-btn { padding: 0.45rem 0.15rem; }
    .super-icon { font-size: 1.15rem; }
    .super-cost { font-size: 0.6rem; }
    .super-lv { font-size: 0.5rem; }
    .start-wave-btn { font-size: 0.72rem; padding: 0.5rem 0.2rem; }

    /* Selected-tower panel slides up as a bottom sheet so the buttons are usable */
    #tower-panel:not(.hidden) {
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
        margin: 0;
        border: 1px solid var(--border-hi); border-bottom: none;
        border-radius: 16px 16px 0 0;
        background: linear-gradient(180deg, var(--panel-hi), var(--panel));
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.6);
        padding: 1rem 1.1rem 1.3rem;
    }
    #tower-panel .btn { font-size: 0.95rem; padding: 0.7rem; }
    .tp-close { top: 8px; right: 12px; font-size: 1.2rem; }
}
