/* ---------------------------------------------------------------
   Snake - game-specific styles.

   Loaded after /assets/base.css, which supplies the design tokens,
   the top bar, the buttons, the footer, the modals, the cookie
   banner and the legal-page layout shared by every Lynxy game.
   Only the board, the controls and the tokens they need live here.
---------------------------------------------------------------- */

/* ------------------------------- tokens -------------------------------- */

/* The board and the snake are drawn on a canvas; app.js reads these
   tokens and redraws whenever the theme changes. */
:root {
  --field-a: #f3f6fd;
  --field-b: #eaeff9;
  --field-line: #dfe5f2;
  --snake-head: #4f6cf7;
  --snake-tail: #a78bfa;
  --snake-eye: #ffffff;
  --snake-pupil: #171b26;
  --bonus-ring: #f5a524;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --field-a: #151a25;
    --field-b: #11161f;
    --field-line: #1e2533;
    --snake-head: #7d96ff;
    --snake-tail: #b794ff;
    --snake-eye: #0e1117;
    --snake-pupil: #e8ecf5;
    --bonus-ring: #f5b544;
  }
}

:root[data-theme="dark"] {
  --field-a: #151a25;
  --field-b: #11161f;
  --field-line: #1e2533;
  --snake-head: #7d96ff;
  --snake-tail: #b794ff;
  --snake-eye: #0e1117;
  --snake-pupil: #e8ecf5;
  --bonus-ring: #f5b544;
}

/* --------------------------- header extras ----------------------------- */

.stats {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 10px;
  text-align: center;
  min-width: 58px;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.stat__value {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
}

@media (max-width: 520px) {
  /* Every pixel of height goes to the field and the pad; the same
     information is in the description under the game. */
  .topbar__hint { display: none; }
  .stats { gap: 6px; }
  .stat { min-width: 44px; padding: 4px 6px; }
  .stat__value { font-size: 15px; }
  .stat__label { font-size: 9px; letter-spacing: .04em; }
  .brand__name { display: none; }
}

.brand__mark--snake {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.topbar__hint {
  max-width: 560px;
  margin: 6px auto 0;
  padding: 0 16px;
  font-size: 12px;
  color: var(--text-dim);
}

/* -------------------------------- page --------------------------------- */

.page {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  display: flex;
  gap: 10px;
  align-items: center;
}

.levels {
  flex: 1;
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}

.level {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 4px;
  border-radius: 9px;
  cursor: pointer;
  display: grid;
  gap: 1px;
  line-height: 1.15;
}

.level small {
  font-size: 10px;
  font-weight: 600;
  opacity: .75;
}

.level.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  color: var(--text-dim);
}

.meta__item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  font-variant-numeric: tabular-nums;
}

.meta__item--score {
  margin-left: auto;
  color: var(--text);
  font-weight: 700;
}

.meta__item--score.is-bump { animation: bump .3s ease; }

@keyframes bump {
  40% { transform: scale(1.14); border-color: var(--accent); }
}

/* -------------------------------- board -------------------------------- */

.board-wrap {
  position: relative;
  align-self: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 8px;
  /* Swipes steer the snake, so the board must not scroll the page. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.board {
  display: block;
  border-radius: 12px;
  /* Size is set by app.js to fit the screen; this is the pre-script size. */
  width: min(100%, 480px);
  aspect-ratio: 1;
}

.board-wrap.is-shake { animation: shake .45s cubic-bezier(.36, .07, .19, .97); }

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

.board-cover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg); /* fallback for browsers without color-mix */
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(5px);
  border-radius: var(--radius-lg);
  z-index: 3;
  animation: fade .2s ease;
}

.board-cover[hidden] { display: none; }

.board-cover__card {
  text-align: center;
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 16px;
  max-width: 280px;
}

.board-cover__icon {
  font-size: 44px;
  line-height: 1;
  animation: float 2.4s ease-in-out infinite;
}

@keyframes float {
  50% { transform: translateY(-6px); }
}

.board-cover__title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.board-cover__text {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}

.board-cover .btn { min-width: 150px; }

/* ------------------------------ controls ------------------------------- */

.controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* The d-pad: four arrows around a pause button, sized for thumbs. */
.dpad {
  --key: 64px;
  display: grid;
  grid-template-columns: repeat(3, var(--key));
  grid-template-rows: repeat(3, var(--key));
  gap: 6px;
  touch-action: none;
}

.dpad__key {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: transform .08s ease, background-color .08s ease, border-color .08s ease;
  -webkit-user-select: none;
  user-select: none;
}

.dpad__key .icon { width: 26px; height: 26px; stroke-width: 2.2; }

.dpad__key.is-down,
.dpad__key:active {
  transform: scale(.93);
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.dpad__key--up { grid-area: 1 / 2; }
.dpad__key--left { grid-area: 2 / 1; }
.dpad__key--right { grid-area: 2 / 3; }
.dpad__key--down { grid-area: 3 / 2; }

.dpad__key--mid {
  grid-area: 2 / 2;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-dim);
  box-shadow: none;
}

.dpad__key--mid .icon { width: 22px; height: 22px; }
.dpad__key[disabled] { opacity: .45; cursor: default; }

/* Pause/play glyphs swap with the state of the game. */
.icon--play { display: none; }
.is-paused .icon--pause { display: none; }
.is-paused .icon--play { display: block; }

.keys-hint {
  display: none;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 13px;
  color: var(--text-dim);
}

kbd {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  min-width: 24px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  background: var(--surface);
  color: var(--text);
  display: inline-block;
  text-align: center;
}

/* A mouse and a keyboard: the arrows beat any on-screen pad, so the pad
   gives way to a short key legend and a plain pause button. */
@media (hover: hover) and (pointer: fine) {
  .dpad { display: none; }
  .keys-hint { display: flex; }
}

.tools {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
}

.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 9px 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}

.tool:active { transform: scale(.97); }
.tool[disabled] { opacity: .45; cursor: default; }

/* On a phone the pause lives in the middle of the pad and "New game" sits
   above the field, so the tool row would only push the pad off the screen. */
@media not all and (hover: hover) and (pointer: fine) {
  .tools { display: none; }
}

/* Short phones (or a browser with its toolbars showing): a smaller pad
   leaves the field room to breathe. */
@media (max-height: 740px) {
  .dpad { --key: 56px; gap: 5px; }
  .dpad__key { border-radius: 16px; }
}

/* ---------------------------- game-over dialog ------------------------- */

.score-row {
  display: flex;
  gap: 8px;
  margin: 18px 0;
}

.score-row__item {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 4px;
  display: grid;
  gap: 2px;
}

.score-row__value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-row__item:first-child .score-row__value { color: var(--ok); }

/* The lynx next to "Play again": a way back to every game on the site
   without having to close the dialog first. */
.modal__actions .modal__home {
  flex: none;
  width: 46px;
  padding: 0;
}

.modal__home img { width: 26px; height: 26px; display: block; }
.modal__home:active { transform: scale(.96); }

.score-row__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
}

/* ------------------------ about / SEO copy ----------------------------- */

.about {
  border-top: 1px solid var(--border);
  padding-top: 18px;
  margin-top: 6px;
  color: var(--text-dim);
  font-size: 14px;
}

.about h1 {
  font-size: 18px;
  letter-spacing: -.02em;
  color: var(--text);
  margin: 0 0 6px;
}

.about h2 {
  font-size: 15px;
  color: var(--text);
  margin: 18px 0 4px;
}

.about p { margin: 0 0 8px; }

.fruits {
  list-style: none;
  margin: 10px 0 12px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.fruits li {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 20px;
}

/* --------------------------- tables in prose --------------------------- */

.about table,
.doc table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 14px;
  font-size: 13px;
}

.about th, .about td,
.doc th, .doc td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.about th, .doc th { background: var(--surface-2); color: var(--text); font-weight: 600; }

.doc table { margin: 14px 0; font-size: 14px; }
.doc th, .doc td { padding: 7px 9px; }
.doc ol { padding-left: 20px; }
