/*
VOICE: a builder's workbench, practical and calm; the tree is the hero.
IDEA: a forester's survey tablet: species tags, stamped seed numbers, marking-paint orange.
PICTURE: the live 3D tree fills the stage, standing on its own patch of ground.
COLOUR and TYPE: deep forest green ground, bark brown support, marking-paint orange accent; Barlow Semi Condensed + Barlow.
LAYOUT: controls column on the left, stage on the right; below 760px: title, stage, controls.
*/
:root {
  color-scheme: light dark;
  --bg: light-dark(#eef1e8, #0f1c17);
  --panel: light-dark(#fbfcf8, #13241e);
  --panel-2: light-dark(#f1f4ec, #192d26);
  --ink: light-dark(#16251d, #e7efe5);
  --muted: light-dark(#59695f, #9bb0a2);
  --line: light-dark(#d8dfd2, #27392f);
  --accent: light-dark(#d9521c, #ff7a3d);
  --accent-ink: light-dark(#ffffff, #1a0c04);
  --bark: light-dark(#6d5434, #b38c5c);
  --sky-top: light-dark(#b9d6e6, #0a1613);
  --sky-bottom: light-dark(#eef3e6, #1f3a2f);
  --ground: light-dark(#78a34b, #2f4a26);
  --grid: light-dark(#5f8a37, #3e5f31);
  --sky: light-dark(#d3e5ec, #20352d);
  --error: light-dark(#b3261e, #ff8a80);
  --ok: light-dark(#2e6b2f, #8fd18f);
  --radius: 10px;
}
:root[data-theme=light] { color-scheme: light; }
:root[data-theme=dark] { color-scheme: dark; }
* { box-sizing: border-box; min-width: 0; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 Barlow, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, summary { font-family: "Barlow Semi Condensed", Barlow, system-ui, sans-serif; }

.app {
  display: grid; height: 100dvh;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "brand stage" "controls stage";
}
.brand { grid-area: brand; padding: 18px 20px 12px; background: var(--panel); border-right: 1px solid var(--line); }
.brand h1 { margin: 0; font-size: 30px; line-height: 1.05; font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; }
.brand p { margin: 6px 0 0; color: var(--muted); }

.controls {
  grid-area: controls; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line);
  padding: 0 20px; display: flex; flex-direction: column; overscroll-behavior: contain;
}
.species h2 { margin: 6px 0 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--panel-2); cursor: pointer;
}
.chips button:hover { border-color: var(--muted); }
.chips button[aria-pressed=true] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
.dot { width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .2); }
.seed-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center; margin: 12px 0 6px; }
.seed-row label { font-weight: 600; }

.group { border-top: 1px solid var(--line); }
.group summary {
  list-style: none; cursor: pointer; padding: 12px 0; font-size: 18px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
}
.group summary::-webkit-details-marker { display: none; }
.group summary::after { content: ""; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg) translateY(-3px); transition: transform .15s; }
.group[open] summary::after { transform: rotate(-135deg) translateY(-2px); }
.rows { display: grid; gap: 12px; padding-bottom: 16px; }

.row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; }
.row > label { font-weight: 500; }
.row > input, .row > select, .row > .block-input, .row > .hint, .row > .field-note, .row > .code-row { grid-column: 1 / -1; }
.row output { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; text-align: right; }
.row.dim { opacity: .45; }
.row.invalid input { border-color: var(--error); }
.hint, .field-note { font-size: 13px; color: var(--muted); }
.field-note:empty { display: none; }

input:not([type]), input[type=text], select {
  width: 100%; min-height: 40px; padding: 7px 10px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2);
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
input:focus-visible, select:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=range] { width: 100%; height: 28px; margin: 0; background: transparent; appearance: none; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: var(--line); }
input[type=range]::-moz-range-track { height: 6px; border-radius: 3px; background: var(--line); }
input[type=range]::-webkit-slider-thumb { appearance: none; width: 20px; height: 20px; margin-top: -7px; border-radius: 50%; background: var(--accent); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--accent); }
input[type=range]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--accent); }

.check { display: flex; gap: 10px; align-items: center; cursor: pointer; min-height: 32px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.block-input { position: relative; }
.block-input input { padding-left: 34px; }
.swatch { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; margin-top: -8px; border-radius: 4px; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .25); }
.code-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; }

button { cursor: pointer; }
.seed-row button, .code-row button, .toolbar button {
  min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); font-weight: 500;
}
.seed-row button:hover, .code-row button:hover { border-color: var(--muted); }

.export-bar {
  position: sticky; bottom: 0; margin: auto -20px 0; padding: 12px 20px 16px;
  background: var(--panel); border-top: 1px solid var(--line); box-shadow: 0 -10px 18px -14px rgb(0 0 0 / .35);
}
.primary {
  width: 100%; min-height: 48px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink); font-size: 17px; font-weight: 600;
  font-family: "Barlow Semi Condensed", Barlow, system-ui, sans-serif;
}
.primary:hover:not(:disabled) { filter: brightness(1.06); }
.primary:disabled { opacity: .5; cursor: not-allowed; }
.status { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.error { color: var(--error); }
.status code { font-size: 12px; }
.warnings { margin: 0 0 10px; padding: 0 0 0 18px; font-size: 13px; color: var(--muted); }
.warnings .error { color: var(--error); }

.stage { grid-area: stage; position: relative; overflow: hidden; background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom)); }
.viewport { position: absolute; inset: 0; }
.viewport canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.toolbar { position: absolute; top: 14px; right: 14px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.toolbar button { background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(6px); }
.toolbar button[aria-pressed=true] { border-color: var(--accent); color: var(--ink); box-shadow: inset 0 -3px 0 var(--accent); }
.toolbar button[aria-pressed=false] { color: var(--muted); }

.stats {
  position: absolute; left: 14px; bottom: 14px; max-width: calc(100% - 28px);
  display: flex; gap: 12px; align-items: stretch; flex-wrap: wrap;
}
.stats dl {
  margin: 0; display: flex; flex-wrap: wrap; gap: 4px 18px; padding: 10px 14px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 88%, transparent); backdrop-filter: blur(6px); border: 1px solid var(--line);
}
.stats dl div { display: grid; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tree-tag {
  position: relative; display: grid; align-content: center; padding: 8px 14px 8px 30px; border-radius: 8px;
  background: linear-gradient(160deg, #e9ecef, #b9c0c6); color: #20282e; box-shadow: 0 1px 0 rgb(255 255 255 / .6) inset, 0 4px 12px -6px rgb(0 0 0 / .5);
  font-family: "Barlow Semi Condensed", Barlow, system-ui, sans-serif;
}
.tree-tag b { font-size: 16px; line-height: 1.1; }
.tree-tag span:last-child { font-size: 13px; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.tag-hole { position: absolute; left: 11px; top: 50%; width: 9px; height: 9px; margin-top: -4.5px; border-radius: 50%; background: #6d757b; box-shadow: inset 0 1px 2px rgb(0 0 0 / .6); }
.stage-notes { position: absolute; left: 14px; top: 14px; max-width: min(460px, calc(100% - 480px)); display: grid; gap: 8px; }
@media (max-width: 1260px) { .stage-notes { top: 66px; max-width: min(460px, calc(100% - 28px)); } }
.notice {
  margin: 0; padding: 10px 14px;
  border-radius: var(--radius); background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--accent); font-size: 14px;
}
.tex-cta {
  display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; padding: 10px 12px; font-size: 14px;
  border-radius: var(--radius); background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--line); backdrop-filter: blur(6px);
}
.tex-cta[hidden] { display: none; }
.cta-btn {
  position: relative; display: inline-grid; place-items: center; min-height: 36px; padding: 0 12px; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
}
.cta-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.cta-btn:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
#tex-cta-close { min-height: 36px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.help { position: absolute; right: 14px; bottom: 14px; margin: 0; font-size: 12px; color: var(--muted); text-shadow: 0 1px 0 color-mix(in srgb, var(--panel) 60%, transparent); }
.probe { position: absolute; width: 0; height: 0; overflow: hidden; }
.group-note { margin: 0; font-size: 13px; color: var(--muted); }
.tex-panel {
  position: absolute; top: 64px; right: 14px; width: min(360px, calc(100% - 28px)); padding: 14px 16px 16px;
  display: grid; gap: 10px; border-radius: var(--radius); border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 96%, transparent); backdrop-filter: blur(8px); box-shadow: 0 12px 32px -16px rgb(0 0 0 / .45);
}
.tex-panel[hidden] { display: none; }
.tex-head { display: flex; justify-content: space-between; align-items: center; }
.tex-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.tex-head button, #tex-forget { min-height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.tex-status { margin: 0; font-size: 14px; }
.tex-panel .hint code { font-size: 12px; overflow-wrap: anywhere; }
.file-btn {
  position: relative; display: grid; place-items: center; min-height: 44px; padding: 0 14px; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-family: "Barlow Semi Condensed", Barlow, system-ui, sans-serif; font-size: 16px;
}
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
#t-textures.has-pack { box-shadow: inset 0 -3px 0 var(--accent); }
.stage.dropping::after { content: "Drop your Minecraft .jar or resource pack"; position: absolute; inset: 12px; display: grid; place-items: center; border: 3px dashed var(--accent); border-radius: var(--radius); background: color-mix(in srgb, var(--panel) 70%, transparent); font-size: 20px; font-weight: 600; pointer-events: none; }
#probe-ground { color: var(--ground); }
#probe-grid { color: var(--grid); }
#probe-sky { color: var(--sky); }

@media (max-width: 1100px) { .help { display: none; } }
@media (max-width: 760px) {
  body { overflow: auto; }
  .app { height: auto; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; grid-template-areas: "brand" "stage" "controls"; }
  .brand, .controls { border-right: 0; }
  .brand h1 { font-size: 26px; }
  .stage { height: 62vh; min-height: 340px; }
  .controls { overflow: visible; }
  .stats dl { gap: 2px 12px; padding: 8px 10px; }
  .stage-notes { max-width: calc(100% - 20px); left: 10px; top: auto; bottom: 96px; }
}
@media (prefers-reduced-motion: reduce) { .group summary::after { transition: none; } }
@media (max-width: 760px) {
  .tree-tag, .stats dl div:nth-child(2), .stats dl div:nth-child(5) { display: none; }
  .stats { left: 10px; bottom: 10px; }
  .stats dt { font-size: 11px; }
  .stats dd { font-size: 14px; }
}

.guide-panel {
  position: absolute; top: 64px; right: 14px; bottom: 14px; width: min(520px, calc(100% - 28px)); overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 10px; border-radius: var(--radius); border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 97%, transparent); backdrop-filter: blur(8px); box-shadow: 0 12px 32px -16px rgb(0 0 0 / .45); z-index: 2;
}
.guide-panel[hidden] { display: none; }
.guide-panel h3 { margin: 6px 0 0; font: 600 16px "Barlow Semi Condensed", Barlow, system-ui, sans-serif; }
.guide-summary, .layer-label { margin: 0; font-size: 14px; }
.layer-label span { color: var(--muted); font-variant-numeric: tabular-nums; }
.layer-nav { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: center; }
.layer-nav button, #copy-materials { min-height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); }
.layer-map-wrap { overflow: auto; border-radius: 8px; border: 1px solid var(--line); max-height: 62vh; }
.layer-map-wrap canvas { display: block; max-width: 100%; height: auto; image-rendering: pixelated; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 14px; font-size: 14px; }
.legend li { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding: 3px 0; }
.legend li b { font-variant-numeric: tabular-nums; }
.legend li small { color: var(--muted); white-space: nowrap; }
.legend li.note { grid-column: 1 / -1; color: var(--muted); border: 0; }
.materials { width: 100%; border-collapse: collapse; font-size: 14px; }
.materials th, .materials td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.materials th:not(:first-child), .materials td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#t-guide[aria-pressed=true] { border-color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
@media (max-width: 760px) { .guide-panel { position: fixed; inset: 10px; width: auto; top: 10px; z-index: 20; } }
.guide-panel > * { flex-shrink: 0; }
.custom-dot { background: conic-gradient(#4f8a2b 0 25%, #f2a8c6 0 50%, #d9822b 0 75%, #6d5434 0); }
