:root {
  --bg: #f2f4f1;
  --surface: #ffffff;
  --surface-2: #e7ebe6;
  --border: #d3d9d1;
  --ink: #1b2420;
  --ink-soft: #4d5850;
  --ink-faint: #7c8880;
  --accent: #256a4a;
  --accent-strong: #1a4d36;
  --accent-soft: #e3ede7;
  --accent-ink: #ffffff;
  --danger: #b3432f;
  --danger-soft: #f6e6e1;
  --warn-soft: #f5ecdc;
  --warn-ink: #7a5115;
  --stage-bg: #10140f;
  --shadow: 0 1px 2px rgba(20,30,20,0.07), 0 10px 26px -14px rgba(20,30,20,0.28);
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 22px;
  --font-display: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121814; --surface: #1a2219; --surface-2: #212b23; --border: #34423b;
    --ink: #eef2ee; --ink-soft: #a9b6ae; --ink-faint: #7e8c83;
    --accent: #57b98a; --accent-strong: #7ccca4; --accent-soft: #1e352a; --accent-ink: #0b1710;
    --danger: #e3806a; --danger-soft: #3a231d; --warn-soft: #3a2f1a; --warn-ink: #e8c37e;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 10px 26px -14px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"] {
  --bg: #121814; --surface: #1a2219; --surface-2: #212b23; --border: #34423b;
  --ink: #eef2ee; --ink-soft: #a9b6ae; --ink-faint: #7e8c83;
  --accent: #57b98a; --accent-strong: #7ccca4; --accent-soft: #1e352a; --accent-ink: #0b1710;
  --danger: #e3806a; --danger-soft: #3a231d; --warn-soft: #3a2f1a; --warn-ink: #e8c37e;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 10px 26px -14px rgba(0,0,0,0.5);
}

* , *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font-display);
}
button { font-family: inherit; }
svg { display: block; }
img { max-width: 100%; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Login gate */
.login-gate {
  position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center;
  background: var(--bg); padding: 20px;
}
.login-gate:not([hidden]) { display: flex; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m);
  box-shadow: var(--shadow); padding: 28px; max-width: 340px; width: 100%;
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-title { margin: 0; font-weight: 700; font-size: 1.05rem; }
.login-sub { margin: 0; font-size: 0.86rem; color: var(--ink-soft); }
.login-card input {
  font-family: var(--font-mono); font-size: 1.1rem; letter-spacing: 0.08em; text-align: center;
  padding: 10px 12px; border-radius: var(--radius-s); border: 1px solid var(--border);
  background: var(--bg); color: var(--ink);
}
.login-card input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-error { margin: 0; font-size: 0.82rem; color: var(--danger); display: none; }
.login-error:not([hidden]) { display: block; }

/* Shell */
.app { display: none; }
.app:not([hidden]) { display: block; }
.chrome { display: flex; flex-direction: column; min-height: 100dvh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px clamp(14px, 3vw, 26px); background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: var(--radius-s); background: var(--accent-soft);
  color: var(--accent-strong); display: flex; align-items: center; justify-content: center; flex: none;
}
.brand-text { line-height: 1.15; }
.brand-title { margin: 0; font-weight: 700; font-size: 0.98rem; letter-spacing: -0.01em; }
.brand-sub { margin: 0; font-size: 0.78rem; color: var(--ink-soft); }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 999px; }
.tab {
  display: flex; align-items: center; gap: 6px; border: none; background: transparent; color: var(--ink-soft);
  padding: 8px 14px; border-radius: 999px; font-size: 0.86rem; font-weight: 600; cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.count-badge { font-family: var(--font-mono); font-size: 0.72rem; background: rgba(0,0,0,0.12); padding: 1px 6px; border-radius: 999px; }
.tab[aria-selected="true"] .count-badge { background: rgba(255,255,255,0.25); }
.logout-link {
  border: none; background: transparent; color: var(--ink-faint); font-size: 0.78rem;
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.logout-link:hover { color: var(--ink-soft); }

.stage { flex: 1; padding: clamp(14px, 3vw, 26px); max-width: 1040px; width: 100%; margin: 0 auto; }
.view { display: none; animation: mdc-fade .18s ease; }
.view:not([hidden]) { display: block; }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } }
@keyframes mdc-fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Capture view */
.capture-stage {
  position: relative; background: var(--stage-bg); border-radius: var(--radius-l); overflow: hidden;
  min-height: 46vh; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px; padding: 32px; text-align: center; color: #f2f4f1;
  transition: transform .12s ease, opacity .12s ease;
}
.capture-stage:hover { transform: translateY(-1px); }
.capture-stage:active { transform: scale(0.99); }
.capture-stage:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }
.capture-stage.flash-active { opacity: 0.55; transition: opacity .15s ease; }
.capture-stage-icon { width: 74px; height: 74px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; }
.capture-stage-text { font-weight: 600; font-size: 1.02rem; }
.capture-stage-hint { font-size: 0.84rem; color: #b7c1ba; max-width: 32ch; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface);
  color: var(--ink); display: flex; align-items: center; justify-content: center; cursor: pointer; flex: none;
  transition: background .15s ease;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.recent-strip { display: flex; gap: 8px; margin-top: 16px; overflow-x: auto; padding-bottom: 2px; }
.recent-thumb {
  flex: none; width: 56px; height: 56px; border-radius: var(--radius-s); overflow: hidden; border: 1px solid var(--border);
  padding: 0; cursor: pointer; background: var(--surface-2);
}
.recent-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Buttons */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); padding: 9px 15px;
  border-radius: 999px; font-size: 0.85rem; font-weight: 600; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-accent:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); }
.btn-danger:hover { background: var(--danger-soft); }

/* Gallery view */
.gallery-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.gallery-summary { margin: 0; font-family: var(--font-mono); font-size: 0.8rem; color: var(--ink-soft); }
.gallery-actions { display: flex; gap: 8px; }
.compare-hint { margin: 10px 0 0; font-size: 0.82rem; color: var(--accent-strong); display: block; }
.compare-hint[hidden] { display: none; }
.gallery-grid { margin-top: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.photo-card {
  position: relative; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-m);
  overflow: hidden; padding: 0; cursor: pointer; aspect-ratio: 4 / 3; box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.photo-card:hover { transform: translateY(-2px); }
.photo-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.photo-card.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.photo-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-time {
  position: absolute; left: 6px; bottom: 6px; background: rgba(16,20,15,0.72); color: #fff; font-family: var(--font-mono);
  font-size: 0.68rem; padding: 2px 6px; border-radius: 999px;
}
.photo-del {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(16,20,15,0.6); color: #fff; display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity .12s ease;
}
.photo-card:hover .photo-del, .photo-card:focus-within .photo-del { opacity: 1; }
.photo-del:hover { background: var(--danger); }

.empty-state { display: none; flex-direction: column; align-items: center; gap: 14px; text-align: center; padding: 48px 20px; color: var(--ink-soft); }
.empty-state p { margin: 0; }

/* Projector view */
.projector-frame {
  position: relative; background: var(--stage-bg); border-radius: var(--radius-l); overflow: hidden;
  min-height: 52vh; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow);
}
#projector-image { max-width: 100%; max-height: 78vh; object-fit: contain; display: block; }
.projector-frame:fullscreen { border-radius: 0; min-height: 100vh; }
.projector-frame:fullscreen #projector-image { max-height: 100vh; }
.projector-fullscreen { position: absolute; right: 12px; top: 12px; background: rgba(16,20,15,0.55); color: #fff; border: none; }
.projector-fullscreen:hover { background: rgba(16,20,15,0.8); }
.projector-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.projector-nav { display: flex; align-items: center; gap: 10px; }
.projector-counter { font-family: var(--font-mono); font-size: 0.85rem; color: var(--ink-soft); min-width: 4.5ch; text-align: center; }

/* Compare view */
.compare-frame { position: relative; background: var(--stage-bg); border-radius: var(--radius-l); overflow: hidden; box-shadow: var(--shadow); }
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 640px) { .compare-grid { grid-template-columns: 1fr; } }
.compare-panel { background: var(--stage-bg); border-radius: var(--radius-l); overflow: hidden; position: relative; min-height: 34vh; display: flex; align-items: center; justify-content: center; }
.compare-panel img { max-width: 100%; max-height: 60vh; object-fit: contain; }
.compare-label { position: absolute; left: 10px; top: 10px; background: rgba(16,20,15,0.65); color: #fff; font-family: var(--font-mono); font-size: 0.72rem; padding: 3px 8px; border-radius: 999px; }
.compare-bar { margin-top: 14px; }
.compare-fullscreen { position: absolute; right: 12px; top: 12px; background: rgba(16,20,15,0.55); color: #fff; border: none; z-index: 2; }
.compare-fullscreen:hover { background: rgba(16,20,15,0.8); }
.compare-frame:fullscreen { border-radius: 0; }
.compare-frame:fullscreen .compare-grid { height: 100vh; gap: 2px; }
.compare-frame:fullscreen .compare-panel { min-height: 100%; border-radius: 0; }
.compare-frame:fullscreen .compare-panel img { max-height: 100vh; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(12px); background: var(--ink);
  color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 0.85rem; opacity: 0; pointer-events: none;
  transition: opacity .18s ease, transform .18s ease; z-index: 50; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-warn { background: var(--warn-soft); color: var(--warn-ink); }
.toast-ok { background: var(--accent); color: var(--accent-ink); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16,20,15,0.5); display: none; align-items: center; justify-content: center; padding: 20px; z-index: 60; }
.modal-backdrop:not([hidden]) { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius-m); padding: 22px; max-width: 360px; width: 100%; box-shadow: var(--shadow); }
.modal-title { margin: 0 0 8px; font-weight: 700; }
.modal-body { margin: 0 0 18px; font-size: 0.86rem; color: var(--ink-soft); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
