:root {
  --soil: #101910;
  --loam: #16211b;
  --ink: #e6f0e4;
  --dim: #b7c9b8;
  --leaf: #9cbf72;
  --young: #dbe6a6;
  --pollen: #f2d48a;
  --xylem: #d49268;
  --spore: #9ed6d0;
  --line: rgba(230, 240, 228, 0.16);
  --font-display: "Fraunces", "Iowan Old Style", Palatino, serif;
  --font-ui: "Schibsted Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--soil);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;
  overscroll-behavior: none;
}

button, summary, a { font: inherit; }

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.world {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  position: relative;
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  z-index: 0;
}

.hud {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(to bottom, rgba(12, 20, 16, 0.92), rgba(12, 20, 16, 0));
  pointer-events: none;
}

.brand { min-width: 0; pointer-events: none; }
.brand h1,
.brand p { pointer-events: none; }

.brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 2rem;
  letter-spacing: -0.03em;
  line-height: 1;
}

.brand p {
  margin: 6px 0 0;
  max-width: 36ch;
  color: var(--dim);
}

.roster {
  position: relative;
  margin-top: 8px;
  pointer-events: auto;
  width: max-content;
  max-width: min(280px, calc(100vw - 140px));
}

.roster summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  width: max-content;
  color: var(--ink);
}

.roster summary:hover { color: var(--pollen); }

#rosterBody {
  position: absolute;
  left: 0;
  top: calc(100% - 6px);
  width: min(280px, calc(100vw - 32px));
  max-height: 34vh;
  overflow: auto;
  background: var(--loam);
  border: 1px solid var(--line);
  padding: 6px;
  z-index: 6;
}

.roster button {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.roster button:hover { background: rgba(242, 212, 138, 0.12); }

.roster button[aria-current="true"] {
  background: var(--pollen);
  color: #241c0e;
}

.roster .empty {
  margin: 0;
  padding: 8px 10px 12px;
  color: var(--dim);
}

.meters {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
  pointer-events: none;
}

.meters p { margin: 0; }

#bestMeter, #canopyMeter { color: var(--dim); font-size: 0.92rem; }
#canopyMeter { color: var(--pollen); }

.season-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

progress {
  appearance: none;
  width: 92px;
  height: 4px;
  border: 0;
  background: rgba(230, 240, 228, 0.16);
  border-radius: 99px;
  overflow: hidden;
}

progress::-webkit-progress-bar {
  background: rgba(230, 240, 228, 0.16);
  border-radius: 99px;
}

progress::-webkit-progress-value { background: var(--pollen); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--pollen); }

.stage {
  position: relative;
  z-index: 2;
  min-height: 0;
  pointer-events: none;
}

.hint,
.card,
.toast { pointer-events: auto; }

.hint {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: min(42ch, calc(100% - 24px));
  background: rgba(16, 25, 16, 0.92);
  border: 1px solid var(--line);
  padding: 10px 12px;
}

.hint p { margin: 0; }

.hint button:not([hidden]) {
  margin-top: 8px;
}

.card {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: min(280px, calc(100% - 24px));
  max-height: min(360px, calc(100% - 24px));
  overflow: auto;
  background: var(--loam);
  border: 1px solid var(--line);
  padding: 14px 14px 12px;
}

.card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  line-height: 1;
}

.epithet {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 500;
  color: var(--pollen);
}

.blurb, .meta, .note { margin: 8px 0 0; }
.blurb, .meta, .note, .hint p { color: var(--dim); }
.meta { color: var(--ink); }

.fields {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

.fields li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  border-top: 1px solid var(--line);
}

.fields .key { color: var(--ink); }
.fields .type { color: var(--dim); text-align: right; }

.field-link {
  background: transparent;
  border: 0;
  color: var(--spore);
  cursor: pointer;
  min-height: 44px;
  padding: 0;
  text-align: right;
}

.field-link:hover { color: var(--ink); }

.toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(440px, calc(100% - 24px));
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 25, 16, 0.94);
  border: 1px solid var(--line);
  padding: 6px 8px 6px 14px;
  z-index: 4;
}

.toast[hidden],
.hint[hidden],
.card[hidden],
#hintAction[hidden],
#toastUndo[hidden],
#bestMeter[hidden],
#canopyMeter[hidden],
.note[hidden] {
  display: none !important;
}

.tools {
  position: relative;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(12, 20, 16, 0.94), rgba(12, 20, 16, 0));
  pointer-events: none;
}

.toolbar, .quiet {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  pointer-events: none;
}

.tool, .danger, .hint button, #toastUndo {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(16, 25, 16, 0.72);
  color: var(--ink);
  cursor: pointer;
  pointer-events: auto;
}

.tool:hover, .danger:hover, .hint button:hover, #toastUndo:hover {
  border-color: var(--pollen);
}

.tool:active, .danger:active { transform: translateY(1px); }

.tool[aria-pressed="true"] {
  background: var(--pollen);
  color: #241c0e;
  border-color: transparent;
}

.world[data-paused="true"] .toolbar .tool { opacity: 0.55; }
.world[data-paused="true"] .toolbar .tool[aria-pressed="true"] { opacity: 1; }

.text-btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  background: transparent;
  border: 0;
  color: var(--dim);
  text-decoration: none;
  cursor: pointer;
  pointer-events: auto;
}

.text-btn:hover { color: var(--ink); }

.danger {
  color: #ffd7d4;
  background: #3c2426;
  border-color: #6e3d40;
}

dialog {
  border: 1px solid var(--line);
  background: var(--loam);
  color: var(--ink);
  max-width: min(460px, calc(100vw - 32px));
  max-height: min(80dvh, 640px);
  overflow: auto;
  padding: 22px;
}

dialog::backdrop { background: rgba(6, 10, 8, 0.72); }

dialog h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.8rem;
  letter-spacing: -0.03em;
}

dialog p, dialog li { color: var(--dim); }
dialog ul { margin: 0 0 12px; padding-left: 1.1rem; }
dialog li { margin: 6px 0; }
dialog a { color: var(--spore); }

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

#helpClose { margin-top: 8px; }

noscript p {
  padding: 24px;
  max-width: 40ch;
}

@media (max-width: 720px) {
  .brand h1 { font-size: 1.6rem; }
  .tool, .danger { padding: 0 12px; }
  .meters { font-size: 0.92rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
