:root {
  --panel: rgba(20, 24, 20, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  --ink: #f1f4ec;
  --muted: #b3bba9;
  --accent: #c8e07a;
  --accent-ink: #18200a;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #1d2a17;
  color: var(--ink);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
}

#mat {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#mat.dragging { cursor: grabbing; }
#mat.measuring { cursor: crosshair; }

#overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- Settings panel ---------- */

.panel {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: calc(16px + env(safe-area-inset-left, 0px));
  width: 280px;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  padding: 14px 16px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  transition: opacity 0.4s;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 16px;
}

.logo {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background:
    linear-gradient(90deg, transparent 6px, rgba(255, 255, 255, 0.75) 6px 7.5px, transparent 7.5px 12.5px, rgba(255, 255, 255, 0.75) 12.5px 14px, transparent 14px),
    linear-gradient(transparent 6px, rgba(255, 255, 255, 0.75) 6px 7.5px, transparent 7.5px 12.5px, rgba(255, 255, 255, 0.75) 12.5px 14px, transparent 14px),
    #3c6e2a;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--ink); }

.group {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.seg {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
}

.seg + .seg, .seg.small { margin-top: 8px; }

.seg button {
  flex: 1;
  padding: 7px 4px;
  white-space: nowrap;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.seg.small button { padding: 5px 6px; font-size: 13px; }
.seg button[data-value="image"] { flex: 1.25; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.row {
  display: flex;
  justify-content: space-between;
  margin: 12px 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.row output { color: var(--ink); font-variant-numeric: tabular-nums; }

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

.inch {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 2px;
  color: var(--muted);
  font-size: 13px;
}

.inch input {
  width: 58px;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--ink);
  font: inherit;
}

.btn {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn.small { padding: 5px 9px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }

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

.ruler-top { display: flex; gap: 6px; margin-bottom: 8px; }
.ruler-top .toggle { flex: 1; }
.btn.toggle.on, .fab.on { background: #ffd64a; border-color: #ffd64a; color: #2a2004; }

.inch select {
  padding: 5px 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--ink);
  font: inherit;
}

.fab {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: opacity 0.4s;
}

.fab svg { width: 26px; height: 26px; }

.img-actions { display: flex; gap: 6px; margin-top: 10px; }
.img-actions .btn { flex: 1; }

.note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.drop {
  position: fixed;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 3px dashed var(--accent);
  border-radius: 18px;
  background: rgba(15, 20, 12, 0.6);
  pointer-events: none;
  z-index: 20;
}

.drop p {
  margin: 0;
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--panel);
  font-size: 18px;
  font-weight: 600;
}
.actions .btn { flex: 1; }

.help {
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.back { margin: 0; font-size: 13px; }
.back a { color: var(--muted); text-decoration: none; }
.back a:hover { color: var(--ink); text-decoration: underline; }

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

.show-btn {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: calc(16px + env(safe-area-inset-left, 0px));
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: opacity 0.4s;
}

.show-btn svg { width: 22px; height: 22px; }

/* After a few quiet seconds, controls and cursor get out of the way */
body.idle .panel, body.idle .show-btn, body.idle .fab { opacity: 0; pointer-events: none; }
body.idle #mat { cursor: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 8px);
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.nogl {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  text-align: center;
}
