:root {
  --ink: #1f1c19;
  --muted: #6f675e;
  --paper: rgba(250, 247, 242, 0.86);
  --paper-solid: #f6f2ec;
  --line: rgba(31, 28, 25, 0.12);
  --accent: #8c6a43;
  --accent-ink: #ffffff;
  --shadow: 0 18px 40px -24px rgba(40, 30, 20, 0.45);
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
}

body[data-tone="dark"] {
  --ink: #f1ece4;
  --muted: #a8a096;
  --paper: rgba(20, 22, 30, 0.78);
  --paper-solid: #151821;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #c9a26e;
  --accent-ink: #15130f;
  --shadow: 0 18px 40px -24px rgba(0, 0, 0, 0.8);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #efe9e1;
  color: var(--ink);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}

#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
}

.brand {
  position: fixed;
  top: 24px;
  left: 28px;
  pointer-events: none;
  text-shadow: 0 1px 12px rgba(255, 255, 255, 0.35);
}

body[data-tone="dark"] .brand { text-shadow: 0 1px 12px rgba(0, 0, 0, 0.5); }

.brand h1 {
  margin: 2px 0 0;
  font: 500 42px/1.02 var(--serif);
  letter-spacing: -0.01em;
}

.brand .meta { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.card {
  position: fixed;
  background: var(--paper);
  backdrop-filter: blur(14px) saturate(1.1);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

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

.sunbar {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  grid-template-areas: "play track readout" "opts opts opts";
  align-items: center;
  gap: 6px 12px;
  width: min(620px, calc(100vw - 560px));
  min-width: 420px;
  padding: 10px 16px 10px 10px;
  background: var(--paper);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.sun-play {
  grid-area: play;
  width: 38px;
  height: 38px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  font-size: 13px;
  background: #f2b64a;
  border-color: #f2b64a;
  color: #2a1c08;
}

.sun-play[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.sun-track { grid-area: track; }
.sun-track input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  margin: 6px 0 4px;
  border-radius: 4px;
  background: var(--sun-gradient, linear-gradient(90deg, #1a2133, #f2b64a, #1a2133));
  outline-offset: 4px;
}

.sun-track input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffd36b;
  border: 2px solid #fff;
  box-shadow: 0 0 0 4px rgba(255, 196, 80, 0.35), 0 2px 6px rgba(0, 0, 0, 0.3);
  cursor: grab;
}

.sun-track input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffd36b;
  border: 2px solid #fff;
  box-shadow: 0 0 0 4px rgba(255, 196, 80, 0.35);
  cursor: grab;
}

.sun-marks { position: relative; height: 14px; font-size: 10.5px; color: var(--muted); }
.sun-marks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
#sun-readout { grid-area: readout; font: 600 13px/1.25 var(--sans); text-align: right; white-space: pre-line; min-width: 92px; }
.sun-opts { grid-area: opts; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.sun-opts .mini { font-weight: 600; color: var(--muted); }
.sun-opts input[type="date"], .sun-opts select {
  font: 500 12px var(--sans);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
}
.sun-opts .check { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.sun-opts input[type="range"] { width: 90px; accent-color: var(--accent); }
.sun-in { flex-basis: 100%; margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }
.sun-in strong { color: var(--ink); font-weight: 600; }
.sun-opts .check input { accent-color: var(--accent); }

.sun-tag, .hour-tag, .compass-tag { pointer-events: none; font: 600 11px/1 var(--sans); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.35); }
.sun-tag { padding: 4px 8px; border-radius: 999px; background: rgba(255, 211, 107, 0.95); color: #2a1c08; text-shadow: none; }
.hour-tag { color: #9a6a2c; text-shadow: 0 0 6px rgba(255, 255, 255, 0.9); }
body[data-tone="dark"] .hour-tag { color: #ffd98a; text-shadow: 0 0 6px rgba(0, 0, 0, 0.8); }
.compass-tag { color: #8c6a43; font-size: 13px; text-shadow: none; }
.compass-tag.north { color: #b5552f; font-size: 15px; }

.plan { top: 24px; right: 24px; width: 220px; padding: 14px 16px 12px; }
.plan svg { display: block; width: 100%; height: auto; margin-top: 8px; }

.plan .room {
  fill: var(--paper-solid);
  stroke: var(--line);
  stroke-width: 0.04;
  cursor: pointer;
  transition: fill 0.2s;
}

.plan .room:hover, .plan .room.active { fill: color-mix(in srgb, var(--accent) 28%, var(--paper-solid)); }
.plan .room.outdoor { stroke-dasharray: 0.12 0.08; }
.plan .outline { fill: none; stroke: var(--ink); stroke-width: 0.12; pointer-events: none; }
.plan text { font: 600 0.38px var(--sans); fill: var(--ink); text-anchor: middle; pointer-events: none; }
.plan .marker { fill: var(--accent); stroke: var(--paper-solid); stroke-width: 0.06; }

.info { top: 50%; right: 24px; width: 300px; padding: 22px 22px 20px; transform: translateY(-50%); }
.info h2 { margin: 4px 0 0; font: 500 32px/1.05 var(--serif); }
.info .area { margin: 6px 0 14px; color: var(--muted); }
.info ul { margin: 0 0 18px; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.info li { padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.info .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.info .close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
}

button {
  font: 500 13px/1 var(--sans);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px;
  min-height: 36px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

button:hover { border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.active, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.toolbar {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 8px;
  max-width: calc(100vw - 32px);
  overflow-x: auto;
  background: var(--paper);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  scrollbar-width: none;
}

.segmented { display: flex; gap: 2px; flex: none; }
.segmented + .segmented { padding-left: 10px; border-left: 1px solid var(--line); }
.segmented button { border-color: transparent; white-space: nowrap; }
.segmented button.active { border-color: var(--accent); }

#hint {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  margin: 0;
  max-width: calc(100vw - 32px);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  pointer-events: none;
}

#caption {
  position: fixed;
  left: 50%;
  bottom: 112px;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 32px));
  margin: 0;
  text-align: center;
  font: italic 500 30px/1.2 var(--serif);
  color: #fff;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

.room-label {
  display: grid;
  gap: 1px;
  padding: 7px 12px;
  border-radius: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  min-height: 0;
  line-height: 1.2;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.room-label strong { font: 600 18px/1.1 var(--serif); }
.room-label span { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }

#tooltip {
  position: fixed;
  pointer-events: none;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--paper);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 500;
  transform: translate(14px, 14px);
  white-space: nowrap;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

body[data-mode="walk"] #tooltip { transform: translate(-50%, 22px); }

#crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

#fade {
  position: fixed;
  inset: 0;
  background: #0b0a09;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#fade.on { opacity: 1; }

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #f3eee7;
  color: #1f1c19;
  transition: opacity 0.8s ease;
}

#loading.done { opacity: 0; pointer-events: none; }
.loading-inner { text-align: center; }
.loading-inner h1 { margin: 6px 0 18px; font: 500 48px/1 var(--serif); }
.bar { width: 220px; height: 2px; margin: 0 auto; background: rgba(31, 28, 25, 0.12); overflow: hidden; }
.bar span { display: block; width: 0; height: 100%; background: #8c6a43; transition: width 0.2s; }
#loading-text { margin: 14px 0 0; font-size: 12px; color: #6f675e; }

body[data-mode="tour"] .brand,
body[data-mode="tour"] .plan,
body[data-mode="tour"] #hint { opacity: 0.0; transition: opacity 0.6s; }

@media (max-width: 760px) {
  .brand { top: 16px; left: 16px; }
  .brand h1 { font-size: 30px; }
  .plan { display: none; }
  .sunbar { top: auto; bottom: 150px; left: 16px; right: 16px; width: auto; min-width: 0; transform: none; }
  .info {
    top: auto;
    bottom: 84px;
    left: 16px;
    right: 16px;
    width: auto;
    transform: none;
    max-height: 46vh;
    overflow-y: auto;
  }
  .toolbar { left: 16px; right: 16px; transform: none; border-radius: 18px; }
  .super { top: auto; bottom: 84px; left: 16px; right: 16px; width: auto; }
  .wind { top: auto; bottom: 84px; left: 16px; right: 16px; width: auto; max-height: 50vh; }
  #hint { bottom: 76px; }
  body:has(#info:not([hidden])) #hint { display: none; }
  #caption { font-size: 22px; bottom: 96px; }
}

.wind { top: 140px; left: 24px; width: 290px; padding: 18px 18px 14px; max-height: calc(100vh - 260px); overflow-y: auto; }
.wind h2 { margin: 2px 0 2px; font: 500 26px/1.1 var(--serif); }
.wind .note { margin: 0 0 12px; color: var(--muted); font-size: 11.5px; }
.wind .field-label, .wind .field { display: flex; justify-content: space-between; margin: 10px 0 6px; font-size: 12px; font-weight: 600; }
.wind input[type="range"] { width: 100%; accent-color: var(--accent); }
.wind .check { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 12.5px; cursor: pointer; }
.wind .check input { accent-color: var(--accent); width: 16px; height: 16px; }
.sim-head { display: flex; justify-content: space-between; align-items: center; }
.sim-head .close { width: 30px; height: 30px; min-height: 0; padding: 0; border-radius: 50%; font-size: 16px; }
.tools { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.tools button { min-height: 30px; padding: 0 10px; font-size: 12px; }
.tools button[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.soon-tag { display: inline-block; margin: 6px 0 10px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); font-size: 11px; color: var(--muted); }
#tool-soon h2 { margin: 0; font: 500 26px/1.1 var(--serif); }
#tool-soon .note { font-size: 12.5px; line-height: 1.5; }
.compass { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; width: 150px; }
.compass button { min-height: 30px; padding: 0; font-size: 12px; }
.compass .hub { display: grid; place-items: center; font-size: 10px; color: var(--muted); }
#wind-rooms { list-style: none; margin: 12px 0 8px; padding: 0; border-top: 1px solid var(--line); }
#wind-rooms li { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
#wind-rooms .bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
#wind-rooms .bar span { display: block; height: 100%; background: var(--accent); }
#wind-rooms em { font-style: normal; color: var(--muted); }
.legend { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--muted); margin-bottom: 6px; }
.legend i { flex: 1; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #1d3557, #2a9d8f, #8ab17d, #e9c46a, #e76f51); }
button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.super { top: 140px; left: 24px; width: 300px; padding: 16px 18px; max-height: calc(100vh - 260px); overflow-y: auto; }
.super .field-label, .super .field { display: flex; justify-content: space-between; margin: 10px 0 6px; font-size: 12px; font-weight: 600; }
.super input[type="range"] { width: 100%; accent-color: var(--accent); }
.super select { font: 500 12px var(--sans); color: var(--ink); background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; }
.super .check { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 12.5px; }
.super .check input { accent-color: var(--accent); }
.super details { margin: 4px 0 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.super summary { cursor: pointer; font-size: 12px; font-weight: 600; }
.render-bar { height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; margin: 10px 0 6px; }
.render-bar span { display: block; width: 0; height: 100%; background: var(--accent); transition: width 0.3s; }
.super h2 { margin: 2px 0 6px; font: 500 26px/1.1 var(--serif); }
.super .note { margin: 0 0 10px; color: var(--muted); font-size: 11.5px; line-height: 1.45; }
.super-stats { margin: 0 0 12px; font: 12px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.super .actions { display: flex; gap: 6px; flex-wrap: wrap; }

#perf {
  position: fixed;
  left: 24px;
  bottom: 96px;
  width: 300px;
  padding: 12px 14px;
  background: var(--paper);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

#perf pre {
  margin: 8px 0 10px;
  font: 11px/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

#perf .actions { display: flex; gap: 6px; flex-wrap: wrap; }

@media (max-width: 760px) {
  #perf { top: 110px; bottom: auto; left: 16px; width: auto; right: 16px; }
}

[hidden] { display: none !important; }
