/* NOVA — merge the starlight */

:root {
  --bg: #080a14;
  --bg-2: #0e1224;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-line: rgba(255, 255, 255, 0.09);
  --text: #eef1ff;
  --muted: #8b93b8;
  --accent: #ffd97a;
  --accent-2: #ff8a5c;

  /* Board geometry: 4 cells + 3 gaps + 2 pads = 100% of the board.
     4(21) + 3(3.2) + 2(3.2) = 100 */
  --gap: 3.2%;   /* board-relative, for width */
  --pad: 3.2%;   /* board-relative, for width */
  --pad-t: 15.238095%;    /* 3.2 / 21  — tile-relative, for transform */
  --step-t: 115.238095%;  /* (21 + 3.2) / 21 — one cell + one gap */
  --radius: 14px;

  --move: 105ms;
  --ease: cubic-bezier(0.22, 0.68, 0.35, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

/* ---------- background ---------- */

.starfield {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 70% 50% at 50% -10%, rgba(120, 90, 255, 0.22), transparent 70%),
    radial-gradient(ellipse 50% 40% at 85% 20%, rgba(255, 120, 90, 0.12), transparent 70%),
    radial-gradient(ellipse 60% 50% at 10% 80%, rgba(60, 190, 255, 0.10), transparent 70%),
    var(--bg);
}

.starfield::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.5;
  background-image:
    radial-gradient(1px 1px at 12% 22%, #fff, transparent),
    radial-gradient(1px 1px at 78% 12%, #fff, transparent),
    radial-gradient(1px 1px at 34% 68%, #fff, transparent),
    radial-gradient(1px 1px at 62% 82%, #fff, transparent),
    radial-gradient(1px 1px at 91% 55%, #fff, transparent),
    radial-gradient(1px 1px at 6% 47%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 45% 35%, #fff, transparent),
    radial-gradient(1px 1px at 24% 90%, #fff, transparent);
}

/* ---------- layout ---------- */

.wrap {
  width: 100%;
  max-width: 470px;
  margin: 0 auto;
  padding: 18px 16px calc(28px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.brand { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #fff5d6, var(--accent) 42%, var(--accent-2) 78%);
  box-shadow: 0 0 16px rgba(255, 180, 90, 0.6);
  flex: none;
}

.brand h1 {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.tagline {
  flex-basis: 100%;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.scores { display: flex; gap: 8px; flex: none; }

.score-box {
  min-width: 74px;
  padding: 7px 11px 8px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 11px;
}

.score-label {
  display: block;
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.score-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.score-value.bump { animation: bump 260ms var(--ease); }

@keyframes bump {
  40% { transform: scale(1.16); color: var(--accent); }
}

/* ---------- controls ---------- */

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.next { display: flex; align-items: center; gap: 9px; }

.next-label {
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.next-slot {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  font-weight: 800;
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  transition: background 160ms, color 160ms, box-shadow 160ms;
}

.buttons { display: flex; gap: 7px; }

.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  color: var(--text);
  padding: 9px 13px;
  border-radius: 10px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  cursor: pointer;
  transition: transform 90ms, background 140ms, opacity 140ms;
}

.btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); }
.btn:active:not(:disabled) { transform: scale(0.95); }
.btn:disabled { opacity: 0.35; cursor: default; }

.btn-primary {
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #23150a;
}

.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(160deg, var(--accent), var(--accent-2)); }

.btn-ghost { width: 36px; padding: 9px 0; text-align: center; }

.btn-lg { padding: 12px 26px; font-size: 15px; }

.pill {
  display: inline-block;
  min-width: 17px;
  margin-left: 3px;
  padding: 1px 5px;
  font-size: 11px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.12);
}

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

.board-shell { position: relative; }

.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 20px;
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--panel-line);
  box-shadow: 0 22px 50px -20px rgba(0, 0, 0, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  touch-action: none;
  outline: none;
  transition: transform 140ms var(--ease);
}

/* Keyboard focus needs to be visible without competing with the tiles. */
.board:focus-visible {
  box-shadow: 0 0 0 2px rgba(255, 217, 122, 0.4), 0 22px 50px -20px rgba(0, 0, 0, 0.85);
}

.cells, .tiles { position: absolute; inset: 0; }

.cell, .tile {
  position: absolute;
  top: 0;
  left: 0;
  width: calc((100% - 2 * var(--pad) - 3 * var(--gap)) / 4);
  aspect-ratio: 1;
  border-radius: var(--radius);
  /* `width` percentages resolve against the board, but `translate` percentages
     resolve against the tile itself — hence the separate *-t values. */
  transform: translate(
    calc(var(--pad-t) + var(--c) * var(--step-t)),
    calc(var(--pad-t) + var(--r) * var(--step-t))
  );
}

.cell { background: rgba(255, 255, 255, 0.038); }

.tile {
  display: grid;
  place-items: center;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  transition: transform var(--move) var(--ease);
  will-change: transform;
  box-shadow: 0 4px 12px -3px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.tile span {
  display: block;
  transform: translateZ(0);
}

.tile.spawn { animation: spawn 190ms var(--ease) both; }
.tile.pop span { animation: pop 210ms var(--ease); }
.tile.dying { opacity: 0; transition: transform var(--move) var(--ease), opacity 90ms linear 40ms; }

@keyframes spawn {
  from { opacity: 0; }
  60%  { opacity: 1; }
}

@keyframes pop {
  45% { transform: scale(1.26); }
}

/* tile skins */
.tile.v2  { background: linear-gradient(158deg, #4b8ff5, #2a5ed6); color: #f4f8ff; }
.tile.v3  { background: linear-gradient(158deg, #ff6f8d, #d92f57); color: #fff2f5; }
.tile.flux {
  background: linear-gradient(158deg, #fdfbff, #cfd4ff);
  color: #3a2a6b;
  box-shadow: 0 0 20px rgba(190, 180, 255, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.7);
  animation: flux-glow 1.6s ease-in-out infinite;
}

@keyframes flux-glow {
  50% { box-shadow: 0 0 30px rgba(215, 205, 255, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.7); }
}

.tile.big {
  color: #fff;
  background: linear-gradient(158deg, var(--t1), var(--t2));
  box-shadow: 0 4px 14px -3px rgba(0, 0, 0, 0.55), 0 0 22px -6px var(--t2), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

/* digit-count driven sizing, set as a class from JS */
.tile.d1 { font-size: clamp(24px, 8.4vw, 40px); }
.tile.d2 { font-size: clamp(22px, 7.6vw, 36px); }
.tile.d3 { font-size: clamp(18px, 6.2vw, 29px); }
.tile.d4 { font-size: clamp(14px, 4.9vw, 23px); }
.tile.d5 { font-size: clamp(12px, 4.0vw, 19px); }

/* ---------- effects ---------- */

.fx-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  border-radius: 20px;
}

.fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.score-pop {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 17px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
  animation: score-pop 850ms var(--ease) forwards;
  pointer-events: none;
  white-space: nowrap;
}

@keyframes score-pop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  22%  { opacity: 1; transform: translate(-50%, -110%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -230%) scale(0.95); }
}

.shake-s { animation: shake 260ms var(--ease); }
.shake-m { animation: shake 330ms var(--ease); --amp: 4px; }
.shake-l { animation: shake 420ms var(--ease); --amp: 7px; }

@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(calc(var(--amp, 2px) * -1), calc(var(--amp, 2px) * 0.4)); }
  32% { transform: translate(var(--amp, 2px), calc(var(--amp, 2px) * -0.5)); }
  52% { transform: translate(calc(var(--amp, 2px) * -0.7), calc(var(--amp, 2px) * -0.3)); }
  74% { transform: translate(calc(var(--amp, 2px) * 0.5), calc(var(--amp, 2px) * 0.3)); }
}

.milestone-flash {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(circle at 50% 50%, var(--flash), transparent 68%);
  animation: milestone 780ms var(--ease) forwards;
}

@keyframes milestone {
  0%   { opacity: 0; }
  18%  { opacity: 0.42; }
  100% { opacity: 0; }
}

/* ---------- overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  border-radius: 20px;
  background: rgba(8, 10, 20, 0.86);
  backdrop-filter: blur(6px);
  animation: fade 260ms ease both;
  z-index: 5;
}

.overlay[hidden] { display: none; }

@keyframes fade { from { opacity: 0; } }

.overlay-card { text-align: center; }
.overlay-card h2 { margin: 0 0 4px; font-size: 27px; letter-spacing: 0.05em; }
.overlay-sub { margin: 0; color: var(--muted); font-size: 13.5px; }

.final-score {
  margin: 14px 0 6px;
  font-size: 52px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay-note { margin: 0 0 18px; font-size: 12.5px; color: var(--muted); min-height: 1em; }

/* ---------- text blocks ---------- */

.hint {
  margin: 13px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
}

kbd {
  font: inherit;
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
}

.rules {
  margin: 22px 0 0;
  padding: 18px 20px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  font-size: 13.5px;
  line-height: 1.62;
  color: #c6ccea;
}

.rules h2 { margin: 0 0 10px; font-size: 15px; letter-spacing: 0.05em; color: var(--text); }
.rules ul { margin: 0; padding-left: 19px; }
.rules li { margin-bottom: 6px; }
.rules li::marker { color: var(--accent); }
.rules strong { color: var(--text); }
.scoring { margin: 12px 0 0; font-size: 12.5px; color: var(--muted); }

.footer {
  margin: 22px 0 0;
  text-align: center;
  font-size: 11px;
  line-height: 1.6;
  color: #5c648a;
}

.footer p { margin: 0 0 4px; }
.footer a { color: #7e87b3; }

.sitenav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
  margin: 0 0 14px;
  padding: 14px 0 0;
  border-top: 1px solid var(--panel-line);
  font-size: 12.5px;
}

.sitenav a {
  color: #9aa2c8;
  text-decoration: none;
}

.sitenav a:hover { color: var(--accent); text-decoration: underline; }

.contact-box {
  margin: 0 0 26px;
  padding: 20px 22px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  text-align: center;
}

.contact-box a {
  font-size: clamp(17px, 4.4vw, 22px);
  font-weight: 700;
  color: var(--accent);
  word-break: break-all;
}

/* ---------- article pages ---------- */

.wrap-wide { max-width: 720px; }

.crumbs {
  margin: 6px 0 18px;
  font-size: 12px;
  color: var(--muted);
}

.crumbs a { color: var(--accent); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

.article { color: #c6ccea; font-size: 15px; line-height: 1.72; }

.article h1 {
  margin: 0 0 14px;
  font-size: clamp(25px, 5.4vw, 35px);
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text);
}

.article h2 {
  margin: 34px 0 10px;
  font-size: 20px;
  letter-spacing: -0.005em;
  color: var(--text);
}

.article h3 {
  margin: 24px 0 6px;
  font-size: 15.5px;
  color: var(--text);
}

.article p { margin: 0 0 14px; }
.article a { color: var(--accent); }
.article strong { color: var(--text); }

.lede {
  font-size: 17px;
  line-height: 1.65;
  color: #d6dcf5;
}

.article ol, .article ul { padding-left: 20px; margin: 0 0 14px; }
.article li { margin-bottom: 7px; }
.article li::marker { color: var(--accent); }

.cta-row { margin: 26px 0 30px; }

/* Needs to outrank `.article a`, which would otherwise paint the label
   accent-on-accent and make it unreadable. */
.article a.cta {
  display: inline-block;
  text-decoration: none;
  border: none;
  color: #23150a;
}

.article a.cta:hover { filter: brightness(1.08); }

.table-scroll {
  overflow-x: auto;
  margin: 0 0 18px;
  border-radius: 12px;
  border: 1px solid var(--panel-line);
}

.article table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 380px;
}

.article th, .article td {
  padding: 9px 11px;
  text-align: left;
  border-bottom: 1px solid var(--panel-line);
}

.article thead th {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.article tbody tr:last-child td { border-bottom: none; }
.article td:first-child { color: var(--muted); white-space: nowrap; }

.disclaimer {
  margin: 36px 0 0;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}

/* ---------- ads ---------- */

.ad-slot {
  display: block;
  margin: 0 auto;
  overflow: hidden;
  text-align: center;
}

.ad-leaderboard {
  width: 100%;
  max-width: 728px;
  min-height: 90px;
  margin-top: 10px;
}

.ad-rect {
  width: 100%;
  max-width: 336px;
  min-height: 280px;
  margin-top: 22px;
}

.ad-slot:empty { display: none; }

/* Placeholders reserve the slot's height but stay invisible, so an unconfigured
   site does not look half-finished to a visitor or an AdSense reviewer.
   Add ?ads=debug to the URL to see the boxes while working on layout. */
.ad-ph {
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
}

.ads-debug .ad-ph {
  display: grid;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.11);
  border-radius: 12px;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #3f4666;
}

@media (max-width: 420px) {
  .wrap { padding-top: 12px; }
  .brand h1 { font-size: 22px; }
  .score-box { min-width: 66px; }
}

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