:root {
  --ground: #ede3d3;
  --panel: #fbf7f0;
  --ink: #2e2723;
  --muted: #685e52;
  --taupe: #7d7365;
  --line: #dccfbb;
  --accent: #b9581f;
  --accent-hover: #a34d1b;
  --accent-ink: #ffffff;
  --wood: #e2cfae;
  --radius: 16px;
  --panel-w: 400px;
  --display: "Fraunces", Georgia, serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.45 "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 18px 28px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.site-nav { display: flex; flex-wrap: wrap; gap: 6px; }
.site-nav a { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-size: .9rem; background: var(--panel); }
.site-nav a:hover { border-color: var(--accent); }
.site-nav a[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.brand-logo { display: block; width: auto; height: 64px; border-radius: 12px; background: #343434; flex: none; }
.brand-title { margin: 0; font-family: var(--display); font-size: 1.45rem; font-weight: 600; letter-spacing: -.01em; line-height: 1.1; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.tagline { margin: 0; color: var(--muted); font-size: .92rem; }
.header-note { margin: 0; color: var(--muted); font-size: .85rem; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  gap: 20px;
  padding: 0 28px 16px;
  min-height: 0;
}

.map-wrap { position: relative; min-height: 0; overflow: hidden; border-radius: 18px; background: var(--wood); }
#map { position: absolute; inset: 0; }

/* The frame stays fixed; the map moves underneath it. */
.frame {
  position: absolute;
  pointer-events: none;
  border: 2px solid var(--accent);
  border-radius: 4px;
  box-shadow: 0 0 0 9999px rgba(46, 39, 35, .34);
  z-index: 2;
}
.frame.templated { border-color: rgba(185, 88, 31, .45); border-style: dashed; }
/* The optional frame, drawn to scale inside the map frame. */
.shape-row { align-items: flex-end; }
.shape-row .btn { min-height: 44px; }
.frame.drawing-shape { display: none; }
.frame-border { position: absolute; inset: 0; box-sizing: border-box; border: 0 solid rgba(206, 170, 120, .92); box-shadow: inset 0 0 0 1px rgba(60, 30, 10, .5); }
.frame-border.round { border-radius: 50%; }
.frame-overlay svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.frame-overlay .tpl-outside { fill: rgba(46, 39, 35, .34); }
.frame-overlay .tpl-edge { fill: none; stroke: var(--accent); stroke-width: 2.5; }
.frame-overlay .tpl-map { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; }
.frame-overlay .tpl-hole { fill: #fbf7f0; stroke: var(--accent); stroke-width: 1.5; }
.frame-overlay .tpl-engrave { fill: rgba(46, 39, 35, .78); }
.frame-size, .frame-scale {
  position: absolute;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 6px;
  white-space: nowrap;
}
.frame-size { top: -32px; left: -2px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.frame-scale { top: -32px; right: -2px; background: var(--panel); color: var(--ink); }

.map-hint {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  margin: 0;
  z-index: 3;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(251, 247, 240, .94);
  color: #4f4436;
  font-size: 13px;
  pointer-events: none;
  text-align: center;
  max-width: calc(100% - 32px);
}

/* MapLibre controls, restyled to match */
.maplibregl-ctrl-group { border-radius: 12px !important; box-shadow: 0 2px 8px rgba(46, 39, 35, .15) !important; background: var(--panel) !important; }
.maplibregl-ctrl-group button { width: 40px !important; height: 40px !important; }
.maplibregl-ctrl-top-right { top: 6px; right: 6px; }
.map-lock { display: grid !important; place-items: center; color: var(--ink); }
.map-lock[aria-pressed="true"] { background: var(--accent) !important; color: var(--accent-ink); }
.maplibregl-ctrl-group button:disabled { opacity: .35; }
.map-wrap.locked .map-hint { background: var(--accent); color: var(--accent-ink); }
.maplibregl-ctrl-scale { border-color: var(--ink) !important; background: rgba(251, 247, 240, .85) !important; color: var(--ink) !important; }

.panel {
  overflow-y: auto;
  min-height: 0;
}
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.step { padding: 18px 20px; border-radius: var(--radius); background: var(--panel); }
.step h2 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 12px;
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 600;
}
.num { color: var(--accent); font-size: .95rem; font-weight: 600; }

.step.send { background: var(--ink); color: var(--panel); }
.step.send h2 { color: var(--panel); }
.step.send .num { color: #e08a55; }
.step.send .status { color: #c9bfb1; }
.step.send .status.error { color: #f0a58a; }
.step.send .status.ok { color: #e8d9bf; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; flex: 1; min-width: 0; }
.field > span { font-size: .85rem; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }

input, select, textarea {
  font: inherit;
  color: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  font: inherit;
  font-size: .85rem;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.chip:hover { border-color: var(--ink); }
.chip[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: var(--panel); }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 12px;
  border-radius: 12px;
  background: var(--ground);
}
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; }
.seg span {
  display: block;
  height: 100%;
  padding: 9px 8px;
  text-align: center;
  font-size: .85rem;
  color: #4f4436;
  border-radius: 9px;
  cursor: pointer;
}
.seg input:checked + span { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(46, 39, 35, .12); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

.lists { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin: 0 0 10px; }
.lists legend { font-size: .85rem; color: var(--muted); padding: 0 4px; }
.check { display: flex; gap: 8px; align-items: center; font-size: .9rem; padding: 3px 0; }
.check input { width: auto; accent-color: var(--accent); }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.btn {
  font: inherit;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { min-height: 48px; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-size: 1rem; font-weight: 600; width: 100%; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.primary:disabled { opacity: .6; cursor: progress; }
.btn.ghost { border: none; background: none; font-size: 1.1rem; }

.status { min-height: 1.2em; margin: 8px 0 0; font-size: .85rem; color: var(--muted); }
.status.error { color: #a1301f; }
.status.ok { color: var(--accent-hover); }

.result {
  width: min(1100px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: none;
  border-radius: 20px;
  padding: 22px;
  background: var(--panel);
  color: var(--ink);
}
.result::backdrop { background: rgba(46, 39, 35, .55); }
.result h2 { margin: 0 0 14px; font-family: var(--display); font-weight: 600; font-size: 1.6rem; }
.result-close { position: absolute; top: 10px; right: 10px; }
.result-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 24px; }
[hidden] { display: none !important; }

.view-tabs { display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 10px; border-radius: 12px; background: var(--ground); }
.tab {
  font: inherit;
  font-size: .9rem;
  padding: 7px 16px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: #4f4436;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(46, 39, 35, .12); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.viewer {
  position: relative;
  height: min(60vh, 560px);
  min-height: 320px;
  border-radius: 14px;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 35%, #fbf7f0 0%, var(--ground) 75%);
  touch-action: none;
}
.viewer canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.viewer canvas:active { cursor: grabbing; }
.viewer-hint {
  position: absolute;
  left: 12px;
  top: 10px;
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(251, 247, 240, .9);
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}
.viewer-flip {
  position: absolute;
  right: 12px;
  top: 8px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(251, 247, 240, .95);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.viewer-flip:hover { border-color: var(--accent); }
.scale-note { margin: 10px 0 0; font-size: .88rem; color: var(--muted); }
.scale-note b { color: var(--ink); font-weight: 600; }

.owner-badge {
  margin: 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--panel);
  font-size: .8rem;
}
.link-btn { font: inherit; padding: 0; border: none; background: none; color: #e08a55; text-decoration: underline; cursor: pointer; }
.btn.owner-only { border-color: var(--accent); color: var(--accent-hover); }

.preview {
  background: var(--ground);
  border-radius: 14px;
  padding: 14px;
  display: grid;
  place-items: center;
}
.preview svg { max-width: 100%; max-height: 60vh; height: auto; box-shadow: 0 6px 18px rgba(46, 39, 35, .25); }
.stats { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .85rem; color: var(--muted); }
.stats b { color: var(--ink); }
.order h3 { margin: 0 0 12px; font-family: var(--display); font-weight: 600; font-size: 1.25rem; }

.site-footer {
  padding: 0 28px 12px;
  color: var(--muted);
  font-size: 11px;
}
.site-footer p { margin: 0; }

@media (max-width: 820px) {
  .map-hint { display: none; }
  body { display: block; height: auto; }
  .site-header { padding: 14px 16px; }
  .brand-logo { height: 52px; }
  .brand-title { font-size: 1.2rem; }
  .layout { display: block; padding: 0 16px 16px; }
  .map-wrap { height: 62vh; margin-bottom: 12px; }
  .frame-size { top: 8px; left: 8px; }
  .frame-scale { top: auto; bottom: 8px; right: 8px; }
  .result-grid { grid-template-columns: 1fr; }
  .viewer { height: 52vh; }
  .result { padding: 16px; }
  .site-footer { padding: 0 16px 12px; }
}

/* Step 4: special places */
.optional {
  font-family: "Instrument Sans", system-ui, sans-serif;
  font-size: .72rem;
  font-weight: 500;
  color: var(--muted);
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.step-note { margin: 0 0 12px; font-size: .88rem; color: var(--muted); }
.places { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.places:empty { display: none; }
.place { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.place .field { margin-bottom: 0; }
.place-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-weight: 600; font-size: .9rem; }
.place-head .link-btn { color: var(--accent-hover); font-size: .85rem; }
.shape-picker { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.shape-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
.shape-btn:hover { border-color: var(--ink); }
.shape-btn[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: var(--panel); }
.shape-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.places-actions { align-items: flex-end; }
.places-actions .btn { flex: 1; min-height: 44px; }
.places-actions .field { margin-bottom: 0; }

.place-marker { position: relative; cursor: grab; filter: drop-shadow(0 1px 2px rgba(46, 39, 35, .45)); }
.place-marker:active { cursor: grabbing; }
.place-marker svg { display: block; }
.place-marker span {
  position: absolute;
  left: 34px;
  top: 50%;
  transform: translateY(-50%);
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(251, 247, 240, .95);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
}
.place-marker span:empty { display: none; }

/* Step 5: customer's own text, shown on the map at its real size on the board */
.text-marker { cursor: grab; }
.text-body {
  position: relative;
  display: block;
  border: 1.5px dashed #b9581f;
  border-radius: 3px;
  background: rgba(251, 247, 240, .55);
  color: #2e2723;
  font-family: "Noto Sans", "Instrument Sans", system-ui, sans-serif;
  line-height: 1.25;
  text-align: center;
  white-space: pre;
}
.text-marker:active { cursor: grabbing; }
/* Grip below the box: a finger-sized handle for dragging on phones. */
.text-grip {
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #b9581f;
  color: #fff;
  box-shadow: 0 1px 4px rgba(46, 39, 35, .4);
  cursor: grab;
  touch-action: none;
}
.text-marker, .text-marker * { touch-action: none; }
.text-words:empty::before { content: "Your text"; color: var(--muted); }
.text-body.clear { background: #fbf7f0; border-style: solid; }
/* Corner handle (top right; the move grip is below): drag to scale the text.
   Sits just outside the corner so it never covers the words, and is finger-sized on touch screens. */
.text-resize {
  position: absolute;
  left: 100%;
  bottom: 100%;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin: 0 0 -6px -6px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #2e2723;
  color: #fff;
  box-shadow: 0 1px 4px rgba(46, 39, 35, .5);
  cursor: nesw-resize;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  z-index: 2;
}
.text-resize svg { pointer-events: none; }
.text-resize.active { background: #b9581f; }
.text-resize::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; } /* bigger touch target */
@media (pointer: coarse) {
  .text-resize { width: 36px; height: 36px; margin: 0 0 -8px -8px; }
}
.text-marker { user-select: none; -webkit-user-select: none; }
.text-size-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 4px; font-size: .88rem; }
.text-size-row input { flex: 1; accent-color: var(--accent); }
.text-size-row output { min-width: 4.2em; text-align: right; color: var(--muted); }
.text-row .check { margin: 4px 0 0; font-size: .88rem; }
.text-clear-note { margin: 2px 0 0; }
.text-input { width: 100%; min-height: 3.2em; resize: vertical; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }

/* Step 5: hiking route */
.route-actions { align-items: center; }
.route-actions .btn { flex: 1; min-height: 44px; }
.file-btn { display: inline-flex; align-items: center; justify-content: center; text-align: center; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: var(--panel); font-weight: 600; }
.btn.dark:hover { background: #000; }
.route-panel { margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.route-panel p { margin: 0 0 10px; font-size: .9rem; }
.route-panel .row .btn { flex: 1; }
#route-points { color: var(--muted); }
.field-note { margin: 4px 0 0; font-size: .8rem; color: var(--muted); }
.field-note:empty { display: none; }
.label-box { margin-top: 2px; }
.field-note-inline { color: var(--muted); font-size: .8rem; }

/* World switch: Earth / Moon / Mars */
.world-switch { grid-template-columns: repeat(3, 1fr); }
.world-switch a {
  display: block;
  padding: 8px;
  text-align: center;
  font-size: .9rem;
  color: #4f4436;
  text-decoration: none;
  border-radius: 9px;
}
.world-switch a[aria-selected="true"] { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(46, 39, 35, .12); }
.world-switch a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Etsy mode: design code panel */
/* Etsy mode: which listing and options this design needs */
.etsy-guide { margin: 4px 0 14px; padding: 12px 14px; border-radius: 12px; background: #f3e2cf; font-size: .9rem; }
.etsy-guide h4 { margin: 0 0 6px; font-family: var(--display); font-size: 1.05rem; font-weight: 600; }
.etsy-guide ol { margin: 0; padding-left: 1.2em; }
.etsy-guide li { margin: 4px 0; }
.etsy-guide .opt { display: inline-block; margin: 2px 4px 0 0; padding: 1px 8px; border-radius: 999px; background: #fbf7f0; border: 1px solid var(--line); font-size: .85rem; }
.etsy-guide .etsy-check { margin: 6px 0 0; font-size: .85rem; font-weight: 600; }
.etsy-guide .warn { margin: 6px 0 0; color: #8f1d17; }
.etsy-done { margin-top: 14px; padding: 16px; border-radius: 14px; background: var(--ground); text-align: center; }
.etsy-label { margin: 0; font-size: .85rem; color: var(--muted); }
.etsy-code { overflow-wrap: anywhere; margin: 4px 0 12px; font-family: var(--display); font-size: 1.8rem; font-weight: 600; letter-spacing: .04em; user-select: all; }
.etsy-order { margin: -6px 0 12px; font-weight: 600; }
.etsy-help { margin: 10px 0 12px; font-size: .88rem; color: var(--muted); }
.etsy-buy { display: block; text-decoration: none; text-align: center; line-height: 28px; }

/* Owner: material cost */
.cost { margin-top: 10px; }
.price { margin: 4px 0 14px; padding: 12px 14px; border-radius: 12px; background: #f3e2cf; }
.price-total { margin: 0; font-family: var(--display); font-size: 1.6rem; font-weight: 600; color: var(--ink); }
.price-total small { font-family: inherit; font-size: .85rem; font-weight: 500; color: var(--muted); }
.price ul { margin: 6px 0 0; padding: 0; list-style: none; font-size: .85rem; color: var(--muted); }
.price li { display: flex; justify-content: space-between; gap: 12px; }
.price-note { margin: 6px 0 0; font-size: .8rem; color: var(--muted); }

.cost-title { margin: 10px 0 6px; font-size: .9rem; font-weight: 600; }
.cost table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.cost th, .cost td { padding: 4px 6px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.cost th { color: var(--muted); font-weight: 500; }
.cost tr.best td { background: #f3e2cf; font-weight: 600; }
.cost-note { margin: 8px 0 0; font-size: .82rem; color: var(--muted); }
.cost-note b { color: var(--ink); }
.contour-note { margin: 0 0 10px 24px; }
