/* Self-hosted fonts (OFL license) — see assets/fonts/CREDITS.md. No
   external font CDN calls, so the game works offline. */
@font-face {
  font-family: "Luckiest Guy";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./assets/fonts/luckiestguy.woff2") format("woff2");
}

@font-face {
  font-family: "Rubik";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("./assets/fonts/rubik-variable.woff2") format("woff2");
}

/*
  DESIGN SYSTEM — "sticker-toy"
  One mechanical rule, applied identically in this file and in the canvas
  drawing code (src/game.js): every shape is a flat saturated colour fill,
  a uniform thick ink outline, and a solid, unblurred, offset "peeled
  sticker" shadow. No gradients, no blur, no paper-grain texture, no pastel
  washing — anywhere. Text sits on every coloured surface in the same ink
  colour, never white, so contrast never has to be special-cased per
  variant. The shadow is the interaction language: it grows on hover (the
  piece lifts off the page) and collapses to nothing on press (it's
  stamped flush against the page) — see button rules below.
*/
:root {
  color-scheme: light;
  --ink: #16162c;
  --ink-soft: rgba(22, 22, 44, 0.62);
  --sky: #4fc3e8;
  --sky-deep: #2ba8d4;
  --green: #2ecc71;
  --green-deep: #1f9c56;
  --yellow: #ffd23f;
  --coral: #ff6262;
  --coral-deep: #e6432f;
  --cream: #fff8ea;
  --cream-deep: #ffe9b8;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;

  --text-2xs: 0.6875rem;
  --text-xs: 0.8125rem;
  --text-sm: 0.9375rem;
  --text-md: 1rem;
  --text-lg: 1.1875rem;
  --text-xl: clamp(1.5rem, 4.4vw, 1.9rem);
  --text-display-sm: clamp(2rem, 7vw, 3.2rem);
  --text-display-lg: clamp(3.2rem, 12vw, 6.8rem);

  --radius: 16px;
  --radius-sm: 10px;
  --pop: 6px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);

  font-family: "Rubik", "Nunito", "Avenir Next", Verdana, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--sky);
  color: var(--ink);
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  background: var(--cream);
  color: var(--ink);
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--pop) var(--pop) 0 0 var(--ink);
  transition: transform 140ms var(--ease-out), box-shadow 140ms var(--ease-out);
}

@media (hover: hover) {
  button:hover {
    transform: translate(-2px, -2px);
    box-shadow: 8px 8px 0 0 var(--ink);
  }
}

button:active {
  transform: translate(var(--pop), var(--pop));
  box-shadow: 0 0 0 0 var(--ink);
  transition-duration: 70ms;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--sky-deep);
  outline-offset: 3px;
}

.primary-button {
  background: var(--green);
}

.danger-button {
  background: var(--coral);
}

.game-shell {
  position: fixed;
  inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: grid;
  place-items: center;
  background: var(--sky);
}

#game-canvas {
  display: block;
  width: min(100vw, calc(100dvh * 9 / 16));
  height: min(100dvh, calc(100vw * 16 / 9));
  max-width: 100vw;
  max-height: 100dvh;
  border: 0;
  aspect-ratio: 9 / 16;
  image-rendering: auto;
  touch-action: none;
}

#game-canvas {
  border-inline: 3px solid var(--ink);
}

.hud {
  position: fixed;
  inset: calc(env(safe-area-inset-top) + 12px) calc(env(safe-area-inset-right) + 12px) auto calc(env(safe-area-inset-left) + 12px);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  pointer-events: none;
  z-index: 5;
}

.hud-score {
  min-width: 70px;
  text-align: center;
  font-family: "Luckiest Guy", "Rubik", sans-serif;
  font-weight: 400;
  font-size: clamp(2.5rem, 9vw, 5rem);
  line-height: 0.9;
  color: var(--cream);
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 4px 4px 0 var(--ink);
}

.hud-strip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  border: 3px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  background: var(--cream);
  box-shadow: 4px 4px 0 0 var(--ink);
  pointer-events: auto;
}

.hud-strip span {
  display: grid;
  min-width: 66px;
  font-size: var(--text-2xs);
  color: var(--ink-soft);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.hud-strip b {
  font-size: var(--text-sm);
  color: var(--ink);
  font-weight: 800;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-weight: 800;
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background: rgba(22, 22, 44, 0.18);
  pointer-events: auto;
}

[hidden] {
  display: none !important;
}

.screen:not([hidden]) {
  animation: screenIn 200ms var(--ease-out) both;
}

.panel,
.wide-panel,
.ready-card {
  animation: panelPop 340ms var(--ease-pop) both;
}

@keyframes screenIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes panelPop {
  from {
    opacity: 0;
    transform: scale(0.86);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

[data-state="playing"] .screen,
[data-state="ready"] .hud,
[data-state="playing"] .hud,
[data-state="paused"] .hud,
[data-state="gameover"] .hud {
  display: flex;
}

[data-state="title"] .hud,
[data-state="loading"] .hud,
[data-state="leaderboard"] .hud,
[data-state="settings"] .hud {
  display: none;
}

.menu-screen {
  align-content: center;
  gap: var(--space-4);
  text-align: center;
}

.brand-lockup {
  display: grid;
  gap: 0;
}

.logo-word {
  font-family: "Luckiest Guy", "Rubik", sans-serif;
  font-weight: 400;
  font-size: var(--text-display-lg);
  line-height: 0.82;
  letter-spacing: 0.01em;
  color: var(--cream);
  -webkit-text-stroke: 3px var(--ink);
  text-shadow: 6px 6px 0 var(--ink);
}

.logo-yoshi {
  color: var(--green);
}

.logo-bird {
  color: var(--yellow);
  transform: translateX(0.32em);
}

.menu-dino {
  width: 92px;
  height: 74px;
  margin-top: var(--space-2);
  border: 3px solid var(--ink);
  border-radius: 58% 48% 50% 44%;
  background: var(--green);
  box-shadow: 5px 5px 0 0 var(--ink);
  position: relative;
  animation: bob 1.5s ease-in-out infinite;
}

.menu-dino::before {
  content: "";
  position: absolute;
  right: -22px;
  top: 18px;
  width: 40px;
  height: 30px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--green);
}

.menu-dino::after {
  content: "";
  position: absolute;
  left: 18px;
  top: 20px;
  width: 34px;
  height: 19px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  transform-origin: right center;
  animation: flap 0.42s ease-in-out infinite;
}

.menu-dino span {
  position: absolute;
  right: 2px;
  top: 13px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink);
  z-index: 2;
}

.best-line,
.control-card,
.toggle-note {
  max-width: min(92vw, 520px);
  margin: 0;
}

.best-line {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-soft);
}

.best-line strong {
  color: var(--ink);
  font-weight: 800;
}

/* Sticker-toy card: flat cream surface, uniform ink border, hard offset
   shadow. No gradient, no grain, no soft glow — the shadow alone gives it
   depth, exactly like every canvas shape. */
.control-card,
.panel,
.wide-panel,
.ready-card {
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--cream);
  box-shadow: var(--pop) var(--pop) 0 0 var(--ink);
}

.control-card {
  padding: var(--space-3) var(--space-4);
}

.toggle-note {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ink-soft);
}

.button-row,
.button-stack {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
}

.button-stack {
  flex-direction: column;
}

.panel,
.wide-panel,
.ready-card {
  width: min(92vw, 520px);
  padding: clamp(var(--space-4), 4vw, var(--space-6));
  text-align: center;
}

.wide-panel {
  width: min(94vw, 760px);
}

.panel h1,
.wide-panel h1,
.ready-card h1 {
  margin: 0 0 var(--space-4);
  font-family: "Luckiest Guy", "Rubik", sans-serif;
  font-weight: 400;
  font-size: var(--text-display-sm);
  line-height: 1;
  color: var(--ink);
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0;
}

.result-grid span,
.rank-pill {
  display: grid;
  gap: var(--space-1);
  border: 3px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  background: var(--cream-deep);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
}

.result-grid b {
  font-size: var(--text-lg);
  font-weight: 800;
  color: var(--ink);
  text-transform: none;
  letter-spacing: 0;
}

.rank-pill {
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
}

.celebration {
  margin: 0 auto var(--space-3);
  width: fit-content;
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: var(--space-2) var(--space-4);
  background: var(--yellow);
  color: var(--ink);
  font-weight: 800;
  font-size: var(--text-sm);
  box-shadow: 4px 4px 0 0 var(--ink);
}

.name-panel {
  display: grid;
  gap: var(--space-2);
  margin: var(--space-4) 0;
}

.name-panel label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.name-panel div {
  display: flex;
  gap: var(--space-2);
}

.name-panel input {
  min-width: 0;
  min-height: 44px;
  flex: 1;
  border: 3px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  text-align: center;
  text-transform: uppercase;
  font-weight: 800;
  background: #fff;
  box-shadow: 3px 3px 0 0 var(--ink);
  transition: box-shadow 140ms ease;
}

.name-panel input:focus-visible {
  outline: 3px solid var(--sky-deep);
  outline-offset: 2px;
}

.table-wrap {
  max-height: min(48dvh, 380px);
  overflow: auto;
  margin: var(--space-4) 0;
  border: 3px solid var(--ink);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: var(--space-3) var(--space-2);
  border-bottom: 2px solid var(--ink);
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: var(--cream-deep);
  color: var(--ink);
  font-size: var(--text-2xs);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink);
}

tbody tr:nth-child(even) {
  background: rgba(79, 195, 232, 0.12);
}

.confirm-reset {
  margin-top: var(--space-4);
  border: 3px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: var(--space-4);
  background: var(--coral);
  box-shadow: 4px 4px 0 0 var(--ink);
  animation: panelPop 220ms var(--ease-pop) both;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin: var(--space-4) 0 var(--space-5);
  text-align: left;
}

.settings-grid label {
  display: grid;
  gap: var(--space-2);
  border: 3px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  background: var(--cream-deep);
  font-size: var(--text-sm);
  font-weight: 700;
  transition: background 120ms ease;
}

@media (hover: hover) {
  .settings-grid label:hover {
    background: var(--yellow);
  }
}

.settings-grid .check-line {
  grid-template-columns: auto 1fr;
  align-items: center;
}

input[type="checkbox"],
input[type="range"] {
  accent-color: var(--green-deep);
}

input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
}

input[type="range"] {
  width: 100%;
  height: 44px;
}

.settings-grid .check-line {
  min-height: 44px;
}

.storybook-mark {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 5px 5px 0 0 var(--ink);
  font-family: "Luckiest Guy", "Rubik", sans-serif;
  font-weight: 400;
  font-size: 2rem;
  color: var(--ink);
  animation: bob 1.2s ease-in-out infinite;
}

.loading-screen {
  gap: var(--space-4);
  text-align: center;
  font-weight: 700;
  color: var(--ink);
}

.high-contrast #game-canvas {
  filter: saturate(1.12) contrast(1.08);
}

@keyframes bob {
  50% {
    transform: translateY(-10px);
  }
}

@keyframes flap {
  50% {
    transform: rotate(-24deg);
  }
}

@media (max-width: 640px) {
  .hud {
    align-items: stretch;
  }

  .hud-strip {
    flex-direction: column;
    align-items: stretch;
  }

  .hud-strip span {
    min-width: 54px;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  th,
  td {
    font-size: var(--text-xs);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
