/* ---------------------------------------------------------------
   Memory Match - 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 and the tokens it needs live here.
---------------------------------------------------------------- */

/* ------------------------------- tokens -------------------------------- */

/* The card surfaces: nothing outside the Memory Match board uses them, so
   they are not in base.css. The pictures themselves carry fixed colours. */
:root {
  --face: #ffffff;
  --face-line: #dfe4ef;
  --back-a: #4f6cf7;
  --back-b: #8b5cf6;
  --match-ring: #17a673;
  --disc-opacity: 1;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --face: #202838;
    --face-line: #2e3748;
    --back-a: #3f5ae0;
    --back-b: #7c4ee8;
    --match-ring: #35d39a;
    --disc-opacity: .92;
  }
}

:root[data-theme="dark"] {
  --face: #202838;
  --face-line: #2e3748;
  --back-a: #3f5ae0;
  --back-b: #7c4ee8;
  --match-ring: #35d39a;
  --disc-opacity: .92;
}

/* --------------------------- header extras ----------------------------- */

.topbar__inner { max-width: 640px; }

.brand__mark svg { width: 20px; height: 20px; display: block; }

.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);
}

/* Three counters, the brand and the two buttons only fit a phone once the
   counters give up their padding and the brand keeps just its mark. */
@media (max-width: 520px) {
  .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; }
}

.topbar__hint {
  max-width: 640px;
  margin: 6px auto 0;
  padding: 0 16px;
  font-size: 12px;
  color: var(--text-dim);
}

/* -------------------------------- page --------------------------------- */

.page {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.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;
  font-variant-numeric: tabular-nums;
}

.level.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.meta {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  color: var(--text-dim);
  flex-wrap: wrap;
}

.meta__item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.meta__item strong { color: var(--text); font-weight: 700; }

/* The move counter is the score of this game, so it reads first. */
.meta__item--moves {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.meta__item--moves strong { color: var(--accent); }
.meta__item--time { margin-left: auto; }

@media (max-width: 380px) {
  .meta { font-size: 12px; gap: 5px; }
  .meta__item { padding: 3px 8px; }
}

/* -------------------------------- board -------------------------------- */

.board-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px;
}

.board {
  --card: 72px;
  --gap: 8px;
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), var(--card));
  grid-auto-rows: var(--card);
  gap: var(--gap);
  justify-content: center;
  touch-action: manipulation;
}

.tile {
  border: 0;
  margin: 0;
  padding: 0;
  background: none;
  font: inherit;
  cursor: pointer;
  perspective: 700px;
  border-radius: calc(var(--card) * .16);
  user-select: none;
  -webkit-user-select: none;
}

.tile__inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .38s cubic-bezier(.3, .7, .3, 1);
}

.tile.is-up .tile__inner { transform: rotateY(180deg); }

.tile__back,
.tile__face {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--card) * .16);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* The back: the Lynxy gradient, a fine diamond lattice, a soft highlight and
   a lynx paw in the middle. */
.tile__back {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64' fill='white' fill-opacity='.92'%3E%3Cellipse cx='32' cy='42' rx='12' ry='10'/%3E%3Cellipse cx='17' cy='29' rx='5' ry='6.5' transform='rotate(-25 17 29)'/%3E%3Cellipse cx='26' cy='19' rx='5' ry='7'/%3E%3Cellipse cx='38' cy='19' rx='5' ry='7'/%3E%3Cellipse cx='47' cy='29' rx='5' ry='6.5' transform='rotate(25 47 29)'/%3E%3C/svg%3E") center / 42% no-repeat,
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, .32), transparent 55%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .08) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, .08) 0 2px, transparent 2px 9px),
    linear-gradient(135deg, var(--back-a), var(--back-b));
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .22), 0 2px 6px rgba(18, 24, 40, .16);
  transition: filter .12s ease;
}

.tile__face {
  transform: rotateY(180deg);
  background: var(--face);
  box-shadow: inset 0 0 0 1px var(--face-line), 0 2px 6px rgba(18, 24, 40, .1);
  display: grid;
  place-items: center;
}

.tile__face svg { width: 84%; height: 84%; display: block; }
.tile__face .disc { opacity: var(--disc-opacity); }

@media (hover: hover) {
  .tile:not(.is-up):hover .tile__back { filter: brightness(1.1); }
}

.tile:not(.is-up):active .tile__inner { transform: scale(.94); }

.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* A found pair stays open, framed, and steps back so the cards still in play
   stand out. */
.tile.is-matched { cursor: default; }
/* The fade sits on the face, not on .tile__inner: opacity on a 3D container
   flattens it and the back would show through. */
.tile.is-matched .tile__face {
  box-shadow: inset 0 0 0 2.5px var(--match-ring);
  opacity: .8;
  transition: opacity .5s ease .7s;
}
.tile.is-fresh .tile__face { animation: matched .5s ease .3s; }

.tile.is-miss .tile__face { box-shadow: inset 0 0 0 2.5px var(--error); animation: shake .36s ease .38s; }

/* Everything turns instantly while a new deck is laid down or a saved game
   is restored - nothing should be seen mid-turn. */
.board.is-still .tile__inner,
.board.is-still .tile__face { transition: none; animation: none; }

@keyframes matched {
  0% { transform: rotateY(180deg) scale(1); }
  45% { transform: rotateY(180deg) scale(1.12); }
  100% { transform: rotateY(180deg) scale(1); }
}

@keyframes shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  25% { transform: rotateY(180deg) translateX(-4px); }
  75% { transform: rotateY(180deg) translateX(4px); }
}

.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) 80%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius);
  z-index: 3;
}

.board-cover[hidden] { display: none; }

.board-cover__card {
  text-align: center;
  display: grid;
  gap: 12px;
  font-weight: 600;
}

.board-cover__card p { margin: 0; }

/* -------------------------------- tools -------------------------------- */

.tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-dim);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 8px 2px 6px;
  display: grid;
  justify-items: center;
  gap: 3px;
  cursor: pointer;
}

.tool:active { transform: scale(.97); }
.tool[disabled] { opacity: .45; cursor: default; }

/* ------------------------------ win 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); }

.score-row__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
}

.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); }

/* ------------------------ about / SEO copy ----------------------------- */

.about {
  border-top: 1px solid var(--border);
  padding-top: 18px;
  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; }

kbd {
  font: inherit;
  font-size: .85em;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 0 5px;
}

/* --------------------------- tables in prose --------------------------- */

/* The level table on this page and in the guide; the shared sheet has no
   table styles because no other page needs one. */
.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; }

/* The guide uses numbered lists; base.css only styles the bulleted ones. */
.doc ol { padding-left: 20px; }
