:root {
  color-scheme: light dark;
  --bg: #f3f1eb;
  --surface: #fbfaf7;
  --text: #1b1b19;
  --muted: #6c6a64;
  --line: #d8d4ca;
  --accent: #176b5a;
  --accent-ink: #ffffff;
  --warm: #d46a33;
  --cooling: #b99a48;
  --cold: #8b9696;
  --danger: #a53b36;
  --shadow: 0 24px 70px rgb(40 35 24 / 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

:root[data-theme="dark"] {
  --bg: #171816;
  --surface: #20211f;
  --text: #f2f0e9;
  --muted: #aaa89f;
  --line: #3a3b37;
  --accent: #70c6af;
  --accent-ink: #10241f;
  --warm: #ee8956;
  --cooling: #d3b765;
  --cold: #82908f;
  --danger: #ee8d86;
  --shadow: 0 24px 70px rgb(0 0 0 / 0.35);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #171816;
    --surface: #20211f;
    --text: #f2f0e9;
    --muted: #aaa89f;
    --line: #3a3b37;
    --accent: #70c6af;
    --accent-ink: #10241f;
    --warm: #ee8956;
    --cooling: #d3b765;
    --cold: #82908f;
    --danger: #ee8d86;
    --shadow: 0 24px 70px rgb(0 0 0 / 0.35);
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-width: 320px; min-height: 100vh; color: var(--text); background: var(--bg); }
button, input, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 3px; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; padding: .75rem 1rem; background: var(--text); color: var(--bg); }
.skip-link:focus { top: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
[hidden] { display: none !important; }

.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(1rem, 4vw, 3.5rem); }
.wordmark, .icon-button, .text-button, .back-button, .dialog-close { border: 0; background: transparent; cursor: pointer; }
.wordmark { min-height: 44px; padding: 0; font-weight: 720; letter-spacing: -.025em; }
.top-actions { display: flex; gap: .25rem; }
.icon-button { width: 44px; height: 44px; border-radius: 50%; font-size: 1.35rem; }
.icon-button:hover, .text-button:hover, .back-button:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.view { min-height: calc(100vh - 72px); }
#map-view { padding: clamp(1.5rem, 4vw, 3.5rem); padding-top: clamp(1rem, 2vw, 2rem); }
.map-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; max-width: 1100px; margin: 0 auto 1.5rem; }
.eyebrow { margin: 0 0 .55rem; color: var(--muted); text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 750; }
h1, h2 { margin: 0; letter-spacing: -.045em; line-height: 1.05; }
h1 { max-width: 760px; font-size: clamp(2rem, 6vw, 4.8rem); font-weight: 620; }
h2 { font-size: clamp(1.7rem, 4vw, 2.5rem); }
.text-button, .back-button { min-height: 44px; border-radius: 10px; padding: 0 .75rem; color: var(--muted); }
.text-button.danger { color: var(--danger); }
.capture-form { display: flex; max-width: 700px; margin: 0 auto 1rem; padding: .35rem; background: var(--surface); border-radius: 16px; box-shadow: 0 1px 0 var(--line), 0 8px 30px rgb(40 35 24 / .06); }
.capture-form input, .command-content input { flex: 1; min-width: 0; border: 0; color: var(--text); background: transparent; padding: 0 1rem; outline: none; }
.primary-button { min-height: 44px; border: 0; border-radius: 12px; padding: .7rem 1.1rem; background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer; }
.primary-button:hover { filter: brightness(.96); }
.map-help { min-height: 32px; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .7rem 1.25rem; color: var(--muted); font-size: .78rem; }
.map-help span { display: inline-flex; align-items: center; gap: .35rem; }
.heat-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.heat-dot.warm { background: var(--warm); box-shadow: 0 0 0 5px color-mix(in srgb, var(--warm) 13%, transparent); }
.heat-dot.cooling { background: var(--cooling); }
.heat-dot.cold { background: var(--cold); }
.map-canvas { position: relative; max-width: 1180px; height: clamp(430px, 58vh, 690px); margin: .5rem auto 0; overflow: hidden; border-top: 1px solid var(--line); background-image: radial-gradient(circle, color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 1px); background-size: 32px 32px; }
.connections { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.connections line { stroke: var(--line); stroke-width: 1.5; stroke-dasharray: 4 7; }
.node { position: absolute; width: clamp(150px, 20vw, 230px); min-height: 118px; transform: translate(-50%, -50%); border: 0; border-radius: 20px; padding: 1rem; text-align: left; background: var(--surface); color: var(--text); box-shadow: var(--shadow); cursor: grab; touch-action: none; transition: transform 150ms ease, box-shadow 150ms ease; }
.node:hover, .node:focus-visible { transform: translate(-50%, -50%) scale(1.025); }
.node.dragging { cursor: grabbing; transition: none; box-shadow: 0 28px 80px rgb(20 20 18 / .24); }
.node.link-source { outline: 3px solid var(--accent); }
.node::before { content: ""; position: absolute; top: 1rem; right: 1rem; width: 10px; height: 10px; border-radius: 50%; background: var(--heat); box-shadow: 0 0 0 6px color-mix(in srgb, var(--heat) 13%, transparent); }
.node[data-heat="warm"] { --heat: var(--warm); }
.node[data-heat="cooling"] { --heat: var(--cooling); }
.node[data-heat="cold"] { --heat: var(--cold); }
.node-title { display: block; margin: 0 1.2rem .7rem 0; font-size: 1.05rem; font-weight: 720; }
.node-next { display: block; color: var(--muted); font-size: .85rem; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.node-meta { display: block; margin-top: .7rem; color: var(--muted); font-size: .7rem; }
.empty-state { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: .5rem; color: var(--muted); }

.focus-view { display: grid; place-items: start center; padding: clamp(1rem, 4vw, 3rem); }
.focus-shell { width: min(760px, 100%); }
.back-button { margin: 0 0 clamp(2rem, 8vh, 5rem) -.75rem; }
.focus-heading h1 { font-size: clamp(2.4rem, 7vw, 5rem); }
.welcome-copy { max-width: 650px; margin: 1.1rem 0 2.5rem; color: var(--muted); font-size: clamp(1rem, 2vw, 1.2rem); line-height: 1.55; }
.state-form { display: grid; gap: 1.5rem; }
label span { display: block; margin: 0 0 .55rem; color: var(--muted); font-size: .82rem; font-weight: 700; }
textarea { width: 100%; resize: vertical; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: .25rem 0 .7rem; background: transparent; color: var(--text); font-size: clamp(1.05rem, 2.5vw, 1.35rem); line-height: 1.45; }
.focus-actions { display: flex; align-items: center; flex-wrap: wrap; gap: .35rem; margin-top: 2rem; }
.inline-error { min-height: 1.2em; margin: 0; color: var(--danger); font-size: .86rem; }

dialog { width: min(650px, calc(100% - 2rem)); max-height: calc(100vh - 2rem); overflow: auto; border: 1px solid var(--line); border-radius: 22px; padding: 0; color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(18 18 16 / .48); backdrop-filter: blur(3px); }
.dialog-content { position: relative; display: grid; gap: 1.1rem; padding: clamp(1.25rem, 5vw, 2.5rem); }
.dialog-content > p:not(.eyebrow, .inline-error) { margin: -.4rem 0 .5rem; color: var(--muted); line-height: 1.5; }
.dialog-close { position: absolute; right: .8rem; top: .8rem; width: 44px; height: 44px; font-size: 1.5rem; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }
.history-item, .archive-item { padding: 1rem 0; border-bottom: 1px solid var(--line); }
.history-item:last-child, .archive-item:last-child { border-bottom: 0; }
.history-item time { color: var(--muted); font-size: .78rem; }
.history-item p { margin: .45rem 0 0; line-height: 1.4; }
.archive-item { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }

.command-content { padding: .6rem; }
.command-content input { width: 100%; height: 54px; font-size: 1.05rem; }
.command-results { display: grid; max-height: 380px; overflow: auto; padding-top: .35rem; border-top: 1px solid var(--line); }
.command-item { display: flex; justify-content: space-between; align-items: center; min-height: 50px; border: 0; border-radius: 10px; padding: .7rem .9rem; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.command-item small { color: var(--muted); }
.command-item.active, .command-item:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.command-hint { margin: .5rem .9rem; color: var(--muted); font-size: .72rem; }
.toast { position: fixed; left: 50%; bottom: 1.25rem; z-index: 50; transform: translateX(-50%); display: flex; align-items: center; gap: 1rem; max-width: calc(100% - 2rem); border-radius: 12px; padding: .65rem .75rem .65rem 1rem; color: var(--bg); background: var(--text); box-shadow: var(--shadow); }
.toast button { min-height: 36px; border: 0; background: transparent; color: var(--bg); text-decoration: underline; cursor: pointer; }

@media (max-width: 640px) {
  .topbar { height: 60px; }
  .view { min-height: calc(100vh - 60px); }
  #map-view { padding: 1rem; }
  .map-heading { align-items: center; }
  .map-heading h1 { font-size: 2rem; }
  .map-canvas { height: calc(100vh - 235px); min-height: 430px; margin-inline: -1rem; }
  .node { width: 150px; min-height: 108px; padding: .85rem; }
  .map-help span:nth-child(-n+3) { display: none; }
  .focus-view { padding: 1rem; }
  .back-button { margin-bottom: 2.5rem; }
  .focus-actions { align-items: stretch; }
  .focus-actions > * { flex: 1 1 auto; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions button { width: 100%; }
}

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