:root {
  --bg: #f4efe6; --card: #fffaf2; --ink: #1d1b18; --dim: #6e675d; --line: #ddd4c5;
  --accent: #b5562e; --accent-ink: #fff; --dark: #121110; --dtext: #f3eee4; --ddim: rgba(243,238,228,.65);
  --glass: rgba(18,17,15,.62); --dline: rgba(239,232,218,.22);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #171614; --card: #201e1b; --ink: #f1ece2; --dim: #a39b8e; --line: #34302b; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

.screen { min-height: 100%; padding: calc(var(--safe-t) + 6px) 14px calc(var(--safe-b) + 20px); }
.screen.dark { background: var(--dark); color: var(--dtext); position: fixed; inset: 0; overflow: auto; padding: 0; }
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 0 12px; }
.bar.dark { padding: calc(var(--safe-t) + 8px) 12px 8px; }
.bar h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { font-size: 28px; line-height: 1; padding: 0 8px 4px 0; color: var(--accent); }
.back.light { color: var(--dtext); }
.btn { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; }
.dark .btn { background: rgba(255,255,255,.06); border-color: var(--dline); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: #c2412d; }
.btn.wide { width: 100%; justify-content: center; padding: 13px; margin-top: 14px; }
.note { font-size: 13px; color: var(--dim); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0 0 12px; }
.empty { color: var(--dim); text-align: center; margin-top: 40px; }

.cards { display: grid; gap: 12px; }
.card { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); text-align: left; width: 100%; }
.card img, .card .ph { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--line); flex: none; }
.card b { display: block; font-size: 16px; }
.card span { color: var(--dim); font-size: 13px; }

.form { display: grid; gap: 12px; padding-top: 6px; }
.form label, .lbl { display: grid; gap: 6px; font-size: 13px; color: var(--dim); font-weight: 600; }
.form input, .form textarea { padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 16px; color: var(--ink); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button { padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 14px; }
.chips button.on { background: var(--ink); color: var(--bg); border-color: transparent; font-weight: 600; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.actions.center { justify-content: center; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { border-radius: 12px; overflow: hidden; background: var(--card); border: 1px solid var(--line); text-align: left; padding: 0; }
.tile img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; display: block; background: var(--line); }
.tile div { padding: 6px 8px 8px; font-size: 12.5px; }
.tile b { display: block; font-size: 13px; }
.tile span { color: var(--dim); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.stage img, .stage canvas { width: 100%; border-radius: 10px; display: block; }
#sStage { position: relative; touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#sStage { display: grid; grid-template-columns: 1fr; gap: 8px; align-items: start; }
#sStage.two { grid-template-columns: 1fr 1fr; }
.pane { position: relative; margin: 0; }
.pane canvas { width: 100%; border-radius: 10px; display: block; }
.pane img { position: absolute; left: 0; top: 0; width: 100%; height: auto; border-radius: 10px; pointer-events: none; }
.pane figcaption { font-size: 12px; color: var(--dim); margin-top: 4px; font-weight: 600; }
#sStage:not(.two) figcaption { display: none; }
#sReading { position: absolute; right: 10px; top: 10px; padding: 3px 9px; border-radius: 999px; background: rgba(20,19,16,.7); color: #f3eee4; font-size: 12px; }
.withRow { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--dim); font-weight: 600; margin: 0 0 10px; }
.withRow select { flex: 1; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-size: 14px; }
.lookBlock { margin-top: 8px; }
.lookBlock h3 { margin: 0 0 4px; font-size: 12.5px; color: var(--dim); }
.refrow { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
.refrow img { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; }
.refrow .grow { flex: 1; font-size: 13px; color: var(--dim); }
.note.warn { border-color: #c98a3a; }
.homeTools { margin-top: 18px; }
#sHold { position: absolute; left: 10px; top: 10px; padding: 3px 9px; border-radius: 999px; background: rgba(20,19,16,.7); color: #f3eee4; font-size: 12px; font-weight: 600; }
.lens { margin: 0 0 10px; gap: 6px; }
.lens::-webkit-scrollbar { display: none; }
.lens button { white-space: nowrap; flex: none; }
.opts { display: flex; gap: 8px; align-items: center; margin: 0 0 10px; }
.opts .btn { padding: 6px 12px; }
.opts .btn.on { background: var(--ink); color: var(--bg); border-color: transparent; }
.seg.light { margin: 0; border-color: var(--line); background: var(--card); }
.seg.light button { color: var(--dim); padding: 6px 12px; }
.seg.light button.on { background: var(--ink); color: var(--bg); }
#lookInfo { margin: 10px 0 4px; font-size: 13.5px; }
.lookBar { display: flex; height: 18px; border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.lookBar:empty { display: none; }
.lookLegend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; color: var(--ink); font-weight: 600; }
.lookLegend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; box-shadow: 0 0 0 1px var(--dim); margin-right: 6px; vertical-align: -1px; }
.lookLegend span.sum { color: var(--dim); font-weight: 500; }
#lookFor { margin: 8px 0 4px; font-size: 13.5px; color: var(--dim); }
#lookFor b { color: var(--ink); }

/* capture */
#camStage { position: fixed; inset: 0; background: #000; }
#video, #ghost, #ghostLines { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#ghost { pointer-events: none; mix-blend-mode: normal; }
#ghostLines { pointer-events: none; }
#capTop { position: fixed; top: calc(var(--safe-t) + 8px); left: 12px; right: 12px; display: flex; align-items: center; gap: 10px; }
.pill { padding: 7px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--glass); border: 1px solid var(--dline); color: var(--dtext); }
.pill.on { background: var(--accent); border-color: transparent; }
.ghostctl { flex: 1; display: flex; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 999px; background: var(--glass); border: 1px solid var(--dline); font-size: 12.5px; color: var(--ddim); }
.ghostctl input { flex: 1; accent-color: var(--accent); }
#capBottom { position: fixed; left: 0; right: 0; bottom: 0; padding: 14px 22px calc(var(--safe-b) + 18px); display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(to top, rgba(0,0,0,.75), transparent); }
.side { width: 72px; font-size: 12px; color: var(--ddim); text-align: center; cursor: pointer; }
#shutter { width: 74px; height: 74px; border-radius: 50%; border: 4px solid var(--dtext); display: grid; place-items: center; }
#shutter span { width: 58px; height: 58px; border-radius: 50%; background: var(--dtext); transition: transform .1s; }
#shutter:active span { transform: scale(.88); }
#level { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 120px; height: 120px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.55); pointer-events: none; display: grid; place-items: center; }
#level::after { content: ''; position: absolute; width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); }
#bubble { position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #e9a23b; box-shadow: 0 0 8px rgba(0,0,0,.6); }
#level.ok { border-color: #8fc79a; } #level.ok #bubble { background: #8fc79a; }
#levelTxt { position: absolute; top: 128px; white-space: nowrap; font-size: 12px; font-weight: 600; text-shadow: 0 1px 4px #000; }

/* crop */
#cropStage { position: relative; touch-action: none; }
#cropCanvas { display: block; width: 100%; touch-action: none; }
#loupe { position: fixed; width: 140px; height: 140px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 4px 18px rgba(0,0,0,.6); pointer-events: none; }
.cropctl { padding: 10px 14px calc(var(--safe-b) + 16px); }
.hint { color: var(--ddim); font-size: 13px; margin: 6px 0 10px; }
.noteIn { display: grid; gap: 6px; font-size: 13px; color: var(--ddim); font-weight: 600; }
.noteIn input { padding: 11px 12px; border-radius: 10px; border: 1px solid var(--dline); background: rgba(255,255,255,.06); font-size: 16px; color: var(--dtext); }

/* compare / lapse */
.pickers { display: flex; gap: 8px; align-items: center; padding: 0 12px 8px; }
.pickers select { flex: 1; padding: 8px; border-radius: 8px; background: rgba(255,255,255,.08); border: 1px solid var(--dline); color: var(--dtext); font-size: 14px; }
.seg { display: flex; margin: 0 12px 10px; border: 1px solid var(--dline); border-radius: 999px; padding: 2px; }
.seg button { flex: 1; padding: 7px; border-radius: 999px; font-size: 13px; color: var(--ddim); }
.seg button.on { background: var(--dtext); color: var(--dark); font-weight: 600; }
#cmpStage, #lapseStage { position: relative; margin: 0 12px; touch-action: none; }
#cmpCanvas, #lapseCanvas { width: 100%; display: block; border-radius: 8px; touch-action: none; }
#cmpLabel, #lapseLabel { position: absolute; left: 10px; top: 10px; padding: 4px 9px; border-radius: 999px; background: var(--glass); font-size: 12.5px; font-weight: 600; pointer-events: none; }
#receipt { margin: 12px 12px calc(var(--safe-b) + 20px); padding-left: 20px; line-height: 1.5; }
.slow { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ddim); }

#toast { position: fixed; z-index: 30; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 110px); max-width: min(92vw, 420px);
  padding: 10px 14px; border-radius: 12px; background: rgba(20,19,16,.9); color: #f3eee4; font-size: 14px; text-align: center; }
#busy { position: fixed; z-index: 40; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; background: rgba(0,0,0,.45); color: #fff; font-weight: 600; }
.spin { width: 26px; height: 26px; border-radius: 50%; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.hint.shape { color: var(--dtext); margin-top: -4px; }
#shapeUse { margin: 0 0 10px; }
.psize { margin: -6px 0 10px; color: var(--dim); font-size: 13px; }
.link { color: var(--accent); font-weight: 600; font-size: 13px; padding: 0; }
