:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #1f2328;
  --muted: #5d636c;
  --line: #ddd7ca;
  --accent: #2c6fb7;
  --good: #2f8f57;
  --warn: #d39a1f;
  --bad: #c9483b;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
button { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 8px; padding: 6px 11px; cursor: pointer; }
button:hover { border-color: #b9b2a2; }
button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; color: var(--muted); text-decoration: underline; padding: 0; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; background: #fff; width: 100%; }
input[type=range] { padding: 0; }
input[type=checkbox] { width: auto; }
textarea { resize: vertical; }
label { display: block; color: var(--muted); font-size: 14px; }
label > input, label > select, label > textarea { margin-top: 3px; color: var(--ink); }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 24px; max-width: 380px; width: 100%; }
.card h1 { margin: 0 0 6px; }
.card form { display: grid; gap: 12px; margin-top: 14px; }
.card button { background: var(--accent); color: #fff; border: 0; padding: 10px; }
.bad { color: var(--bad); margin: 0; }

/* ---------- desktop: everything on one screen, no page scrolling ---------- */
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.top { display: flex; align-items: center; gap: 12px; padding: 7px 14px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
.top h1 { font-size: 17px; margin: 0; }
.top .spacer { flex: 1; }
#who { color: var(--muted); font-size: 14px; }

.strip { display: flex; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; align-items: stretch; }
.drop { display: grid; place-content: center; gap: 1px; text-align: center; border: 2px dashed #c5bda9; border-radius: 10px; padding: 6px 14px; cursor: pointer; color: var(--ink); flex: none; width: 150px; }
.drop.over { border-color: var(--accent); background: #eef4fb; }
.drop span { color: var(--muted); font-size: 12px; }
.stripside { min-width: 0; flex: 1; display: grid; gap: 5px; }
.filters { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.filters button { padding: 3px 9px; font-size: 13px; }
.filters b { font-weight: 600; opacity: .7; }
#uploads { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
#uploads .err { color: var(--bad); }
#list { list-style: none; margin: 0; padding: 0 0 4px; display: flex; gap: 6px; overflow-x: auto; }
#list li { position: relative; cursor: pointer; border-radius: 7px; overflow: hidden; border: 2px solid transparent; background: #e8e3d7; flex: none; width: 78px; height: 58px; }
#list li.sel { border-color: var(--accent); }
#list img { width: 100%; height: 100%; object-fit: cover; display: block; }
#list .dot { position: absolute; top: 4px; right: 4px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; }
#list .tag { position: absolute; left: 0; right: 0; bottom: 0; font-size: 10px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.65)); padding: 8px 4px 2px; white-space: nowrap; overflow: hidden; }
.s-new { background: var(--bad); } .s-located { background: var(--warn); } .s-done { background: var(--good); } .s-skip { background: #8a8f98; }

main { flex: 1; min-height: 0; padding: 10px 14px; }
.empty { max-width: 560px; margin: 30px auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px 24px; }
#editor { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 10px; height: 100%; }
/* the two big pictures, side by side */
.views { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; min-height: 0; min-width: 0; }
.pane { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 8px 8px; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.pane figcaption { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 5px; flex: none; min-height: 22px; }
.hint { opacity: .8; }
.ovl { display: inline-flex; gap: 6px; align-items: center; margin-left: auto; font-size: 13px; }
.ovl input[type=range] { width: 80px; }
.fit { flex: 1; min-height: 0; position: relative; }            /* JS sizes .frame to fit here at the photo's shape */
.frame { position: absolute; background: #d9d4c8; border-radius: 7px; overflow: hidden; }
.frame img, .frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.frame img { object-fit: contain; }
#overlayCanvas { pointer-events: none; display: none; }
#renderFrame canvas { touch-action: none; cursor: grab; }
.placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; z-index: 2; pointer-events: none; }
.placeholder.small { place-items: end center; font-size: 13px; }
.camnav { position: absolute; right: 8px; bottom: 8px; z-index: 3; display: grid; grid-template-columns: repeat(3, 34px); gap: 4px;
  background: rgba(31,35,40,.35); padding: 5px; border-radius: 10px; }
.camnav button { width: 34px; height: 30px; padding: 0; font-size: 15px; background: rgba(255,255,255,.88); border-color: transparent; touch-action: none; user-select: none; }
.camnav button.on { background: var(--accent); color: #fff; }
#camFine { font-size: 11px; }
.camnav.tiny { grid-template-columns: repeat(3, 24px); gap: 2px; padding: 3px; right: 4px; bottom: 4px; opacity: .85; }
.camnav.tiny button { width: 24px; height: 22px; font-size: 11px; }
.camnav.tiny #camFine { font-size: 8px; }
.nopreview { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; color: var(--muted); }

/* narrow sidebar: small map to get a starting spot, then compact controls */
.side { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.mapwrap { position: relative; background: #cfc9bb; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); height: 210px; flex: none; }
.mapwrap.big { position: fixed; inset: 60px 40px 30px 40px; height: auto; z-index: 50; box-shadow: 0 10px 40px rgba(0,0,0,.35); }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.mapbtns { position: absolute; right: 6px; top: 6px; display: grid; gap: 4px; }
.mapbtns button { width: 30px; height: 30px; padding: 0; font-size: 16px; }
.maphint { position: absolute; left: 6px; right: 44px; bottom: 6px; background: rgba(31,35,40,.82); color: #fff; padding: 3px 8px; border-radius: 7px; font-size: 12px; pointer-events: none; }
.mapclose { position: absolute; right: 10px; bottom: 10px; z-index: 2; background: var(--accent); color: #fff; border-color: var(--accent); }
.controls { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; display: grid; gap: 7px; align-content: start; flex: 1; min-height: 0; overflow: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.grid2 .wide, .grid1 { grid-column: 1 / -1; }
.grid1 { display: grid; grid-template-columns: 0.8fr 1.2fr; gap: 6px 8px; }
.grid1 textarea { min-height: 31px; height: 31px; }
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button { padding: 3px 8px; font-size: 13px; }
.ctl { display: grid; gap: 2px; font-size: 12px; color: var(--muted); align-content: start; }
.ctl b { color: var(--ink); }
.nudge, .presets { display: flex; gap: 3px; flex-wrap: wrap; align-items: center; }
.nudge button, .presets button { padding: 2px 7px; font-size: 12px; }
.small { font-size: 12px; color: var(--muted); }
.presets.inline { display: inline-flex; margin-left: 4px; }
.presets.inline button { padding: 1px 5px; font-size: 11px; }
.actions { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; position: sticky; bottom: -8px; background: var(--panel); padding: 6px 0 2px; border-top: 1px solid var(--line); margin-top: 2px; }
.actions button { padding: 5px 10px; font-size: 14px; }
.save { font-size: 12px; color: var(--muted); width: 100%; }
.save.err { color: var(--bad); }
label { font-size: 13px; }
input, select, textarea { padding: 4px 7px; }

/* ---------- phones / narrow: photo + model side by side pinned on top, map and controls scroll below ---------- */
@media (max-width: 900px) {
  body { height: auto; overflow: visible; display: block; }
  .strip { flex-direction: column; }
  .drop { width: auto; padding: 8px; }
  main { padding: 8px; }
  #editor { display: block; height: auto; }
  .views { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 4px 0 6px; height: 42vh; gap: 6px; }
  .pane { padding: 4px; }
  .pane figcaption { font-size: 11px; margin-bottom: 3px; }
  .hint, .ovl input[type=range] { display: none; }
  .side { display: block; }
  .mapwrap { height: 30vh; margin-top: 8px; }
  .mapwrap.big { inset: 10px; height: auto; margin: 0; }
  .controls { margin-top: 8px; overflow: visible; }
  .grid1 { grid-template-columns: 1fr; }
  .actions { position: static; }
}
