/* ───────────── Coding Club Arcade loader ─────────────
   Shared by the boot screen in index.html and the React <ArcadeLoader />.
   Lives in /public so it loads before the JS bundle. Classes are prefixed al-. */

.al-screen {
  --al-bg: #07070e;
  --al-panel: #0e0e1c;
  --al-line: #38386a;
  --al-text: #dde2ff;
  --al-muted: #7c80a8;
  --al-yellow: #facc15;
  --al-red: #f87171;
  --al-green: #4ade80;
  --al-blue: #38bdf8;
  --al-violet: #818cf8;
  --al-bar-w: min(360px, 78vw);

  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 50% at 50% 58%, rgba(129, 140, 248, 0.22), transparent 70%),
    radial-gradient(ellipse 60% 40% at 50% 0%, rgba(250, 204, 21, 0.08), transparent 70%),
    var(--al-bg);
  color: var(--al-text);
  font-family: 'Press Start 2P', ui-monospace, monospace;
  -webkit-font-smoothing: none;
  user-select: none;
  -webkit-user-select: none;
}

.al-screen *,
.al-screen *::before,
.al-screen *::after {
  box-sizing: border-box;
}

/* CRT scanlines and a soft vignette over everything. */
.al-screen::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, transparent 0 2px, rgba(0, 0, 0, 0.22) 2px 3px),
    radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.65) 100%);
}

/* Synthwave grid floor scrolling toward the viewer. */
.al-floor {
  position: absolute;
  left: -50%;
  right: -50%;
  bottom: 0;
  height: 48%;
  z-index: 0;
  background:
    linear-gradient(rgba(129, 140, 248, 0.4) 2px, transparent 2px) 0 0 / 64px 64px,
    linear-gradient(90deg, rgba(129, 140, 248, 0.4) 2px, transparent 2px) 0 0 / 64px 64px;
  transform: perspective(320px) rotateX(62deg);
  transform-origin: 50% 0;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 45%);
  mask-image: linear-gradient(to bottom, transparent 0%, #000 45%);
  animation: al-floor 1.1s linear infinite;
}

/* Glowing horizon line where the floor meets the sky. */
.al-floor::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--al-violet), #f0abfc, var(--al-violet), transparent);
  box-shadow: 0 0 18px 4px rgba(240, 171, 252, 0.45);
}

@keyframes al-floor {
  to { background-position: 0 64px, 0 0; }
}

/* ───────────── Centre stack ───────────── */

.al-core {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(16px, 3.2vh, 26px);
  padding: 24px;
  margin-top: -6vh;
  text-align: center;
}

.al-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--al-muted);
  font-size: 9px;
  letter-spacing: 3px;
}

.al-brand img {
  width: 36px;
  height: 36px;
  border: 2px solid var(--al-line);
  border-radius: 6px;
  box-shadow: 0 0 0 2px #000, 0 0 16px rgba(129, 140, 248, 0.35);
  image-rendering: auto;
}

/* Big title with an RGB-split CRT edge and a slow flicker. */
.al-title {
  margin: 0;
  color: var(--al-yellow);
  font-size: clamp(30px, 8vw, 60px);
  font-weight: 400;
  line-height: 1.1;
  letter-spacing: 6px;
  text-shadow:
    -3px 0 rgba(56, 189, 248, 0.75),
    3px 0 rgba(248, 113, 113, 0.75),
    0 0 28px rgba(250, 204, 21, 0.45),
    0 6px 0 #3a2a00;
  animation: al-flicker 4s steps(1) infinite;
}

@keyframes al-flicker {
  0%, 100% { opacity: 1; }
  92%      { opacity: 1; }
  93%      { opacity: 0.55; }
  94%      { opacity: 1; }
  96%      { opacity: 0.8; }
  97%      { opacity: 1; }
}

/* ───────────── Game sprite parade ───────────── */

.al-parade {
  display: flex;
  align-items: flex-end;
  gap: clamp(14px, 3vw, 24px);
  height: 46px;
  margin: 2px 0;
}

.al-sprite {
  position: relative;
  width: 28px;
  height: 28px;
  animation: al-hop 1.4s ease-in-out infinite;
  animation-delay: calc(var(--i, 0) * 0.12s);
}

/* Floor shadow that shrinks as the sprite jumps. */
.al-sprite::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 22px;
  height: 4px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  transform: translateX(-50%);
  animation: al-shadow 1.4s ease-in-out infinite;
  animation-delay: inherit;
}

@keyframes al-hop {
  0%, 40%, 100% { transform: translateY(0); }
  20%           { transform: translateY(-14px); }
}

@keyframes al-shadow {
  0%, 40%, 100% { transform: translateX(-50%) scale(1); opacity: 1; }
  20%           { transform: translateX(-50%) scale(0.55); opacity: 0.5; }
}

/* Pac-Man */
.al-pac i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--al-yellow);
  animation: al-chomp 0.32s steps(2) infinite alternate;
}

@keyframes al-chomp {
  from { clip-path: polygon(50% 50%, 100% 12%, 100% 0, 0 0, 0 100%, 100% 100%, 100% 88%); }
  to   { clip-path: polygon(50% 50%, 100% 46%, 100% 0, 0 0, 0 100%, 100% 100%, 100% 54%); }
}

/* Ghost */
.al-ghost i {
  position: absolute;
  inset: 0;
  border-radius: 14px 14px 0 0;
  background:
    radial-gradient(circle at 36% 42%, #1e3a8a 0 2.5px, transparent 3px),
    radial-gradient(circle at 70% 42%, #1e3a8a 0 2.5px, transparent 3px),
    radial-gradient(circle at 34% 40%, #fff 0 5px, transparent 5.5px),
    radial-gradient(circle at 68% 40%, #fff 0 5px, transparent 5.5px),
    #f472b6;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 83% 84%, 66% 100%, 50% 84%, 33% 100%, 17% 84%, 0 100%);
}

/* Tetromino (T) built from one square plus box-shadows. */
.al-tetro i {
  position: absolute;
  left: 0;
  top: 5px;
  width: 9px;
  height: 9px;
  background: var(--al-violet);
  box-shadow:
    inset -2px -2px 0 rgba(0, 0, 0, 0.3),
    9.5px 0 0 0 var(--al-violet),
    19px 0 0 0 var(--al-violet),
    9.5px 9.5px 0 0 var(--al-violet);
}

/* Snake: three body segments and a head. */
.al-snake i {
  position: absolute;
  left: 0;
  bottom: 2px;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: #22c55e;
  box-shadow: 7px 0 0 #22c55e, 14px -1px 0 #22c55e, 21px -3px 0 1px var(--al-green);
}

.al-snake i::after {
  content: '';
  position: absolute;
  left: 23px;
  top: -4px;
  width: 2px;
  height: 2px;
  background: #000;
}

/* Mine: round body, diagonal spikes on the inner element, straight spikes behind. */
.al-mine::before {
  content: '';
  position: absolute;
  inset: 1px;
  background:
    linear-gradient(#111827, #111827) center / 2px 100% no-repeat,
    linear-gradient(#111827, #111827) center / 100% 2px no-repeat;
}

.al-mine i {
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 2px, #6b7280 3px, #111827 70%);
  box-shadow: 0 0 0 1px rgba(248, 113, 113, 0.6), 0 0 10px rgba(248, 113, 113, 0.35);
}

.al-mine i::before,
.al-mine i::after {
  content: '';
  position: absolute;
  z-index: -1;
  left: 50%;
  top: -5px;
  bottom: -5px;
  width: 2px;
  margin-left: -1px;
  background: #111827;
}

.al-mine i::before { transform: rotate(45deg); }
.al-mine i::after  { transform: rotate(-45deg); }

/* Wordle tile. */
.al-word i {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 3px;
  background: #16a34a;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25);
  color: #fff;
  font: 11px/1 'Press Start 2P', monospace;
  font-style: normal;
  animation: al-flip 2.8s ease-in-out infinite;
}

@keyframes al-flip {
  0%, 70%, 100% { transform: rotateX(0); background: #16a34a; }
  78%           { transform: rotateX(90deg); background: #16a34a; }
  86%           { transform: rotateX(0); background: #ca8a04; }
}

/* Flappy bird. */
.al-bird i {
  position: absolute;
  inset: 3px 2px 3px 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 70% 34%, #000 0 1.5px, #fff 2px 4px, transparent 4.5px),
    #fde047;
  box-shadow: inset -3px -3px 0 rgba(234, 88, 12, 0.35);
}

.al-bird i::after {
  content: '';
  position: absolute;
  right: -5px;
  top: 11px;
  width: 8px;
  height: 5px;
  border-radius: 0 4px 4px 0;
  background: #f97316;
}

.al-bird i::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 10px;
  width: 10px;
  height: 6px;
  border-radius: 50%;
  background: #fef9c3;
  transform-origin: 80% 50%;
  animation: al-flap 0.25s steps(2) infinite alternate;
}

@keyframes al-flap {
  from { transform: rotate(-25deg); }
  to   { transform: rotate(25deg); }
}

/* ───────────── Progress bar ───────────── */

.al-progress {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: var(--al-bar-w);
}

.al-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 9px;
  letter-spacing: 1px;
}

.al-meta-label::after {
  content: '';
  display: inline-block;
  width: 3ch;
  text-align: left;
  animation: al-dots 1.2s steps(1) infinite;
}

@keyframes al-dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
}

.al-pct {
  color: var(--al-yellow);
  font-variant-numeric: tabular-nums;
}

.al-bar {
  position: relative;
  height: 24px;
  padding: 4px;
  border: 3px solid var(--al-line);
  border-radius: 3px;
  background: var(--al-panel);
  box-shadow: 0 0 0 3px #000, 4px 4px 0 3px #000, 0 0 28px rgba(129, 140, 248, 0.2);
}

/* Rainbow of the game colours, revealed left to right as the bar fills. */
.al-bar-fill {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--al-red), var(--al-yellow), var(--al-green), var(--al-blue), var(--al-violet));
  background-size: calc(var(--al-bar-w) - 14px) 100%;
  box-shadow: 0 0 12px rgba(250, 204, 21, 0.35);
  transition: width 0.18s steps(3);
}

/* Cut the fill into chunky segments. */
.al-bar::after {
  content: '';
  position: absolute;
  inset: 4px;
  pointer-events: none;
  background: repeating-linear-gradient(90deg, transparent 0 13px, var(--al-panel) 13px 17px);
}

/* ───────────── Tip + coin line ───────────── */

.al-tip {
  min-height: 2.6em;
  max-width: min(440px, 86vw);
  margin: 0;
  color: var(--al-muted);
  font-size: 8px;
  line-height: 1.9;
  letter-spacing: 0.5px;
}

.al-tip b {
  color: var(--al-blue);
  font-weight: 400;
}

.al-coin {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(26px, env(safe-area-inset-bottom));
  z-index: 2;
  color: var(--al-text);
  font-size: 9px;
  letter-spacing: 3px;
  text-align: center;
  animation: al-blink 1s steps(1) infinite;
}

@keyframes al-blink {
  50% { opacity: 0; }
}

/* ───────────── States ───────────── */

/* React route loader: wait briefly before appearing so fast loads don't flash. */
.al-screen.is-route {
  animation: al-in 0.2s ease-out 0.15s both;
}

@keyframes al-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.al-screen.is-done .al-pct { color: var(--al-green); }
.al-screen.is-done .al-meta-label::after { content: '' !important; animation: none; }

/* CRT power-off: squash to a bright line, then to a dot, revealing the app. */
.al-screen.is-off {
  animation: al-crt-off 0.55s cubic-bezier(0.7, 0, 0.84, 0) forwards;
  pointer-events: none;
}

@keyframes al-crt-off {
  0%   { transform: scale(1, 1); filter: brightness(1); opacity: 1; }
  55%  { transform: scale(1, 0.005); filter: brightness(4); opacity: 1; }
  85%  { transform: scale(0.15, 0.005); filter: brightness(6); opacity: 1; }
  100% { transform: scale(0, 0); filter: brightness(8); opacity: 0; }
}

/* ───────────── Responsive ───────────── */

@media (max-width: 480px) {
  .al-brand { font-size: 7px; letter-spacing: 2px; }
  .al-brand img { width: 30px; height: 30px; }
  .al-title { letter-spacing: 4px; }
  .al-sprite { transform-origin: bottom; scale: 0.82; }
  .al-parade { gap: 10px; }
  .al-meta { font-size: 8px; }
  .al-coin { font-size: 8px; }
}

@media (max-height: 520px) {
  .al-core { gap: 12px; margin-top: 0; }
  .al-title { font-size: clamp(24px, 6vw, 40px); }
  .al-tip, .al-coin { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .al-screen *,
  .al-screen *::before,
  .al-screen *::after {
    animation: none !important;
  }

  .al-screen.is-off {
    animation: al-in 0.3s reverse forwards;
  }
}
