/* PERIMETER — the minigame. Runs on its own page at /perimeter/ and embedded
   in the homepage, where it takes the content column's place between the
   side HUD panels (those sit at z-index 50, above everything here). */

.pm-page {
    height: 100vh;
    overflow: hidden;
}

.pm-root[hidden] { display: none; }

#pm-canvas {
    position: fixed;
    inset: 0;
    display: block;
    z-index: 1;
}

/* While a round is running the reticle is the only cursor over the battlefield */
.pm-running #pm-canvas {
    cursor: none;
}

/* Homepage: the content column fades out while the game is up */
.content {
    transition: opacity 0.35s ease, visibility 0s;
}

body.pm-active .content {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0s linear 0.35s;
}

/* no page scrolling under the battlefield; keep the scrollbar's space so nothing shifts */
html.pm-lock {
    overflow: hidden;
    scrollbar-gutter: stable;
}

.pm-label {
    font-family: 'Orbitron', sans-serif;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--accent-color);
    opacity: 0.8;
}

/* ---------- Panels (start, pause, game over) ---------- */
.pm-panel {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 42;
    width: min(560px, calc(100vw - 48px));
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    padding: 36px 40px;
    background: var(--panel-bg);
    border: var(--border-width) solid var(--border-color);
    backdrop-filter: blur(6px);
    line-height: 1.6;
}

.pm-panel[hidden] { display: none; }

.pm-panel-small { width: min(420px, calc(100vw - 48px)); text-align: center; }
.pm-panel-small .header-line { margin: 0 auto; }

.pm-panel p { margin-top: 18px; }

.pm-title {
    font-family: 'Orbitron', sans-serif;
    font-weight: 900;
    font-size: 34px;
    letter-spacing: 6px;
    color: var(--heading-color);
    margin-bottom: 10px;
}

.pm-panel-small .pm-title { font-size: 24px; letter-spacing: 4px; }
.pm-title-alert { color: #ff3b5c; text-shadow: 0 0 12px rgba(255, 59, 92, 0.6); }

.pm-legend {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-top: 22px;
}

.pm-legend li {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 4px 10px;
    border: 1px solid color-mix(in srgb, var(--ammo) 45%, transparent);
    font-size: 12px;
    letter-spacing: 1px;
    color: var(--ammo);
}

.pm-legend small {
    font-size: 9px;
    letter-spacing: 1.5px;
    color: var(--text-color);
    opacity: 0.6;
    margin-top: -4px;
}

.pm-legend svg,
.pm-slot svg {
    width: 28px;
    height: 28px;
    fill: color-mix(in srgb, var(--ammo) 20%, transparent);
    stroke: var(--ammo);
    stroke-width: 1.6;
    filter: drop-shadow(0 0 4px var(--ammo));
}

.pm-root kbd {
    font-family: 'Orbitron', sans-serif;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-color);
    border: 1px solid rgba(255, 255, 255, 0.35);
    padding: 1px 6px;
}

.pm-controls {
    font-size: 12px;
    letter-spacing: 1px;
    opacity: 0.75;
}

.pm-btn {
    display: inline-block;
    margin-top: 24px;
    padding: 10px 22px;
    background: transparent;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    font-family: 'Orbitron', sans-serif;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 3px;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.pm-btn:hover {
    background: var(--accent-color);
    color: var(--page-bg);
}

.pm-btn:disabled { opacity: 0.3; pointer-events: none; }

.pm-actions {
    display: flex;
    justify-content: center;
    gap: 14px;
}

.pm-panel:not(.pm-panel-small) .pm-actions { justify-content: flex-start; }

/* panels power up once the grid has materialized */
.pm-panel:not([hidden]) { animation: pm-panel-in 0.35s ease; }

@keyframes pm-panel-in {
    from { opacity: 0; clip-path: inset(50% 0 50% 0); }
    to   { opacity: 1; clip-path: inset(0 0 0 0); }
}

.pm-needs { color: #ffc400; font-size: 13px; }

.pm-results {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 24px;
    margin: 24px auto 0;
    max-width: 260px;
    text-align: left;
}

.pm-results dt { font-size: 12px; letter-spacing: 2px; opacity: 0.7; }
.pm-results dd { font-family: 'Orbitron', sans-serif; color: var(--accent-color); text-align: right; }

.pm-new-best {
    color: #ffc400;
    letter-spacing: 3px;
    animation: pm-blink 0.8s steps(2) infinite;
}

@keyframes pm-blink { 50% { opacity: 0.3; } }

/* ---------- In-game HUD ---------- */
.pm-hud {
    position: fixed;
    inset: 0;
    z-index: 40;
    pointer-events: none;
}

.pm-hud[hidden] { display: none; }

.pm-stats {
    position: absolute;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 36px;
}

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

.pm-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--heading-color);
}

.pm-console {
    position: absolute;
    bottom: 36px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.pm-integrity {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pm-integrity-bars { display: flex; gap: 4px; }

.pm-integrity-bars span {
    width: 26px;
    height: 8px;
    background: var(--accent-color);
    box-shadow: 0 0 6px var(--accent-color);
    transition: background 0.2s, box-shadow 0.2s;
}

.pm-integrity-bars span.is-lost {
    background: transparent;
    box-shadow: none;
    outline: 1px solid rgba(255, 255, 255, 0.25);
    outline-offset: -1px;
}

.pm-integrity.is-critical .pm-integrity-bars span:not(.is-lost) {
    background: #ff3b5c;
    box-shadow: 0 0 8px #ff3b5c;
    animation: pm-blink 0.6s steps(2) infinite;
}

.pm-slots { display: flex; gap: 10px; }

.pm-slot {
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 64px;
    padding: 8px 0 6px;
    background: var(--panel-bg);
    border: 1px solid rgba(255, 255, 255, 0.2);
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, opacity 0.3s;
}

.pm-slot.is-active {
    border-color: var(--ammo);
    box-shadow: 0 0 14px color-mix(in srgb, var(--ammo) 60%, transparent),
                inset 0 0 12px color-mix(in srgb, var(--ammo) 25%, transparent);
    transform: translateY(-5px);
}

.pm-slot.is-active kbd { border-color: var(--ammo); color: var(--ammo); }

/* ammo for enemies that haven't shown up yet */
.pm-slot.is-unknown { opacity: 0.25; }

/* ---------- Wave banner ---------- */
.pm-banner {
    position: fixed;
    top: 24%;
    left: 50%;
    transform: translateX(-50%);
    z-index: 41;
    text-align: center;
    pointer-events: none;
    opacity: 0;
}

.pm-banner.is-showing { animation: pm-banner 2.4s ease forwards; }

.pm-banner-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 30px;
    font-weight: 900;
    letter-spacing: 8px;
    color: var(--heading-color);
    text-shadow: 0 0 14px var(--accent-color);
    white-space: nowrap;
}

.pm-banner-sub {
    margin-top: 8px;
    font-size: 14px;
    letter-spacing: 3px;
    color: var(--banner-sub-color, var(--accent-color));
}

@keyframes pm-banner {
    0%   { opacity: 0; }
    12%  { opacity: 1; }
    80%  { opacity: 1; }
    100% { opacity: 0; }
}

/* narrow windows: drop the readout below the back button so they don't collide */
@media (max-width: 1000px) {
    .pm-stats { top: 100px; gap: 24px; }
}

@media (max-height: 640px) {
    .pm-stats { top: 24px; }
    .pm-console { bottom: 20px; }
}
