/*
 * Genix Ventures brand layer on top of Pico CSS (https://picocss.com).
 * Pico does the heavy lifting; this file only sets brand colours and the page shell.
 * Colours come from the Genix Ventures logo gradient.
 */

:root {
  --genix-blue: #2087c9;
  --genix-blue-light: #52bae4;
  --genix-blue-dark: #186a9e;
  --genix-charcoal: #313131;
}

:root:not([data-theme="dark"]),
[data-theme="light"] {
  --pico-primary: var(--genix-blue-dark);
  --pico-primary-background: var(--genix-blue);
  --pico-primary-hover: var(--genix-charcoal);
  --pico-primary-hover-background: var(--genix-blue-dark);
  --pico-primary-underline: rgba(32, 135, 201, 0.5);
}

@media only screen and (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --pico-primary: var(--genix-blue-light);
    --pico-primary-background: var(--genix-blue);
    --pico-primary-hover: #8fd3ef;
    --pico-primary-underline: rgba(82, 186, 228, 0.5);
  }
}

/* Page shell: a Genix blue band across the top that fades into the page, with the content card overlapping it */
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(to bottom, transparent 6rem, var(--pico-background-color) 18rem) top center / 100% 18rem no-repeat,
    url("/assets/background.svg") top center / 100% 18rem no-repeat,
    var(--pico-background-color);
}

body > main.container {
  flex: 1;
  max-width: 40rem;
  padding-top: 0;
}

body > header {
  padding-block: 3rem 1.5rem;
  text-align: center;
}

body > header img {
  width: 14rem;
  height: auto;
  border-radius: 0.6rem;
  box-shadow: 0 0 0 3px #fff, 0 0.75rem 2rem rgba(0, 0, 0, 0.2);
}

body > main article {
  box-shadow: 0 0.75rem 2.5rem rgba(0, 0, 0, 0.12);
}

body > footer {
  text-align: center;
  font-size: 0.875rem;
  color: var(--pico-muted-color);
}

h1 {
  font-weight: 800;
}

/* Cloudflare error boxes (::CLOUDFLARE_ERROR_500S_BOX:: and friends).
   Show only the useful bits: Cloudflare's own heading and blurb are hidden in favour of ours,
   and only the 2nd and 3rd list items are kept. */
.cf-error-details {
  margin-bottom: var(--pico-spacing);
}

.cf-error-details h1,
.cf-error-details p,
.cf-error-details li {
  display: none;
}

.cf-error-details li:nth-child(2),
.cf-error-details li:nth-child(3) {
  display: list-item;
}

/* Mini games on the error pages (assets/arcade.js).
   Fixed traffic-light colours rather than Pico's ins/del ones, so white text reads in light and dark mode. */
:root {
  --arcade-red: #d64545;
  --arcade-green: #2e9d6f;
  /* Minesweeper numbers, one colour per count, readable on the open squares in light mode */
  --mine-1: #2087c9;
  --mine-2: #23805a;
  --mine-3: #c23a3a;
  --mine-4: #1b4f8a;
  --mine-5: #9a3d12;
  --mine-6: #0f7069;
  --mine-7: var(--pico-color);
  --mine-8: var(--pico-muted-color);
  /* The page's text colour, captured here because inside a button Pico's --pico-color means button text (white) */
  --arcade-ink: var(--pico-color);
}

/* ...and lighter versions of the same for dark mode */
@media only screen and (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --mine-1: #52bae4;
    --mine-2: #4cc38a;
    --mine-3: #f07a7a;
    --mine-4: #8fb8f0;
    --mine-5: #f0a066;
    --mine-6: #4fd1c5;
  }
}
[data-theme="dark"] {
  --mine-1: #52bae4;
  --mine-2: #4cc38a;
  --mine-3: #f07a7a;
  --mine-4: #8fb8f0;
  --mine-5: #f0a066;
  --mine-6: #4fd1c5;
}

.arcade {
  margin-top: calc(var(--pico-spacing) * 2);
  padding-top: var(--pico-spacing);
  border-top: 1px solid var(--pico-muted-border-color);
}

.arcade details {
  margin-bottom: 0;
}

/* Equal tabs that still fit side by side on a phone */
.arcade-tabs button {
  flex: 1 1 0;
  min-width: 0;
  padding-inline: 0.5rem;
}

.arcade-best {
  margin: var(--pico-spacing) 0 0;
  color: var(--pico-muted-color);
}

.arcade-hud {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.rack {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.rack button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0;
  padding: 0.75rem;
  font-family: var(--pico-font-family-monospace);
  font-size: 0.8rem;
  color: var(--pico-muted-color);
  background: var(--pico-card-sectioning-background-color);
  border: 1px solid var(--pico-muted-border-color);
}

.rack button::after {
  content: "";
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: var(--arcade-green);
}

.rack button.down {
  color: var(--arcade-red);
  border-color: var(--arcade-red);
}

.rack button.down::after {
  background: var(--arcade-red);
  animation: arcade-blink 0.4s steps(2) infinite;
}

.rack button.oops {
  animation: arcade-shake 0.3s;
}

/* arcade.js draws on a fixed 480 x 260 playfield, so keep that shape and let it shrink on small screens */
.arcade-canvas {
  display: block;
  width: 100%;
  max-width: 480px;
  height: auto;
  aspect-ratio: 480 / 260;
  margin-inline: auto;
  border-radius: var(--pico-border-radius);
  background: var(--pico-card-sectioning-background-color);
  border: 1px solid var(--pico-muted-border-color);
  touch-action: none;
}

.reflex {
  width: 100%;
  min-height: 9rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  border: 0;
  user-select: none;
}

.reflex.wait {
  background: var(--arcade-red);
}

.reflex.go {
  background: var(--arcade-green);
}

/* A press on red shakes the button, and the note below says what that cost */
.reflex.oops {
  animation: arcade-shake 0.3s;
}

.reflex-note {
  min-height: 1.5rem;
  margin: 0.5rem 0 0;
  color: var(--pico-muted-color);
}

/* Minesweeper: a 9 x 9 board of square buttons that shrinks to fit a phone */
.minefield {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 3px;
  max-width: 22rem;
  margin-inline: auto;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

/* The board is a role="group" for screen readers, which Pico styles as a joined-up button bar. Undo that:
   no ring around the whole board, and every square keeps its own rounded corners. */
.minefield[role="group"],
.minefield[role="group"]:focus-within {
  margin-bottom: 0;
  border-radius: 0;
  box-shadow: none;
}

.minefield[role="group"] > button {
  border-radius: 4px;
}

.minefield button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  aspect-ratio: 1;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  color: #fff;
  background: var(--pico-secondary-background);
}

/* Only plain hidden squares light up on hover, so a flag you've just placed still looks flagged */
.minefield button:not(.open):not(.flag):not(.mine):hover {
  background: var(--pico-secondary-hover-background);
}

.minefield .open,
.minefield .mine {
  cursor: default;
  background: var(--pico-card-sectioning-background-color);
  box-shadow: inset 0 0 0 1px var(--pico-muted-border-color);
}

.minefield .flag {
  background: var(--arcade-red);
}

.minefield .flag.wrong {
  opacity: 0.4;
  text-decoration: line-through;
}

.minefield .mine {
  color: var(--arcade-ink);
}

.minefield .mine::before {
  content: "";
  width: 50%;
  height: 50%;
  border-radius: 50%;
  background: currentColor;
}

.minefield .mine.hit {
  color: #fff;
  background: var(--arcade-red);
}

.minefield .n1 { color: var(--mine-1); }
.minefield .n2 { color: var(--mine-2); }
.minefield .n3 { color: var(--mine-3); }
.minefield .n4 { color: var(--mine-4); }
.minefield .n5 { color: var(--mine-5); }
.minefield .n6 { color: var(--mine-6); }
.minefield .n7 { color: var(--mine-7); }
.minefield .n8 { color: var(--mine-8); }

.mine-mode {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

@keyframes arcade-blink {
  50% { opacity: 0.2; }
}

@keyframes arcade-shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
