:root {
  --bg: #0d0f12;
  --panel: #171a1f;
  --panel2: #20242b;
  --line: #2c313a;
  --text: #f2f4f7;
  --muted: #9aa3ae;
  --accent: #34c759;
  --accent-ink: #062b10;
  --warn: #ffb020;
  --bad: #ff453a;
  --ghost: #38d6ff;
  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
input, textarea { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; overflow: hidden; }
.view { position: absolute; inset: 0; display: none; flex-direction: column; background: var(--bg); }
.view.active { display: flex; }
.scroll {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px calc(16px + var(--sar)) calc(24px + var(--sab)) calc(16px + var(--sal));
}

/* ---------- top bar ---------- */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--sat) + 8px) calc(10px + var(--sar)) 8px calc(10px + var(--sal));
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.bar h1 { flex: 1; margin: 0; font-size: 19px; font-weight: 650; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  min-width: 44px; height: 44px; border: 0; background: transparent; font-size: 24px;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 22px;
}
.icon-btn:active { background: var(--panel2); }
.tap-edit { text-decoration: underline dotted var(--muted); text-underline-offset: 4px; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 12px;
  padding: 12px 16px; min-height: 46px; font-weight: 600; flex: 1;
}
.btn:active { filter: brightness(1.25); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.big { padding: 16px; font-size: 18px; display: flex; flex-direction: column; align-items: center; }
.btn small { font-weight: 400; font-size: 13px; opacity: 0.8; }
.btn[disabled] { opacity: 0.45; }
.hero-actions { display: grid; gap: 10px; margin: 6px 0 14px; }
.row-actions { display: flex; gap: 10px; margin: 12px 0; flex-wrap: wrap; }

.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 8px; }
.note { background: #13324a; border: 1px solid #1e5378; border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 8px; }
.empty { color: var(--muted); text-align: center; padding: 24px 12px; }
.small { font-size: 14px; color: var(--muted); }

/* ---------- lists ---------- */
.list { display: grid; gap: 10px; }
.job {
  display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); width: 100%; text-align: left;
}
.job .thumbs { display: flex; width: 104px; height: 64px; border-radius: 10px; overflow: hidden; flex: none; background: var(--panel2); }
.job .thumbs img { width: 50%; height: 100%; object-fit: cover; }
.job .meta { flex: 1; min-width: 0; }
.job b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job span { color: var(--muted); font-size: 14px; }

.shot { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.shot .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; background: var(--line); }
.shot .cell { position: relative; aspect-ratio: 4 / 3; background: var(--panel2); border: 0; padding: 0; overflow: hidden; }
.shot .cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot .cell .tag { position: absolute; left: 6px; top: 6px; font-size: 11px; font-weight: 700; letter-spacing: .05em;
  background: rgba(0,0,0,.6); padding: 2px 6px; border-radius: 6px; }
.shot .cell.todo { display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--accent); font-weight: 700; gap: 4px; }
.shot .cell.todo small { color: var(--muted); font-weight: 400; }
.shot .info { display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.shot .info .lbl { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shot .info .lbl small { color: var(--muted); }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 10px; background: var(--panel2); }
.badge.good { background: #123d1c; color: #6ee38b; }
.badge.ok { background: #3d2f10; color: #ffcf70; }
.badge.bad { background: #44160f; color: #ff8a80; }

/* ---------- form bits ---------- */
.field { margin: 14px 0; }
.field label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.field small { display: block; color: var(--muted); font-size: 13px; margin-top: 6px; }
input[type=text] {
  width: 100%; font-size: 17px; padding: 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text);
}
.seg { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.4); }
.switch-row { display: flex; align-items: center; gap: 12px; padding: 10px 2px; font-size: 15px; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
.group { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px 10px; margin-bottom: 14px; }
.group h3 { margin: 12px 0 4px; font-size: 16px; }

dialog {
  border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--text);
  width: min(92vw, 420px); padding: 18px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h3 { margin-top: 0; }
dialog ol { padding-left: 20px; }
dialog li { margin-bottom: 8px; }
#menu-items { display: grid; gap: 8px; margin-bottom: 10px; }
#menu-form > .btn { width: 100%; }

.in-cam .toast { bottom: auto; top: calc(var(--sat) + 190px); }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab) + 24px); z-index: 50;
  background: #f2f4f7; color: #111; padding: 10px 16px; border-radius: 22px; font-weight: 600; font-size: 15px;
  box-shadow: 0 6px 24px rgba(0,0,0,.4); max-width: 90vw; text-align: center;
}

/* ================= CAMERA ================= */
.cam { background: #000; }
#stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
#frame { position: relative; overflow: hidden; background: #000; }
#frame video, #frame img, #frame canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#frame video { object-fit: cover; }
#ghost { object-fit: fill; pointer-events: none; opacity: .5; }
#edges { pointer-events: none; }
#overlay { pointer-events: none; }
#wipe-handle { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: #fff; box-shadow: 0 0 6px #000; pointer-events: none; }
#wipe-handle::after { content: "⇆"; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: #fff; color: #000; border-radius: 50%; width: 34px; height: 34px; display: grid; place-items: center; font-weight: 700; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
#flash.on { opacity: .85; transition: none; }

.cam-top {
  position: absolute; z-index: 2; left: 0; right: 0; top: 0; display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--sat) + 6px) calc(10px + var(--sar)) 6px calc(10px + var(--sal)); pointer-events: none;
}
.cam-top > * { pointer-events: auto; }
.glass { background: rgba(0,0,0,.45); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.cam-title { background: rgba(0,0,0,.45); padding: 6px 12px; border-radius: 16px; font-weight: 600; font-size: 15px;
  max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#hud { position: absolute; left: 50%; top: 50%; width: 100%; height: 100%; transform: translate(-50%, -50%);
  pointer-events: none; transition: transform .25s; }
.guide {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--sat) + 60px);
  background: rgba(0,0,0,.62); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 18px; padding: 10px 16px; text-align: center; min-width: 220px; max-width: 92%;
  border: 2px solid transparent; transition: border-color .2s, background .2s; pointer-events: none;
}
#guide-main { font-size: 24px; font-weight: 750; letter-spacing: -.01em; }
#guide-chips { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 4px; }
#guide-chips span { font-size: 13px; background: rgba(255,255,255,.14); padding: 2px 8px; border-radius: 10px; }
.guide.good { border-color: var(--accent); background: rgba(10,60,25,.75); }
.guide.close { border-color: var(--warn); }
.guide.lost { opacity: .85; }
.sensor-chip { position: absolute; z-index: 3; left: 50%; transform: translateX(-50%); top: calc(var(--sat) + 56px);
  border: 0; background: rgba(255,69,58,.92); color: #fff; font-weight: 650; font-size: 13px; padding: 7px 12px;
  border-radius: 14px; max-width: 92vw; }
.cam-hint { position: absolute; left: 50%; transform: translateX(-50%); top: calc(var(--sat) + 150px);
  background: rgba(255,176,32,.92); color: #231500; font-weight: 650; padding: 8px 14px; border-radius: 14px;
  font-size: 15px; max-width: 90vw; text-align: center; pointer-events: none; }

.level { position: absolute; left: 50%; top: 50%; width: 120px; height: 0; transform: translate(-50%,-50%); pointer-events: none; }
.level i { position: absolute; left: 0; right: 0; top: -1px; height: 2px; background: rgba(255,255,255,.85); box-shadow: 0 0 3px #000; transition: background .15s; }
.level.ok i { background: var(--accent); }
.level span { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 700; white-space: nowrap; text-shadow: 0 0 3px #000; }
.zoom-label { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--sab) + 236px);
  background: rgba(0,0,0,.55); border-radius: 14px; padding: 4px 10px; font-weight: 700; font-size: 14px; pointer-events: none; }

.cam-bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 8px calc(12px + var(--sar)) calc(var(--sab) + 10px) calc(12px + var(--sal));
  background: linear-gradient(transparent, rgba(0,0,0,.65) 30%);
}
.opacity-row { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; max-width: 520px; margin: 0 auto; }
.opacity-row input { flex: 1; accent-color: var(--ghost); height: 32px; }
.opacity-row span:last-child { width: 40px; text-align: right; }
.tools { display: flex; justify-content: center; gap: 6px; margin: 6px 0 8px; }
.tool { border: 0; background: rgba(255,255,255,.1); border-radius: 12px; width: 54px; height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: #ddd; }
.tool b { font-size: 18px; line-height: 1.1; }
.tool.on { background: rgba(56,214,255,.25); color: #fff; box-shadow: inset 0 0 0 1.5px var(--ghost); }
.shutter-row { display: flex; align-items: center; justify-content: space-around; max-width: 420px; margin: 0 auto; }
#shutter { position: relative; width: 84px; height: 84px; border-radius: 50%; border: 0; background: transparent; padding: 0; }
#shutter svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
#shutter::before { content: ""; position: absolute; inset: 11px; border-radius: 50%; background: #fff; transition: transform .1s; }
#shutter:active::before { transform: scale(.9); }
#shutter .ring-bg { fill: none; stroke: rgba(255,255,255,.35); stroke-width: 6; }
#shutter .ring { fill: none; stroke: var(--bad); stroke-width: 6; stroke-linecap: round; stroke-dasharray: 289; stroke-dashoffset: 289; transition: stroke-dashoffset .2s, stroke .2s; }
#score { position: relative; color: #111; font-weight: 800; font-size: 17px; }
.peek { width: 60px; height: 60px; border-radius: 12px; border: 2px solid rgba(255,255,255,.7); padding: 0; overflow: hidden; background: #222; position: relative; }
.peek img { width: 100%; height: 100%; object-fit: cover; display: block; }
.peek span { position: absolute; bottom: 0; left: 0; right: 0; font-size: 10px; background: rgba(0,0,0,.6); }
.peek.spacer { border: 0; background: transparent; }

.cam-msg { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.75); padding: 24px; }
.cam-msg .card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; max-width: 420px; }
.cam-msg p { white-space: pre-line; }

/* Landscape: controls move to the right edge so the frame gets the height. */
@media (orientation: landscape) and (max-height: 540px) {
  .cam-bottom { left: auto; top: 0; width: 230px; display: flex; flex-direction: column; justify-content: flex-end;
    background: linear-gradient(90deg, transparent, rgba(0,0,0,.65) 25%); padding-top: calc(var(--sat) + 60px); }
  .tools { flex-wrap: wrap; }
  .tool { width: 60px; height: 46px; }
  .opacity-row > span:first-child { display: none; }
  .cam-title { display: none; }
  .guide { top: calc(var(--sat) + 8px); left: calc(50% - 115px); }
  #guide-main { font-size: 20px; }
  .cam-hint { top: auto; bottom: 16px; left: calc(50% - 115px); }
  .zoom-label { bottom: 16px; left: 70px; transform: none; }
}

/* ================= COMPARE ================= */
.review-body { max-width: 760px; margin: 0 auto; width: 100%; }
.compare { position: relative; margin-top: 12px; border-radius: 12px; overflow: hidden; background: #000; touch-action: pan-y; }
.compare img { display: block; width: 100%; height: auto; }
.compare .after-wrap { position: absolute; inset: 0; overflow: hidden; }
.compare .after-wrap img { position: absolute; inset: 0; width: 100%; height: 100%; }
.compare .handle { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1.5px; background: #fff; box-shadow: 0 0 6px #000; }
.compare .handle::after { content: "⇆"; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: #fff; color: #000; border-radius: 50%; width: 38px; height: 38px; display: grid; place-items: center; font-weight: 800; }
.compare .tag { position: absolute; top: 8px; font-size: 12px; font-weight: 800; letter-spacing: .06em; background: rgba(0,0,0,.6); padding: 3px 8px; border-radius: 8px; }
.compare .tag.l { left: 8px; } .compare .tag.r { right: 8px; }
.compare.side { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; background: var(--line); }
.compare.side.stack { grid-template-columns: 1fr; }
.compare.side > div { position: relative; }
.match-report { margin: 10px 2px 0; font-size: 15px; }
.match-report b.good { color: #6ee38b; } .match-report b.ok { color: #ffcf70; } .match-report b.bad { color: #ff8a80; }
.exp-preview { width: 100%; border-radius: 10px; margin-top: 8px; background: var(--panel); min-height: 40px; }

/* progress strip on an angle card */
.shot .prog { display: flex; align-items: center; gap: 6px; padding: 6px 10px 0; overflow-x: auto; }
.shot .prog-l { font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-right: 2px; }
.pthumb { position: relative; flex: none; width: 52px; height: 40px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: var(--panel2); padding: 0; }
.pthumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pthumb span { position: absolute; right: 2px; bottom: 1px; font-size: 10px; font-weight: 800; background: rgba(0,0,0,.6); padding: 0 4px; border-radius: 5px; }
.pthumb.add { color: var(--accent); font-size: 20px; font-weight: 700; border-style: dashed; }
#btn-area-new { width: 100%; margin-top: 12px; }

/* work area editor */
.area-box { position: relative; margin-top: 10px; border-radius: 12px; overflow: hidden; touch-action: none; background: #000; }
.area-box img { display: block; width: 100%; height: auto; pointer-events: none; }
#area-rect { position: absolute; border: 2px dashed #ffb020; background: repeating-linear-gradient(45deg, rgba(255,176,32,.28) 0 10px, rgba(255,176,32,.12) 10px 20px); pointer-events: none; }
#area-rect span { position: absolute; left: 6px; top: 4px; font-size: 12px; font-weight: 800; color: #fff; text-shadow: 0 0 3px #000; }
#ghost, #edges { transition: opacity .3s; }

/* follow-through */
.section-title.warn { color: #ffb020; }
.todo-item { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: left;
  padding: 12px 14px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.todo-item span { color: var(--muted); font-size: 14px; }
.todo-item.due { border-color: #ffb020; background: #2a210d; }
.todo-item.overdue { border-color: var(--bad); background: #2c1110; }
.due-row { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--muted); margin: -2px 2px 12px; }
.due-row.alert { color: #ffcf70; }
.due-btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 10px; padding: 6px 10px; font-weight: 600; }
.dlg-btns { display: grid; gap: 8px; }
.dlg-btns .btn { width: 100%; }
b.siri { display: block; font-size: 18px; color: #6ee38b; }
#info-body { line-height: 1.5; }

/* truck alert setup */
#v-truck p { line-height: 1.5; }
#truck-url { font-size: 13px; font-family: ui-monospace, Menlo, monospace; }
ol.steps { padding-left: 22px; line-height: 1.5; }
ol.steps li { margin-bottom: 10px; }
ol.steps code { background: var(--panel2); padding: 1px 6px; border-radius: 6px; }
