:root {
  --bg: #f3f5f2;
  --panel: #dce6db;
  --panel-border: #97ac95;
  --text: #10201c;
  --accent: #1f6b57;
  --accent-strong: #0b4b3a;
  --canvas-bg: #f9fbf8;
  --grid-major: rgba(39, 91, 74, 0.2);
  --grid-minor: rgba(39, 91, 74, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 10% 20%, #c6d8c4 0, transparent 22%),
    radial-gradient(circle at 90% 80%, #bed8d1 0, transparent 26%),
    var(--bg);
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  padding: 0.9rem 1rem;
  border-bottom: 2px solid var(--panel-border);
  background: linear-gradient(90deg, #dbe8d7 0%, #c9e0d8 100%);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-main {
  flex: 1;
  min-width: 180px;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.usyd-logo {
  height: 32px;
  width: auto;
  object-fit: contain;
}

.brand h1 {
  margin: 0;
  letter-spacing: 0.03em;
  font-size: 1.25rem;
}

.brand p {
  margin: 0.15rem 0 0;
  font-size: 0.82rem;
  opacity: 0.85;
}

.io-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  justify-content: flex-end;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--accent-strong);
  background: var(--accent);
  color: #fff;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button.toggle-on {
  background: #f3f9dd;
  color: #19402e;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 270px 1fr;
}

.control-panel {
  border-right: 2px solid var(--panel-border);
  background: var(--panel);
  padding: 0.7rem;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.control-panel section + section {
  margin-top: 0.7rem;
}

.control-panel h2 {
  margin: 0 0 0.55rem;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.3rem;
}

.tool-actions {
  margin-top: 0.25rem;
}

.tool-actions button {
  width: 100%;
}

/* Two-button row that splits evenly */
.btn-row {
  display: flex;
  gap: 0.3rem;
  margin-top: 0.25rem;
}

.btn-row button {
  flex: 1;
  min-width: 0;
}

.control-panel button {
  padding: 0.3rem 0.48rem;
  border-radius: 6px;
  font-size: 0.82rem;
}

.tool-btn.active {
  background: #f4fbe5;
  color: var(--accent-strong);
  border-color: var(--accent-strong);
  font-weight: 700;
}

label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}

label input,
label select,
textarea {
  display: block;
  margin-top: 0.18rem;
  width: 100%;
  border: 1px solid #819a80;
  border-radius: 7px;
  padding: 0.28rem 0.38rem;
  background: #f8fcf7;
}

textarea {
  resize: vertical;
  min-height: 90px;
}

.segment-metrics-list {
  margin-top: 0.35rem;
  font-size: 0.76rem;
  border: 1px solid #8fa48d;
  border-radius: 7px;
  background: #eef6ed;
  padding: 0.3rem 0.35rem;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
}

.xy-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
  margin-bottom: 0.4rem;
}

.xy-row label {
  margin-bottom: 0;
}

.xy-row > button {
  width: 100%;
}

.demo-choice {
  margin-bottom: 0.4rem;
}

.demo-choice label {
  margin-bottom: 0.18rem;
}

.demo-inline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.35rem;
  align-items: center;
}

.demo-inline select {
  margin-top: 0;
}

.demo-inline button {
  white-space: nowrap;
}

input[readonly] {
  background: #e8efe7;
  color: #2b453d;
}

.status #statusText {
  padding: 0.45rem;
  border: 1px solid #8fa48d;
  border-radius: 8px;
  background: #eef6ed;
  font-size: 0.84rem;
}

.quick-help ol {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.8rem;
}

.quick-help li + li {
  margin-top: 0.22rem;
}

.help-note {
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
  color: #24443b;
}

.help-note code {
  font-size: 0.76rem;
}

.status ul {
  margin: 0.7rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.84rem;
}

.status li + li {
  margin-top: 0.35rem;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: contain;
  background: var(--canvas-bg);
}

.canvas-stack {
  display: grid;
  grid-template-rows: 1fr 6px var(--vp-height, 260px);
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.canvas-stack.panel-hidden {
  grid-template-rows: 1fr 0 0;
}

/* ── Profile-panel drag resizer ── */
.vp-resizer {
  grid-row: 2;
  cursor: row-resize;
  background: var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: none;
  transition: background 0.15s;
  z-index: 5;
}

.vp-resizer::after {
  content: "";
  display: block;
  width: 40px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,0.55);
  box-shadow: 0 3px 0 rgba(255,255,255,0.55), 0 -3px 0 rgba(255,255,255,0.55);
}

.vp-resizer:hover,
.vp-resizer.dragging {
  background: var(--accent);
}

.vp-resizer.hidden {
  display: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
}

.vertical-panel {
  border-top: 2px solid var(--panel-border);
  background: #eef5ee;
  display: grid;
  grid-template-rows: auto 1fr;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.07);
  overflow: hidden;
  min-height: 0;
}

.vertical-panel.hidden {
  display: none;
}

/* ── New panel header ── */
.vp-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.5rem;
  background: #d8ecda;
  border-bottom: 1px solid #b6c7b5;
  min-height: 2rem;
  flex-wrap: wrap;
}

.vp-stats {
  flex: 1 1 auto;
  font-size: 0.75rem;
  color: #1e3a28;
  min-width: 0;
}

.vp-sep {
  color: #7aaa80;
  margin: 0 0.25rem;
  font-weight: 300;
}

.vp-stat {
  color: #1e3a28;
  white-space: nowrap;
}

.vp-stat b {
  font-weight: 600;
  margin-right: 0.15rem;
}

.vp-cut b { color: #a03020; }
.vp-fill b { color: #1a5090; }

.vp-tab-strip {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.vp-tab {
  padding: 0.18rem 0.55rem;
  font-size: 0.74rem;
  font-weight: 600;
  border: 1px solid #96b89a;
  border-radius: 4px;
  background: #eef5ee;
  color: #2a4a38;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.vp-tab:hover {
  background: #c8e8cc;
}

.vp-tab-active {
  background: #2a6b46;
  color: #fff;
  border-color: #1e5238;
}

.vp-close-btn {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  border: 1px solid #96b89a;
  border-radius: 50%;
  background: #eef5ee;
  color: #2a4a38;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.vp-close-btn:hover {
  background: #fde;
  border-color: #c44;
  color: #c44;
}

.vp-save-btn {
  flex-shrink: 0;
  height: 1.5rem;
  padding: 0 0.55rem;
  border: 1px solid #6a9e78;
  border-radius: 4px;
  background: #e4f0e8;
  color: #2a4a38;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.vp-save-btn:hover {
  background: #c8e8d0;
  border-color: #4a8e58;
}

.vp-save-btn:active {
  background: #a8d4b4;
}

/* backward compat — keep .vertical-meta pointing at .vp-header */
.vertical-meta {
  display: none; /* replaced by .vp-header */
}

#verticalCanvas {
  cursor: crosshair;
  display: block;
}

/* ── Profile chart popup button in Step 4 ── */
.profile-chart-btn {
  display: block;
  width: 100%;
  margin-top: 0.45rem;
  padding: 0.4rem 0.6rem;
  background: linear-gradient(135deg, #2a6b46 0%, #1f5238 100%);
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  transition: opacity 0.15s, transform 0.1s;
}

.profile-chart-btn:hover {
  opacity: 0.88;
  transform: translateY(-1px);
}

.profile-chart-btn.chart-open {
  background: linear-gradient(135deg, #8a3020 0%, #6e2018 100%);
}

/* ── Workflow steps ── */
.workflow-step {
  border-left: 3px solid var(--accent);
  padding-left: 0.55rem;
  margin-bottom: 0.1rem;
}

.workflow-step h2 {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.45rem;
  height: 1.45rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
}

.step-hint {
  font-size: 0.78rem;
  color: #2f5047;
  margin: 0 0 0.4rem;
  line-height: 1.4;
}

.field-hint {
  display: block;
  font-size: 0.72rem;
  color: #527060;
  margin-top: 0.1rem;
}

/* ── Tab strip ── */
.tab-strip {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.tab-btn {
  flex: 1;
  background: #c8ddc6;
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 6px 6px 0 0;
  padding: 0.3rem 0.4rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-strong);
  font-weight: 700;
}

.tab-pane {
  display: block;
}

.tab-pane.hidden {
  display: none;
}

/* ── Range slider ── */
.range-input {
  display: block;
  width: 100%;
  margin-top: 0.18rem;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Collapsible details sections ── */
details.collapsible {
  margin-top: 0.5rem;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  background: #e8f0e7;
}

details.collapsible > summary {
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--accent-strong);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  user-select: none;
}

details.collapsible > summary::before {
  content: "▶";
  font-size: 0.6rem;
  transition: transform 0.15s;
}

details.collapsible[open] > summary::before {
  transform: rotate(90deg);
}

.adv-body,
details.collapsible > section,
details.collapsible > div {
  padding: 0.45rem 0.5rem 0.55rem;
  border-top: 1px solid var(--panel-border);
}

.advanced-section {
  background: #e2ece0;
}

.demo-collapsible {
  margin-top: 0.4rem;
}

/* ── Section divider ── */
.section-divider {
  border: none;
  border-top: 1px solid var(--panel-border);
  margin: 0.5rem 0 0.4rem;
}

/* ── Contour drawing controls ── */
.contour-draw-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
  align-items: end;
  margin-bottom: 0.35rem;
}

.color-label {
  text-align: center;
}

.color-swatch {
  display: block;
  width: 100%;
  height: 28px;
  border: 1px solid #819a80;
  border-radius: 5px;
  padding: 1px 2px;
  cursor: pointer;
  background: #f8fcf7;
  margin-top: 0.18rem;
}

/* ── Contour list ── */
.contour-list {
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid var(--panel-border);
  border-radius: 7px;
  background: #f0f8ef;
  margin: 0.35rem 0;
  padding: 0.25rem 0.3rem;
}

.contour-list:empty::before {
  content: "No contour lines yet.";
  display: block;
  font-size: 0.76rem;
  color: #7a9a78;
  text-align: center;
  padding: 0.3rem;
}

.contour-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.15rem;
  font-size: 0.78rem;
  border-radius: 4px;
  cursor: default;
}

.contour-item:hover {
  background: #ddf0db;
}

.contour-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.2);
}

.contour-label {
  flex: 1;
  font-weight: 500;
}

.contour-pts {
  color: #7a9a78;
  font-size: 0.72rem;
}

.contour-delete-btn {
  background: transparent;
  border: none;
  color: #a03030;
  padding: 0 0.2rem;
  font-size: 0.85rem;
  border-radius: 3px;
  cursor: pointer;
  line-height: 1;
}

.contour-delete-btn:hover {
  background: #ffd6d6;
}

/* ── Results cards ── */
.results-step .results-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
}

.result-card {
  border-radius: 7px;
  padding: 0.35rem 0.4rem;
  text-align: center;
}

.result-card .rc-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  opacity: 0.8;
  margin-bottom: 0.1rem;
}

.result-card .rc-value {
  font-size: 0.92rem;
  font-weight: 700;
}

.rc-length   { background: #dff0df; color: #174a28; }
.rc-cut      { background: #fde8e4; color: #7a1c10; }
.rc-fill     { background: #dce8fc; color: #0d2d6e; }
.rc-road-cost  { background: #fff3cc; color: #5a3e00; }
.rc-total-cost { background: #e8dff8; color: #2b1260; grid-column: 1 / -1; }

.result-placeholder {
  font-size: 0.78rem;
  color: #7a9a78;
  text-align: center;
  padding: 0.6rem 0.4rem;
  border: 1px dashed var(--panel-border);
  border-radius: 7px;
  grid-column: 1 / -1;
}

/* cursor crosshair override when snapping */
canvas.snap-active {
  cursor: crosshair;
}

@media (max-width: 980px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-main {
    min-width: 0;
  }

  .topbar-right {
    justify-content: flex-start;
  }

  .usyd-logo {
    height: 26px;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 2px solid var(--panel-border);
  }
}
