/* Space Invaders: Quizzes hub easter egg (Konami code, or seven taps on the
   hero icon on a touch screen). Built by quizzes/includes/invaders.js.
   CRT treatment after learn/includes/trail.css: scanlines, phosphor glow,
   vignette, flicker and a rolling band; motion off under reduced motion. */

/* The hero icon takes the seven-tap opener: no double-tap zoom, no selection. */
.page-hero h1 > i { touch-action: manipulation; -webkit-user-select: none; user-select: none; }

#flInvaders {
    position: fixed; inset: 0; z-index: 99999;
    box-sizing: border-box;
    display: flex; flex-direction: column;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: radial-gradient(ellipse at center, #0b100d 0%, #040605 62%, #000 100%);
    color: #b8ffbf;
    font-family: "DejaVu Sans Mono", Menlo, Consolas, "Courier New", monospace;
    font-size: 16px; line-height: 1.4;
    overflow: hidden;
    touch-action: none; overscroll-behavior: none;
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
#flInvaders *, #flInvaders *::before, #flInvaders *::after { box-sizing: border-box; }

/* Vignette and phosphor flicker over the whole cabinet. */
#flInvaders::after {
    content: ''; position: absolute; inset: 0; z-index: 6; pointer-events: none;
    background: radial-gradient(ellipse 120% 110% at 50% 50%, transparent 62%, rgba(0,0,0,0.32) 88%, rgba(0,0,0,0.72) 100%);
    animation: flInvFlicker 3.3s steps(1) infinite;
}
@keyframes flInvFlicker {
    0%, 100% { opacity: 1; } 7% { opacity: .9; } 8% { opacity: 1; } 33% { opacity: .95; } 34% { opacity: 1; }
    61% { opacity: .88; } 62% { opacity: 1; } 85% { opacity: .94; } 86% { opacity: 1; }
}

/* ---- top bar ---- */
#flInvaders .fl-inv-hud {
    position: relative; z-index: 7; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .5rem 16px;
}
#flInvaders .fl-inv-brand {
    color: #3f8f48; font-weight: 700; font-size: .85rem; letter-spacing: .16em; white-space: nowrap;
    text-shadow: 0 0 6px rgba(125,255,138,0.35);
}
#flInvaders .fl-inv-hud-btns { display: flex; gap: .4rem; margin-left: auto; }
#flInvaders .fl-inv-btn {
    font: inherit; font-size: .8rem; font-weight: 700; letter-spacing: .06em; line-height: 1;
    min-height: 40px; min-width: 44px; padding: .25rem .65rem;
    background: transparent; color: #7dff8a; border: 1px solid #2e6b35; border-radius: 3px;
    cursor: pointer; white-space: nowrap;
    text-shadow: 0 0 6px rgba(125,255,138,0.55);
}
#flInvaders .fl-inv-btn:hover,
#flInvaders .fl-inv-btn:focus-visible { background: #7dff8a; color: #050805; border-color: #7dff8a; outline: none; text-shadow: none; }
#flInvaders .fl-inv-snd[aria-pressed="false"] { color: #3f8f48; }
#flInvaders .fl-inv-snd[aria-pressed="false"]:hover,
#flInvaders .fl-inv-snd[aria-pressed="false"]:focus-visible { color: #050805; }
#flInvaders .fl-inv-close { font-size: 1.05rem; }

/* ---- the screen ---- */
#flInvaders .fl-inv-stage {
    position: relative; flex: 1 1 auto; min-height: 0;
    display: flex; align-items: center; justify-content: center;
    padding: 0 16px;
}
#flInvaders .fl-inv-screen { position: relative; line-height: 0; border-radius: 6px; outline: none; overflow: hidden; }
#flInvaders .fl-inv-screen:focus-visible { box-shadow: 0 0 0 2px #2e6b35; }
#flInvaders .fl-inv-canvas {
    display: block;
    image-rendering: crisp-edges; image-rendering: pixelated;
    filter: drop-shadow(0 0 1.5px rgba(225,255,232,0.5)) drop-shadow(0 0 7px rgba(140,255,170,0.16));
}
/* Scanlines: one dark band under every board pixel row. */
#flInvaders .fl-inv-screen::after {
    content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none;
    background: repeating-linear-gradient(180deg,
        transparent 0, transparent calc(var(--fl-inv-px, 3px) * 0.62),
        rgba(0,0,0,0.3) calc(var(--fl-inv-px, 3px) * 0.62), rgba(0,0,0,0.3) var(--fl-inv-px, 3px));
}
/* The slow rolling band. */
#flInvaders .fl-inv-screen::before {
    content: ''; position: absolute; left: 0; right: 0; height: 18%; z-index: 1; pointer-events: none;
    background: linear-gradient(180deg, transparent 0%, rgba(160,255,190,0.045) 45%, rgba(0,0,0,0.1) 55%, transparent 100%);
    animation: flInvRoll 7.5s linear infinite;
}
@keyframes flInvRoll { from { top: -20%; } to { top: 105%; } }
/* Power-on: the picture snaps open from a bright line. */
#flInvaders.is-booting .fl-inv-screen { animation: flInvPowerOn 0.85s cubic-bezier(0.2, 0.8, 0.2, 1) both; transform-origin: 50% 50%; }
@keyframes flInvPowerOn {
    0%   { transform: scale(1.3, 0.004); filter: brightness(6); }
    35%  { transform: scale(1.06, 0.02); filter: brightness(3); }
    60%  { transform: scale(1, 0.6); filter: brightness(1.6); }
    100% { transform: scale(1, 1); filter: brightness(1); }
}

/* ---- touch controls (coarse pointers) ---- */
#flInvaders .fl-inv-touch { display: none; }
#flInvaders.is-touch .fl-inv-touch {
    position: relative; z-index: 7; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 16px 16px;
}
#flInvaders .fl-inv-pad { display: flex; gap: 12px; }
#flInvaders .fl-inv-tbtn {
    font: inherit; font-weight: 700; font-size: 1.35rem; letter-spacing: .08em; line-height: 1;
    min-width: 76px; min-height: 64px; padding: 0 .9rem;
    background: rgba(125,255,138,0.06); color: #7dff8a;
    border: 2px solid #2e6b35; border-radius: 10px;
    cursor: pointer; touch-action: none;
    text-shadow: 0 0 6px rgba(125,255,138,0.6);
}
#flInvaders .fl-inv-fire { min-width: 120px; color: #ffcf4a; border-color: #7a5d1a; background: rgba(255,207,74,0.06); text-shadow: 0 0 6px rgba(255,207,74,0.55); }
#flInvaders .fl-inv-tbtn.is-down { background: #7dff8a; color: #050805; border-color: #7dff8a; text-shadow: none; }
#flInvaders .fl-inv-fire.is-down { background: #ffcf4a; color: #050805; border-color: #ffcf4a; }
#flInvaders .fl-inv-tbtn:focus-visible { outline: 2px solid #e8ffe9; outline-offset: 2px; }

/* ---- the leaderboard panel ---- */
#flInvaders .fl-inv-board {
    position: absolute; z-index: 8; left: 50%; top: 50%; transform: translate(-50%, -50%);
    width: min(640px, calc(100% - 32px)); max-height: calc(100% - 32px);
    overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
    -webkit-user-select: text; user-select: text;
    padding: 1rem 1.25rem 1.25rem;
    background: #030805; color: #b8ffbf;
    border: 2px solid #3f8f48; border-radius: 4px;
    box-shadow: 0 0 0 1px rgba(125,255,138,0.15), 0 0 28px rgba(125,255,138,0.22);
}
#flInvaders .fl-inv-board[hidden] { display: none; }
#flInvaders .fl-inv-board-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
#flInvaders .fl-inv-board-title { margin: 0; font: inherit; font-size: 1.1rem; font-weight: 700; letter-spacing: .14em; color: #e8ffe9; text-shadow: 0 0 8px rgba(125,255,138,0.5); }
#flInvaders .fl-inv-board-cols { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem 1.5rem; }
@media (min-width: 640px) { #flInvaders .fl-inv-board-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
#flInvaders .fl-inv-board-sub { margin: 0 0 .4rem; font: inherit; font-size: .85rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #ffcf4a; }
#flInvaders .fl-inv-board-list { list-style: none; margin: 0; padding: 0; }
#flInvaders .fl-inv-board-list li {
    display: flex; align-items: center; gap: .5rem;
    padding: .3rem 0; border-bottom: 1px solid #12301a; font-size: .95rem;
}
#flInvaders .fl-inv-board-list li.is-mine { color: #ffcf4a; }
#flInvaders .fl-inv-rk { flex: 0 0 2ch; text-align: right; color: #3f8f48; }
#flInvaders .fl-inv-nm { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#flInvaders .fl-inv-sc { flex: 0 0 auto; font-weight: 700; color: #e8ffe9; }
#flInvaders .fl-inv-board-list li.is-mine .fl-inv-sc { color: #ffcf4a; }
#flInvaders .fl-inv-wv { flex: 0 0 3.5ch; text-align: right; color: #3f8f48; font-size: .8rem; }
#flInvaders .fl-inv-del {
    flex: 0 0 auto; font: inherit; font-size: .72rem; letter-spacing: .04em; line-height: 1;
    min-height: 28px; padding: .2rem .45rem; cursor: pointer;
    background: transparent; color: #ff8a80; border: 1px solid #6b2a26; border-radius: 3px;
}
#flInvaders .fl-inv-del:hover, #flInvaders .fl-inv-del:focus-visible { background: #ff8a80; color: #050805; border-color: #ff8a80; outline: none; }
#flInvaders .fl-inv-del[data-armed="1"] { background: #ff8a80; color: #050805; border-color: #ff8a80; }
#flInvaders .fl-inv-del:disabled { opacity: .5; cursor: progress; }
#flInvaders .fl-inv-board-note, #flInvaders .fl-inv-board-empty { margin: .75rem 0 0; color: #9fd4a6; }
#flInvaders .fl-inv-link { color: #7dff8a; text-decoration: underline; text-underline-offset: 2px; }
#flInvaders .fl-inv-link:hover, #flInvaders .fl-inv-link:focus-visible { color: #e8ffe9; outline: none; }

/* Screen-reader only (announcements). */
#flInvaders .fl-inv-sr {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Wide landscape screens: the controls float in a column at the top right
   so the board gets the full height (a whole-number scale on 768-800 px). */
@media (min-width: 900px) and (min-aspect-ratio: 4/3) {
    #flInvaders .fl-inv-hud {
        position: absolute; top: 0; left: 0; right: 0;
        align-items: flex-start;
        padding-top: max(.75rem, env(safe-area-inset-top));
        pointer-events: none;
    }
    #flInvaders .fl-inv-hud > * { pointer-events: auto; }
    #flInvaders .fl-inv-hud-btns { flex-direction: column; align-items: stretch; }
    #flInvaders .fl-inv-btn { min-width: 84px; }
}
/* A touch screen held sideways (invaders.js sets .is-side when it gives a
   bigger board): the bar floats at the top in two columns, the move pad sits
   left of the board and FIRE right of it, so the board gets the full height.
   Absolute boxes ignore the cabinet's safe-area padding, so they carry it. */
#flInvaders.is-side .fl-inv-hud {
    position: absolute; top: 0; left: 0; right: 0;
    align-items: flex-start;
    padding: max(.5rem, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    pointer-events: none;
}
#flInvaders.is-side .fl-inv-hud > * { pointer-events: auto; }
#flInvaders.is-side .fl-inv-brand { white-space: normal; max-width: 7.5em; line-height: 1.5; }
#flInvaders.is-side .fl-inv-hud-btns { display: grid; grid-template-columns: repeat(2, auto); }
#flInvaders.is-side .fl-inv-btn { min-width: 64px; }
#flInvaders.is-touch.is-side .fl-inv-touch {
    position: absolute; left: 0; right: 0; bottom: 0;
    align-items: flex-end;
    padding: 0 max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    pointer-events: none;
}
#flInvaders.is-side .fl-inv-touch > * { pointer-events: auto; }
@media (max-width: 420px) {
    #flInvaders .fl-inv-brand { display: none; }
    #flInvaders .fl-inv-btn { padding: .25rem .5rem; }
}
/* Reduced motion: no flicker, no power-on, no rolling band. The game still runs. */
@media (prefers-reduced-motion: reduce) {
    #flInvaders::after, #flInvaders .fl-inv-screen::before, #flInvaders.is-booting .fl-inv-screen { animation: none; }
    #flInvaders .fl-inv-screen::before { display: none; }
}
