:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --ink: #1f1d1a;
  --muted: #6d675f;
  --line: #e2ddd5;
  --accent: #1f1d1a;
  --accent-ink: #ffffff;
  --stage: #2a2825;
  --focus: #8a6b3d;
  --radius: 10px;
  /* Poppins throughout. --serif is kept as the name for the heading font. */
  --serif: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --sans: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; } /* no double-tap zoom */
body { overflow-x: hidden; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--sans);
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand:empty { display: none; }
.art-heading { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.art-title { font-family: var(--serif); font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-meta { color: var(--muted); font-size: 13px; }

.unit-toggle { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.unit-toggle button {
  border: 0; background: transparent; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; color: var(--muted);
}
.unit-toggle button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

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

.stage-wrap {
  background: var(--stage);
  min-height: 300px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.stage-area {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.measure-bar {
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 12px 16px 14px;
}
.measure-step { margin: 0 0 10px; font-family: var(--serif); font-size: 16px; }
.measure-step small { display: block; font: 13px var(--sans); color: var(--muted); margin-top: 2px; }
.measure-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 10px;
  font-size: 13px;
  color: var(--muted);
}
.measure-controls select { width: 100%; min-width: 0; }
.measure-len { display: flex; align-items: center; gap: 6px; min-width: 0; }
.measure-len input { width: 7em; }
.measure-bar .btn-row .btn { flex: 1 1 auto; }
#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: default;
  outline: none;
}
#stage:focus-visible { box-shadow: inset 0 0 0 3px var(--focus); }

.stage-hint {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  background: rgba(20, 18, 16, 0.82);
  color: #fff;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  pointer-events: none;
  max-width: calc(100% - 32px);
  text-align: center;
}
.drop-overlay {
  position: absolute;
  inset: 12px;
  border: 2px dashed rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 18px;
  background: rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 16px;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  font-size: 14px;
  max-width: calc(100% - 32px);
}

.panel {
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 6px 18px 24px;
}
.step { padding: 14px 0; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: 0; }
.step h2 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 17px;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.num {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--ink);
  font: 12px var(--sans);
}
.pill {
  margin-left: auto;
  font: 12px var(--sans);
  padding: 2px 9px;
  border-radius: 999px;
  background: #f1e6d3;
  color: #7a5a22;
}
.pill.ok { background: #e1efe2; color: #2f6a35; }

.help { color: var(--muted); font-size: 13px; margin: 0 0 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--ink);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: #f3f0ea; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: #3a3631; }
.btn.ghost { border-color: var(--line); }
.btn.block { width: 100%; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.btn-row .btn { flex: 1; }

.field { margin: 12px 0 0; }
.field > label, .field > .label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field.inline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.field.inline > label { margin: 0; }
.field.check { display: flex; align-items: center; gap: 8px; }
.field.check label { margin: 0; color: var(--ink); font-size: 14px; }
select, input[type="number"] {
  font: inherit;
  font-size: 14px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
}
select { width: 100%; }
input[type="number"] { width: 84px; }
input[type="range"] { width: 100%; accent-color: var(--ink); }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: pointer;
  position: relative;
  padding: 0;
  background: var(--surface);
}
.swatch span {
  position: absolute;
  inset: 6px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 5px var(--c, transparent), inset 0 0 0 6.5px var(--c2, var(--c, transparent));
  background: linear-gradient(135deg, #e0a35b, #8a3b2a);
}
.swatch[aria-checked="true"] { outline: 2px solid var(--ink); outline-offset: 2px; }

.own-art { margin-top: 14px; font-size: 14px; }
.own-art summary { cursor: pointer; color: var(--muted); }
.own-art .btn { margin-top: 10px; }

.actions .btn-row { margin-top: 8px; }
.actions > .btn + .btn, .actions > .btn-row + .btn { margin-top: 8px; }

/* AR dialog */
.ar-dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  width: min(880px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  background: var(--surface);
  color: var(--ink);
}
.ar-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.ar-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.ar-head h2 { font-family: var(--serif); font-weight: 500; font-size: 19px; margin: 0; }
.icon-btn { border: 0; background: transparent; font-size: 18px; cursor: pointer; padding: 6px 8px; color: var(--ink); }
.ar-body { display: grid; grid-template-columns: minmax(0, 1fr) 260px; }
.ar-viewer { height: 440px; background: linear-gradient(#efece6, #d9d4cb); position: relative; }
.ar-viewer model-viewer { width: 100%; height: 100%; --poster-color: transparent; }
.ar-viewer .loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--muted); }
.ar-side { padding: 16px 18px; font-size: 14px; }
.ar-size { font-family: var(--serif); font-size: 17px; margin: 0 0 10px; }
.ar-steps { padding-left: 18px; margin: 0 0 12px; }
.ar-steps li { margin-bottom: 6px; }
.qr { width: 180px; height: 180px; margin-top: 8px; }
.qr img, .qr canvas { width: 100%; height: 100%; }
.ar-launch {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
}

@media (max-width: 820px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; }
  /* 16px stops iPhone Safari zooming (and shifting the page sideways) when a box is tapped. */
  select, input[type="number"] { font-size: 16px; }
  /* Measuring controls: each label above its box, full width. */
  .measure-controls { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .measure-controls label { margin-top: 6px; }
  .measure-len input { flex: 1; width: auto; min-width: 0; max-width: 10em; }
  .stage-wrap { min-height: 0; }
  .stage-area { flex: none; aspect-ratio: var(--photo-aspect, 4 / 3); max-height: 72vh; min-height: 240px; }
  body { height: auto; min-height: 100%; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; padding: 4px 16px 28px; }
  .topbar { padding: 8px 16px; gap: 10px; }
  .brand { display: none; }
  .ar-body { grid-template-columns: 1fr; }
  .ar-viewer { height: 55vh; }
}
