/* D Puzzle Game v2: dark fantasy puzzle adventure. Tokens first, then components. */

@font-face {
  font-family: "Tektur";
  font-style: normal;
  font-display: swap;
  font-weight: 400 900;
  font-stretch: 75% 100%;
  src: url("/assets/tektur.woff2") format("woff2");
}

@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-display: swap;
  font-weight: 400 700;
  src: url("/assets/archivo.woff2") format("woff2");
}

:root {
  --void: #0e0b1c;
  --night: #17122e;
  --dusk: #241c47;
  --line: #3a2f6b;
  --arcane: #9b7bff;
  --ember: #ffb547;
  --ember-hi: #ffc86f;
  --mist: #f1ecff;
  --haze: #b3a9d9;

  --display: "Tektur", "Arial Narrow", sans-serif;
  --body: "Archivo", "Helvetica Neue", Helvetica, Arial, sans-serif;

  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;
  --s-9: 96px;
  --s-10: 128px;

  --r-s: 8px;
  --r-m: 14px;
  --r-l: 22px;
  --r-full: 999px;

  --max: 1200px;
  --gutter: clamp(20px, 5vw, 64px);

  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --t-fast: 160ms;
  --t-slide: 200ms;
  --t-reveal: 520ms;

  --glow-arcane: 0 0 48px rgb(155 123 255 / 0.28);
  --glow-ember: 0 0 28px rgb(255 181 71 / 0.38);

  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  background: var(--void);
}

body {
  margin: 0;
  background: var(--void);
  color: var(--mist);
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

img,
svg {
  display: block;
  max-width: 100%;
}

h1,
h2,
h3,
p,
ul {
  margin: 0;
}

h1,
h2,
h3 {
  font-family: var(--display);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0.005em;
  text-wrap: balance;
}

p {
  text-wrap: pretty;
}

a {
  color: inherit;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 3px solid var(--ember);
  outline-offset: 3px;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.skip-link {
  position: absolute;
  left: var(--s-4);
  top: var(--s-4);
  z-index: 20;
  padding: var(--s-3) var(--s-4);
  background: var(--ember);
  color: var(--void);
  font-weight: 700;
  border-radius: var(--r-s);
  transform: translateY(-200%);
}

.skip-link:focus-visible {
  transform: none;
  outline-color: var(--mist);
}

.wrap {
  width: 100%;
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: 52px;
  padding: var(--s-3) var(--s-5);
  border: 0;
  border-radius: var(--r-m);
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.0625rem;
  letter-spacing: 0.02em;
  line-height: 1.1;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: box-shadow var(--t-fast) ease, background-color var(--t-fast) ease, transform 90ms ease;
}

.btn:hover {
  text-decoration: none;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: linear-gradient(180deg, var(--ember-hi), var(--ember));
  color: var(--void);
  box-shadow: inset 0 -3px 0 rgb(14 11 28 / 0.22), var(--glow-ember);
}

.btn-primary:hover {
  box-shadow: inset 0 -3px 0 rgb(14 11 28 / 0.22), 0 0 40px rgb(255 181 71 / 0.6);
}

.btn-primary:focus-visible {
  outline-color: var(--mist);
}

.btn-ghost {
  background: rgb(155 123 255 / 0.08);
  color: var(--mist);
  box-shadow: inset 0 0 0 1px rgb(155 123 255 / 0.55);
}

.btn-ghost:hover {
  background: rgb(155 123 255 / 0.18);
}

.btn-small {
  min-height: 44px;
  padding: var(--s-2) var(--s-4);
  font-size: 0.9375rem;
}

/* ---------- Header ---------- */

.site-header {
  position: relative;
  z-index: 5;
}

.site-header .wrap {
  display: flex;
  align-items: center;
  gap: var(--s-5);
  min-height: 76px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  min-height: 44px;
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.125rem;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand svg {
  width: 32px;
  height: 32px;
  flex: none;
}

.nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--haze);
  text-decoration: none;
  font-weight: 600;
}

.nav a:hover {
  color: var(--mist);
}

.header-cta {
  display: none;
}

@media (min-width: 560px) {
  .header-cta {
    display: inline-flex;
    margin-left: auto;
  }
}

@media (min-width: 900px) {
  .header-cta {
    margin-left: 0;
  }
}

/* ---------- Hero ---------- */

.hero {
  padding-block: clamp(var(--s-6), 6vw, var(--s-9)) clamp(var(--s-8), 8vw, var(--s-10));
}

.atmosphere {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(60% 55% at 78% 30%, rgb(155 123 255 / 0.30), transparent 70%),
    radial-gradient(45% 40% at 12% 88%, rgb(255 181 71 / 0.16), transparent 70%),
    radial-gradient(90% 70% at 50% 0%, #1d1640, transparent 75%);
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.runes {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.runes li {
  position: absolute;
  width: 26px;
  height: 26px;
  color: var(--arcane);
  opacity: 0.35;
  animation: drift 14s ease-in-out infinite;
}

.runes li:nth-child(1) { left: 6%; top: 18%; animation-delay: -2s; }
.runes li:nth-child(2) { left: 44%; top: 10%; width: 18px; height: 18px; animation-delay: -7s; color: var(--ember); }
.runes li:nth-child(3) { left: 92%; top: 14%; animation-delay: -4s; }
.runes li:nth-child(4) { left: 52%; top: 82%; width: 20px; height: 20px; animation-delay: -9s; }
.runes li:nth-child(5) { left: 3%; top: 64%; width: 20px; height: 20px; animation-delay: -1s; color: var(--ember); }
.runes li:nth-child(6) { left: 88%; top: 86%; animation-delay: -11s; }
.runes li:nth-child(7) { left: 36%; top: 48%; width: 16px; height: 16px; animation-delay: -5s; }

@keyframes drift {
  0%, 100% { transform: translateY(0) rotate(0deg); opacity: 0.18; }
  50% { transform: translateY(-18px) rotate(12deg); opacity: 0.5; }
}

.hero-grid {
  display: grid;
  gap: var(--s-8);
  align-items: center;
}

@media (min-width: 900px) {
  .hero-grid {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  }
}

.hero-copy {
  display: grid;
  gap: var(--s-5);
  min-width: 0;
}

.hero-title {
  font-size: clamp(3rem, 8.5vw, 6.5rem);
  font-weight: 900;
  line-height: 0.92;
  text-shadow: 0 0 36px rgb(155 123 255 / 0.45);
}

.hero-title span {
  display: block;
}

.hero-lede {
  max-width: 36ch;
  color: var(--haze);
  font-size: clamp(1.1875rem, 1.6vw, 1.375rem);
  line-height: 1.5;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin-top: var(--s-2);
}

.hero-note {
  color: var(--haze);
  font-size: 0.9375rem;
}

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

.puzzle {
  display: grid;
  gap: var(--s-4);
  justify-items: start;
  min-width: 0;
}

@media (min-width: 900px) {
  .puzzle {
    justify-items: end;
  }
}

.board {
  --gap: 7px;
  position: relative;
  width: min(100%, 440px);
  aspect-ratio: 1 / 1;
  padding: 12px;
  background: linear-gradient(160deg, #130f28, #0a0816);
  border-radius: var(--r-l);
  box-shadow: inset 0 0 0 1px rgb(155 123 255 / 0.45), inset 0 2px 12px rgb(0 0 0 / 0.6), var(--glow-arcane);
  transition: box-shadow var(--t-reveal) ease;
}

.board-grid {
  position: relative;
  width: 100%;
  height: 100%;
}

.tile {
  --x: 0;
  --y: 0;
  position: absolute;
  top: 0;
  left: 0;
  width: calc((100% - 2 * var(--gap)) / 3);
  height: calc((100% - 2 * var(--gap)) / 3);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--r-m);
  background: linear-gradient(160deg, #2c2358, #19132f 70%);
  color: var(--ember);
  box-shadow: inset 0 0 0 1px rgb(155 123 255 / 0.3), inset 0 1px 0 rgb(255 255 255 / 0.08), 0 6px 14px rgb(0 0 0 / 0.45);
  transform: translate(calc(var(--x) * (100% + var(--gap))), calc(var(--y) * (100% + var(--gap))));
  transition: transform var(--t-slide) var(--ease-out);
  overflow: hidden;
  font: inherit;
  touch-action: manipulation;
}

button.tile {
  cursor: pointer;
}

button.tile[aria-disabled="true"] {
  cursor: default;
}

button.tile[aria-disabled="false"]:hover {
  box-shadow: inset 0 0 0 1px rgb(255 181 71 / 0.7), inset 0 1px 0 rgb(255 255 255 / 0.1), 0 6px 14px rgb(0 0 0 / 0.45);
}

.tile svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
  filter: drop-shadow(0 0 6px rgb(255 181 71 / 0.5));
}

.tile:focus-visible {
  outline: 3px solid var(--mist);
  outline-offset: 2px;
  z-index: 2;
}

.tile-n {
  position: absolute;
  top: 7px;
  left: 7px;
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding-inline: 5px;
  border-radius: var(--r-full);
  background: rgb(14 11 28 / 0.78);
  color: var(--haze);
  box-shadow: inset 0 0 0 1px var(--line);
  font-family: var(--display);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  transition: opacity var(--t-reveal) ease;
}

.tile[data-pos="0"] { --x: 0; --y: 0; }
.tile[data-pos="1"] { --x: 1; --y: 0; }
.tile[data-pos="2"] { --x: 2; --y: 0; }
.tile[data-pos="3"] { --x: 0; --y: 1; }
.tile[data-pos="4"] { --x: 1; --y: 1; }
.tile[data-pos="5"] { --x: 2; --y: 1; }
.tile[data-pos="6"] { --x: 0; --y: 2; }
.tile[data-pos="7"] { --x: 1; --y: 2; }
.tile[data-pos="8"] { --x: 2; --y: 2; }

.board.is-instant .tile {
  transition: none;
}

.tile-final {
  opacity: 0;
  pointer-events: none;
  transform: translate(calc(2 * (100% + var(--gap))), calc(2 * (100% + var(--gap)))) scale(0.7);
  transform-origin: center;
  transition: opacity var(--t-reveal) ease, transform var(--t-reveal) var(--ease-out);
}

.board.is-solved {
  box-shadow: inset 0 0 0 1px rgb(255 181 71 / 0.8), inset 0 2px 12px rgb(0 0 0 / 0.6), 0 0 80px rgb(255 181 71 / 0.35);
}

.board.is-solved .tile-final {
  opacity: 1;
  transform: translate(calc(2 * (100% + var(--gap))), calc(2 * (100% + var(--gap)))) scale(1);
}

.board.is-solved .tile-n {
  opacity: 0;
}

.board.is-solved .tile svg {
  filter: drop-shadow(0 0 10px rgb(255 181 71 / 0.85));
}

.puzzle-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-3) var(--s-4);
  width: min(100%, 440px);
}

.puzzle:not(.is-ready) .puzzle-controls {
  visibility: hidden;
}

.puzzle-status {
  flex: 1 1 180px;
  min-width: 0;
  color: var(--haze);
  font-size: 0.9375rem;
}

/* ---------- Sections ---------- */

.section {
  padding-block: clamp(var(--s-7), 6vw, var(--s-9));
}

.section-head {
  display: grid;
  gap: var(--s-3);
  max-width: 40rem;
  margin-bottom: var(--s-7);
}

.section-head h2,
.story h2 {
  font-size: clamp(2rem, 4.4vw, 3.25rem);
}

.section-head p {
  color: var(--haze);
  font-size: 1.125rem;
}

/* Story: text + cipher wheel */

.story {
  display: grid;
  gap: var(--s-7);
  align-items: center;
}

@media (min-width: 900px) {
  .story {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--s-9);
  }
}

.story-copy {
  display: grid;
  gap: var(--s-4);
  min-width: 0;
}

.story-copy p {
  color: var(--haze);
  max-width: 46ch;
  font-size: 1.125rem;
}

.cipher {
  width: min(100%, 420px);
  justify-self: center;
  color: var(--haze);
}

.cipher text {
  font-family: var(--display);
  font-weight: 700;
}

/* Features */

.features {
  display: grid;
  gap: var(--s-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 640px) {
  .features {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .features {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.feature {
  display: grid;
  align-content: start;
  gap: var(--s-3);
  padding: var(--s-5);
  background: linear-gradient(180deg, var(--night), rgb(23 18 46 / 0.4));
  border-radius: var(--r-l);
  box-shadow: inset 0 0 0 1px var(--line);
}

.feature-icon {
  width: 48px;
  height: 48px;
  padding: 11px;
  margin-bottom: var(--s-2);
  border-radius: var(--r-m);
  background: rgb(155 123 255 / 0.12);
  color: var(--arcane);
  box-shadow: inset 0 0 0 1px rgb(155 123 255 / 0.35);
}

.feature-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.feature h3 {
  font-size: 1.25rem;
}

.feature p {
  color: var(--haze);
  font-size: 1rem;
}

/* Modes */

.modes {
  display: grid;
  gap: var(--s-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 900px) {
  .modes {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.mode {
  position: relative;
  display: grid;
  align-content: start;
  gap: var(--s-3);
  padding: var(--s-6) var(--s-5) var(--s-5);
  border-radius: var(--r-l);
  background:
    radial-gradient(80% 60% at 100% 0%, rgb(155 123 255 / 0.22), transparent 70%),
    var(--dusk);
  box-shadow: inset 0 0 0 1px rgb(155 123 255 / 0.3);
  overflow: hidden;
}

.mode-3 {
  background:
    radial-gradient(80% 60% at 100% 0%, rgb(255 181 71 / 0.22), transparent 70%),
    var(--dusk);
  box-shadow: inset 0 0 0 1px rgb(255 181 71 / 0.4);
}

.mode h3 {
  font-size: 1.625rem;
}

.mode p {
  color: var(--haze);
}

.pips {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pips span {
  width: 12px;
  height: 12px;
  transform: rotate(45deg);
  border-radius: 2px;
  box-shadow: inset 0 0 0 1.5px var(--ember);
}

.pips span.on {
  background: var(--ember);
  box-shadow: 0 0 10px rgb(255 181 71 / 0.6);
}

.pips-label {
  margin-left: var(--s-2);
  color: var(--haze);
  font-size: 0.875rem;
}

/* CTA band */

.cta-band {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: grid;
  gap: var(--s-5);
  justify-items: start;
  padding: clamp(var(--s-6), 6vw, var(--s-8));
  border-radius: var(--r-l);
  background:
    radial-gradient(60% 90% at 90% 50%, rgb(255 181 71 / 0.22), transparent 70%),
    radial-gradient(70% 90% at 0% 0%, rgb(155 123 255 / 0.3), transparent 70%),
    var(--night);
  box-shadow: inset 0 0 0 1px var(--line);
}

.cta-band h2 {
  font-size: clamp(1.875rem, 4vw, 3rem);
  max-width: 18ch;
}

.cta-band p {
  color: var(--haze);
  max-width: 44ch;
}

/* ---------- Footer ---------- */

.site-footer {
  padding-block: var(--s-7);
  border-top: 1px solid var(--line);
  font-size: 0.9375rem;
}

.footer-grid {
  display: grid;
  gap: var(--s-5);
}

@media (min-width: 768px) {
  .footer-grid {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }
}

.footer-note {
  color: var(--haze);
  max-width: 52ch;
  margin-top: var(--s-2);
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1) var(--s-5);
  padding: 0;
  list-style: none;
}

.footer-links a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--haze);
}

.footer-links a:hover {
  color: var(--mist);
}

/* ---------- Legal pages ---------- */

.legal {
  padding-block: clamp(var(--s-6), 5vw, var(--s-8)) clamp(var(--s-8), 8vw, var(--s-10));
}

.legal article {
  max-width: 68ch;
}

.legal h1 {
  font-size: clamp(2.5rem, 6vw, 4rem);
  text-shadow: 0 0 30px rgb(155 123 255 / 0.4);
}

.legal .updated {
  margin-top: var(--s-3);
  color: var(--haze);
  font-size: 0.9375rem;
}

.legal .intro {
  margin-top: var(--s-6);
  font-size: 1.1875rem;
}

.legal h2 {
  font-size: 1.375rem;
  margin-top: var(--s-7);
  color: var(--mist);
}

.legal p,
.legal ul {
  margin-top: var(--s-3);
  color: #d9d2f5;
}

.legal ul {
  padding-left: 1.25em;
}

.legal li + li {
  margin-top: var(--s-2);
}

.legal li::marker {
  color: var(--arcane);
}

.legal a {
  color: var(--ember);
  overflow-wrap: anywhere;
}

/* ---------- 404 ---------- */

.notfound {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  align-content: center;
  padding-block: var(--s-8);
}

.notfound .wrap {
  display: grid;
  gap: var(--s-5);
  justify-items: start;
}

.notfound h1 {
  font-size: clamp(3rem, 9vw, 6.5rem);
  font-weight: 900;
  line-height: 0.92;
  text-shadow: 0 0 36px rgb(155 123 255 / 0.45);
}

.notfound p {
  max-width: 40ch;
  color: var(--haze);
  font-size: 1.25rem;
}

/* ---------- Load sequence (one orchestrated moment) ---------- */

@media (prefers-reduced-motion: no-preference) {
  .hero-copy > *,
  .puzzle {
    animation: rise 700ms var(--ease-out) both;
  }

  .hero-copy > :nth-child(2) { animation-delay: 80ms; }
  .hero-copy > :nth-child(3) { animation-delay: 160ms; }
  .hero-copy > :nth-child(4) { animation-delay: 220ms; }
  .puzzle { animation-delay: 260ms; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Sprite consumers ---------- */

.runes svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav {
  display: none;
  gap: var(--s-5);
  margin-left: auto;
}

@media (min-width: 900px) {
  .nav {
    display: flex;
  }
}

body {
  position: relative;
  isolation: isolate;
  overflow-x: clip;
}

.page-atmosphere {
  inset: 0 0 auto 0;
  height: min(115vh, 1150px);
  -webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent);
  mask-image: linear-gradient(to bottom, #000 55%, transparent);
}

.pips-label {
  font-style: normal;
}
