:root {
  color-scheme: light;
  --paper: #f4f3ef;
  --surface: #fff;
  --ink: #171a1d;
  --muted: #667078;
  --line: #cfd3d4;
  --line-dark: #9da5aa;
  --blue: #175cd3;
  --blue-soft: #e8f0ff;
  --green: #247a4a;
  --green-soft: #e8f5ed;
  --red: #b42318;
  --red-soft: #ffebe9;
  --amber: #a95208;
  --shadow: 0 12px 35px rgba(23, 26, 29, .12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--paper); color: var(--ink); }
button, input, textarea { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(20px, 6vw, 28px); letter-spacing: -.025em; }
h2 { font-size: 17px; letter-spacing: -.018em; }

.capture-app { width: min(100%, 680px); min-height: 100dvh; margin: 0 auto; border-right: 1px solid var(--line); border-left: 1px solid var(--line); background: var(--surface); }
.app-bar { min-height: calc(60px + env(safe-area-inset-top)); display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: env(safe-area-inset-top) 16px 12px; border-bottom: 1px solid var(--ink); }
.brand { display: flex; min-width: 0; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; width: 32px; height: 32px; flex: 0 0 auto; place-items: center; background: var(--ink); color: white; font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; }
.brand strong, .brand small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand strong { font-size: 15px; }
.brand small { max-width: 185px; margin-top: 1px; color: var(--muted); font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.app-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 8px; }
.connection-state { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.connection-state i, .record-state i { width: 8px; height: 8px; border: 1px solid var(--line-dark); border-radius: 50%; background: var(--surface); }
.connection-state.online i { border-color: var(--green); background: var(--green); }
.connection-state.pending i { border-color: var(--amber); background: var(--amber); }
.icon-button { display: inline-grid; width: 34px; height: 34px; padding: 7px; place-items: center; border: 1px solid var(--line-dark); border-radius: 8px; background: var(--surface); cursor: pointer; }
.icon-button:hover { background: var(--paper); }
.icon-button svg, .camera-switch svg, .finish-action svg, .capture-error svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.pairing-notice { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 12px; padding: 30px 18px; border-bottom: 1px solid var(--ink); background: var(--paper); }
.pairing-notice h1 { margin-bottom: 8px; }
.pairing-notice p { max-width: 48ch; color: var(--muted); font-size: 14px; line-height: 1.48; }
.notice-number, .eyebrow { color: var(--muted); font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; text-transform: uppercase; }
.pairing-notice .button { grid-column: 2; justify-self: start; margin-top: 6px; }

.button { min-height: 39px; padding: 8px 12px; border: 1px solid var(--ink); border-radius: 9px; background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 700; cursor: pointer; }
.button.primary { border-color: var(--blue); background: var(--blue); color: white; }
.button.secondary { border-color: var(--line-dark); }
.button:disabled, .round-action:disabled, .shutter-action:disabled { opacity: .42; cursor: default; }
.text-button { padding: 5px 0; border: 0; background: transparent; color: var(--blue); font-size: 12px; font-weight: 700; cursor: pointer; }
.text-button:disabled { color: var(--muted); cursor: default; }

.capture-workspace { padding-bottom: max(22px, env(safe-area-inset-bottom)); }
.camera-field { position: relative; min-height: min(58dvh, 565px); overflow: hidden; background: #171a1d; }
.camera-field video { display: block; width: 100%; height: min(58dvh, 565px); object-fit: cover; background: #171a1d; }
.camera-empty { position: absolute; inset: 0; display: grid; padding: 28px; place-content: center; justify-items: center; color: #fff; text-align: center; }
.camera-empty svg { width: 39px; height: 39px; margin-bottom: 13px; fill: none; stroke: currentColor; stroke-width: 1.25; }
.camera-empty p { font-size: 16px; font-weight: 700; }
.camera-empty small { max-width: 27ch; margin-top: 5px; color: #cfd3d4; font-size: 12px; line-height: 1.45; }
.camera-rule { position: absolute; left: 0; right: 0; height: 1px; background: rgba(255,255,255,.75); }
.camera-rule-top { top: 17%; }
.camera-rule-bottom { bottom: 17%; }
.camera-hud { position: absolute; top: 0; right: 0; left: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px; color: white; text-shadow: 0 1px 4px rgba(0,0,0,.55); }
.record-state { display: inline-flex; align-items: center; gap: 6px; font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; text-transform: uppercase; }
.record-state.recording i { border-color: #fb7c76; background: #fb7c76; box-shadow: 0 0 0 4px rgba(251,124,118,.25); }
.camera-hud output { font: 700 14px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .05em; }
.camera-switch { justify-self: end; display: grid; width: 34px; height: 34px; padding: 7px; place-items: center; border: 1px solid rgba(255,255,255,.65); border-radius: 8px; background: rgba(23,26,29,.58); color: white; cursor: pointer; }

.capture-dock { padding: 14px 16px 16px; border-bottom: 1px solid var(--ink); background: var(--surface); }
.capture-summary { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 19px; color: var(--muted); font-size: 12px; }
.capture-summary b { color: var(--ink); font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.summary-divider { width: 1px; height: 12px; background: var(--line); }
.control-row { display: grid; grid-template-columns: 1fr 78px 1fr; align-items: center; gap: 11px; max-width: 420px; margin: 10px auto 8px; }
.round-action { display: inline-flex; min-width: 0; min-height: 44px; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line-dark); border-radius: 10px; background: var(--surface); font-size: 12px; font-weight: 700; cursor: pointer; }
.record-action[aria-pressed="true"] { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.record-icon { width: 10px; height: 10px; border-radius: 50%; background: var(--red); }
.record-action[aria-pressed="true"] .record-icon { border-radius: 2px; }
.finish-action { color: var(--green); }
.shutter-action { display: grid; width: 78px; height: 78px; padding: 6px; place-items: center; border: 2px solid var(--ink); border-radius: 50%; background: var(--surface); cursor: pointer; }
.shutter-inner { display: block; width: 100%; height: 100%; border-radius: 50%; background: var(--blue); box-shadow: inset 0 0 0 4px var(--surface); }
.capture-guidance { color: var(--muted); font-size: 12px; line-height: 1.4; text-align: center; }

.evidence-strip { padding: 20px 16px 0; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.section-heading h2 { margin-top: 4px; }
.empty-evidence { margin: 14px 0 4px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.evidence-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; padding: 14px 0 0; margin: 0; list-style: none; }
.evidence-item { position: relative; min-width: 0; border: 1px solid var(--line); background: var(--paper); }
.evidence-thumb { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--line); }
.evidence-item.no-preview .evidence-thumb { display: grid; place-items: center; color: var(--muted); font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.evidence-caption { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 7px; font-size: 11px; }
.evidence-caption b { font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.evidence-caption span { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.upload-dot { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border: 1px solid white; border-radius: 50%; background: var(--amber); }
.evidence-item.uploaded .upload-dot { background: var(--green); }
.evidence-item.failed .upload-dot { background: var(--red); }

.server-log { padding: 20px 16px 0; border-top: 1px solid var(--ink); }
.server-log-list { padding: 0; margin: 14px 0 0; list-style: none; border-top: 1px solid var(--line); }
.server-log-item { display: grid; grid-template-columns: 58px 72px minmax(0, 1fr); gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 12px; line-height: 1.38; }
.server-log-time { color: var(--muted); font: 10px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.server-log-stage { align-self: start; color: var(--blue); font: 700 10px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; text-transform: uppercase; }
.server-log-content { min-width: 0; }
.server-log-content span, .server-log-content small { display: block; }
.server-log-content small { margin-top: 3px; overflow-wrap: anywhere; color: var(--muted); font-size: 10px; }
.server-log-item.event-processing_failed .server-log-stage { color: var(--red); }
.server-log-item.event-processing_complete .server-log-stage { color: var(--green); }

.capture-error { position: fixed; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); left: 14px; z-index: 5; display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 10px; max-width: 652px; padding: 11px 12px; margin: auto; border: 1px solid var(--red); border-radius: 10px; background: var(--red-soft); color: var(--ink); box-shadow: var(--shadow); }
.capture-error svg { color: var(--red); }
.capture-error p { font-size: 12px; line-height: 1.35; }
.capture-error .text-button { color: var(--ink); }

dialog { width: min(calc(100% - 24px), 510px); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--ink); border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(23,26,29,.55); }
dialog form { display: grid; gap: 12px; padding: 16px; }
dialog header, dialog footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
dialog header h2 { margin-top: 4px; }
dialog #photo-preview { display: grid; width: 100%; min-height: 120px; max-height: min(44dvh, 360px); place-items: center; background: var(--paper); }
dialog #photo-preview img { display: block; width: 100%; max-height: min(44dvh, 360px); object-fit: contain; }
dialog label { color: var(--ink); font-size: 12px; font-weight: 700; }
dialog label em { color: var(--muted); font-style: normal; font-weight: 400; }
textarea { width: 100%; padding: 9px; border: 1px solid var(--line-dark); border-radius: 8px; background: var(--surface); color: var(--ink); line-height: 1.4; resize: vertical; }
.dialog-hint, .finish-dialog p { color: var(--muted); font-size: 12px; line-height: 1.43; }
.finish-warning { color: var(--amber) !important; }
.toast { position: fixed; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); left: 14px; z-index: 6; max-width: 652px; padding: 11px 13px; margin: auto; border: 1px solid var(--ink); border-radius: 9px; background: var(--ink); color: white; font-size: 12px; opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity 160ms ease, transform 160ms ease; }
.toast.visible { opacity: 1; transform: translateY(0); }

@media (min-width: 680px) {
  body { padding: 22px; }
  .capture-app { min-height: calc(100dvh - 44px); box-shadow: var(--shadow); }
  .capture-error, .toast { right: auto; left: 50%; width: min(calc(100% - 48px), 652px); transform: translate(-50%, 12px); }
  .toast.visible { transform: translate(-50%, 0); }
}

@media (max-width: 390px) {
  .connection-state span { display: none; }
  .camera-field, .camera-field video { min-height: 46dvh; height: 46dvh; }
  .control-row { grid-template-columns: 1fr 70px 1fr; }
  .shutter-action { width: 70px; height: 70px; }
  .round-action { padding: 7px 5px; font-size: 11px; }
  .server-log-item { grid-template-columns: 54px 64px minmax(0, 1fr); gap: 6px; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition-duration: .01ms !important; } }
