/*
 * The look of every game in the pack.
 *
 * Colours are CSS custom properties written by shared/brand.js from
 * brand.config.js, so restyling the whole pack is one file and no CSS edit.
 * This sheet owns the shell — page, header, stat strip, board frame,
 * buttons, overlay, leaderboard, toast — and each game styles only its own
 * board on top.
 *
 * Two rules worth keeping if you edit it:
 *   1. Never write a brand colour here. Read --la-* or the rebrand stops at
 *      the edge of whatever you hard-coded.
 *   2. Depth comes from layered shadows plus a light top edge, not from
 *      heavy borders. One flat shadow is what made the earlier version look
 *      like a wireframe.
 */

:root {
  /* Fallbacks only — brand.js overwrites these on load. */
  --la-primary: #5b3df5;
  --la-primary-hover: #4a2ed6;
  --la-primary-soft: #eee9fe;
  --la-primary-tint: rgb(91 61 245 / 0.1);
  --la-primary-glow: rgb(91 61 245 / 0.22);
  --la-on-primary: #ffffff;
  --la-ink: #0e0f13;
  --la-ink-soft: #5a5d68;
  --la-ink-faint: #8b8e99;
  --la-bg: #faf8f3;
  --la-bg-wash: rgb(91 61 245 / 0.07);
  --la-surface: #ffffff;
  --la-surface-sunken: #f2efe9;
  --la-surface-edge: rgb(255 255 255 / 0.9);
  --la-line: rgb(14 15 19 / 0.12);
  --la-line-strong: rgb(14 15 19 / 0.2);
  --la-shadow-sm: 0 1px 2px rgb(30 20 70 / 0.06);
  --la-shadow-md: 0 1px 2px rgb(30 20 70 / 0.05), 0 6px 16px -6px rgb(30 20 70 / 0.16);
  --la-shadow-lg: 0 2px 4px rgb(30 20 70 / 0.06), 0 18px 40px -18px rgb(30 20 70 / 0.3);
  --la-shadow-inset: inset 0 1px 0 rgb(255 255 255 / 0.85);

  --la-radius-sm: 10px;
  --la-radius: 16px;
  --la-radius-lg: 22px;

  --la-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  /* Numbers that do not jitter as a score ticks up. */
  --la-numeric: "Segoe UI Variable Display", ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: clamp(14px, 3vw, 32px) clamp(12px, 3vw, 28px) clamp(28px, 6vw, 56px);
  min-height: 100vh;
  background-color: var(--la-bg);
  /* A brand-tinted wash behind the top of the page, so the board has
     something to sit on instead of floating on flat paper. */
  background-image: radial-gradient(120% 62% at 50% -12%, var(--la-bg-wash), transparent 68%);
  background-repeat: no-repeat;
  color: var(--la-ink);
  font-family: var(--la-font);
  font-size: 16px;
  line-height: 1.5;
  font-synthesis-weight: none;
}

.la-shell {
  max-width: 780px;
  margin: 0 auto;
  display: grid;
  gap: clamp(14px, 2.4vw, 22px);
}

/* ---- Header ---------------------------------------------------------- */
.la-header {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.la-brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  padding: 6px 0;
  opacity: 0.75;
  transition: opacity 0.15s ease;
}
.la-brand:hover {
  opacity: 1;
}
.la-brand__logo {
  height: 28px;
  width: auto;
  display: block;
}
.la-brand__word {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--la-ink-soft);
}

.la-titles {
  margin-right: auto;
  min-width: 0;
}
.la-title {
  margin: 0;
  font-size: clamp(21px, 3.6vw, 27px);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.15;
}
.la-tagline {
  margin: 3px 0 0;
  font-size: 13.5px;
  color: var(--la-ink-soft);
}

.la-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---- Buttons --------------------------------------------------------- */
.la-icon-btn,
.la-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 9px 15px;
  border-radius: 999px;
  border: 1px solid var(--la-line);
  background: var(--la-surface);
  color: var(--la-ink);
  cursor: pointer;
  box-shadow: var(--la-shadow-sm);
  transition:
    transform 0.12s cubic-bezier(0.2, 0.8, 0.3, 1),
    box-shadow 0.15s ease,
    border-color 0.15s ease,
    background 0.15s ease;
}
.la-icon-btn:hover,
.la-btn:hover {
  border-color: var(--la-line-strong);
  box-shadow: var(--la-shadow-md);
  transform: translateY(-1px);
}
.la-icon-btn:active,
.la-btn:active {
  transform: translateY(0);
  box-shadow: var(--la-shadow-sm);
}
.la-icon-btn[disabled],
.la-btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.la-btn--primary {
  /* The gradient is the same colour twice over: enough to catch the light
     without inventing a second brand colour. */
  background-image: linear-gradient(180deg, var(--la-primary), var(--la-primary-hover));
  border-color: transparent;
  color: var(--la-on-primary);
  box-shadow: var(--la-shadow-md), inset 0 1px 0 rgb(255 255 255 / 0.18);
}
.la-btn--primary:hover {
  box-shadow: var(--la-shadow-lg), 0 0 0 4px var(--la-primary-glow), inset 0 1px 0 rgb(255 255 255 / 0.18);
  border-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--la-primary);
  outline-offset: 3px;
  border-radius: var(--la-radius-sm);
}

/* The board is a focus target only so key presses land somewhere; a hard
   ring around the whole frame reads as an error, so it gets a halo. */
.la-board:focus-visible {
  outline: none;
  box-shadow: var(--la-shadow-lg), var(--la-shadow-inset), 0 0 0 4px var(--la-primary-glow);
}

/* ---- Stat strip ------------------------------------------------------ */
.la-scorebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 18px;
  background: var(--la-surface);
  border: 1px solid var(--la-line);
  border-radius: var(--la-radius);
  box-shadow: var(--la-shadow-md), var(--la-shadow-inset);
}
.la-score {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.la-score__label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--la-ink-soft);
}
.la-score__value {
  font-family: var(--la-numeric);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.la-meta {
  margin: 0;
  font-size: 13px;
  color: var(--la-ink-soft);
  font-variant-numeric: tabular-nums;
}

/* ---- Board ----------------------------------------------------------- */
.la-board {
  /* Sized to its contents and centred: a board floating in a much wider
     white panel was most of what made the games look unfinished.
     min(100%, max-content) rather than fit-content, because fit-content
     lays the track out at the child width BEFORE max-width clamps the box,
     so a board with a fixed-width child overflowed the viewport on a
     phone. */
  width: min(100%, max-content);
  min-width: min(100%, 320px);
  margin: 0 auto;
  background-image: linear-gradient(180deg, var(--la-surface), var(--la-surface-sunken));
  border: 1px solid var(--la-line);
  border-radius: var(--la-radius-lg);
  box-shadow: var(--la-shadow-lg), var(--la-shadow-inset);
  padding: clamp(16px, 3.4vw, 26px);
  display: grid;
  gap: 16px;
  justify-items: center;
}

/* Screen-reader announcements, kept off screen without being hidden. */
.la-live {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Leaderboard ----------------------------------------------------- */
.la-leaderboard {
  background: var(--la-surface);
  border: 1px solid var(--la-line);
  border-radius: var(--la-radius);
  box-shadow: var(--la-shadow-sm);
  padding: 16px 20px;
}
.la-leaderboard__title {
  margin: 0 0 10px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--la-ink-soft);
}
.la-leaderboard__list {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: la-rank;
  display: grid;
  gap: 2px;
}
.la-leaderboard__list li {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  padding: 6px 8px;
  border-radius: var(--la-radius-sm);
}
.la-leaderboard__list li::before {
  counter-increment: la-rank;
  content: counter(la-rank);
  flex: none;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--la-surface-sunken);
  color: var(--la-ink-soft);
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
/* The best score earns the accent; the rest stay quiet. */
.la-leaderboard__list li:first-child {
  background: var(--la-primary-tint);
}
.la-leaderboard__list li:first-child::before {
  background: var(--la-primary);
  color: var(--la-on-primary);
}
.la-leaderboard__name {
  color: var(--la-ink-soft);
}
.la-leaderboard__score {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.la-leaderboard__list li.la-leaderboard__empty {
  color: var(--la-ink-soft);
  font-size: 14px;
  padding: 6px 2px;
  background: none;
}
.la-leaderboard__list li.la-leaderboard__empty::before {
  content: none;
}
.la-leaderboard__note {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--la-ink-soft);
}

/* ---- Ad slots -------------------------------------------------------- */
.la-ad {
  min-height: 90px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--la-line-strong);
  border-radius: var(--la-radius);
  color: var(--la-ink-soft);
  background: var(--la-surface-sunken);
}
.la-ad__label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 600;
}

/* ---- Overlay --------------------------------------------------------- */
.la-overlay {
  position: fixed;
  inset: 0;
  background: rgb(10 10 16 / 0.5);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 10;
  animation: la-fade 0.18s ease both;
}
.la-overlay[hidden] {
  display: none;
}
.la-overlay__panel {
  background-image: linear-gradient(180deg, var(--la-surface), var(--la-surface-sunken));
  border: 1px solid var(--la-line);
  border-radius: var(--la-radius-lg);
  padding: clamp(20px, 4vw, 30px);
  max-width: 440px;
  width: 100%;
  box-shadow: 0 30px 70px -24px rgb(10 10 16 / 0.55), var(--la-shadow-inset);
  animation: la-rise 0.22s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}
.la-overlay__title {
  margin: 0 0 12px;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.025em;
}
.la-overlay__line {
  margin: 0 0 10px;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--la-ink-soft);
}
.la-overlay__actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

@keyframes la-fade {
  from {
    opacity: 0;
  }
}
@keyframes la-rise {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

/* ---- Toast ----------------------------------------------------------- */
.la-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  max-width: min(320px, calc(100vw - 32px));
  text-align: center;
  background: var(--la-ink);
  color: var(--la-bg);
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--la-shadow-lg);
  z-index: 20;
  animation: la-toast-in 0.2s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}
.la-toast[hidden] {
  display: none;
}
@keyframes la-toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
}

/* ---- Shared pieces games can reuse ----------------------------------- */

/** A small labelled figure: "PAIRS 3/8". */
.la-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  font-size: 12px;
  color: var(--la-ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
}
.la-stat__value {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--la-ink);
  text-transform: none;
  font-variant-numeric: tabular-nums;
}

/** A pill of secondary information sitting above or below a board. */
.la-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--la-surface-sunken);
  border: 1px solid var(--la-line);
  font-size: 12px;
  font-weight: 600;
  color: var(--la-ink-soft);
}

/** The tray a board's cells sit in — sunken, so the pieces read as on top. */
.la-tray {
  background: var(--la-surface-sunken);
  border: 1px solid var(--la-line);
  border-radius: var(--la-radius);
  box-shadow: inset 0 2px 6px rgb(0 0 0 / 0.05);
  padding: clamp(8px, 1.8vw, 14px);
}

.la-hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--la-ink-soft);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .la-icon-btn:hover,
  .la-btn:hover {
    transform: none;
  }
}
