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

html {
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    position: relative;
    background: #0d1117;

    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 24px 16px;
    font-family: 'Fredoka', 'Segoe UI', Arial, sans-serif;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
    overflow: hidden;
}

#body-starfield {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}

.body-star {
    position: absolute;
    left: var(--star-x);
    top: var(--star-y);
    width: var(--star-size);
    height: var(--star-size);
    border-radius: 50%;
    background: var(--star-color);
    box-shadow: 0 0 calc(var(--star-size) * 2.8) var(--star-color);
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
    animation: body-star-object-blink var(--star-speed) ease-in-out infinite;
    animation-delay: var(--star-delay);
}

@keyframes body-star-object-blink {
    0%, 100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.45);
    }
    28%, 64% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

#game-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: 100vw;
}

#game-stage {
    position: relative; /* anchors the absolutely-positioned difficulty overlay */
    display: grid;
    /* Desktop: SCORE | CANVAS | NEXT — side panels sit beside the playfield. */
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "score canvas next";
    align-items: start;
    width: 100%;
    gap: 12px;
}

#game-stage > #score-panel   { grid-area: score; }
#game-stage > #canvas-wrapper { grid-area: canvas; }
#game-stage > #next-panel    { grid-area: next; }

.panel {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 12px;
    padding: 8px 14px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.panel-label {
    font-size: 10px;
    letter-spacing: 3px;
    opacity: 0.45;
    font-weight: 600;
}

#score {
    font-size: 30px;
    font-weight: 700;
    letter-spacing: 1px;
}

#next-canvas { display: block; }

.next-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Choose-power arrows: pinned just below the red danger line, centered as a
   pair with a small gap. Static targets so the player can click without the
   buttons sliding away under the cursor. Inner edges anchored via `right`
   (left arrow) and `left` (right arrow) so the gap stays constant. */
.current-arrow {
    position: absolute;
    top: 18%; /* DANGER_Y (133/927 ≈ 14.3%) plus breathing room */
    display: none;
    background: rgba(125, 223, 255, 0.18);
    border: 1px solid rgba(125, 223, 255, 0.6);
    color: #e3f5ff;
    width: 44px;
    height: 56px;
    border-radius: 8px;
    font-size: 26px;
    font-family: inherit;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    z-index: 5;
    transition: background 0.15s, transform 0.1s;
}

#current-prev { right: calc(50% + 90px); }
#current-next { left: calc(50% + 90px); }

.current-arrow:hover  { background: rgba(125, 223, 255, 0.32); }
.current-arrow:active { transform: scale(0.9); }

#canvas-wrapper.power-active .current-arrow {
    display: block;
    animation: heartbeat-glow 1.1s ease-in-out infinite;
}

/* Label between the two choose-arrows. Same Fredoka face as the difficulty
   picker so the choose-power UI feels visually consistent. Anchored to the
   same y-band as the arrows so the trio reads as one widget. */
#choose-label {
    position: absolute;
    top: 18%;
    left: 50%;
    transform: translateX(-50%);
    height: 56px; /* matches .current-arrow height for vertical alignment */
    display: none;
    align-items: center;
    color: #e3f5ff;
    font-family: 'Fredoka', 'Segoe UI', sans-serif;
    font-size: 19px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.45), 0 0 14px rgba(125, 223, 255, 0.35);
    pointer-events: none;
    white-space: nowrap;
    z-index: 5;
}

#canvas-wrapper.power-active #choose-label { display: flex; }

/* ── FULLSCREEN TOGGLE ─────────────────────────────────────────────────
   Small icon-only button in the canvas's bottom-right. Swaps between an
   "enter" (corner arrows out) and "exit" (corner arrows in) icon via the
   .is-fullscreen class. JS toggles `body.fullscreen` on fullscreenchange,
   which the layout overrides below key off. */
.fs-btn {
    position: fixed;
    bottom: 12px;
    right: 12px;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.82);
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s, border-color 0.15s;
}

.fs-btn:hover  { background: rgba(0, 0, 0, 0.6); color: #fff; border-color: rgba(255, 255, 255, 0.28); }
.fs-btn:active { transform: scale(0.92); }

.fs-icon { display: block; }
.fs-btn .fs-icon-exit  { display: none; }
.fs-btn.is-fullscreen .fs-icon-enter { display: none; }
.fs-btn.is-fullscreen .fs-icon-exit  { display: block; }

/* In fullscreen, drop the centered max-width cap so the canvas can grow to
   fit the screen, and size the wrapper by viewport height (canvas keeps its
   840:927 aspect ratio). The side panels sit alongside as usual. */
body.fullscreen {
    padding: 0;
    height: 100vh;
}

body.fullscreen #game-container {
    max-width: none;
    height: 100vh;
    padding: 12px;
    box-sizing: border-box;
    justify-content: center;
}

body.fullscreen #game-stage {
    height: 100%;
    width: auto;
    align-items: center;
}

body.fullscreen #canvas-wrapper {
    height: 100%;
    width: auto;
    aspect-ratio: 840 / 927;
}

body.fullscreen #dev-panel { display: flex; }

@keyframes heartbeat-glow {
    0%, 100% {
        box-shadow: 0 0 3px 0 rgba(125, 223, 255, 0.45),
                    inset 0 0 6px rgba(125, 223, 255, 0.12);
    }
    50% {
        box-shadow: 0 0 11px 2px rgba(125, 223, 255, 0.95),
                    inset 0 0 9px rgba(125, 223, 255, 0.28);
    }
}

#canvas-wrapper {
    position: relative;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 16px 64px rgba(0,0,0,0.7);
    width: 100%;
    aspect-ratio: 840 / 927;        /* matches canvas internal resolution */
}

#game-canvas {
    display: block;
    cursor: crosshair;
    border-radius: 14px;
    width: 100%;                    /* CSS scales display; internal pixels stay 840×927 */
    height: 100%;
    touch-action: none;             /* prevent page scroll while dragging on canvas */
}

#game-canvas.destroy-armed {
    cursor: cell;                   /* signals "pick a target" mode */
}

/* Destroy-power overlay: prompt + skip button, pinned just below the red
   danger line so the prompt stays in one predictable spot while the player
   moves their cursor over the board to pick a target. */
#destroy-overlay {
    position: absolute;
    left: 50%;
    top: 16%; /* DANGER_Y (133/927 ≈ 14.3%) plus a small gap */
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none; /* allow clicks to fall through except button */
}

#destroy-overlay #destroy-text {
    background: rgba(255, 105, 180, 0.14);
    color: #ff66b2;
    padding: 8px 18px;
    border-radius: 12px;
    font-size: 19px;
    font-weight: 600;
    letter-spacing: 0.5px;
    pointer-events: none;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

#destroy-overlay #destroy-skip {
    pointer-events: auto; /* button must be clickable */
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.12);
    color: #fff;
    padding: 6px 12px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
}

#destroy-overlay[style*="display:none"] {
    display: none;
}

#game-over-overlay {
    display: none;
    position: absolute;
    inset: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background: rgba(5,10,20,0.88);
    backdrop-filter: blur(12px);
    border-radius: 14px;
}

#game-over-overlay.visible { display: flex; }

#game-over-overlay h2 {
    font-size: 38px;
    color: #FF6B6B;
    letter-spacing: 2px;
}

.final-line {
    font-size: 18px;
    opacity: 0.65;
}

.final-line span {
    font-size: 26px;
    font-weight: 700;
    color: #FECA57;
    opacity: 1;
}

#restart-btn {
    background: linear-gradient(135deg, #FF6B6B, #FF9F43);
    color: #fff;
    border: none;
    padding: 13px 44px;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 1px;
    transition: transform 0.1s, opacity 0.15s;
}

#restart-btn:hover  { opacity: 0.88; transform: scale(1.03); }
#restart-btn:active { transform: scale(0.96); }

#change-difficulty-btn {
    background: transparent;
    color: rgba(255,255,255,0.65);
    border: 2px solid rgba(255,255,255,0.18);
    padding: 8px 22px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 1px;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
#change-difficulty-btn:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
    border-color: rgba(255,255,255,0.3);
}

/* ── DIFFICULTY PICKER ─────────────────────────────────────────────────
   Full-canvas overlay shown on first load and re-openable from the game-over
   screen. Big rounded buttons, planet icons, color-coded per difficulty.
   Font is Fredoka via Google Fonts (loaded in play.html). */
#difficulty-overlay {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 20;
    background: radial-gradient(circle at 50% 35%, #3a5680 0%, #1a2540 65%, #0a1020 100%);
    border-radius: 14px;
    box-shadow: 0 16px 64px rgba(0,0,0,0.7);
    align-items: center;
    justify-content: center;
    padding: 4% 5%;
    font-family: 'Fredoka', 'Segoe UI', sans-serif;
}

#difficulty-overlay.visible { display: flex; }

.difficulty-inner {
    width: 100%;
    max-width: 460px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.difficulty-title {
    font-size: clamp(30px, 6vw, 44px);
    font-weight: 700;
    color: #FECA57;
    text-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 8px 18px rgba(254,202,87,0.35);
    letter-spacing: 1px;
    margin: 0;
}

.difficulty-sub {
    font-size: clamp(14px, 2.5vw, 17px);
    font-weight: 500;
    color: rgba(255,255,255,0.72);
    margin-bottom: 14px;
}

.difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.diff-btn {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 18px;
    border-radius: 22px;
    border: 4px solid;
    background: rgba(255,255,255,0.06);
    cursor: pointer;
    font-family: inherit;
    color: #fff;
    text-align: left;
    width: 100%;
    transition: transform 0.15s ease, background 0.15s, box-shadow 0.2s;
}

.diff-btn:hover  { transform: translateY(-3px) scale(1.02); }
.diff-btn:active { transform: scale(0.96); transition: transform 0.05s; }

.diff-easy   { border-color: #7ed957; box-shadow: 0 6px 0 rgba(126,217,87,0.25); }
.diff-easy:hover   { background: rgba(126,217,87,0.18); box-shadow: 0 10px 24px rgba(126,217,87,0.45); }

.diff-normal { border-color: #7ddfff; box-shadow: 0 6px 0 rgba(125,223,255,0.25); }
.diff-normal:hover { background: rgba(125,223,255,0.18); box-shadow: 0 10px 24px rgba(125,223,255,0.45); }

.diff-hard   { border-color: #ff8a8a; box-shadow: 0 6px 0 rgba(255,138,138,0.25); }
.diff-hard:hover   { background: rgba(255,138,138,0.18); box-shadow: 0 10px 24px rgba(255,138,138,0.45); }

.diff-icon {
    width: 58px;
    height: 58px;
    flex-shrink: 0;
    filter: drop-shadow(0 3px 6px rgba(0,0,0,0.4));
    pointer-events: none;
}

.diff-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: none;
}

.diff-label {
    font-size: clamp(20px, 3.5vw, 26px);
    font-weight: 700;
    line-height: 1;
}

.diff-blurb {
    font-size: clamp(11px, 1.8vw, 13px);
    font-weight: 500;
    opacity: 0.78;
    line-height: 1.25;
}

@media (max-width: 480px) {
    .diff-icon { width: 48px; height: 48px; }
    .diff-btn  { padding: 12px 14px; gap: 12px; }
}

/* ── DEV PANEL ─────────────────────────────────────────────────────────── */
/* Hidden by default. The parent page adds ?dev=1 for authenticated admins,
   which sets html.dev-mode and reveals the panel. */
#dev-panel {
    position: fixed;
    right: 24px;
    bottom: 74px;
    z-index: 40;
    width: min(360px, calc(100vw - 24px));
    display: none;
    flex-direction: column;
    gap: 0;
    touch-action: none;
}

html.dev-mode #dev-panel {
    display: flex;
}

/* ── MOBILE TWEAKS ─────────────────────────────────────────────────────── */
@media (max-width: 700px) {
    body { padding: 12px 8px; }
    #score { font-size: 22px; }
    .panel { padding: 6px 10px; }

    /* Two-row stack: SCORE | NEXT on top, canvas spans both columns below. */
    #game-stage {
        grid-template-columns: 1fr 1fr;
        grid-template-areas:
            "score next"
            "canvas canvas";
    }
}

/* ── DESKTOP: panels sit beside the canvas (not overlaid) ─────────────── */
@media (min-width: 701px) {
    /* Tighter cap so the canvas isn't huge — base styles handle centering */
    #game-container {
        max-width: 700px;
    }

    /* Fixed-width side panels — prevents canvas from resizing as score grows */
    #score-panel {
        flex-direction: column;
        align-items: center;
        gap: 4px;
        width: 90px;
        flex-shrink: 0;
        overflow: hidden;
    }

    #next-panel {
        flex-direction: column;
        align-items: center;
        gap: 4px;
        width: 100px;
        flex-shrink: 0;
    }

    #dev-panel { padding: 0; }
}

#dev-toggle {
    align-self: flex-end;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.38);
    border-radius: 8px;
    padding: 5px 14px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    touch-action: none;
}

#dev-toggle:hover { background: rgba(255,255,255,0.09); color: rgba(255,255,255,0.7); }
#dev-toggle.open  { color: #FECA57; border-color: rgba(254,202,87,0.35); }

#dev-body {
    display: none;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.09);
    border-radius: 12px;
    padding: 14px 16px;
    max-height: min(72vh, 640px);
    overflow-y: auto;
    touch-action: auto;
}

#dev-body.open { display: flex; }

.dev-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dev-label {
    font-size: 11px;
    letter-spacing: 1.5px;
    opacity: 0.45;
    font-weight: 600;
    width: 68px;
    flex-shrink: 0;
}

.dev-pill {
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    border-radius: 20px;
    padding: 4px 18px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    min-width: 60px;
}

.dev-pill.active {
    background: rgba(29,209,161,0.18);
    border-color: #1DD1A1;
    color: #1DD1A1;
}

#auto-speed, #auto-x {
    flex: 1;
    accent-color: #FECA57;
    cursor: pointer;
}

#drop-mode {
    flex: 1;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}

#drop-mode option { background: #16213e; color: #fff; }

#auto-speed-val, #auto-x-val {
    font-size: 11px;
    opacity: 0.55;
    width: 52px;
    text-align: right;
    flex-shrink: 0;
}

.dev-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    padding-top: 6px;
    border-top: 1px solid rgba(255,255,255,0.07);
    font-size: 11px;
}

.dev-stats > span {
    opacity: 0.5;
}

.dev-stats b {
    color: #FECA57;
    opacity: 1;
    font-size: 13px;
}

.dev-star-editor {
    order: 2;
    flex: 1 0 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    padding-top: 12px;
    border-top: 1px solid rgba(255,255,255,0.07);
    opacity: 1;
}

.dev-section-title {
    color: #FECA57;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.6px;
    text-transform: uppercase;
}

.dev-hint {
    font-size: 11px;
    opacity: 0.55;
}

.dev-star-editor input[type="range"] {
    flex: 1;
    accent-color: #FECA57;
}

.dev-star-editor input[type="number"] {
    width: 72px;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    border-radius: 6px;
    padding: 5px 8px;
    font-family: inherit;
    font-size: 12px;
}

.dev-star-editor input[type="color"] {
    width: 34px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.16);
    border-radius: 6px;
    cursor: pointer;
}

#star-base-speed-val {
    width: 52px;
    text-align: right;
    font-size: 11px;
    opacity: 0.65;
}

#star-config-json {
    width: 100%;
    min-height: 150px;
    resize: vertical;
    background: rgba(0,0,0,0.26);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    color: rgba(255,255,255,0.84);
    padding: 10px;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 11px;
    line-height: 1.45;
}

#star-config-json.is-error {
    border-color: #FF6B6B;
    box-shadow: 0 0 0 2px rgba(255,107,107,0.16);
}
