/* Blueprint theme: drafting grid, white line work, cut-corner tags, dimension lines */
:root {
  --bp: #2357c8;            /* blueprint blue */
  --deep: #1b47ab;          /* deeper blue behind the photo */
  --ink: #ffffff;
  --muted: rgba(255, 255, 255, .72);
  --line: rgba(255, 255, 255, .6);
  --faint: rgba(255, 255, 255, .14);
  --hi: #ffd84a;            /* highlighter: logo + focus */
  --body: "Archivo", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --grid: linear-gradient(rgba(255,255,255,.13) 1px, transparent 1px) 0 0 / 100px 100px,
          linear-gradient(90deg, rgba(255,255,255,.13) 1px, transparent 1px) 0 0 / 100px 100px,
          linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px) 0 0 / 20px 20px,
          linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px) 0 0 / 20px 20px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  height: 100dvh; display: flex; flex-direction: column;
  font: 15px/1.4 var(--body); color: var(--ink); background: var(--grid), var(--bp);
}
[hidden] { display: none !important; }

/* ---------- app frame ---------- */
.app { flex: 1; min-height: 0; display: grid; grid-template-rows: auto 1fr; }
header { display: flex; align-items: center; gap: 18px; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.logo { margin: 0; font: 900 22px/1 var(--body); letter-spacing: -.02em; white-space: nowrap; margin-right: 4px; }
.logo span { background: var(--hi); color: var(--deep); padding: 1px 6px; }
.pages { display: flex; gap: 6px; margin-right: auto; }
.pages a { font: 500 12px var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 7px 12px; border: 1px solid transparent; text-decoration: none; }
.pages a:hover { color: #fff; }
.pages a.on { color: #fff; border-color: #fff; }
footer { text-align: center; font: 11px var(--mono); letter-spacing: .08em; color: var(--muted); padding: 4px 12px max(6px, env(safe-area-inset-bottom)); border-top: 1px solid var(--faint); }

/* ---------- buttons: white line work, selected ones fill in ---------- */
button {
  font: 600 14px var(--body); color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.8); border-radius: 0;
  min-height: 36px; padding: 0 14px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  white-space: nowrap; cursor: pointer; user-select: none; -webkit-user-select: none;
}
button:hover:not(:disabled) { background: rgba(255,255,255,.12); }
button:disabled { opacity: .4; cursor: default; }
button.primary, button.active { background: #fff; color: var(--deep); border-color: #fff; }
button.primary:hover:not(:disabled) { background: #e8eeff; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, label:focus-visible { outline: 2px solid var(--hi); outline-offset: 2px; }
.pill { min-height: 32px; padding: 0 11px; font-size: 13px; }
.big { width: 100%; min-height: 46px; font-size: 15px; }

/* ---------- workspace ---------- */
.work { display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
#stage { position: relative; display: flex; overflow: auto; min-height: 0; padding: 56px 40px 84px 64px; background: var(--grid), var(--deep); border-right: 1px solid var(--line); }
.app.empty #wrap, .app.empty .quick, .app:not(.empty) #drop { display: none; }
.app.empty .panel, .app.empty header button:not(#newBtn) { opacity: .45; pointer-events: none; }

/* empty state: a hatched drop zone */
#drop {
  flex: 1; margin: -24px -8px -48px -24px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  text-align: center; padding: 24px; cursor: pointer; border: 1px dashed #fff;
  background: repeating-linear-gradient(45deg, transparent 0 9px, rgba(255,255,255,.07) 9px 10px);
}
#drop.over { background: rgba(255,216,74,.18); }
#drop .big { font: 900 28px/1.1 var(--body); width: auto; min-height: 0; letter-spacing: -.01em; }
#drop p { margin: 0; max-width: 440px; color: var(--muted); }
#drop .tag { font: 600 11px var(--mono); letter-spacing: .1em; text-transform: uppercase; border: 1px solid #fff; padding: 4px 10px; }

/* the photo, outlined like a drawn frame */
#wrap { margin: auto; position: relative; flex: none; touch-action: none; outline: 1px solid #fff; outline-offset: 6px; }
#wrap.checker, .swatch.checker {
  background-color: #fff;
  background-image: linear-gradient(45deg, #dfe6f5 25%, transparent 25%), linear-gradient(-45deg, #dfe6f5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dfe6f5 75%), linear-gradient(-45deg, transparent 75%, #dfe6f5 75%);
  background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
.swatch.checker { background-size: 10px 10px; background-position: 0 0, 0 5px, 5px -5px, -5px 0; }
#canvas { display: block; position: absolute; }
#bgView { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; display: none; }
#wrap > .orig { position: absolute; pointer-events: none; visibility: hidden; z-index: 2; }
#wrap.comparing > .orig { visibility: visible; }
#stage.tool-move #wrap { cursor: grab; }
#stage.tool-magic #wrap, #stage.tool-blurbox #wrap { cursor: crosshair; }
#stage.tool-erase #wrap, #stage.tool-restore #wrap, #stage.tool-blurbrush #wrap { cursor: none; }
#cursor { position: fixed; pointer-events: none; border-radius: 50%; display: none; z-index: 5; border: 1.5px solid #fff; box-shadow: 0 0 0 1px #000, inset 0 0 0 1px #000; }

/* architect's dimension lines along the top and left of the photo */
.dim { position: absolute; display: flex; align-items: center; color: #fff; font: 500 11px var(--mono); letter-spacing: .04em; pointer-events: none; z-index: 8; }
.dim i { flex: 1; }
.dim span { white-space: nowrap; }
.dim.w { top: -32px; height: 12px; border-left: 1px solid #fff; border-right: 1px solid #fff; }
.dim.w i { border-top: 1px solid #fff; }
.dim.w span { padding: 0 8px; }
.dim.h { left: -34px; width: 12px; flex-direction: column; border-top: 1px solid #fff; border-bottom: 1px solid #fff; }
.dim.h i { border-left: 1px solid #fff; }
.dim.h span { writing-mode: vertical-rl; transform: rotate(180deg); padding: 8px 0; }

/* undo / compare / zoom strip, and the size readout */
.quick { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--deep); border: 1px solid var(--line); z-index: 9; }
.quick button { border: 0; min-height: 32px; padding: 0 10px; font-size: 13px; }
.quick .bar { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
.info { font: 11px var(--mono); letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }

/* found faces: dashed circle with a labeled pointer */
#wrap { counter-reset: face; }
.face-mark { position: absolute; z-index: 6; cursor: pointer; border-radius: 50%; border: 2px dashed #fff; background: rgba(255,216,74,.14); counter-increment: face; }
.face-mark.rect { border-radius: 0; }
.face-mark::after {
  content: "FACE " counter(face); position: absolute; left: 100%; top: 8%; margin-left: 22px; white-space: nowrap;
  font: 600 10.5px var(--mono); letter-spacing: .06em; background: #fff; color: var(--deep); padding: 2px 6px;
}
.face-mark::before { content: ""; position: absolute; left: 100%; top: calc(8% + 9px); width: 22px; border-top: 1px solid #fff; }
.face-mark.off { border-style: dotted; border-color: rgba(255,255,255,.6); background: transparent; }
.face-mark.off::after { content: "SKIPPED"; background: transparent; color: #fff; border: 1px solid #fff; }
#stage:not([data-tab="blur"]) .face-mark { display: none; }
#fxBand { position: absolute; display: none; border: 2px dashed #fff; background: rgba(255,255,255,.1); pointer-events: none; z-index: 6; }

/* crop: dashed box, the cut-away part tinted blueprint blue */
#cropLayer { position: absolute; overflow: hidden; z-index: 7; touch-action: none; cursor: crosshair; }
#cropBox {
  position: absolute; cursor: move; outline: 2px dashed #fff; box-shadow: 0 0 0 9999px rgba(20, 52, 140, .72);
  background-image:
    linear-gradient(to right, transparent calc(33.33% - 1px), rgba(255,255,255,.5) calc(33.33% - 1px) 33.33%, transparent 33.33% calc(66.66% - 1px), rgba(255,255,255,.5) calc(66.66% - 1px) 66.66%, transparent 66.66%),
    linear-gradient(to bottom, transparent calc(33.33% - 1px), rgba(255,255,255,.5) calc(33.33% - 1px) 33.33%, transparent 33.33% calc(66.66% - 1px), rgba(255,255,255,.5) calc(66.66% - 1px) 66.66%, transparent 66.66%);
}
.crop-h { position: absolute; width: var(--hs, 22px); height: var(--hs, 22px); border: 3px solid #fff; }
.crop-h.nw { left: -3px; top: -3px; border-right: 0; border-bottom: 0; cursor: nwse-resize; }
.crop-h.ne { right: -3px; top: -3px; border-left: 0; border-bottom: 0; cursor: nesw-resize; }
.crop-h.sw { left: -3px; bottom: -3px; border-right: 0; border-top: 0; cursor: nesw-resize; }
.crop-h.se { right: -3px; bottom: -3px; border-left: 0; border-top: 0; cursor: nwse-resize; }

/* ---------- side panel: tool tabs + one open card ---------- */
.panel { display: grid; grid-template-rows: auto 1fr; min-height: 0; background: rgba(14, 40, 110, .22); }
.tooltabs { display: grid; grid-template-columns: repeat(var(--n, 4), 1fr); gap: 8px; padding: 14px 14px 6px; }
.tooltab { flex-direction: column; gap: 5px; min-height: 58px; padding: 6px 4px; border-color: var(--line); font: 600 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.tooltab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.card { overflow: auto; min-height: 0; padding: 14px 14px 20px; }
.sec { border: 1px solid var(--line); padding: 0 12px 12px; margin: 0 0 12px; }
.sec.plain { padding-top: 12px; }
/* cut-corner label tag sitting on the box edge */
.lbl {
  position: relative; isolation: isolate; display: inline-block; margin: -1px 0 12px -13px; padding: 5px 26px 5px 12px;
  font: 600 11px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: #fff; background: #fff;
  clip-path: polygon(0 0, 100% 0, calc(100% - 12px) 100%, 0 100%);
}
.lbl::before { content: ""; position: absolute; inset: 1px; z-index: -1; background: var(--bp); clip-path: polygon(0 0, 100% 0, calc(100% - 12px) 100%, 0 100%); }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row + .row, .row + .slider, .slider + .row, .slider + .slider { margin-top: 10px; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.hint b { color: #fff; font-weight: 600; }
.found { margin-right: auto; font-size: 14px; }

/* sliders: hairline track, diamond thumb */
.slider { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.slider > span:first-child { width: 72px; flex: none; }
input[type=range] { -webkit-appearance: none; appearance: none; flex: 1; min-width: 80px; height: 22px; background: none; cursor: pointer; }
input[type=range]::-webkit-slider-runnable-track { height: 1px; background: rgba(255,255,255,.85); }
input[type=range]::-moz-range-track { height: 1px; background: rgba(255,255,255,.85); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; margin-top: -6px; background: var(--bp); border: 2px solid #fff; transform: rotate(45deg); }
input[type=range]::-moz-range-thumb { width: 11px; height: 11px; border-radius: 0; background: var(--bp); border: 2px solid #fff; transform: rotate(45deg); }

/* color swatches + position grid */
.swatch { width: 32px; height: 32px; min-height: 0; padding: 0; border: 1px solid #fff; position: relative; }
.swatch.active { outline: 1px solid #fff; outline-offset: 4px; }
.swatch input[type=color] { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; padding: 0; cursor: pointer; opacity: 0; }
#bgColorSwatch { background: conic-gradient(#f87171, #facc15, #4ade80, #38bdf8, #a78bfa, #f87171); }
.anchor { display: grid; grid-template-columns: repeat(3, 22px); gap: 4px; }
.anchor button { width: 22px; height: 22px; min-height: 0; padding: 0; }

/* ---------- messages and progress ---------- */
#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); max-width: min(320px, 86vw); z-index: 40;
  padding: 10px 14px; background: #fff; color: var(--deep); font: 600 13px var(--body); box-shadow: 6px 6px 0 rgba(10,30,90,.45);
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
#busy { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; z-index: 30; padding: 16px; background: rgba(20, 52, 140, .75); }
#busy .card { width: min(360px, 100%); padding: 20px 22px 22px; text-align: center; background: var(--grid), var(--bp); border: 1px solid #fff; overflow: visible; font: 700 17px var(--body); }
#busy .bar { position: relative; height: 14px; margin-top: 16px; border: 1px solid #fff; }
#busy .bar > div { position: absolute; left: 0; top: 0; bottom: 0; width: 0; max-width: 100%; transition: width .2s;
  background: repeating-linear-gradient(45deg, #fff 0 4px, transparent 4px 8px); }
#busy small { display: block; color: var(--muted); margin-top: 10px; font: 12px var(--mono); }

/* ---------- phones ---------- */
@media (max-width: 760px) {
  header { padding: 10px 12px; gap: 8px; flex-wrap: wrap; row-gap: 8px; }
  .logo { font-size: 19px; margin-right: auto; }
  .pages { order: 3; flex-basis: 100%; margin: 0; }
  .hide-sm { display: none; }
  .work { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  #stage { border-right: 0; padding: 42px 16px 62px 44px; }
  #drop { margin: -26px 0 -46px -28px; }
  #drop .big { font-size: 22px; }
  .quick { bottom: 10px; }
  .quick .zoom { display: none; }
  .face-mark::after, .face-mark::before { display: none; }
  .panel { grid-template-rows: auto auto; border-top: 1px solid var(--line); }
  .card { order: 1; max-height: 34vh; padding: 10px 10px 0; }
  .tooltabs { order: 2; padding: 8px; border-top: 1px solid var(--line); }
  .tooltab { min-height: 50px; }
  .sec { margin-bottom: 10px; }
  .card .row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
  .card .row::-webkit-scrollbar { display: none; }
  .card .row > * { flex: none; }
  .hint { display: none; }
  footer { padding-top: 2px; }
}
@media (prefers-reduced-motion: reduce) { #toast, #busy .bar > div { transition: none; } }
