@font-face {
  font-family: "Nunito";
  src: url("fonts/nunito_variable.ttf") format("truetype");
  font-weight: 200 900;
  font-display: swap;
}

@font-face {
  font-family: "Fredoka";
  src: url("fonts/fredoka_variable.ttf") format("truetype");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  --ink: #583f2f;
  --ink-dim: #785f4e;
  --paper: #f7efe0;
  --paper-deep: #efe2cc;
  --sticker: #fffaf2;
  --line: rgba(88, 63, 47, 0.14);
  --shadow: rgba(77, 43, 23, 0.16);
  --green: #86b86d;
  --green-deep: #598f59;
  --coral: #e0614d;
  --sky: #7bb4d4;
  --butter: #e0bc3c;
  --door: #3fa86a;
  --wall: #c9b89a;
  --floor-a: #c56a4a;
  --floor-b: #b85d40;
  --static: #9a7b4f;
  --player: #3d9a5c;
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background:
    radial-gradient(1200px 520px at 12% -10%, rgba(255, 198, 120, 0.35), transparent 60%),
    radial-gradient(900px 480px at 90% 8%, rgba(123, 180, 212, 0.22), transparent 55%),
    linear-gradient(180deg, #fbf5ea 0%, var(--paper) 38%, #f3e7d4 100%);
  font-family: "Nunito", "Segoe UI", sans-serif;
  font-weight: 500;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image:
    linear-gradient(rgba(88, 63, 47, 0.5) 1px, transparent 1px),
    linear-gradient(90deg, rgba(88, 63, 47, 0.5) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(circle at 50% 20%, black, transparent 75%);
}

.hidden {
  display: none !important;
}

.view.gallery {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 0 0 4rem;
}

.hero {
  position: relative;
  min-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 0 4rem;
  text-align: center;
  animation: rise 0.7s ease both;
}

.hero-glow {
  position: absolute;
  inset: 10% 18% auto;
  height: 180px;
  background: radial-gradient(ellipse at center, rgba(224, 188, 60, 0.28), transparent 70%);
  filter: blur(8px);
  z-index: -1;
}

.brand {
  margin: 0;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: clamp(2.6rem, 7vw, 4.4rem);
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 0.95;
  color: var(--ink);
  text-shadow: 0 3px 0 rgba(255, 250, 242, 0.8);
}

.hero h1 {
  margin: 0.55rem 0 0;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: clamp(1.35rem, 3.2vw, 1.85rem);
  font-weight: 550;
  color: var(--ink-dim);
}

.lede {
  max-width: 34rem;
  margin: 0.9rem auto 0;
  font-size: 1.05rem;
  line-height: 1.45;
  color: var(--ink-dim);
}

.hero-actions {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.4rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.15rem;
  border: 3px solid var(--sticker);
  border-radius: 999px;
  background: var(--green);
  color: #fffdf8;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 1rem;
  font-weight: 560;
  text-decoration: none;
  box-shadow: 0 4px 0 var(--shadow);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--shadow);
}

.btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 0 var(--shadow);
}

.btn.primary {
  background: var(--green);
}

.btn.ghost {
  background: var(--sticker);
  color: var(--ink);
  border-color: rgba(88, 63, 47, 0.12);
}

.chapter-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: 0 0 2rem;
  padding-top: 0.5rem;
  scroll-margin-top: 1rem;
  animation: rise 0.7s ease 0.08s both;
}

.chapter-chip {
  padding: 0.4rem 0.8rem;
  border: 2px solid transparent;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.72);
  color: var(--ink-dim);
  font-family: "Nunito", sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.chapter-chip:hover {
  transform: translateY(-1px);
  background: var(--sticker);
  border-color: color-mix(in srgb, var(--chip, var(--green)) 55%, white);
}

.chapters {
  display: flex;
  flex-direction: column;
  gap: 2.75rem;
}

.chapter {
  scroll-margin-top: 1.25rem;
  animation: rise 0.65s ease both;
}

.chapter-head {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  margin-bottom: 1rem;
  padding-bottom: 0.55rem;
  border-bottom: 3px solid color-mix(in srgb, var(--chapter, var(--green)) 45%, transparent);
}

.chapter-head h2 {
  margin: 0;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 1.55rem;
  font-weight: 600;
}

.chapter-head .subtitle {
  color: var(--ink-dim);
  font-size: 0.95rem;
}

.chapter-head .count {
  margin-left: auto;
  color: var(--ink-dim);
  font-size: 0.82rem;
  font-weight: 700;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
}

.level-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.85rem;
  border: 3px solid var(--sticker);
  border-radius: var(--radius);
  background: var(--sticker);
  color: inherit;
  text-align: left;
  text-decoration: none;
  box-shadow: 0 5px 0 var(--shadow);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  animation: pop 0.45s ease both;
}

.level-card:hover {
  transform: translateY(-3px) rotate(-0.4deg);
  box-shadow: 0 8px 0 var(--shadow);
}

.level-card:focus-visible {
  outline: 3px solid var(--sky);
  outline-offset: 2px;
}

.level-card .thumb {
  display: block;
  width: 100%;
  aspect-ratio: 1.15;
  border-radius: 14px;
  background: #efe2cc;
}

.level-card .card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.level-card .num {
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--ink-dim);
}

.tier {
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--tier, var(--green)) 22%, white);
  color: color-mix(in srgb, var(--tier, var(--green)) 70%, var(--ink));
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tier[data-tier="tutorial"] { --tier: #86b86d; }
.tier[data-tier="easy"] { --tier: #7bb4d4; }
.tier[data-tier="medium"] { --tier: #e0bc3c; }
.tier[data-tier="hard"] { --tier: #e0614d; }
.tier[data-tier="expert"] { --tier: #6b5b8a; }

.level-card .name {
  margin: 0;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.15;
}

.level-card .detail {
  margin: 0;
  color: var(--ink-dim);
  font-size: 0.78rem;
  line-height: 1.35;
}

.site-footer {
  margin-top: 3.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  color: var(--ink-dim);
  font-size: 0.85rem;
  text-align: center;
}

.site-footer code {
  font-size: 0.8rem;
  color: var(--ink);
}

/* —— Detail view —— */
.view.detail {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  padding: 1.25rem 1rem 2.5rem;
  animation: rise 0.35s ease both;
}

.detail-shell {
  width: min(1100px, 100%);
  margin: 0 auto;
}

.back {
  margin-bottom: 1rem;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.kicker {
  margin: 0 0 0.25rem;
  color: var(--ink-dim);
  font-size: 0.82rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.detail-header h2 {
  margin: 0;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: clamp(1.7rem, 4vw, 2.3rem);
  font-weight: 650;
  line-height: 1.05;
}

.meta {
  margin: 0.35rem 0 0;
  color: var(--ink-dim);
  font-size: 0.95rem;
}

.banner {
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--coral) 18%, white);
  color: var(--coral);
  font-size: 0.82rem;
  font-weight: 750;
  white-space: nowrap;
}

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(240px, 0.8fr);
  gap: 1.1rem;
  align-items: start;
}

.canvas-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 420px;
  padding: 1rem;
  border: 3px solid var(--sticker);
  border-radius: calc(var(--radius) + 4px);
  background:
    linear-gradient(180deg, rgba(255, 250, 242, 0.95), rgba(243, 231, 212, 0.95));
  box-shadow: 0 6px 0 var(--shadow);
  overflow: hidden;
}

canvas#grid {
  display: block;
  max-width: 100%;
  max-height: min(70vh, 640px);
}

.move-label {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  padding: 0.4rem 0.95rem;
  border: 2px solid rgba(255, 250, 242, 0.9);
  border-radius: 999px;
  background: rgba(88, 63, 47, 0.82);
  color: #fff8ee;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 0.9rem;
  font-weight: 550;
  pointer-events: none;
}

.detail-side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 0.85rem;
  margin: 0;
  padding: 1rem 1.1rem;
  border: 3px solid var(--sticker);
  border-radius: var(--radius);
  background: var(--sticker);
  box-shadow: 0 5px 0 var(--shadow);
}

.facts dt {
  color: var(--ink-dim);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.facts dd {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.solution-panel {
  padding: 1rem 1.1rem 1.15rem;
  border: 3px solid var(--sticker);
  border-radius: var(--radius);
  background: var(--sticker);
  box-shadow: 0 5px 0 var(--shadow);
}

.solution-panel h3 {
  margin: 0;
  font-family: "Fredoka", "Nunito", sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
}

.solution-blurb {
  margin: 0.45rem 0 0.85rem;
  color: var(--ink-dim);
  font-size: 0.88rem;
  line-height: 1.4;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.transport {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.transport button {
  width: 2.35rem;
  height: 2.35rem;
  border: 2px solid rgba(88, 63, 47, 0.12);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.9rem;
}

.transport button:hover {
  border-color: var(--green-deep);
}

.transport button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.speed {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink-dim);
  font-size: 0.8rem;
  font-weight: 700;
}

.speed input {
  width: 100px;
}

.scrub {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.scrub input[type="range"] {
  flex: 1;
}

#frame-counter {
  color: var(--ink-dim);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-weight: 700;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.1rem;
  color: var(--ink-dim);
  font-size: 0.78rem;
  font-weight: 700;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(88, 63, 47, 0.15);
}

.swatch.player { background: var(--player); }
.swatch.door { background: var(--door); }
.swatch.static { background: #8a6a3e; }
.swatch.wall { background: #b9a88a; }

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

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 860px) {
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .chapter-head {
    flex-wrap: wrap;
  }

  .chapter-head .count {
    margin-left: 0;
  }
}

@media (max-width: 560px) {
  .view.gallery {
    width: min(1120px, calc(100% - 1.25rem));
  }

  .hero {
    min-height: calc(100svh - 1.5rem);
    padding: 2.5rem 0 3rem;
  }

  .level-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .level-card {
    padding: 0.65rem;
  }

  .level-card .name {
    font-size: 0.95rem;
  }
}
