/* Humanity: sky above, soil below. Deeper is older. */

:root {
  --sky-top: #9FC3CC;
  --sky-low: #E7D9B8;
  --leaf: #4E8A3E;
  --leaf-dark: #2F5E28;
  --ochre: #C8912E;
  --ochre-glow: #F0C667;
  --soil-0: #6B4528;
  --soil-1: #5A3920;
  --soil-2: #4A2E1A;
  --soil-3: #3C2515;
  --soil-4: #2F1C10;
  --soil-5: #24150B;
  --soil-text: #F1E4CC;
  --soil-muted: #C9B08C;
  --stone: #ECE6DA;
  --stone-2: #DDD4C3;
  --ink: #2A1D13;
  --ink-soft: #5B4A3A;
  --iron: #8A3A1E;
  --serif: 'Libre Caslon Text', 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --display: 'Libre Caslon Display', 'Libre Caslon Text', 'Iowan Old Style', Georgia, serif;
  --measure: 68ch;
  box-sizing: border-box;
}
*, *::before, *::after { box-sizing: inherit; }

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

body {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.7;
  color: var(--ink);
  background: var(--soil-5);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--ochre-glow); outline-offset: 3px; border-radius: 2px; }

.visually-hidden, .hp {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip { position: absolute; left: -9999px; top: 0; background: var(--stone); padding: .5rem 1rem; z-index: 50; }
.skip:focus { left: 1rem; top: 1rem; }

/* ---------- Top bar ---------- */
.topbar {
  position: absolute; inset: 0 0 auto 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: calc(env(safe-area-inset-top, 0px) + .9rem) clamp(1rem, 4vw, 2.5rem) .9rem;
  color: var(--ink);
}
.brand { font-family: var(--display); font-size: 1.25rem; text-decoration: none; }
.topbar nav { display: flex; gap: clamp(.8rem, 3vw, 1.8rem); font-size: .95rem; align-items: center; }
.topbar nav a { text-decoration: none; }
.topbar nav a:hover { text-decoration: underline; }
@media (max-width: 520px) { .topbar nav a:first-child { display: none; } }

.flash {
  position: relative; z-index: 11;
  max-width: 44rem; margin: 0 auto 2rem; padding: .9rem 1.2rem; text-align: left;
  background: var(--stone); border-left: 4px solid var(--leaf); color: var(--ink);
}
.flash-error { border-left-color: var(--iron); }

/* ---------- The tree ---------- */
.tree-stage {
  background: linear-gradient(to bottom, var(--sky-top) 0, var(--sky-low) 520px, var(--sky-low) 100%);
  overflow: hidden;
}
.sky {
  text-align: center;
  padding: calc(env(safe-area-inset-top, 0px) + 6.5rem) 1.25rem 0;
}
.sky h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(3.6rem, 13vw, 9.5rem);
  line-height: .9;
  letter-spacing: -.02em;
  margin: 0;
  color: var(--ink);
}
.tagline {
  font-style: italic;
  font-size: clamp(1.1rem, 2.4vw, 1.45rem);
  margin: .9rem auto 0;
  color: var(--ink-soft);
}

.tree-wrap { position: relative; max-width: 1100px; margin: 0 auto; }
#tree-svg { display: block; width: 100%; height: auto; overflow: visible; }
.tree-hint {
  position: absolute; left: 0; right: 0; bottom: .5rem;
  margin: 0; text-align: center; font-size: .9rem; font-style: italic; color: var(--soil-muted);
}

.stratum.s0 { fill: var(--soil-0); }
.stratum.s1 { fill: var(--soil-1); }
.stratum.s2 { fill: var(--soil-2); }
.stratum.s3 { fill: var(--soil-3); }
.stratum.s4 { fill: var(--soil-4); }
.stratum.s5 { fill: var(--soil-5); }
.pebble { fill: rgba(255, 235, 200, .07); }
.grass { fill: var(--leaf); }

.trunk { fill: #5B3A22; }
.root, .rootlet, .branch { fill: none; stroke-linecap: round; }
.root { stroke: var(--ochre); }
.rootlet { stroke: var(--ochre); opacity: .65; }
.branch { stroke: #5B3A22; }
.bud-stem { stroke-dasharray: 6 8; opacity: .7; }
.leaf { fill: var(--leaf); opacity: .92; }
.leaf:nth-child(3n) { fill: var(--leaf-dark); }

.now-label { font-family: var(--serif); font-style: italic; font-size: 19px; fill: var(--ink); }

.node { cursor: pointer; outline: none; }
.node-hit { fill: transparent; }
.node-dot { fill: var(--ochre); stroke: var(--soil-text); stroke-width: 3; transition: r .2s, fill .2s; }
.node-title { font-family: var(--display); fill: var(--soil-text); }
.node-period { font-family: var(--serif); font-style: italic; fill: var(--soil-muted); }
.node-future .node-title { fill: var(--ink); }
.node-future .node-period { fill: var(--ink-soft); }
.node-future .node-dot { fill: var(--leaf); }
.node:hover .node-dot, .node:focus-visible .node-dot, .node.active .node-dot { fill: var(--ochre-glow); r: 16; }
.node:focus-visible .node-hit { stroke: var(--ochre-glow); stroke-width: 3; }
.node.active .node-title { text-decoration: underline; }

.growing .node, .growing .leaf, .growing .now-label, .growing .bud { opacity: 0; }
.node, .leaf, .now-label, .bud { transition: opacity .8s ease; }

.bud { cursor: pointer; outline: none; }
.bud .bud-dot { fill: none; stroke: var(--leaf-dark); stroke-width: 3; stroke-dasharray: 5 5; }
.bud .node-title { fill: var(--ink); }
.bud:hover .bud-dot, .bud:focus-visible .bud-dot { fill: rgba(78, 138, 62, .25); }

/* Era index under the tree */
.era-index { background: var(--soil-5); color: var(--soil-text); padding: 1rem clamp(1rem, 4vw, 2.5rem) 3rem; }
.era-index ol {
  list-style: none; margin: 0 auto; padding: 0; max-width: 1100px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: .25rem 1.5rem;
}
.era-index button {
  width: 100%; text-align: left; background: none; border: 0; color: inherit; cursor: pointer;
  padding: .55rem 0; border-bottom: 1px solid rgba(241, 228, 204, .15); font: inherit;
  display: flex; flex-direction: column;
}
.era-index button:hover .t { text-decoration: underline; }
.era-index .t { font-family: var(--display); font-size: 1.1rem; }
.era-index .p { font-style: italic; font-size: .9rem; color: var(--soil-muted); }
.era-index .is-future .t { color: #A9D18E; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; z-index: 30; top: 0; right: 0; bottom: 0;
  width: min(34rem, 100%);
  background: var(--stone); color: var(--ink);
  padding: calc(env(safe-area-inset-top, 0px) + 2.5rem) clamp(1.25rem, 4vw, 2.5rem) calc(env(safe-area-inset-bottom, 0px) + 2rem);
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .35s cubic-bezier(.2, .7, .2, 1);
  box-shadow: -18px 0 40px rgba(20, 10, 4, .35);
  visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }
@media (max-width: 640px) {
  .drawer {
    top: auto; width: 100%; max-height: 82vh;
    transform: translateY(100%);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -18px 40px rgba(20, 10, 4, .35);
  }
}
.drawer-close {
  position: absolute; top: calc(env(safe-area-inset-top, 0px) + .75rem); right: .9rem;
  font-size: 2rem; line-height: 1; background: none; border: 0; cursor: pointer; color: var(--ink); padding: .2rem .5rem;
}
.drawer-period { margin: 0; font-style: italic; color: var(--ink-soft); }
.drawer h2 { font-family: var(--display); font-weight: 400; font-size: clamp(2rem, 5vw, 2.8rem); line-height: 1.05; margin: .3rem 0 1.2rem; }
.drawer-body p { margin: 0 0 1em; }
.drawer-nav { display: flex; justify-content: space-between; margin-top: 1.5rem; }

/* ---------- Buttons and forms ---------- */
.btn {
  font: inherit; font-size: 1rem; cursor: pointer;
  background: var(--leaf-dark); color: #F6F1E6; border: 0;
  padding: .7rem 1.3rem; border-radius: 999px;
}
.btn:hover { background: var(--leaf); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-quiet { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px currentColor; }
.btn-quiet:hover { background: rgba(42, 29, 19, .07); }
.linkish { background: none; border: 0; font: inherit; color: inherit; text-decoration: underline; cursor: pointer; padding: 0; }
form.inline { display: inline; }

label { display: block; margin: 0 0 1rem; font-size: .95rem; color: var(--ink-soft); }
input, textarea {
  display: block; width: 100%; margin-top: .3rem;
  font: inherit; font-size: 1rem; color: var(--ink);
  background: #FBF8F2; border: 1.5px solid var(--stone-2); border-radius: 6px; padding: .6rem .75rem;
}
input:focus, textarea:focus { border-color: var(--leaf); outline: none; box-shadow: 0 0 0 3px rgba(78, 138, 62, .2); }
.help { display: block; font-size: .85rem; margin-top: .3rem; font-style: italic; }
.form-status { min-height: 1.5em; margin: .8rem 0 0; }
.form-status.is-error { color: var(--iron); }

/* ---------- The written record ---------- */
.record { background: var(--stone); padding: clamp(3rem, 8vw, 6rem) clamp(1.25rem, 5vw, 3rem); }
.record-inner, .next-inner { max-width: 60rem; margin: 0 auto; }
.record h2, .next h2 {
  font-family: var(--display); font-weight: 400;
  font-size: clamp(2.4rem, 6vw, 4rem); line-height: 1; margin: 0 0 .6rem;
}
.lede { font-size: 1.2rem; max-width: var(--measure); color: var(--ink-soft); margin: 0 0 2.2rem; }

.chapter { border-top: 1px solid var(--stone-2); }
.chapter:last-of-type { border-bottom: 1px solid var(--stone-2); }
.chapter summary {
  cursor: pointer; list-style: none;
  font-family: var(--display); font-size: clamp(1.4rem, 3vw, 1.9rem);
  padding: 1.1rem 0; display: flex; gap: 1rem; align-items: baseline;
}
.chapter summary::-webkit-details-marker { display: none; }
.chapter summary::after { content: '+'; margin-left: auto; font-family: var(--serif); color: var(--ink-soft); }
.chapter[open] summary::after { content: '−'; }
.ch-n { font-family: var(--serif); font-size: 1rem; color: var(--iron); min-width: 1.2rem; }
.ch-body { padding: 0 0 2rem 2.2rem; max-width: calc(var(--measure) + 2.2rem); }
@media (max-width: 640px) { .ch-body { padding-left: 0; } }
.ch-body h4 { font-family: var(--display); font-weight: 400; font-size: 1.3rem; margin: 2rem 0 .4rem; }
.ch-body code { font-family: var(--serif); background: var(--stone-2); padding: .05em .35em; border-radius: 3px; white-space: nowrap; }
.alphabet { letter-spacing: .12em; }
.muted { color: var(--ink-soft); font-style: italic; }

.table-wrap { overflow-x: auto; margin: 1rem 0; }
table { border-collapse: collapse; width: 100%; font-size: .96rem; }
th, td { text-align: left; vertical-align: top; padding: .55rem .9rem .55rem 0; border-bottom: 1px solid var(--stone-2); }
thead th { font-weight: 700; font-size: .88rem; color: var(--ink-soft); border-bottom: 1.5px solid var(--ink-soft); }
tbody th { font-weight: 700; }
table.count { width: auto; }
table.count td { padding-right: 2rem; }
td.dots { color: var(--ochre); letter-spacing: .1em; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
table.built { min-width: 38rem; }

.picture-words {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(5.5rem, 1fr)); gap: 1rem;
  margin: 1rem 0; max-width: 40rem;
}
.picture-words figure { margin: 0; text-align: center; }
.picture-words svg {
  width: 3.4rem; height: 3.4rem; color: var(--ink);
  fill: currentColor; stroke: currentColor; stroke-width: 2.4; stroke-linejoin: round;
}
.picture-words figcaption { font-size: 1rem; }

.knew, .lessons { padding-left: 1.2rem; }
.knew li, .lessons li { margin-bottom: .7rem; }

.closing { margin-top: 3.5rem; max-width: var(--measure); font-size: 1.2rem; }
.closing .sign { font-style: italic; }

/* ---------- The next era ---------- */
.next { background: #DCE3CF; padding: clamp(3rem, 8vw, 6rem) clamp(1.25rem, 5vw, 3rem); }
.next-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: clamp(2rem, 5vw, 4rem); align-items: start; }
@media (max-width: 820px) { .next-grid { grid-template-columns: 1fr; } }
.next h3 { font-family: var(--display); font-weight: 400; font-size: 1.6rem; margin: 0 0 1rem; }

.propose { background: #F4F2EA; padding: clamp(1.25rem, 3vw, 2rem); border-radius: 10px; }

.proposal-list { list-style: none; margin: 0; padding: 0; }
.proposal { padding: 1.2rem 0 1.4rem; border-top: 1px solid rgba(42, 29, 19, .18); }
.proposal h4 { font-family: var(--display); font-weight: 400; font-size: 1.45rem; margin: 0; line-height: 1.2; }
.proposal .period { margin: .1rem 0 .5rem; font-style: italic; color: var(--ink-soft); }
.proposal p { margin: 0 0 .6rem; }
.proposal details summary { cursor: pointer; color: var(--leaf-dark); margin-bottom: .6rem; }
.story { white-space: normal; margin-bottom: .8rem; }
.meter { height: 8px; background: rgba(42, 29, 19, .12); border-radius: 999px; overflow: hidden; margin: .8rem 0 .4rem; }
.meter span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--ochre), var(--leaf)); border-radius: inherit; }
.count { font-size: .95rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.empty { font-style: italic; color: var(--ink-soft); }

/* ---------- Dialog ---------- */
dialog {
  border: 0; border-radius: 12px; padding: clamp(1.25rem, 4vw, 2rem);
  max-width: 26rem; width: calc(100% - 2rem);
  background: var(--stone); color: var(--ink);
}
dialog::backdrop { background: rgba(36, 21, 11, .6); }
dialog h3 { font-family: var(--display); font-weight: 400; font-size: 1.6rem; margin: 0 0 .5rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .7rem; }

/* ---------- Footer ---------- */
.foot {
  background: var(--soil-5); color: var(--soil-muted); text-align: center;
  padding: 2.5rem 1.25rem calc(env(safe-area-inset-bottom, 0px) + 2.5rem); font-size: .95rem;
}
.foot a { color: var(--soil-text); }
.foot .small { font-size: .85rem; max-width: 40rem; margin: .6rem auto 0; }

/* ---------- Keepers (admin) ---------- */
body.admin { background: var(--stone); }
body.admin .topbar { position: static; }
.admin-main { max-width: 52rem; margin: 0 auto; padding: 1rem clamp(1.25rem, 5vw, 3rem) 4rem; }
.admin-main h1 { font-family: var(--display); font-weight: 400; font-size: 2.8rem; margin: 1rem 0 .5rem; }
.admin-main h2 { font-family: var(--display); font-weight: 400; font-size: 1.7rem; margin: 2.5rem 0 .8rem; }
.admin-main .flash { margin: 1rem 0; }
.login { max-width: 26rem; }
.stats { color: var(--ink-soft); }
.who { font-size: .9rem; color: var(--ink-soft); }
.admin-list { list-style: none; padding: 0; margin: 0; }
.admin-list li { border-top: 1px solid var(--stone-2); padding: 1rem 0; }
.admin-list h3 { font-family: var(--display); font-weight: 400; font-size: 1.35rem; margin: 0; }
.admin-list .period { margin: 0 0 .4rem; font-style: italic; color: var(--ink-soft); font-size: .95rem; }
.tag { font-family: var(--serif); font-size: .8rem; background: var(--stone-2); padding: .1rem .5rem; border-radius: 999px; vertical-align: middle; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .6rem; }
