:root {
  color-scheme: light;

  /* Palette */
  --page: #e4e6fb;
  --ink: #1b1f4b;
  --panel: #f7f8ff;
  --board: #232a66;
  --board-dot: rgba(255, 255, 255, 0.1);
  --worm: #ff5c9d;
  --worm-shine: #ffb3d1;
  --eye: #ffffff;
  --pupil: #1b1f4b;
  --candy-1: #c6f14b;
  --candy-2: #ffd23f;
  --candy-3: #3ddcc8;
  --candy-4: #ff9b3d;

  /* Type */
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;

  /* Layout */
  --size: min(92vw, 66dvh, 560px);
}

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

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.4;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

.game {
  width: var(--size);
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.9rem;
  padding: 1rem 0;
}

.game-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.015em;
  line-height: 1;
}

.score { margin: 0; display: flex; align-items: baseline; gap: 0.5rem; }
.score-label { font-size: 1rem; font-weight: 600; }
.score output {
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  text-align: right;
}

.board {
  position: relative;
  width: var(--size);
  border-radius: 22px;
  overflow: hidden;
  background: var(--board);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(35, 42, 102, 0.72);
}
.overlay[hidden] { display: none; }

.panel {
  width: min(100%, 22rem);
  padding: 1.4rem 1.4rem 1.5rem;
  border-radius: 20px;
  background: var(--panel);
  text-align: center;
}
.panel h2 { margin: 0 0 0.4rem; font-size: 1.5rem; font-weight: 800; line-height: 1.15; }
.panel p { margin: 0 0 1.1rem; font-size: 1rem; }

button {
  font: inherit;
  font-weight: 800;
  color: var(--ink);
  background: var(--worm);
  border: 0;
  border-radius: 999px;
  padding: 0.8rem 1.8rem;
  cursor: pointer;
}
button:active { transform: scale(0.97); }
button:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }

.hint { margin: 0; font-size: 0.95rem; max-width: 60ch; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .overlay { animation: fade-in 160ms ease-out; }
  @keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
}

/* Submission form (inside the overlay panel) */
.submit-form { text-align: left; }
.submit-form label { display: block; margin: 0 0 0.35rem; font-weight: 700; }
.submit-form input {
  width: 100%;
  font: inherit;
  font-size: 1rem; /* 16px, so phones do not zoom in on focus */
  color: var(--ink);
  background: #ffffff;
  border: 2px solid #b9bde8;
  border-radius: 12px;
  padding: 0.65rem 0.85rem;
}
.submit-form input:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-color: var(--ink); }
.form-hint { margin: 0.5rem 0 0.9rem; font-size: 0.9rem; }
.panel .form-error { margin: 0 0 0.9rem; font-size: 0.95rem; font-weight: 700; }
.form-error[hidden] { display: none; }
.actions { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; }
button.secondary { background: transparent; box-shadow: inset 0 0 0 2px var(--ink); }
button[hidden], .submit-form[hidden] { display: none; }
button:disabled { opacity: 0.6; cursor: default; }

/* Leaderboard, always visible under the board */
.leaderboard h2 { margin: 0.4rem 0 0.5rem; font-size: 1.25rem; font-weight: 800; }
.leaderboard-note { margin: 0 0 0.5rem; font-size: 0.95rem; }
.leaderboard-note:empty { display: none; }
.leaderboard ol {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: rank;
  background: var(--panel);
  border-radius: 16px;
  overflow: hidden;
}
.leaderboard ol:empty { display: none; }
.leaderboard li {
  counter-increment: rank;
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.45rem 0.9rem;
}
.leaderboard li:nth-child(odd) { background: rgba(35, 42, 102, 0.06); }
.leaderboard li::before { content: counter(rank); font-weight: 700; font-variant-numeric: tabular-nums; }
.leaderboard .name { overflow-wrap: anywhere; }
.leaderboard .points { font-weight: 800; font-variant-numeric: tabular-nums; }

/* Text pages (privacy) */
a { color: var(--ink); text-underline-offset: 0.15em; }
a:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; border-radius: 4px; }
.prose { max-width: 40rem; width: min(92vw, 40rem); justify-content: flex-start; padding: 1.5rem 0 3rem; gap: 0.75rem; }
.prose h2 { margin: 1rem 0 0; font-size: 1.25rem; font-weight: 800; }
.prose p, .prose ul { margin: 0; }
.prose ul { padding-left: 1.2rem; display: grid; gap: 0.6rem; }
.updated { font-size: 0.95rem; }
.site-footer { margin: 0.5rem 0 0; font-size: 0.95rem; }
