/* Enchanted Grove palette (night sky, lantern gold, violet mist). */
:root {
  --bg: #07060d;
  --panel: rgba(20, 16, 36, 0.72);
  --line: rgba(242, 200, 107, 0.18);
  --text: #ece6f7;
  --muted: #a99cc7;
  --gold: #f2c86b;
  --gold-soft: #f7e4b0;
  --mist: #8e6cf0;
  --leaf: #7ff2d0;
  --flower: #f7a8c9;
  --seed: #f2c86b;
  --done: #f7e4b0;
  --accent: #f7e4b0;
  --error: #ff9b9b;
  --title: "Cinzel", Georgia, serif;
  --display: "Cormorant Garamond", Georgia, serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); color-scheme: dark; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "DM Sans", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  color: var(--text);
  background:
    radial-gradient(ellipse 60% 55% at 50% 52%, rgba(142, 108, 240, 0.22), transparent 70%),
    radial-gradient(ellipse 90% 60% at 50% 110%, rgba(242, 200, 107, 0.08), transparent 70%),
    var(--bg) fixed;
  overflow-x: hidden;
  display: flex; flex-direction: column; min-height: 100vh;
}
code { background: rgba(242, 200, 107, .1); color: var(--gold-soft); padding: 1px 6px; border-radius: 5px; font-size: .92em; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }
a, button { touch-action: manipulation; }

header {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 16px 20px; position: relative; z-index: 2; border-bottom: 1px solid rgba(242, 200, 107, .12);
}
.brand { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; }
.logo { width: 30px; height: 30px; color: var(--gold); filter: drop-shadow(0 0 8px rgba(242, 200, 107, .5)); flex: none; }
.wordmark {
  display: block; font-family: var(--title); font-size: 20px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .18em; color: var(--gold-soft); text-shadow: 0 0 18px rgba(242, 200, 107, .35);
}
.sub { display: block; color: var(--muted); font-size: 13px; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select, input, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 12px;
}
button {
  font: inherit; font-size: 14px; cursor: pointer; color: var(--gold-soft);
  background: rgba(242, 200, 107, .06); border: 1px solid rgba(242, 200, 107, .45);
  border-radius: 999px; padding: 7px 16px; transition: background .2s, box-shadow .2s;
}
button:hover, button:focus-visible { background: rgba(242, 200, 107, .14); box-shadow: 0 0 18px rgba(242, 200, 107, .25); }
button.primary { background: var(--gold); border-color: var(--gold); color: #1a1408; font-weight: 500; }
button.primary:hover, button.primary:focus-visible { background: var(--gold-soft); }
:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 3px; }

.view { position: relative; z-index: 1; flex: 1; }
h1 { font-family: var(--display); font-style: italic; font-weight: 600; color: var(--gold-soft); }
h2 { font-family: var(--title); font-weight: 500; text-transform: uppercase; letter-spacing: .14em; color: var(--gold-soft); }
.lead { color: var(--text); font-size: 16px; margin-top: 4px; }

/* ---------- gate ---------- */
.gateCard {
  max-width: 560px; margin: 6vh auto 0; padding: 32px 24px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; backdrop-filter: blur(10px);
  box-shadow: 0 0 80px rgba(142, 108, 240, .12);
}
.gateCard h1 { font-size: clamp(34px, 7vw, 52px); line-height: 1.1; margin: 0; }
#codeForm { display: flex; gap: 8px; margin-top: 20px; }
#codeInput {
  flex: 1; min-width: 0; font-size: 20px; letter-spacing: 2px; text-align: center; text-transform: uppercase;
  padding: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--gold-soft);
}
#codeInput:focus { border-color: rgba(242, 200, 107, .6); }
#codeForm button { padding: 10px 20px; }
.error { color: var(--error); min-height: 1.2em; margin: 8px 0 0; }
.hint { color: var(--muted); font-size: 14px; line-height: 1.6; }
#saved h2 { font-size: 13px; margin: 22px 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 0; border-radius: 999px; overflow: hidden; }
.chip button { border: 0; border-radius: 0; background: transparent; padding: 6px 12px; box-shadow: none; }
.chip button.x { padding: 6px 10px 6px 4px; color: var(--muted); }
.chip { border: 1px solid rgba(242, 200, 107, .45); background: rgba(242, 200, 107, .06); }

.how {
  max-width: 980px; margin: 40px auto 0; padding: 0 16px;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px;
}
.how div { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; backdrop-filter: blur(10px); }
.how span { font-size: 26px; }
.how b { display: block; margin: 6px 0 4px; font-family: var(--display); font-style: italic; font-size: 21px; font-weight: 600; color: var(--gold-soft); }
.how p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }

.builtWith { max-width: 980px; margin: 40px auto 32px; padding: 0 16px; }
.builtWith h2 { font-size: 16px; text-align: center; }
.tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 12px; }
.tool { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; backdrop-filter: blur(10px); }
.tool b { display: flex; align-items: center; gap: 8px; }
.tool p { margin: 6px 0 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.pill { font-size: 11px; font-weight: 500; padding: 1px 8px; border-radius: 999px; margin-left: auto; }
.pill.on { background: var(--gold); color: #1a1408; }
.pill.off { background: rgba(255,255,255,.06); color: var(--muted); }

/* ---------- grove ---------- */
.groveHead { text-align: center; padding: 8px 16px 0; }
.groveHead h1 { margin: 0; font-size: clamp(32px, 6vw, 52px); }
.groveTrees {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-end; align-content: flex-end; gap: 16px 0;
  max-width: 1200px; min-height: 58vh; margin: 12px auto 0; padding: 0 16px; position: relative; z-index: 1;
}
.groveTree {
  background: none; border: 0; padding: 0 0 8px; width: 300px; max-width: 48vw; text-align: center;
  border-radius: 20px; transition: transform .3s, background .3s; color: var(--text);
}
.groveTree:hover, .groveTree:focus-visible { transform: translateY(-6px); background: rgba(142, 108, 240, .1); box-shadow: none; }
.groveTree svg { width: 100%; height: auto; display: block; }
.groveTree b { display: block; font-family: var(--display); font-style: italic; font-size: 22px; font-weight: 600; color: var(--gold-soft); }
.groveTree span { font-size: 12px; color: var(--muted); }
.groveGround {
  height: 120px; margin-top: -96px; position: relative; z-index: 0;
  background: radial-gradient(55% 100% at 50% 20%, rgba(242, 200, 107, .14), transparent 70%);
}

/* ---------- tree ---------- */
main {
  display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px;
  padding: 16px 20px 24px;
}
@media (max-width: 900px) { main { grid-template-columns: 1fr; padding: 16px 16px 24px; } }
.treeWrap { position: relative; }
.treeTitle {
  text-align: center; margin: 0; font-family: var(--title); font-style: normal; font-weight: 500;
  text-transform: uppercase; letter-spacing: .18em; font-size: clamp(18px, 3.4vw, 26px);
  text-shadow: 0 0 18px rgba(242, 200, 107, .35);
}
#tree { width: 100%; height: auto; max-height: calc(100vh - 160px); display: block; transform-origin: 50% 100%; animation: sway 12s ease-in-out infinite; }
@keyframes sway { 0%, 100% { transform: rotate(-.6deg); } 50% { transform: rotate(.6deg); } }
.legend { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; font-size: 13px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.dot.leaf { background: var(--leaf); box-shadow: 0 0 8px var(--leaf); }
.dot.flower { background: var(--flower); box-shadow: 0 0 8px var(--flower); }
.dot.seed { background: var(--seed); box-shadow: 0 0 8px var(--seed); }
.dot.done { background: var(--done); box-shadow: 0 0 8px var(--done); }

#tooltip {
  position: absolute; pointer-events: none; max-width: 260px; padding: 10px 12px; font-size: 13px;
  background: rgba(20, 16, 36, .95); border: 1px solid var(--line); border-radius: 12px; z-index: 5;
  backdrop-filter: blur(10px);
}
#tooltip b { display: block; margin-bottom: 4px; font-family: var(--display); font-style: italic; font-size: 18px; font-weight: 600; color: var(--gold-soft); line-height: 1.25; }

aside {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px;
  backdrop-filter: blur(10px); align-self: start; max-height: calc(100vh - 110px); overflow: auto;
}
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: rgba(242, 200, 107, .05); border: 1px solid rgba(242, 200, 107, .1); border-radius: 10px; padding: 8px 4px; text-align: center; }
.stat b { display: block; font-size: 22px; font-weight: 500; color: var(--gold-soft); }
.stat span { font-size: 11px; color: var(--muted); }
aside h3 { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .14em; color: var(--gold); margin: 16px 0 6px; font-family: inherit; }
aside ul { list-style: none; padding: 0; margin: 0; }
aside li { padding: 8px 0; border-bottom: 1px solid rgba(242, 200, 107, .1); font-size: 14px; }
aside li .meta { display: block; font-size: 12px; color: var(--muted); }
aside li.done { opacity: .6; text-decoration: line-through; }
.badge { font-size: 11px; padding: 1px 8px; border-radius: 999px; border: 1px solid rgba(242, 200, 107, .45); color: var(--gold-soft); margin-left: 4px; }
.privacy { font-size: 12px; color: var(--muted); margin-top: 14px; line-height: 1.6; }
.rings svg { width: 100%; height: auto; display: block; }
.rings .src { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); }
.rings .empty { fill: var(--muted); font-size: 11px; }

/* tree nodes */
.node { cursor: pointer; transition: transform .3s; transform-box: fill-box; transform-origin: center; }
.node:hover { transform: scale(1.35); }
.node.new { animation: grow 600ms cubic-bezier(.2, .9, .3, 1.2) both, bloomGlow 1200ms ease-out both; }
@keyframes grow { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes bloomGlow {
  0% { filter: brightness(2); }
  40% { filter: drop-shadow(0 0 10px var(--gold)) brightness(1.6); }
  100% { filter: none; }
}
.glow { animation: pulse 3.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .75; } 50% { opacity: 1; } }
.branchLabel {
  font-family: var(--display); font-style: italic; font-weight: 600; font-size: 20px;
  paint-order: stroke; stroke: var(--bg); stroke-opacity: .75; stroke-width: 3px; stroke-linejoin: round;
}

footer {
  position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between;
  padding: 14px 20px; font-size: 12px; color: var(--muted); border-top: 1px solid rgba(242, 200, 107, .12);
}

/* stars + fireflies */
#stars, #fireflies { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.star { position: absolute; width: 2px; height: 2px; border-radius: 50%; background: #fff8e1; animation: twinkle 4s ease-in-out infinite; }
@keyframes twinkle { 0%, 100% { opacity: .15; } 50% { opacity: .9; } }
.ff { position: absolute; width: 4px; height: 4px; border-radius: 50%; background: var(--gold);
  box-shadow: 0 0 10px 2px var(--gold); opacity: 0; animation: drift linear infinite; }
@keyframes drift {
  0% { transform: translate(0, 0); opacity: 0; }
  20% { opacity: .9; }
  80% { opacity: .7; }
  100% { transform: translate(var(--dx), -120px); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .ff, .star, .glow, .node.new, #tree { animation: none; } .groveTree { transition: none; } }

dialog {
  background: #141024; color: var(--text); border: 1px solid var(--line); border-radius: 18px;
  width: min(560px, calc(100vw - 32px)); box-shadow: 0 0 60px rgba(142, 108, 240, .2);
}
dialog::backdrop { background: rgba(7, 6, 13, .7); backdrop-filter: blur(2px); }
dialog h2 { margin-top: 0; }
dialog label { display: block; margin: 10px 0; font-size: 14px; }
dialog input:not([type=file]), dialog textarea { width: 100%; margin-top: 4px; }
.row { display: flex; gap: 8px; justify-content: flex-end; }

@media (max-width: 640px) {
  button { padding: 6px 13px; font-size: 13px; }
  .wordmark { font-size: 16px; }
}
