:root {
  --bg: #0a1210;
  --panel: rgba(17, 28, 24, 0.94);
  --panel-solid: #111c18;
  --panel-raised: #1a2a24;
  --panel-border: #263b32;
  --text: #e6efe9;
  --text-dim: #93a69b;
  --accent: #e8a13a;
  --accent-ink: #1b1305;
  --link: #8fd3ae;
  --good: #6fcf8e;
  --warn: #f0c04a;
  --bad: #ef6b5a;
  --font-ui: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Mono", Consolas, ui-monospace, monospace;
  --radius: 10px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font-ui);
  overflow: hidden;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.4; }
h1, h2, h3, h4 { margin: 0; }
p { margin: 0; }
.dim { color: var(--text-dim); }
.small { font-size: 12px; }

#terrainCanvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
}

body:not(.in-app) .app-only { display: none !important; }

/* ---------- shared controls ---------- */

.floating-panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
}

.primary-button {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 8px;
  padding: 7px 14px;
  font-weight: 700;
}
.primary-button:hover:not(:disabled) { filter: brightness(1.08); }
.primary-button.big { padding: 13px 24px; font-size: 16px; letter-spacing: 0.02em; }

.menu-button, .chip, .icon-button {
  background: var(--panel-raised);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 12px;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}
.menu-button:hover, .chip:hover:not(:disabled), .icon-button:hover:not(:disabled) { border-color: #3d5a4d; background: #20332c; }
.menu-button.primary-outline { border-color: var(--accent); }
.menu-button.open { background: #26403a; }
.chip { padding: 3px 9px; font-size: 12.5px; }
.chip.active, .segmented button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.icon-button { padding: 4px 9px; font-size: 17px; line-height: 1.1; }

.link-button { background: none; border: 0; padding: 0; color: var(--link); text-decoration: underline; }

.segmented { display: inline-flex; gap: 0; }
.segmented button {
  background: var(--panel-raised);
  border: 1px solid var(--panel-border);
  padding: 6px 12px;
  margin-left: -1px;
}
.segmented button:first-child { border-radius: 8px 0 0 8px; margin-left: 0; }
.segmented button:last-child { border-radius: 0 8px 8px 0; }
.segmented.wide { display: flex; }
.segmented.wide button { flex: 1; }

input[type="text"], input[type="search"], input[type="number"], select {
  background: #0d1714;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 6px 10px;
}
input[type="range"] { accent-color: var(--accent); }
kbd {
  font: 11px var(--font-mono);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text-dim);
}

/* ---------- top bar ---------- */

#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  background: linear-gradient(#0c1613, rgba(12, 22, 19, 0.92));
  border-bottom: 1px solid var(--panel-border);
  z-index: 20;
}
.brand { background: none; border: 0; text-align: left; padding: 2px 6px; line-height: 1.15; }
.brand-name { font-size: 21px; font-weight: 300; letter-spacing: 0.01em; }
.brand-name b { font-weight: 800; color: var(--accent); }
.brand-name.large { font-size: 26px; }
.brand-project { display: block; font-size: 11px; color: var(--text-dim); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-divider { width: 1px; height: 26px; background: var(--panel-border); margin: 0 4px; }
.topbar-spacer { flex: 1; }
.search-box { display: flex; align-items: center; gap: 6px; background: #0d1714; border: 1px solid var(--panel-border); border-radius: 8px; padding: 0 8px; width: 240px; }
.search-box input { border: 0; background: none; flex: 1; min-width: 0; padding: 6px 2px; outline: none; }
.saved-indicator { font-size: 12px; color: var(--text-dim); margin-left: 4px; min-width: 60px; }
.saved-indicator.unsaved { color: var(--warn); }

/* ---------- dropdown menus ---------- */

#menuLayer { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
.dropdown {
  position: absolute;
  min-width: 230px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 6px;
  background: var(--panel-solid);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
}
.dropdown button.menu-item {
  display: flex; width: 100%; align-items: center; gap: 8px;
  background: none; border: 0; border-radius: 6px; padding: 6px 10px; text-align: left;
}
.dropdown button.menu-item:hover:not(:disabled) { background: #20332c; }
.dropdown .menu-check { width: 14px; color: var(--accent); flex: none; }
.dropdown .menu-hint { margin-left: auto; color: var(--text-dim); font-size: 11.5px; }
.dropdown .menu-heading { padding: 8px 10px 3px; font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); }
.dropdown .menu-separator { height: 1px; background: var(--panel-border); margin: 5px 4px; }
.dropdown .menu-custom { padding: 6px 10px; }

/* ---------- bottom controls ---------- */

.pill {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 999px;
  padding: 7px 16px; z-index: 10;
}
.pill input { width: 150px; }

#bottomRight {
  position: fixed; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 10;
}
#bottomRight .floating-panel { position: static; }
.legend { padding: 8px 12px; font: 12px/1.6 var(--font-mono); text-align: right; }
.legend-row { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
#slopeKey { margin-top: 6px; text-align: left; }
#slopeKey .key-row { display: flex; align-items: center; gap: 8px; }
#slopeKey .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.round-button {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--panel-border);
  display: grid; place-items: center; padding: 0;
}
.readout { padding: 8px 12px; font: 12.5px var(--font-mono); color: var(--text); text-align: right; }

.status-toast {
  top: 70px; left: 50%; transform: translateX(-50%);
  padding: 10px 16px; display: flex; align-items: center; gap: 12px; z-index: 60; max-width: 80vw;
}
.status-toast.error { border-color: var(--bad); }
.warning-toast {
  top: 70px; right: 16px; max-width: 360px; padding: 10px 14px; z-index: 30;
  border-color: var(--warn); font-size: 13px;
}

/* ---------- side sheets (settings, plans, help) ---------- */

.side-sheet {
  top: 66px; right: 16px; width: 400px; max-height: calc(100vh - 90px);
  overflow-y: auto; padding: 16px 18px; z-index: 35;
}
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-header h2 { font-size: 18px; }
.sheet-section { margin-top: 16px; }
.sheet-section h3 { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); margin-bottom: 8px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.setting-row .setting-text { flex: 1; }
.setting-row .setting-text small { display: block; color: var(--text-dim); }
.setting-row input[type="number"] { width: 84px; }

/* ---------- map picker ---------- */

#mapPicker {
  position: fixed; inset: 0; z-index: 80; background: var(--bg);
  display: flex; flex-direction: column;
}
.picker-top, .picker-bottom {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 16px; background: #0c1613;
}
.picker-top-controls { display: flex; align-items: center; gap: 8px; }
.picker-top-controls input { width: 210px; }
#pickerMap { position: relative; flex: 1; overflow: hidden; background: #06100d; cursor: crosshair; touch-action: none; }
#pickerTiles { position: absolute; inset: 0; }
#pickerTiles img { position: absolute; width: 256px; height: 256px; user-select: none; -webkit-user-drag: none; pointer-events: none; }
#pickerBox {
  position: absolute; border: 2px solid var(--accent); background: rgba(232, 161, 58, 0.14);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6); pointer-events: none;
}
.picker-zoom { position: absolute; top: 12px; left: 12px; display: flex; flex-direction: column; }
.picker-zoom button { width: 32px; height: 32px; background: #fff; color: #111; border: 1px solid #bbb; font-size: 20px; line-height: 1; }
.picker-credit { position: absolute; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.55); padding: 2px 8px; font-size: 11px; }
#pickerStatus { flex: 1; }

/* ---------- start page ---------- */

#startPage {
  position: fixed; inset: 0; z-index: 70; overflow-y: auto;
  background:
    radial-gradient(1200px 600px at 78% -10%, rgba(111, 207, 142, 0.14), transparent 60%),
    radial-gradient(900px 500px at 0% 100%, rgba(232, 161, 58, 0.10), transparent 60%),
    var(--bg);
}
.start-inner { max-width: 1040px; margin: 0 auto; padding: 28px 28px 80px; }
.start-header { display: flex; align-items: center; gap: 12px; }
.tag { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; border: 1px solid var(--panel-border); border-radius: 999px; padding: 2px 10px; color: var(--text-dim); }
.hero { padding: 64px 0 36px; max-width: 720px; }
.eyebrow { font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); margin-bottom: 12px; }
.hero h1 { font-size: 52px; line-height: 1.06; font-weight: 800; letter-spacing: -0.015em; }
.lead { font-size: 18px; color: #c9d6ce; margin: 18px 0 26px; }
#startActions { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.phone-gate { border: 1px solid var(--warn); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; }
#startPage section { margin-top: 44px; }
#startPage h2 { font-size: 24px; margin-bottom: 16px; }
#startPage h3 { font-size: 16px; margin-bottom: 6px; }
#startPage section p { color: #c1cdc6; }
#projectList { display: flex; flex-direction: column; gap: 8px; max-width: 520px; margin-bottom: 8px; }
.project-row { display: flex; gap: 6px; }
.project-open {
  flex: 1; text-align: left; background: var(--panel-raised); border: 1px solid var(--panel-border);
  border-radius: var(--radius); padding: 10px 14px;
}
.project-open:hover { border-color: var(--accent); }
.project-open b { display: block; }
.project-open span { color: var(--text-dim); font-size: 12.5px; }
.project-remove { background: none; border: 1px solid var(--panel-border); border-radius: var(--radius); width: 40px; color: var(--text-dim); font-size: 18px; }
.project-remove:hover { color: var(--bad); border-color: var(--bad); }
.steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.steps li, .why-cards > div, .faq > div {
  background: rgba(26, 42, 36, 0.6); border: 1px solid var(--panel-border); border-radius: var(--radius); padding: 16px;
}
.step-number {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; margin-bottom: 10px;
}
.why-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 24px; }
.faq { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }

/* ---------- busy overlay ---------- */

#busyOverlay { position: fixed; inset: 0; z-index: 90; background: rgba(6, 12, 10, 0.78); display: grid; place-items: center; }
.busy-card { display: flex; align-items: center; gap: 14px; background: var(--panel-solid); border: 1px solid var(--panel-border); border-radius: var(--radius); padding: 18px 24px; font-size: 16px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--panel-border); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .hero h1 { font-size: 36px; }
  .steps, .why-cards, .faq { grid-template-columns: 1fr; }
}

/* ---------- edit, stats and profile panels ---------- */

#editPanel { top: 70px; left: 16px; width: 330px; max-height: calc(100vh - 300px); overflow-y: auto; padding: 12px 14px; z-index: 10; }
.panel-title { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: #a9c7ff; font-weight: 700; margin: 0; }
.panel-hint { color: #c1cdc6; font-size: 12.5px; margin: 8px 0 10px; padding-bottom: 10px; border-bottom: 1px solid var(--panel-border); }
.panel-label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); margin: 10px 0 6px; }
.panel-heading { color: #8fd3ae; font-size: 14px; margin: 14px 0 6px; padding-top: 10px; border-top: 1px solid var(--panel-border); }
.button-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.hole-row, .plan-row { border: 1px solid var(--panel-border); border-radius: 8px; margin-bottom: 5px; background: var(--panel-raised); }
.hole-row.selected, .plan-row.selected, .feature-row.selected { border-color: var(--accent); }
.hole-main { display: flex; align-items: baseline; gap: 8px; width: 100%; background: none; border: 0; padding: 7px 10px; text-align: left; }
.hole-main span { color: var(--text-dim); font-size: 12.5px; }
.hole-tools { display: flex; gap: 5px; padding: 0 8px 7px; }
.warning-mark { color: var(--warn); margin-left: auto; font-size: 13px; }
.accordion-header { display: flex; justify-content: space-between; width: 100%; background: var(--panel-raised); border: 1px solid var(--panel-border); border-radius: 8px; padding: 7px 10px; margin-bottom: 5px; text-align: left; font-weight: 600; }
.accordion-arrow { color: var(--text-dim); font-size: 10px; margin-left: 8px; }
.accordion-body { display: flex; flex-wrap: wrap; gap: 5px; padding: 2px 2px 8px; }
.feature-row { display: flex; gap: 5px; align-items: center; border: 1px solid transparent; border-radius: 8px; }
.feature-main { flex: 1; background: none; border: 0; text-align: left; padding: 4px 6px; }

#statsPanel { top: 70px; right: 16px; width: 290px; max-height: calc(100vh - 330px); overflow-y: auto; padding: 10px 14px; z-index: 9; }
.stats-toggle { display: flex; align-items: center; width: 100%; background: none; border: 0; padding: 2px 0; gap: 8px; }
.stats-toggle .accordion-arrow { margin-left: auto; }
.stats-toggle .warning-mark { margin-left: auto; }
.stats-toggle .warning-mark + .accordion-arrow { margin-left: 8px; }
.stat-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.warning-item { display: block; width: 100%; text-align: left; background: rgba(240, 192, 74, 0.08); border: 1px solid rgba(240, 192, 74, 0.35); border-radius: 8px; padding: 6px 9px; margin-bottom: 5px; font-size: 12.5px; }

#profilePanel { left: 16px; bottom: 16px; width: 440px; padding: 10px 12px; z-index: 10; }
#profilePanel.collapsed { width: 260px; }
.profile-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.profile-controls { display: flex; align-items: center; gap: 6px; }
.profile-controls .segmented button { padding: 2px 8px; font-size: 12px; }
.profile-canvas { display: block; width: 100%; height: 130px; margin-top: 8px; cursor: crosshair; touch-action: none; }
.profile-readout { min-height: 16px; margin-top: 4px; }

/* ---------- stage 4: simulator, brush, present, search, help, coach ---------- */

#simPanel { left: 50%; bottom: 16px; transform: translateX(-50%); padding: 10px 14px; z-index: 12; max-width: calc(100vw - 32px); }
.sim-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.sim-title { flex: 1; min-width: 220px; }
.sim-readout { font: 13px var(--font-mono); margin-bottom: 8px; color: var(--accent); }
.sim-row .segmented button { padding: 3px 9px; font-size: 12.5px; }
body.in-app:has(#simPanel:not([hidden])) #overlaySlider { display: none; }

#treeBrushPanel { top: 70px; left: 50%; transform: translateX(-50%); padding: 12px 14px; width: 300px; z-index: 12; display: flex; flex-direction: column; gap: 8px; }
.brush-size { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }

.present-bar { top: 70px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; padding: 10px 16px; z-index: 30; }
.present-title { display: flex; flex-direction: column; }

#searchResults { z-index: 45; padding: 6px; background: var(--panel-solid); }
#searchResults .menu-item { display: flex; width: 100%; align-items: center; gap: 8px; background: none; border: 0; border-radius: 6px; padding: 6px 10px; text-align: left; }
#searchResults .menu-item:hover, #searchResults .menu-item.first { background: #20332c; }
#searchResults .menu-hint { margin-left: auto; color: var(--text-dim); font-size: 11.5px; }
.search-empty { padding: 8px 10px; }

.help-topic { border-bottom: 1px solid var(--panel-border); padding: 8px 0; }
.help-topic summary { cursor: pointer; font-weight: 600; }
.help-topic p { margin-top: 6px; color: #c1cdc6; }

.coach-card { left: 50%; bottom: 76px; transform: translateX(-50%); width: 420px; max-width: calc(100vw - 32px); padding: 14px 16px; z-index: 50; border-color: var(--accent); }
.coach-card h3 { margin: 2px 0 6px; font-size: 17px; }
.coach-card p { color: #c9d6ce; }
