:root {
  /* `theme` palette generated at https://clrbug.pages.dev/f89828/44003c */

  --theme-50: oklch(0.9800 0.0253 63.48deg);
  --theme-100: oklch(0.9423 0.0560 63.48deg);
  --theme-200: oklch(0.8904 0.0905 63.48deg);
  --theme-300: oklch(0.8233 0.1295 63.48deg);
  --theme-400: oklch(0.7627 0.1616 63.48deg);
  /* #f89828 */
  --theme-500: oklch(0.6633 0.1530 45.63deg);
  --theme-600: oklch(0.5639 0.1444 27.79deg);
  --theme-700: oklch(0.4645 0.1358 9.94deg);
  --theme-800: oklch(0.3650 0.1272 352.10deg);
  --theme-900: oklch(0.2656 0.1186 334.25deg);
  /* #44003c */
  --theme-950: oklch(0.1200 0.0628 334.25deg);

  --radius: 14px;
  --shadow: 0 1px 2px oklch(0.2656 0.1186 334.25deg / 0.06),
    0 4px 12px oklch(0.2656 0.1186 334.25deg / 0.06);
}

@font-face {
  font-family: "Relik Grotesque VF";
  src: url("fonts/RelikGrotesqueVF.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

/* Emphasis uses the ital axis. font-style stays normal so the browser does not add a faux oblique. */
em {
  font-style: normal;
  font-variation-settings: "opsz" 16, "ital" 1;
}

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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  padding: 3rem 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: "Relik Grotesque VF", system-ui, -apple-system, sans-serif;
  color: var(--theme-900);
  background: var(--theme-50);
  font-variation-settings: "ital" 0, "opsz" 16;
  font-feature-settings: "ss07" 1, "ss10" 1, "liga" 1;
}

@media (min-width: 640px) {
  body {
    padding: 3rem 1rem;
  }
}

.card {
  width: min(100%, 640px);
  margin: 0 auto;
}

h1 {
  margin: 0 0 0.25rem;
  text-align: center;
  font-size: 2.5rem;
  /* letter-spacing: 0.05em; */
  /* text-transform: uppercase; */
  color: var(--theme-800);
}

.player {
  margin: 0 0 1.5rem;
  text-align: center;
  font-size: 1.1rem;
  color: var(--theme-600);
}

/* --- Name form --- */

.name-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  margin-top: 2rem;
  font-size: 1.1rem;
}

.name-form input {
  width: min(100%, 280px);
  padding: 0.7rem 1rem;
  border: 1px solid var(--theme-200);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  font: inherit;
  color: inherit;
  text-align: center;
}

.name-form input:focus {
  outline: none;
  border-color: var(--theme-400);
  box-shadow: 0 0 0 4px var(--theme-100);
}

/* --- Buttons --- */

.name-form button,
.controls button {
  padding: 0.65rem 1.4rem;
  border: 1px solid var(--theme-200);
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
  font: inherit;
  color: var(--theme-800);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.15s;
}

/* Name form button is the primary action, so it's filled by default */
.name-form button {
  border-color: var(--theme-800);
  background: var(--theme-800);
  color: var(--theme-50);
}

.name-form button:hover {
  background: var(--theme-900);
}

.controls button:hover {
  border-color: var(--theme-800);
  background: var(--theme-800);
  color: var(--theme-50);
}

.name-form button:active,
.controls button:active {
  transform: scale(0.97);
}

/* --- Grid --- */

.grid:empty {
  display: none;
}

.grid {
  display: grid;
  --gap: 0;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: var(--gap);
  container-type: inline-size;
}

@media (min-width: 640px) {
  .grid {
    --gap: 0.5rem;
  }

  .cell {
    border-radius: var(--radius);
  }
}

/* Square by default; if text overflows, every row grows together so cells stay identical */
.cell {
  min-height: calc((100cqi - 4 * var(--gap)) / 5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  border: none;
  /* border-radius: var(--radius); */
  background: #fff;
  box-shadow: var(--shadow);
  font: inherit;
  font-size: clamp(0.65rem, 1.8vw, 0.9rem);
  line-height: 1.25;
  text-align: center;
  color: inherit;
  overflow-wrap: anywhere;
  hyphens: auto;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.cell:hover {
  border-color: var(--theme-300);
  transform: translateY(-1px);
}

.cell:active {
  transform: scale(0.97);
}

.cell[aria-pressed="true"] {
  border-color: var(--theme-400);
  background: var(--theme-300);
  color: var(--theme-950);
}

.cell.free {
  flex-direction: column;
  gap: 0.35rem;
  border-color: var(--theme-400);
  background: var(--theme-400);
  color: var(--theme-950);
  font-weight: 500;
  cursor: default;
  transform: none;
}

.free-title {
  font-weight: 700;
  font-size: 1.15em;
  letter-spacing: 0.05em;
}

.free-note {
  font-weight: 400;
  /* font-size: 0.8em; */
  line-height: 1.2;
}

.cell:focus-visible,
.controls button:focus-visible,
.name-form button:focus-visible {
  outline: 3px solid var(--theme-400);
  outline-offset: 2px;
}

.message {
  margin-top: 1rem;
  text-align: center;
  color: var(--theme-700);
}

.controls {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 2rem;
}

/* --- Print: clean A4 card, no ticks or buttons --- */

@page {
  size: A4 portrait;
  margin: 15mm;
}

@media print {
  body {
    padding: 0;
    background: none;
    color: #000;
  }

  .card {
    width: 180mm;
  }

  h1,
  .player {
    color: #000;
  }

  h1 {
    font-size: 32pt;
  }

  .player {
    margin-bottom: 8mm;
  }

  .grid {
    --gap: 2mm;
  }

  .cell,
  .cell[aria-pressed="true"],
  .cell.free {
    border: 0.4mm solid #000;
    border-radius: 3mm;
    background: none;
    box-shadow: none;
    color: #000;
    font-size: 11pt;
    padding: 2mm;
  }

  .free-title {
    font-size: 14pt;
  }

  .free-note {
    font-size: 8pt;
  }

  .controls {
    display: none;
  }
}
