/* Terrazed — dark, dense, tool-like. The terrain is the bright thing on
   screen; the chrome stays out of its way. */

:root {
  --bg: #0b0e13;
  --bg-panel: #11151c;
  --bg-raised: #171c25;
  --bg-input: #0d1117;
  --border: #232a35;
  --border-strong: #313a48;
  --text: #e6eaf0;
  --text-dim: #9aa4b2;
  --text-faint: #6b7583;
  --accent: #6ee7b7;
  --accent-dim: #34d399;
  --accent-ink: #05231a;
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 7px;
  --radius-sm: 5px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

a { color: var(--accent); }
a:hover { color: var(--accent-dim); }

h2, h3 { margin: 0; font-weight: 600; }
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.muted { color: var(--text-dim); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.warn { color: var(--warn); }
.spacer { flex: 1; }
.pad { padding: 8px 10px; }
.grow { flex: 1; }
.span-2 { grid-column: 1 / -1; }

/* ------------------------------------------------------------------ header */

.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  height: 52px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
}

.brand-mark {
  width: 24px;
  height: 24px;
  color: var(--accent);
}

.project-name {
  flex: 0 1 280px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------------------------------------------------------------- beta */

/* Always present next to the wordmark, so the beta status is stated even after
   the banner below has been dismissed. */
.beta-badge {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  padding: 2px 6px 2px 7px;
  border-radius: 3px;
  color: var(--accent-ink);
  background: linear-gradient(135deg, var(--warn), #f59e0b);
  box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.35), 0 0 12px rgba(251, 191, 36, 0.25);
  align-self: center;
  user-select: none;
}

.beta-banner {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  flex: 0 0 auto;
  background:
    linear-gradient(90deg, rgba(251, 191, 36, 0.10), rgba(251, 191, 36, 0.02) 55%, transparent),
    var(--bg-panel);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

/* A slow sheen travelling along the top edge — enough to read as "unfinished,
   in motion" without the blinking-marquee energy of a typical beta bar. */
.beta-banner::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--warn), transparent);
  animation: beta-sweep 5s ease-in-out infinite;
}

@keyframes beta-sweep {
  0%, 100% { transform: translateX(-60%); opacity: 0.35; }
  50% { transform: translateX(60%); opacity: 1; }
}

.beta-banner-tag {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--warn);
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: 3px;
  padding: 3px 8px;
  flex: 0 0 auto;
}

.beta-banner-text {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
  flex: 1;
  min-width: 0;
}
.beta-banner-text strong { color: var(--text); font-weight: 600; }

.beta-banner-close {
  flex: 0 0 auto;
  background: none;
  border: 1px solid transparent;
  color: var(--text-faint);
  border-radius: var(--radius-sm);
  width: 24px;
  height: 24px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.beta-banner-close:hover { background: var(--bg-raised); color: var(--text); }

.beta-banner[hidden] { display: none; }

/* -------------------------------------------------------------- app layout */

.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 340px;
  min-height: 0;
}

.panel {
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-left { border-right: 1px solid var(--border); }
.panel-right { border-left: 1px solid var(--border); }

.panel-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1;
  min-height: 0;
}

.panel-section {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.panel-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin-bottom: 10px;
}

.panel-footer {
  padding: 14px;
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.6;
}
.panel-footer p { margin: 0 0 6px; }

/* --------------------------------------------------------------- the stage */

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.stage-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex: 0 0 auto;
}

.tabs { display: flex; gap: 2px; background: var(--bg-input); padding: 3px; border-radius: var(--radius); }

.tabs button {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 5px 13px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { background: var(--bg-raised); color: var(--text); }

.stage-body {
  flex: 1;
  position: relative;
  min-height: 0;
}

.stage-pane {
  position: absolute;
  inset: 0;
}

#preview2d, #preview3d {
  width: 100%;
  height: 100%;
  display: block;
}

#preview3d { cursor: grab; }
#preview3d:active { cursor: grabbing; }

#preview2d { cursor: crosshair; touch-action: none; }
#preview2d.grabbing { cursor: grabbing; }

#zoom-level {
  font-family: var(--mono);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.stage-hint {
  position: absolute;
  left: 14px;
  bottom: 12px;
  margin: 0;
  font-size: 11px;
  color: var(--text-faint);
  pointer-events: none;
}

.map-canvas { position: absolute; inset: 0; }

.stat-row { display: flex; gap: 18px; flex-wrap: wrap; }

.stat { display: flex; flex-direction: column; gap: 1px; }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); }
.stat strong { font-size: 13px; font-weight: 600; }

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.count-list { display: flex; flex-wrap: wrap; gap: 4px; }
.count-pill {
  font-size: 11px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--text-dim);
}

/* -------------------------------------------------------------- progress */

.progress {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(11, 14, 19, 0.92);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 7px 14px;
  backdrop-filter: blur(6px);
}

.progress-track {
  width: 160px;
  height: 4px;
  background: var(--bg-raised);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.12s linear;
}

.progress-label { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

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

.group { border-bottom: 1px solid var(--border); }

.group > summary {
  padding: 11px 14px;
  cursor: pointer;
  font-weight: 550;
  font-size: 13px;
  list-style: none;
  display: flex;
  align-items: center;
  user-select: none;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before {
  content: "›";
  display: inline-block;
  margin-right: 8px;
  color: var(--text-faint);
  transition: transform 0.15s ease;
}
.group[open] > summary::before { transform: rotate(90deg); }
.group > summary:hover { background: var(--bg-raised); }

.group-body { padding: 4px 14px 14px; }
.group-help { margin: 0 0 12px; font-size: 12px; color: var(--text-dim); }

.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-inline { margin-bottom: 10px; }

.field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 5px;
}

.field-help {
  margin: 5px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-faint);
}

.row { display: flex; gap: 8px; align-items: center; }
.row > input[type="text"], .row > input[type="search"] { flex: 1; }

.mini {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-faint);
}
.mini input { width: 100%; }

input[type="text"],
input[type="number"],
input[type="search"],
input[type="email"],
input[type="password"],
select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  width: 100%;
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid var(--accent-dim);
  outline-offset: 1px;
}

input.num {
  width: 74px;
  text-align: right;
  font-family: var(--mono);
  font-size: 12px;
  padding: 3px 6px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 18px;
}

input[type="color"] {
  width: 30px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: none;
  cursor: pointer;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  cursor: pointer;
}
.checkbox input { width: auto; accent-color: var(--accent); }

.check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}

/* ----------------------------------------------------------------- chips */

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 8px; }

.chip {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 4px 11px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

/* --------------------------------------------------------------- buttons */

.btn {
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--text-faint); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { display: block; width: 100%; margin-bottom: 8px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-dim); border-color: var(--accent-dim); }

.btn.danger, .icon-btn.danger { color: var(--danger); }

.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  width: 26px;
  height: 26px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover:not(:disabled) { background: var(--bg-raised); color: var(--text); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ------------------------------------------------------------- segmented */

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  background: var(--bg-input);
  padding: 3px;
  border-radius: var(--radius);
}

.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }

.segmented span {
  display: block;
  text-align: center;
  padding: 6px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}
.segmented input:checked + span { background: var(--bg-raised); color: var(--text); font-weight: 550; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent-dim); }

/* ---------------------------------------------------------------- layers */

.layer-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }

.layer {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.layer.disabled { opacity: 0.5; }
.layer > summary { list-style: none; cursor: pointer; padding: 7px 9px; }
.layer > summary::-webkit-details-marker { display: none; }

.layer-header { display: flex; align-items: center; gap: 8px; }
.layer-tag {
  font-size: 10px;
  color: var(--text-faint);
  font-family: var(--mono);
  text-transform: uppercase;
}

.layer-body { padding: 4px 10px 10px; }

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

.map-root {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #0d1117;
  cursor: grab;
  touch-action: none;
}
.map-root.dragging { cursor: grabbing; }

.map-tiles { position: absolute; inset: 0; }

.map-tile {
  position: absolute;
  top: 0;
  left: 0;
  width: 256px;
  height: 256px;
  user-select: none;
  pointer-events: none;
  /* OSM tiles are bright; take the edge off so the selection reads clearly. */
  filter: saturate(0.8) brightness(0.82);
}
.map-tile.failed { visibility: hidden; }

.map-overlay { position: absolute; inset: 0; pointer-events: none; }

.map-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.map-controls button {
  width: 30px;
  height: 30px;
  background: rgba(17, 21, 28, 0.92);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 15px;
  cursor: pointer;
}
.map-controls button:hover { background: var(--bg-raised); }

.map-attribution {
  position: absolute;
  right: 6px;
  bottom: 4px;
  font-size: 10px;
  color: var(--text-dim);
  background: rgba(11, 14, 19, 0.75);
  padding: 2px 6px;
  border-radius: 3px;
}

/* --------------------------------------------------------------- search */

.search-wrap { position: relative; }

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  max-height: 240px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.search-result {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.search-result:hover { background: var(--bg-input); }
.search-result:last-child { border-bottom: none; }

/* ------------------------------------------------------------- provider */

.provider-note { margin-top: 8px; }
.provider-note p { margin: 0 0 5px; }

/* Licence is the thing people skip and later regret, so give it colour. */
.license {
  border-left: 2px solid var(--border-strong);
  padding-left: 8px;
  color: var(--text-dim);
}
.license-public-domain { border-left-color: var(--accent); }
.license-cc-by-nc-sa { border-left-color: var(--warn); }
.license-restricted { border-left-color: var(--danger); }

/* ------------------------------------------------------------- swatches */

.swatch-grid { display: flex; flex-direction: column; gap: 3px; }

.swatch {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  border-radius: 4px;
}
.swatch:hover { background: var(--bg-input); }
.swatch input[type="checkbox"] { width: auto; accent-color: var(--accent); }
.swatch-label { flex: 1; font-size: 12px; }
.swatch-count { font-size: 10px; color: var(--text-faint); font-family: var(--mono); }

/* --------------------------------------------------------------- modals */

.modal {
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 0;
  width: 90vw;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
.modal::backdrop { background: rgba(5, 7, 10, 0.7); }

.modal-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 15px; flex: 1; }

.modal-body { padding: 16px; max-height: 70vh; overflow-y: auto; }
.modal-body h3 { font-size: 13px; margin: 18px 0 8px; }
.modal-body h3:first-child { margin-top: 0; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-dim); }
.form-error { color: var(--danger); font-size: 12px; margin: 0; }

.key-list { display: flex; flex-direction: column; gap: 14px; }
.key-row { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; }
.key-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.key-row p { margin: 0 0 8px; }

.project-list { display: flex; flex-direction: column; gap: 8px; }

.project-card {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
}
.project-thumb {
  width: 56px;
  height: 56px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg-input);
}
.project-thumb.empty { border: 1px dashed var(--border-strong); }
.project-meta { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.project-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------- task status */

.task-status {
  margin: 4px 0 12px;
  padding: 9px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.task-bar {
  height: 4px;
  background: var(--bg-raised);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 7px;
}

.task-bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

/* No byte counts yet (still waiting on the upstream service): sweep instead of
   implying a percentage we do not know. */
.task-bar.indeterminate .task-bar-fill {
  width: 35%;
  animation: task-sweep 1.4s ease-in-out infinite;
}

@keyframes task-sweep {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(320%); }
}

.task-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
}

.task-phase { color: var(--text); }

.task-elapsed {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.task-hint {
  margin: 6px 0 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-faint);
}

.task-status.done .task-bar-fill { background: var(--accent); }
.task-status.done .task-phase { color: var(--accent); }
.task-status.failed .task-bar-fill { background: var(--danger); }
.task-status.failed .task-phase { color: var(--danger); }

/* --------------------------------------------------------------- toasts */

.toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  max-width: min(420px, calc(100vw - 32px));
}

.toast {
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--text-faint);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.45;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.18s ease;
}
.toast-success { border-left-color: var(--accent); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: #60a5fa; }
.toast.leaving { opacity: 0; transform: translateX(12px); transition: 0.2s ease; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.noscript {
  padding: 24px;
  text-align: center;
  color: var(--warn);
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 1200px) {
  .app-body { grid-template-columns: 280px minmax(0, 1fr) 300px; }
}

@media (max-width: 980px) {
  body { overflow: auto; }
  .app-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 60vh auto;
  }
  .panel { max-height: 60vh; border: none; border-top: 1px solid var(--border); }
  .panel-left { order: 2; }
  .stage { order: 1; min-height: 60vh; }
  .panel-right { order: 3; }
  .project-name { flex-basis: 140px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
