:root {
  --bg: #090d18;
  --panel: rgba(255, 255, 255, 0.035);
  --panel-2: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.085);
  --line-2: rgba(255, 255, 255, 0.16);
  --ink: #efe8da;
  --ink-2: #c9c3b6;
  --muted: #8a92a6;
  --tile-a: #161f35;
  --tile-b: #1b253f;
  --flame: #ffb547;
  --flame-hot: #fff4d2;
  --flame-deep: #ff7a2e;
  --shadow: #a798ff;
  --mirror: #5adcca;
  --danger: #ff8080;

  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;

  --tile: 64px;
  --gap: 5px;
  --pad: 10px;
  --ease-jump: cubic-bezier(0.4, 0.05, 0.25, 1);

  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(120% 70% at 50% -12%, #1b2849 0%, #0e1527 48%, #070a13 100%) fixed,
    var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
}

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

/* faint stars */
.sky {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.55;
  background-image:
    radial-gradient(1px 1px at 8% 14%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 22% 32%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 35% 9%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 48% 22%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 63% 6%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 77% 18%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 91% 11%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 86% 38%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 4% 46%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 95% 62%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 12% 78%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 70% 88%, #fff 50%, transparent 51%);
}

.app {
  position: relative;
  max-width: 720px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------------ top bar */

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 4px 0 8px;
}

.topbar-right {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-decoration: none;
  color: inherit;
  line-height: 1;
}

.brand-site {
  font-size: 10.5px;
  letter-spacing: 0.32em;
  text-transform: lowercase;
  color: var(--muted);
  margin-bottom: 6px;
  padding-left: 0.32em;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(26px, 7vw, 36px);
  letter-spacing: -0.02em;
}

.brand-name em {
  font-weight: 500;
  color: var(--flame);
  text-shadow: 0 0 18px rgba(255, 170, 70, 0.45);
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s, transform 0.1s;
}

.icon-btn:hover {
  background: var(--panel-2);
  color: var(--ink);
  border-color: var(--line-2);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

:focus-visible {
  outline: 2px solid var(--flame);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ game view */

.view[hidden] {
  display: none !important;
}

.view-game {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: rise 0.45s ease-out both;
}

.level-head {
  text-align: center;
  margin: 6px 0 14px;
  min-height: 52px;
  max-width: 460px;
}

.level-label {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.level-label b {
  color: var(--ink-2);
  font-weight: 600;
}

.level-tip {
  margin: 6px 0 0;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 16px;
  color: var(--ink-2);
  text-wrap: balance;
}

.level-tip:empty {
  display: none;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
}

.board {
  --step: calc(var(--tile) + var(--gap));
  position: relative;
  padding: var(--pad);
  border-radius: calc(var(--tile) * 0.22 + var(--pad));
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.015));
  border: 1px solid var(--line);
  box-shadow:
    0 40px 90px -40px rgba(0, 0, 0, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: filter 0.6s ease;
}

.board.enter {
  animation: board-in 0.5s cubic-bezier(0.2, 0.8, 0.3, 1) both;
}

.board.stuck {
  filter: saturate(0.6) brightness(0.85);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile));
  grid-auto-rows: var(--tile);
  gap: var(--gap);
}

.tile {
  position: relative;
  width: var(--tile);
  height: var(--tile);
  padding: 0;
  border: 0;
  border-radius: calc(var(--tile) * 0.17);
  background: var(--tile-a);
  box-shadow:
    inset 0 -2px 0 rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.035);
  cursor: default;
  outline-offset: -2px;
}

.tile.alt {
  background: var(--tile-b);
}

.tile.hole {
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}

.tile.hole::before {
  content: '';
  position: absolute;
  inset: 40%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
}

/* warm glow of a lit square */
.tile::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle at 50% 62%, rgba(255, 174, 80, 0.4), rgba(255, 120, 40, 0.13) 52%, rgba(255, 120, 40, 0) 80%);
  box-shadow:
    inset 0 0 0 1px rgba(255, 196, 120, 0.3),
    0 0 calc(var(--tile) * 0.45) rgba(255, 140, 50, 0.22);
  opacity: 0;
  transition: opacity 0.5s ease;
}

.tile.lit::before {
  opacity: 1;
}

.flame {
  position: absolute;
  left: 50%;
  top: 56%;
  width: 34%;
  height: 34%;
  margin: -17% 0 0 -17%;
  transform: scale(0);
  opacity: 0;
  transition: transform 0.38s cubic-bezier(0.55, 0, 0.75, 0.2), opacity 0.38s ease-in;
  pointer-events: none;
}

.tile.lit .flame {
  transform: scale(1);
  opacity: 1;
  transition: transform 0.45s cubic-bezier(0.2, 1.6, 0.4, 1), opacity 0.25s ease-out;
}

.flame-body {
  position: absolute;
  inset: 0;
  transform-origin: 50% 85%;
  animation: flicker var(--flicker, 1.7s) ease-in-out infinite alternate;
  animation-delay: var(--delay, 0s);
}

.flame-body::before,
.flame-body::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 0 50% 50% 50%;
  transform: rotate(45deg);
}

.flame-body::before {
  background: radial-gradient(circle at 62% 62%, var(--flame-hot) 0%, #ffd77e 28%, var(--flame) 50%, var(--flame-deep) 78%);
  box-shadow:
    0 0 calc(var(--tile) * 0.18) rgba(255, 170, 60, 0.75),
    0 0 calc(var(--tile) * 0.42) rgba(255, 120, 40, 0.35);
}

.flame-body::after {
  inset: 34% 30% 14% 34%;
  background: radial-gradient(circle at 60% 60%, #fff 0%, rgba(255, 250, 230, 0.8) 45%, rgba(255, 240, 200, 0) 75%);
  border-radius: 0 50% 50% 50%;
}

@keyframes flicker {
  0% {
    transform: scale(1, 1) rotate(-2deg);
  }
  40% {
    transform: scale(0.95, 1.07) rotate(1.5deg);
  }
  100% {
    transform: scale(1.04, 0.96) rotate(-1deg);
  }
}

/* smoke left behind when a light goes out */
.smoke {
  position: absolute;
  left: 50%;
  top: 40%;
  width: 0;
  height: 0;
  pointer-events: none;
}

.smoke i {
  position: absolute;
  width: calc(var(--tile) * 0.16);
  height: calc(var(--tile) * 0.16);
  margin: calc(var(--tile) * -0.08);
  border-radius: 50%;
  background: rgba(205, 210, 225, 0.4);
  filter: blur(1.5px);
  animation: smoke 0.95s ease-out forwards;
}

.smoke i:nth-child(2) {
  animation-delay: 0.08s;
  --sx: -1;
}

.smoke i:nth-child(3) {
  animation-delay: 0.16s;
  --sx: 0.6;
}

@keyframes smoke {
  0% {
    opacity: 0;
    transform: translate(0, 0) scale(0.5);
  }
  25% {
    opacity: 0.85;
  }
  100% {
    opacity: 0;
    transform: translate(calc(var(--sx, 0.3) * var(--tile) * 0.18), calc(var(--tile) * -0.55)) scale(1.8);
  }
}

/* a spark when an echo knight lights a square */
.spark {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 2px solid rgba(255, 210, 140, 0.9);
  pointer-events: none;
  animation: spark 0.6s ease-out forwards;
}

@keyframes spark {
  0% {
    opacity: 1;
    transform: scale(0.3);
  }
  100% {
    opacity: 0;
    transform: scale(1.25);
  }
}

/* where the selected knight may jump */
.tile.target {
  cursor: pointer;
}

.tile.target::after,
.tile.hint::after {
  content: '';
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 238, 205, 0.6);
  animation: ring 1.8s ease-in-out infinite;
  pointer-events: none;
}

.tile.target:hover::after,
.tile.target:focus-visible::after,
.tile.target.peek::after {
  inset: 6%;
  border-width: 2px;
  border-color: rgba(255, 244, 222, 0.95);
  background: rgba(255, 240, 210, 0.07);
  animation: none;
}

.tile.hint::after {
  inset: 2%;
  border: 2.5px solid var(--flame-hot);
  box-shadow: 0 0 18px rgba(255, 200, 110, 0.7);
  animation: ring 0.9s ease-in-out infinite;
}

.tile.nope {
  animation: nope 0.32s ease;
}

@keyframes ring {
  0%,
  100% {
    transform: scale(0.94);
    opacity: 0.75;
  }
  50% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes nope {
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

/* ------------------------------------------------------------------ pieces */

.pieces {
  position: absolute;
  inset: var(--pad);
  pointer-events: none;
}

.piece,
.ghost {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--tile);
  height: var(--tile);
  transform: translate(calc(var(--x) * var(--step)), calc(var(--y) * var(--step)));
  transition: transform 0.32s var(--ease-jump);
  z-index: 2;
}

.piece.jumping {
  z-index: 4;
}

.piece-body {
  position: absolute;
  inset: 6% 9% 9%;
}

.piece-body svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.piece.hop .piece-body {
  animation: hop 0.32s ease-out;
}

.piece.bump .piece-body {
  animation: bump 0.38s ease-out;
}

@keyframes hop {
  0% {
    transform: translateY(0) scale(1);
  }
  45% {
    transform: translateY(-30%) scale(1.12);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes bump {
  0%,
  100% {
    transform: translate(0, 0);
  }
  35% {
    transform: translate(calc(var(--bx) * 14%), calc(var(--by) * 14%)) scale(1.04);
  }
  60% {
    transform: translate(calc(var(--bx) * -4%), calc(var(--by) * -4%));
  }
}

.piece--K {
  --k-body: #f3ead6;
  --k-collar: #ddd0b4;
  --k-base: #e7dbc0;
  --k-line: rgba(40, 30, 15, 0.35);
  --k-mane: rgba(110, 85, 45, 0.3);
  --k-eye: #151b2c;
  --k-cast: rgba(0, 0, 0, 0.45);
}

.piece--K .piece-body {
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
}

.piece--S {
  --k-body: rgba(167, 152, 255, 0.5);
  --k-collar: rgba(167, 152, 255, 0.55);
  --k-base: rgba(167, 152, 255, 0.6);
  --k-line: rgba(214, 206, 255, 0.95);
  --k-mane: rgba(230, 225, 255, 0.55);
  --k-eye: rgba(240, 236, 255, 0.95);
  --k-cast: rgba(120, 100, 255, 0.25);
}

.piece--M {
  --k-body: rgba(90, 220, 202, 0.42);
  --k-collar: rgba(90, 220, 202, 0.5);
  --k-base: rgba(90, 220, 202, 0.55);
  --k-line: rgba(190, 255, 245, 0.95);
  --k-mane: rgba(215, 255, 248, 0.55);
  --k-eye: rgba(230, 255, 250, 0.95);
  --k-cast: rgba(60, 220, 200, 0.22);
}

.piece--S .piece-body {
  filter: drop-shadow(0 0 7px rgba(150, 130, 255, 0.65));
}

.piece--M .piece-body {
  filter: drop-shadow(0 0 7px rgba(70, 220, 200, 0.6));
}

.piece--M .piece-body svg,
.ghost--M svg {
  transform: scaleX(-1);
}

/* the selected knight stands in a pool of light */
.piece::before {
  content: '';
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 2%;
  height: 26%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 222, 160, 0.55), rgba(255, 200, 120, 0));
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.25s, transform 0.25s;
}

.piece.selected::before {
  opacity: 1;
  transform: scale(1);
}

.piece.hint .piece-body {
  animation: hint-bob 0.9s ease-in-out infinite;
}

@keyframes hint-bob {
  50% {
    transform: translateY(-9%);
  }
}

.piece.trapped .piece-body {
  animation: nope 0.4s ease 2;
}

/* preview of where echoes would go */
.ghost {
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 1;
}

.ghost.show {
  opacity: 1;
}

.ghost svg {
  position: absolute;
  inset: 14% 17% 17%;
  width: 66%;
  height: 70%;
  opacity: 0.55;
}

.ghost::after {
  content: '';
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  border: 2px dashed currentColor;
  opacity: 0.8;
}

.ghost--S {
  color: var(--shadow);
  --k-body: rgba(167, 152, 255, 0.35);
  --k-line: rgba(214, 206, 255, 0.9);
  --k-base: rgba(167, 152, 255, 0.4);
  --k-collar: rgba(167, 152, 255, 0.4);
  --k-eye: #fff;
  --k-mane: transparent;
  --k-cast: transparent;
}

.ghost--M {
  color: var(--mirror);
  --k-body: rgba(90, 220, 202, 0.32);
  --k-line: rgba(190, 255, 245, 0.9);
  --k-base: rgba(90, 220, 202, 0.4);
  --k-collar: rgba(90, 220, 202, 0.4);
  --k-eye: #fff;
  --k-mane: transparent;
  --k-cast: transparent;
}

.piece .stay {
  position: absolute;
  right: 2%;
  top: 2%;
  width: 34%;
  height: 34%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #0d1322;
  border: 1.5px solid currentColor;
  font-size: calc(var(--tile) * 0.2);
  font-weight: 600;
  line-height: 1;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.15s, transform 0.15s;
}

.piece--S .stay {
  color: var(--shadow);
}

.piece--M .stay {
  color: var(--mirror);
}

.piece.staying .stay {
  opacity: 1;
  transform: scale(1);
}

/* ------------------------------------------------------------------ hud */

.hud {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  margin-top: 18px;
}

.counter {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.counter-flame {
  width: 18px;
  height: 18px;
  align-self: center;
  color: var(--flame);
  filter: drop-shadow(0 0 6px rgba(255, 170, 70, 0.6));
  transition: color 0.3s, filter 0.3s;
}

.counter.done .counter-flame {
  color: var(--muted);
  filter: none;
}

.counter-num {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  min-width: 1.2ch;
}

.counter-label {
  color: var(--muted);
  font-size: 13px;
}

.actions {
  display: flex;
  gap: 8px;
}

.act {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s, transform 0.1s, opacity 0.2s;
}

.act svg {
  width: 17px;
  height: 17px;
}

.act:hover:not(:disabled) {
  background: var(--panel-2);
  border-color: var(--line-2);
  color: var(--ink);
}

.act:active:not(:disabled) {
  transform: scale(0.95);
}

.act:disabled {
  opacity: 0.4;
  cursor: default;
}

.act.glow {
  border-color: rgba(255, 200, 120, 0.6);
  color: var(--ink);
  box-shadow: 0 0 0 3px rgba(255, 180, 80, 0.12);
}

.status {
  flex-basis: 100%;
  margin: 0;
  min-height: 22px;
  text-align: center;
  font-size: 13.5px;
  color: var(--ink-2);
}

.status.warn {
  color: var(--danger);
}

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

.veil {
  position: absolute;
  inset: -6px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: rgba(7, 10, 19, 0.5);
  backdrop-filter: blur(2.5px);
  -webkit-backdrop-filter: blur(2.5px);
  z-index: 10;
  animation: fade 0.35s ease both;
}

.veil[hidden] {
  display: none;
}

/* when stuck, keep the board readable behind the card */
.veil.soft {
  align-items: end;
  padding-bottom: 8%;
  background: linear-gradient(180deg, rgba(7, 10, 19, 0) 35%, rgba(7, 10, 19, 0.6));
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.card {
  width: min(320px, calc(100% - 24px));
  padding: 22px 22px 20px;
  text-align: center;
  border-radius: 20px;
  background: linear-gradient(180deg, #172039, #10172a);
  border: 1px solid var(--line-2);
  box-shadow: 0 30px 70px -20px rgba(0, 0, 0, 0.85);
  animation: pop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.card-kicker {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.card-title {
  margin: 6px 0 4px;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-title em {
  color: var(--flame);
  font-weight: 500;
}

.card-text {
  margin: 0 0 16px;
  color: var(--ink-2);
  font-size: 14px;
}

.card-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--ink);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.btn:hover {
  background: var(--panel-2);
}

.btn:active {
  transform: scale(0.96);
}

.btn svg {
  width: 17px;
  height: 17px;
}

.btn-primary {
  border-color: transparent;
  background: linear-gradient(180deg, #ffc76a, #ff9d42);
  color: #2a1606;
  box-shadow: 0 8px 24px -8px rgba(255, 150, 60, 0.7);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #ffd182, #ffa852);
}

/* ------------------------------------------------------------------ menu */

.view-menu {
  animation: rise 0.4s ease-out both;
  padding-bottom: 24px;
}

.menu-intro {
  text-align: center;
  max-width: 480px;
  margin: 10px auto 26px;
}

.menu-intro h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.01em;
}

.menu-intro p {
  margin: 0;
  color: var(--ink-2);
}

.chapters {
  display: grid;
  gap: 14px;
}

.chapter,
.endless {
  padding: 16px 16px 18px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.endless {
  margin-top: 14px;
}

.chapter.locked {
  opacity: 0.55;
}

.chapter-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 12px;
  margin-bottom: 12px;
}

.chapter-head h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 700;
}

.chapter-num {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.chapter-icon {
  width: 22px;
  height: 22px;
  color: var(--ink-2);
}

.chapter-head p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.chapter-progress {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

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

.lv {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--tile-a);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.2s, background-color 0.2s;
}

.lv:nth-child(even) {
  background: var(--tile-b);
}

.lv:hover:not(:disabled) {
  border-color: var(--line-2);
  transform: translateY(-1px);
}

.lv::after {
  content: '';
  position: absolute;
  bottom: 13%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--flame);
  box-shadow: 0 0 8px 2px rgba(255, 160, 60, 0.6);
}

.lv.solved {
  color: var(--muted);
  font-weight: 500;
}

.lv.solved::after {
  background: transparent;
  box-shadow: none;
  width: 10px;
  height: 5px;
  border-left: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  border-radius: 0;
  transform: rotate(-45deg);
  bottom: 15%;
}

.lv.current {
  border-color: rgba(255, 200, 120, 0.75);
  box-shadow: 0 0 0 3px rgba(255, 180, 80, 0.12);
}

.lv:disabled {
  cursor: default;
  color: var(--muted);
  opacity: 0.6;
}

.lv:disabled::after {
  display: none;
}

.lv svg {
  width: 16px;
  height: 16px;
}

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

.mode {
  padding: 12px 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--tile-a);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.12s;
}

.mode:hover {
  border-color: var(--line-2);
  transform: translateY(-1px);
}

.mode b {
  display: block;
  font-family: var(--font-display);
  font-size: 17px;
}

.mode span {
  font-size: 12px;
  color: var(--muted);
}

/* ------------------------------------------------------------------ help dialog */

.help {
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 22px;
  background: linear-gradient(180deg, #151d34, #0f1528);
  color: var(--ink);
  box-shadow: 0 40px 90px -20px rgba(0, 0, 0, 0.9);
}

.help::backdrop {
  background: rgba(4, 6, 12, 0.6);
  backdrop-filter: blur(3px);
}

.help[open] {
  animation: pop 0.35s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}

.help-inner {
  position: relative;
  padding: 24px 22px 20px;
}

.help-close {
  position: absolute;
  right: 14px;
  top: 14px;
}

.help h2 {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-size: 24px;
}

.rules {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 14px;
}

.rules li {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
  color: var(--ink-2);
  font-size: 14px;
}

.rules b {
  color: var(--ink);
  font-weight: 600;
}

.rules .t-lit {
  color: var(--flame);
}

.rules .t-shadow {
  color: var(--shadow);
}

.rules .t-mirror {
  color: var(--mirror);
}

.rule-ill {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--tile-b);
  display: grid;
  place-items: center;
}

.rule-ill svg {
  width: 34px;
  height: 34px;
  overflow: visible;
}

.rule-ill--knight {
  --k-body: #f3ead6;
  --k-collar: #ddd0b4;
  --k-base: #e7dbc0;
  --k-line: rgba(40, 30, 15, 0.35);
  --k-mane: rgba(110, 85, 45, 0.3);
  --k-eye: #151b2c;
  --k-cast: transparent;
}

.rule-ill--shadow {
  --k-body: rgba(167, 152, 255, 0.5);
  --k-collar: rgba(167, 152, 255, 0.55);
  --k-base: rgba(167, 152, 255, 0.6);
  --k-line: rgba(214, 206, 255, 0.95);
  --k-mane: rgba(230, 225, 255, 0.55);
  --k-eye: #fff;
  --k-cast: transparent;
}

.rule-ill--mirror {
  --k-body: rgba(90, 220, 202, 0.42);
  --k-collar: rgba(90, 220, 202, 0.5);
  --k-base: rgba(90, 220, 202, 0.55);
  --k-line: rgba(190, 255, 245, 0.95);
  --k-mane: rgba(215, 255, 248, 0.55);
  --k-eye: #fff;
  --k-cast: transparent;
}

.rule-ill--mirror svg {
  transform: scaleX(-1);
}

.rule-ill--flip {
  color: var(--flame);
}

.rule-ill--flip svg {
  width: 24px;
  height: 24px;
  filter: drop-shadow(0 0 6px rgba(255, 170, 70, 0.7));
}

.help-goal {
  margin: 18px 0 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--ink);
}

.help-keys {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  font-family: var(--font-ui);
  font-size: 11.5px;
  text-align: center;
  color: var(--ink-2);
}

/* ------------------------------------------------------------------ shared animations */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

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

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(8px);
  }
}

@keyframes board-in {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(10px);
  }
}

.board.won .tile:not(.hole) {
  animation: dawn 1.4s ease-out both;
  animation-delay: calc(var(--d, 0) * 45ms);
}

@keyframes dawn {
  30% {
    box-shadow:
      inset 0 0 0 1px rgba(255, 220, 160, 0.45),
      0 0 18px rgba(255, 190, 110, 0.25);
  }
}

@media (max-width: 420px) {
  .act span {
    display: none;
  }

  .act {
    width: 44px;
    padding: 0;
    justify-content: center;
  }

  .level-grid {
    gap: 6px;
  }

  .endless-modes {
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .flame-body,
  .tile.target::after,
  .tile.hint::after,
  .piece.hint .piece-body {
    animation: none;
  }

  .piece,
  .ghost {
    transition-duration: 0.12s;
  }
}

.chapter-pieces {
  display: inline-flex;
  gap: 3px;
  margin-left: 2px;
}

.chapter-piece {
  width: 26px;
  height: 26px;
  border-radius: 7px;
}

.chapter-piece svg {
  width: 20px;
  height: 20px;
}
