:root {
  color-scheme: dark;
  --bg: #101311;
  --surface: #171d1a;
  --surface-2: #202822;
  --ink: #f1f5ed;
  --muted: #aeb8ad;
  --line: #344039;
  --accent: #00c2a8;
  --accent-2: #f4c430;
  --danger: #ff4f5e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

button,
.file-button {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
}

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

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 1px;
  min-height: 100vh;
  background: var(--line);
}

.workspace,
.panel {
  background: var(--bg);
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 26px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.1;
}

h2 {
  font-size: 15px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.file-button {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}

.file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
}

.canvas-frame {
  position: relative;
  display: block;
  flex: 1;
  overflow: auto;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
}

.canvas-stage {
  position: relative;
  width: 720px;
  height: 520px;
  margin: auto;
}

.canvas-stage[hidden] {
  display: none;
}

.canvas-stack {
  position: absolute;
  inset: 0 auto auto 0;
  width: 720px;
  height: 520px;
  transform-origin: 0 0;
}

canvas {
  position: absolute;
  inset: 0;
  display: block;
}

#imageCanvas {
  background: #050605;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.4);
}

#overlayCanvas {
  touch-action: none;
  cursor: crosshair;
}

.empty-state {
  display: grid;
  gap: 8px;
  place-items: center;
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(520px, 86vw);
  min-height: 300px;
  border: 1px dashed #526058;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-state strong {
  color: var(--ink);
  font-size: 24px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.control-group {
  background: var(--surface);
  padding: 20px;
}

.help-panel {
  display: grid;
  gap: 12px;
  background: #111612;
  border-top: 1px solid var(--line);
  padding: 18px 20px 20px;
}

.help-panel[hidden] {
  display: none;
}

.help-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.help-head button {
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.help-steps {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.help-steps li {
  display: list-item;
  padding: 0;
  border: 0;
  background: transparent;
}

.help-steps li::before {
  content: none;
}

.help-steps strong {
  color: var(--ink);
}

.control-group {
  display: grid;
  gap: 14px;
  border-top: 1px solid var(--line);
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #041b17;
  font-weight: 800;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.unit-input {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d100e;
  padding: 0 12px;
}

.unit-input input {
  width: 100%;
  min-height: 42px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.metric {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: right;
}

.message {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.message.warning {
  color: var(--accent-2);
  font-weight: 700;
}

.zoom-control {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px 58px;
  gap: 8px;
  align-items: center;
}

.zoom-control button {
  min-height: 36px;
  padding: 0;
  font-weight: 800;
}

.zoom-control input {
  width: 100%;
  accent-color: var(--accent);
}

.zoom-control strong {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  text-align: right;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d100e;
}

.segmented button {
  border: 0;
  min-height: 36px;
  background: transparent;
  color: var(--muted);
}

.segmented .active {
  background: var(--surface-2);
  color: var(--ink);
}

.results {
  align-content: start;
  min-height: 0;
  flex: 1;
  overflow: auto;
}

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.export-actions {
  display: flex;
  gap: 8px;
}

.export-actions button {
  min-height: 34px;
  padding: 0 10px;
  white-space: nowrap;
}

#measurementList {
  align-content: start;
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

#measurementList li {
  --line-color: var(--accent);
  align-self: start;
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 10px;
  padding: 12px 12px 12px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111612;
}

#measurementList li::before {
  content: "";
  position: absolute;
  inset: 12px auto 12px 8px;
  width: 4px;
  border-radius: 999px;
  background: var(--line-color);
}

#measurementList li strong {
  color: var(--line-color);
}

#measurementList li small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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