/* TerraSlice 3D: dark survey-instrument UI floating over the globe. */
:root {
  --bg: #0b1016;
  --panel: rgba(13, 19, 26, 0.88);
  --surface: #151d27;
  --surface-2: #1c2632;
  --line: rgba(148, 170, 190, 0.14);
  --text: #e6edf3;
  --muted: #8b9aab;
  --accent: #2dd4bf;
  --accent-ink: #062b27;
  --sun: #ffd166;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #34d399;
  --radius: 10px;
  --radius-sm: 6px;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --panel-w: 372px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 13px/1.45 Inter, system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }

#cesium { position: fixed; inset: 0; }
body.studio #cesium { background: radial-gradient(120% 90% at 62% 30%, #33475a 0%, #16212c 50%, #080c11 100%); }
.cesium-viewer-bottom { left: calc(var(--panel-w) + 24px) !important; bottom: 30px !important; }
.cesium-credit-logoContainer { display: none !important; }

/* ---------- panel ---------- */
#panel {
  position: fixed; z-index: 5; top: 12px; left: 12px; bottom: 12px; width: var(--panel-w);
  display: flex; flex-direction: column;
  background: var(--panel); backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition: transform 0.35s var(--ease), opacity 0.35s var(--ease);
}
body.panel-closed #panel { transform: translateX(calc(-100% - 24px)); opacity: 0; }

.brand { display: flex; gap: 12px; align-items: center; padding: 16px 18px 14px; border-bottom: 1px solid var(--line); }
.brand svg { width: 38px; height: 38px; flex: none; filter: drop-shadow(0 4px 10px rgba(45, 212, 191, 0.25)); }
.brand h1 { margin: 0; font-size: 17px; letter-spacing: -0.01em; font-weight: 700; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 11.5px; }

.scroll { overflow-y: auto; padding: 6px 12px 16px; scrollbar-width: thin; scrollbar-color: #2a3644 transparent; }

.sec { border-bottom: 1px solid var(--line); padding: 4px 4px 12px; }
.sec:last-child { border-bottom: 0; }
.sec > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 10px 0 8px; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: #c9d4df;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::after { content: '▾'; margin-left: auto; color: var(--muted); transition: transform 0.2s; }
.sec:not([open]) > summary::after { transform: rotate(-90deg); }
.sec > summary .n {
  display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: rgba(45, 212, 191, 0.12); color: var(--accent); font: 600 11px var(--mono);
}
.sec > *:not(summary) + *:not(summary) { margin-top: 8px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 6px 12px; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text); font-weight: 500;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.btn:hover:not(:disabled) { background: #243140; border-color: rgba(148, 170, 190, 0.3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.accent { color: var(--accent); border-color: rgba(45, 212, 191, 0.35); background: rgba(45, 212, 191, 0.08); }
.btn.primary {
  background: linear-gradient(180deg, #34e0ca, #1fb8a5); color: var(--accent-ink); border: 0; font-weight: 700;
  min-height: 40px; box-shadow: 0 8px 22px rgba(45, 212, 191, 0.25);
}
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #4ff0db, #26c9b4); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.file { position: relative; overflow: hidden; }
.btn.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.icon { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 3px 5px; border-radius: 4px; font-size: 11px; }
.icon:hover:not(:disabled) { color: var(--text); background: var(--surface-2); }
.icon.danger:hover:not(:disabled) { color: var(--danger); }
.icon:disabled { opacity: 0.25; cursor: default; }

input[type=search], input[type=text], input[type=number], input[type=date], select {
  width: 100%; min-height: 32px; padding: 5px 9px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
}
select { cursor: pointer; }
input:disabled, select:disabled { opacity: 0.45; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2.tight { gap: 6px; }
.search { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.seed { display: grid; grid-template-columns: 1fr 64px; gap: 4px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 30px; cursor: pointer; }
.layer { padding: 4px 0; border-top: 1px dashed var(--line); }
.layer:first-of-type { border-top: 0; }
.layer .sub { padding: 2px 0 4px 24px; display: grid; gap: 6px; }

/* switch */
.switch { appearance: none; width: 34px; height: 20px; border-radius: 20px; background: #2a3644; position: relative; cursor: pointer; flex: none; transition: background 0.2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #c3ced9; transition: transform 0.2s var(--ease), background 0.2s; }
.switch:checked { background: rgba(45, 212, 191, 0.35); }
.switch:checked::after { transform: translateX(14px); background: var(--accent); }

/* sliders */
.slider { display: grid; grid-template-columns: 82px 1fr 64px; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.slider output { font: 500 11.5px var(--mono); color: var(--text); text-align: right; white-space: nowrap; }
input[type=range] { appearance: none; width: 100%; height: 4px; border-radius: 4px; background: #2a3644; cursor: pointer; }
input[type=range]::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid #0b1016; box-shadow: 0 0 0 1px var(--accent); }
input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid #0b1016; }
input[type=range]:disabled { opacity: 0.4; }

.muted { color: var(--muted); }
.small { font-size: 11.5px; margin: 0; }
.right { text-align: right; }

/* stats & tables */
.stats { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 10px; }
.kv { width: 100%; border-collapse: collapse; }
.kv th { text-align: left; font-weight: 400; color: var(--muted); padding: 3px 8px 3px 0; white-space: nowrap; vertical-align: top; }
.kv td { text-align: right; font: 500 12px var(--mono); padding: 3px 0; word-break: break-word; }
.kv a { color: var(--accent); text-decoration: none; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; border: 1px solid rgba(255, 255, 255, 0.2); }

/* search hits */
#search-results:empty { display: none; }
#search-results { display: grid; gap: 4px; max-height: 210px; overflow: auto; }
.hit { display: grid; grid-template-columns: 1fr auto; align-items: center; background: var(--surface); border-radius: var(--radius-sm); }
.hit-go { text-align: left; border: 0; background: transparent; padding: 6px 9px; cursor: pointer; display: grid; border-radius: var(--radius-sm); }
.hit-go:hover { background: var(--surface-2); }
.hit-go small { color: var(--muted); font-size: 11px; }
.hit-use { font-size: 15px; margin-right: 4px; }

/* progress */
#progress .bar { height: 4px; border-radius: 4px; background: #2a3644; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--sun)); transition: width 0.4s var(--ease); }
#progress-text { margin-top: 5px; }

/* soil layer editor */
.lrows { display: grid; gap: 4px; }
.lrow { display: grid; grid-template-columns: 26px 1fr 62px 12px repeat(3, 20px); align-items: center; gap: 4px; }
.lrow input[type=color] { width: 26px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: none; cursor: pointer; }
.lrow input[type=color]::-webkit-color-swatch-wrapper { padding: 2px; }
.lrow input[type=color]::-webkit-color-swatch { border: 0; border-radius: 3px; }
.lrow input[type=text], .lrow input[type=number] { min-height: 26px; padding: 3px 6px; font-size: 12px; }
.lrow input[type=number] { font-family: var(--mono); }
.lrow .unit { color: var(--muted); font-size: 11px; }
.add { margin-top: 6px; }

.readout { font: 500 12px var(--mono); color: var(--sun); min-height: 30px; background: rgba(255, 209, 102, 0.07); border: 1px solid rgba(255, 209, 102, 0.18); border-radius: var(--radius-sm); padding: 7px 10px; }
.views { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.views .btn { padding: 6px 4px; font-size: 12px; }

/* ---------- floating cards ---------- */
.card {
  position: fixed; z-index: 4; background: var(--panel); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4); padding: 12px 14px;
}
.card h3 { margin: 2px 0 8px; font-size: 15px; letter-spacing: -0.01em; }
.kicker { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); font-weight: 600; }

.info { top: 12px; right: 12px; width: 300px; max-height: calc(100vh - 80px); overflow: auto; animation: rise 0.25s var(--ease); }
.info .close { position: absolute; top: 8px; right: 8px; }
.log { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 11.5px; }
.log th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 4px 4px 4px 0; }
.log td { padding: 4px 4px 4px 0; border-bottom: 1px solid rgba(148, 170, 190, 0.06); font-family: var(--mono); }
.log td:first-child { font-family: inherit; }

.legend { right: 12px; bottom: 40px; width: 230px; }
.column { display: flex; flex-direction: column; height: 190px; margin: 8px 0 6px; border-radius: 4px; overflow: hidden; border: 1px solid var(--line); }
.strat { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px; min-height: 0; font-size: 11px; border-top: 1px solid rgba(0, 0, 0, 0.35); overflow: hidden; }
.strat:first-child { border-top: 0; }
.strat i { align-self: stretch; }
.strat span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strat em { font: normal 10.5px var(--mono); color: var(--muted); padding-right: 6px; }

.hint {
  position: fixed; z-index: 6; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 16px; border-radius: 999px; background: rgba(6, 43, 39, 0.92); border: 1px solid rgba(45, 212, 191, 0.4);
  color: var(--accent); font-size: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}
.hint span { color: #a7c9c4; font-size: 11px; }
[hidden] { display: none !important; }

#statusbar {
  position: fixed; z-index: 3; left: calc(var(--panel-w) + 24px); right: 12px; bottom: 8px;
  display: flex; justify-content: space-between; gap: 16px; font: 11px var(--mono); color: #b4c2cf; text-shadow: 0 1px 2px #000; pointer-events: none;
}

#toast {
  position: fixed; z-index: 8; left: 50%; bottom: 46px; transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  max-width: min(560px, calc(100vw - 32px)); padding: 10px 16px; border-radius: var(--radius-sm);
  background: #18222d; border: 1px solid var(--line); border-left: 3px solid var(--accent); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  transition: opacity 0.25s, transform 0.25s var(--ease);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { border-left-color: var(--danger); }
#toast.warn { border-left-color: var(--warn); }
#toast.ok { border-left-color: var(--ok); }

.dropzone {
  position: fixed; inset: 0; z-index: 9; display: none; place-items: center; font-size: 18px; font-weight: 600; color: var(--accent);
  background: rgba(6, 43, 39, 0.55); border: 3px dashed var(--accent); pointer-events: none;
}
body.dropping .dropzone { display: grid; }

.panel-toggle {
  position: fixed; z-index: 7; top: 12px; left: calc(var(--panel-w) + 22px); width: 34px; height: 34px; border-radius: 8px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text); cursor: pointer; transition: left 0.35s var(--ease);
}
body.panel-closed .panel-toggle { left: 12px; }
body.panel-closed #statusbar, body.panel-closed .cesium-viewer-bottom { left: 12px !important; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* phone: panel becomes a bottom sheet */
@media (max-width: 760px) {
  :root { --panel-w: calc(100vw - 32px); }
  #panel { top: auto; left: 16px; right: 16px; bottom: 16px; width: auto; max-height: 55vh; }
  body.panel-closed #panel { transform: translateY(calc(100% + 24px)); }
  .panel-toggle { left: auto; right: 16px; top: 12px; }
  body.panel-closed .panel-toggle { left: auto; }
  .legend { display: none; }
  .info { left: 16px; right: 16px; width: auto; }
  #statusbar { left: 16px; top: 14px; bottom: auto; right: 60px; }
}

.copyright { padding: 9px 16px; border-top: 1px solid var(--line); font-size: 11px; color: var(--muted); text-align: center; }
.copyright a, .copyright-help a { color: var(--accent); text-decoration: none; }
.copyright a:hover, .copyright-help a:hover { text-decoration: underline; }
.copyright-help { margin: 0 0 6px; font-size: 12px; color: var(--muted); }

/* ---------- v2: tools, key box, chart drawer, help ---------- */
.brand .help-btn { margin-left: auto; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); font: 700 13px Inter, sans-serif; color: var(--accent); }
.keybox { display: grid; gap: 6px; padding: 8px; border-radius: var(--radius-sm); background: rgba(45, 212, 191, 0.05); border: 1px dashed rgba(45, 212, 191, 0.3); }
.keybox b { color: var(--text); font-weight: 600; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tool { display: grid; gap: 6px; padding: 8px 0; border-top: 1px dashed var(--line); }
.tool:first-of-type { border-top: 0; }
.tool-h { font-weight: 600; }
.readout.water { color: #7cc4ff; background: rgba(47, 143, 232, 0.08); border-color: rgba(47, 143, 232, 0.25); }
.readout:empty { display: none; }

.profile {
  position: fixed; z-index: 6; left: calc(var(--panel-w) + 24px); right: 12px; bottom: 30px; max-height: 46vh;
  display: flex; flex-direction: column; background: #f8fafc; color: #111827; border-radius: 12px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5); animation: rise 0.3s var(--ease);
}
.profile header { display: flex; align-items: center; gap: 12px; padding: 8px 10px 8px 16px; background: #eef2f6; border-bottom: 1px solid #dde3ea; }
.profile header .muted { color: #6b7280; font: 12px var(--mono); }
.profile .actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.profile .btn { background: #fff; color: #111827; border-color: #d4dae1; min-height: 28px; padding: 3px 10px; }
.profile .btn:hover { background: #f1f5f9 !important; }
.profile .icon { color: #4b5563; font-size: 14px; }
.profile-body { overflow: auto; padding: 6px; }
.profile-body svg { display: block; width: 100%; height: auto; min-width: 640px; }
body.panel-closed .profile { left: 12px; }

.modal { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(4, 8, 12, 0.6); backdrop-filter: blur(3px); }
.modal-card { position: relative; width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 22px 26px; border-radius: 16px; background: #111922; border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6); animation: rise 0.3s var(--ease); }
.modal-card h2 { margin: 4px 0 12px; font-size: 20px; letter-spacing: -0.015em; }
.modal-card .close { position: absolute; top: 12px; right: 12px; font-size: 14px; }
.steps { margin: 0 0 16px; padding-left: 20px; display: grid; gap: 8px; line-height: 1.55; }
.steps b { color: var(--accent); }
.cols { display: grid; grid-template-columns: 1fr 1.2fr; gap: 20px; margin-bottom: 10px; }
.keys th { text-align: left; }
.keys td { text-align: left; font-family: inherit; color: var(--muted); }
kbd { display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); border-bottom-width: 2px; font: 600 11px var(--mono); color: var(--text); text-align: center; }
pre { margin: 6px 0; padding: 8px 10px; border-radius: var(--radius-sm); background: #0b1117; border: 1px solid var(--line); font: 11px/1.5 var(--mono); color: #b8d4cf; overflow: auto; }
@media (max-width: 760px) {
  .profile { left: 16px; right: 16px; bottom: auto; top: 60px; }
  .cols { grid-template-columns: 1fr; }
}

/* ---------- 3D objects ---------- */
.pal-g { margin-bottom: 6px; }
.pal-h { color: var(--muted); font: 600 10.5px var(--mono); text-transform: uppercase; letter-spacing: 0.06em; margin: 2px 0 4px; }
.pal { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }
.pal-b {
  display: grid; justify-items: center; gap: 2px; padding: 5px 2px; min-height: 52px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); color: var(--text);
}
.pal-b i { font-style: normal; font-size: 18px; line-height: 1.2; }
.pal-b span { font-size: 9.5px; line-height: 1.15; color: var(--muted); text-align: center; }
.pal-b:hover { background: var(--surface-2); border-color: rgba(148, 170, 190, 0.3); }
.pal-b.on { border-color: var(--accent); background: rgba(45, 212, 191, 0.12); box-shadow: 0 0 0 1px var(--accent) inset; }
.pal-b.on span { color: var(--accent); }
.olist { display: grid; gap: 3px; max-height: 180px; overflow: auto; margin: 4px 0; }
.orow { display: grid; grid-template-columns: 1fr auto; align-items: center; background: var(--surface); border-radius: var(--radius-sm); border: 1px solid transparent; }
.orow.on { border-color: rgba(45, 212, 191, 0.5); }
.orow-b { display: grid; grid-template-columns: 22px 1fr auto; gap: 6px; align-items: center; text-align: left; border: 0; background: transparent; color: var(--text); padding: 4px 8px; cursor: pointer; }
.orow-b i { font-style: normal; }
.orow-b span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.orow-b small { color: var(--muted); font: 11px var(--mono); }
.dims label { display: grid; gap: 2px; color: var(--muted); font-size: 11px; }
.dims input { font-family: var(--mono); min-height: 28px; }
#obj-edit input[type=color] { width: 100%; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); background: none; cursor: pointer; }
[hidden] { display: none !important; }

/* building height legend */
.ramp { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 0; font: 11px var(--mono); color: var(--muted); }
.ramp i { grid-column: 1 / -1; height: 8px; border-radius: 4px; }
.ramp span:last-child { text-align: right; }

.row.sm { min-height: 26px; font-size: 12px; color: var(--muted); }
.swatch-in { width: 44px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: none; cursor: pointer; }

/* Earth Engine box */
.gee { grid-template-columns: 1fr 72px; }
#gee-year { font-family: var(--mono); }
#gee-settings { display: grid; gap: 6px; }
#gee-settings[open] { padding-top: 2px; }
#gee-settings summary { cursor: pointer; }
#gee-status.ok { color: var(--ok); }
#gee-status.error { color: var(--danger); }
#gee-status.warn { color: var(--warn); }

.field { display: grid; gap: 2px; color: var(--muted); font-size: 11px; }
.field input { font-family: var(--mono); min-height: 28px; }

/* north arrow (js/north.js): corner set by #north-pos; the svg turns, the button stays put */
.north { position: fixed; z-index: 3; padding: 0; border: 0; background: none; cursor: pointer; line-height: 0; filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45)); }
.north svg { display: block; transition: transform 0.08s linear; }
.north:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 50%; }
.north.tr { top: 12px; right: 12px; }
.north.tl { top: 58px; left: calc(var(--panel-w) + 22px); }
.north.br { bottom: 40px; right: 254px; }
.north.bl { bottom: 72px; left: calc(var(--panel-w) + 22px); }
body.panel-closed .north.tl, body.panel-closed .north.bl { left: 12px; }
@media (max-width: 760px) { .north.tr, .north.br { top: 56px; bottom: auto; right: 16px; } .north.tl, .north.bl { top: 56px; bottom: auto; left: 16px; } }
