:root {
  --depth: 0;               /* 0 at the surface → 1 deep underground */
  --soil: #2a1f17;
  --soil-deep: #0c0907;
  --paper: #f6eedf;
  --paper-2: #ece0c9;
  --ink: #2b211a;
  --ink-soft: #6b5a4b;
  --accent: #e2722f;
  --accent-ink: #fff7ef;
  --glow: #ffc98a;
  --good: #2f8a57;
  --bad: #b8432f;
  --radius: 18px;
  --font-head: "Fraunces", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--paper);
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(255, 201, 138, calc(0.22 - var(--depth) * 0.18)), transparent 70%),
    linear-gradient(180deg,
      color-mix(in srgb, var(--soil) calc(100% - var(--depth) * 100%), var(--soil-deep)) 0%,
      var(--soil-deep) 100%);
  background-attachment: fixed;
  transition: background 0.8s ease;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(180deg, rgba(12, 9, 7, 0.85), rgba(12, 9, 7, 0));
  backdrop-filter: blur(6px);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; padding: 0;
  font-family: var(--font-head); font-weight: 700; font-size: 18px; letter-spacing: 0.2px;
}
.brand em { font-style: italic; color: var(--glow); }
.hole {
  width: 26px; height: 16px; border-radius: 50%;
  background: radial-gradient(closest-side, #000 55%, #3b2a1e 80%, transparent 100%);
  box-shadow: 0 0 0 2px #5a412f inset;
}
.depth {
  display: flex; align-items: baseline; gap: 5px;
  padding: 7px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.14);
}
.depth-num { font-family: var(--font-head); font-weight: 900; font-size: 18px; color: var(--glow); font-variant-numeric: tabular-nums; }
.depth-label { font-size: 12px; opacity: 0.75; }

/* ---------- main ---------- */
main { max-width: 680px; margin: 0 auto; padding: 4px 16px 64px; }
main.down { animation: fall 0.55s cubic-bezier(.2, .8, .2, 1); }
main.up { animation: rise 0.45s cubic-bezier(.2, .8, .2, 1); }
@keyframes fall { from { opacity: 0; transform: translateY(60px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(-40px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { main.down, main.up { animation: none; } }

.kicker, .meta {
  font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--glow); margin: 0 0 8px;
}

/* ---------- surface ---------- */
.surface { padding-top: 24px; }
.surface h1 {
  font-family: var(--font-head); font-weight: 900; font-size: clamp(40px, 11vw, 64px);
  line-height: 0.98; margin: 0 0 14px;
}
.lede { font-size: 17px; line-height: 1.55; color: #e7dccb; margin: 0 0 24px; max-width: 34em; }
.entrances { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.entrance {
  position: relative; overflow: hidden; text-align: left;
  min-height: 190px; padding: 0; border: 0; border-radius: var(--radius);
  background: #3a2a1f; display: flex; align-items: flex-end;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s ease;
}
.entrance:active { transform: scale(0.97); }
.entrance-img {
  position: absolute; inset: 0; background-size: cover; background-position: center;
  filter: saturate(0.85);
}
.entrance-img::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0) 20%, rgba(12, 9, 7, 0.92) 100%);
}
.entrance-text { position: relative; padding: 14px; }
.entrance-text .meta { display: block; margin-bottom: 4px; font-size: 11px; }
.entrance-title { font-family: var(--font-head); font-weight: 700; font-size: 17px; line-height: 1.15; }

/* ---------- node card ---------- */
.card {
  background: var(--paper); color: var(--ink);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
.hero {
  margin: 0; height: 240px; position: relative;
  background: linear-gradient(135deg, #4a3526, #2a1f17) center / cover no-repeat;
}
.hero.loaded { animation: fadeIn 0.6s ease; }
@keyframes fadeIn { from { opacity: 0.4; } to { opacity: 1; } }
.hero-shade { position: absolute; inset: auto 0 0 0; height: 60px; background: linear-gradient(180deg, transparent, var(--paper)); }
.card-body { padding: 4px 20px 22px; }
.card .meta { color: var(--accent); }
.card h1 {
  font-family: var(--font-head); font-weight: 900; font-size: clamp(28px, 7vw, 38px);
  line-height: 1.05; margin: 0 0 14px;
}
.card p { font-size: 17px; line-height: 1.6; margin: 0 0 14px; }
.whoa {
  margin: 18px 0; padding: 14px 16px; border-radius: 14px;
  background: #fff6e2; border-left: 4px solid var(--accent);
  font-size: 16px; line-height: 1.5;
}
.whoa-tag {
  display: block; font-family: var(--font-head); font-weight: 900; font-style: italic;
  color: var(--accent); font-size: 18px; margin-bottom: 4px;
}

.quiz { margin: 18px 0; padding: 14px 16px; border-radius: 14px; background: var(--paper-2); }
.quiz-q { font-weight: 600; margin: 0 0 10px !important; font-size: 16px !important; }
.quiz-opts { display: grid; gap: 8px; }
.quiz-opts button {
  text-align: left; padding: 11px 14px; border-radius: 10px;
  background: #fffaf1; border: 1px solid #d8c8ac; color: var(--ink);
}
.quiz.done .quiz-opts button { cursor: default; }
.quiz-opts .right { background: var(--good); color: #fff; border-color: var(--good); }
.quiz-opts .right::after { content: "  ✓"; }
.quiz-opts .wrong { background: var(--bad); color: #fff; border-color: var(--bad); }

.links { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.links a {
  padding: 9px 14px; border-radius: 999px; text-decoration: none; font-weight: 600; font-size: 14px;
  color: var(--ink); background: var(--paper-2);
}

/* ---------- branches ---------- */
.branches { margin-top: 26px; }
.branches h2 { font-family: var(--font-head); font-size: 24px; margin: 0 0 12px; }
.branches h2 span { color: var(--glow); display: inline-block; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(4px); } }
.tunnel-choice {
  width: 100%; text-align: left; margin-bottom: 10px;
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px 18px 16px 54px; position: relative;
  border-radius: var(--radius); border: 1px solid rgba(255, 201, 138, 0.25);
  background: linear-gradient(90deg, rgba(255, 201, 138, 0.12), rgba(255, 255, 255, 0.03));
  transition: transform 0.15s ease, background 0.2s ease;
}
.tunnel-choice::before {
  content: ""; position: absolute; left: 16px; top: 50%; translate: 0 -50%;
  width: 24px; height: 15px; border-radius: 50%;
  background: radial-gradient(closest-side, #000 55%, #5a412f 85%, transparent 100%);
}
.tunnel-choice:hover { background: linear-gradient(90deg, rgba(255, 201, 138, 0.2), rgba(255, 255, 255, 0.05)); }
.tunnel-choice:active { transform: scale(0.98); }
.tc-teaser { font-family: var(--font-head); font-weight: 700; font-size: 18px; line-height: 1.25; }
.tc-meta { font-size: 12px; opacity: 0.7; }
.tunnel-choice.explored { opacity: 0.55; }

.row { display: flex; gap: 10px; margin-top: 16px; }
.row > * { flex: 1; }
.climb, .jump {
  padding: 14px 16px; border-radius: 999px; font-weight: 600; font-size: 15px;
}
.climb { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.18); }
.jump { background: var(--accent); color: var(--accent-ink); border: 0; box-shadow: 0 8px 24px rgba(226, 114, 47, 0.35); }
.jump.big { width: 100%; font-size: 17px; padding: 16px; }

/* ---------- tunnel drawer ---------- */
.tunnel {
  position: fixed; z-index: 20; right: 0; top: 0; bottom: 0; width: min(360px, 88vw);
  background: #120d0a; border-left: 1px solid rgba(255, 255, 255, 0.1);
  padding: max(16px, env(safe-area-inset-top)) 18px 24px; overflow-y: auto;
  box-shadow: -20px 0 40px rgba(0, 0, 0, 0.5);
  animation: slideIn 0.25s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: none; } }
.tunnel-head { display: flex; justify-content: space-between; align-items: center; }
.tunnel h2 { font-family: var(--font-head); margin: 0; }
.ghost { background: none; border: 0; font-size: 18px; padding: 6px; }
#trail { list-style: none; margin: 18px 0 0; padding: 0 0 0 14px; border-left: 2px dashed rgba(255, 201, 138, 0.35); }
#trail li { position: relative; margin: 0 0 6px; }
#trail li::before {
  content: ""; position: absolute; left: -21px; top: 14px;
  width: 12px; height: 12px; border-radius: 50%; background: #5a412f;
}
#trail li.here::before { background: var(--accent); box-shadow: 0 0 0 4px rgba(226, 114, 47, 0.3); }
#trail li.jumped { margin-top: 18px; }
#trail li.jumped::after {
  content: "⤳ jumped to a new hole"; position: absolute; top: -16px; left: 0;
  font-size: 11px; color: var(--glow); opacity: 0.8;
}
#trail button {
  width: 100%; text-align: left; background: none; border: 0; padding: 8px 6px; border-radius: 10px;
  display: flex; flex-direction: column; gap: 2px;
}
#trail button:hover { background: rgba(255, 255, 255, 0.06); }
.t-lvl { font-size: 11px; color: var(--glow); font-weight: 600; }
.t-title { font-size: 15px; line-height: 1.3; }
#trail .empty { opacity: 0.7; font-size: 14px; }

@media (max-width: 380px) {
  .entrances { grid-template-columns: 1fr; }
  .row { flex-direction: column; }
}
