:root {
  --bg: #131110;
  --surface: #1c1815;
  --surface-2: #262019;
  --border: #3a3226;
  --border-soft: #2a2420;
  --text: #f3ede1;
  --text-dim: #a89a83;
  --text-faint: #6f6455;
  --accent: #e65100;
  --accent-soft: #ff8a3d;
  --accent-ink: #fff3e8;
  --danger: #ef5b4e;
  --focus: #ffb673;
  --font-ui: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --radius: 10px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */

.topbar {
  flex: none;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  color: var(--accent-soft);
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.brand-title {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.brand-sub {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
}

.brand-sub.connected { color: var(--text-dim); }

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.date-picker input[type="date"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text);
  color-scheme: dark;
}
.date-picker input[type="date"]:disabled { opacity: 0.4; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}
.btn:hover { background: #2d271e; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface-2); }

.btn-ghost { background: transparent; }

.btn-icon {
  padding: 8px;
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-accent:hover { background: var(--accent-soft); border-color: var(--accent-soft); }

#compareToggle[aria-pressed="true"] {
  background: color-mix(in srgb, var(--accent) 22%, var(--surface-2));
  border-color: var(--accent);
  color: var(--accent-soft);
}

/* ---------- Stage ---------- */

.stage {
  flex: 1;
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--accent) 7%, transparent), transparent 60%),
    var(--bg);
}

.state-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  max-width: 360px;
  text-align: center;
  color: var(--text-dim);
}

.state-icon { font-size: 34px; line-height: 1; margin-bottom: 4px; }

.state-panel h2 {
  margin: 0;
  font-size: 17px;
  color: var(--text);
}

.state-panel p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
}

.spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Single viewer ---------- */

.viewer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-frame {
  height: calc(100% - 48px);
  width: calc(100% - 140px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-frame img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 20px 60px -20px rgba(0,0,0,0.6);
  background: #000;
}

.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(28, 24, 21, 0.85);
  backdrop-filter: blur(4px);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease, opacity 0.12s ease;
}
.nav-arrow:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.nav-arrow:disabled { opacity: 0.25; cursor: not-allowed; }
.nav-arrow-left { left: 22px; }
.nav-arrow-right { right: 22px; }

/* ---------- Compare viewer ---------- */

.compare {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.compare-endpoints {
  display: flex;
  gap: 22px;
}

.endpoint {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.endpoint-label {
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 10.5px;
  color: var(--accent-soft);
}

.endpoint select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
  font-family: var(--font-mono);
  font-size: 12px;
  max-width: 220px;
}

.compare-wrap {
  position: relative;
  height: calc(100% - 88px);
  width: calc(100% - 140px);
  border-radius: 6px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 20px 60px -20px rgba(0,0,0,0.6);
  user-select: none;
}

.compare-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  pointer-events: none;
}

.compare-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
  width: 50%;
}

.compare-clip .compare-img { width: var(--wrap-w, 100%); }

.compare-tag {
  position: absolute;
  top: 12px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 4px 9px;
  border-radius: 5px;
  background: rgba(19, 17, 16, 0.72);
  color: var(--text-dim);
  pointer-events: none;
}
.compare-tag-before { left: 12px; }
.compare-tag-after { right: 12px; }

.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 0;
  cursor: ew-resize;
  touch-action: none;
}

.compare-handle-line {
  position: absolute;
  top: 0; bottom: 0;
  left: -1px;
  width: 2px;
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4);
}

.compare-handle-grip {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}

/* ---------- Bottom bar ---------- */

.bottombar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--surface);
  border-top: 1px solid var(--border-soft);
}

.meta {
  flex: none;
  display: flex;
  flex-direction: column;
  min-width: 132px;
  line-height: 1.3;
}

.meta-index {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.meta-date {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.scrubber {
  flex: 1;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  cursor: pointer;
}
.scrubber:disabled { opacity: 0.4; cursor: not-allowed; }
.scrubber::-webkit-slider-thumb {
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--accent-ink);
  margin-top: -5px;
  cursor: pointer;
}
.scrubber::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--accent-ink);
  cursor: pointer;
}
.scrubber::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--border); }
.scrubber::-moz-range-track { height: 4px; border-radius: 2px; background: var(--border); }

.btn-download { flex: none; }

/* ---------- Settings modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 7, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
}

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,0.6);
}

.modal h2 {
  margin: 0 0 6px;
  font-size: 17px;
}

.modal-hint {
  margin: 0 0 18px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-dim);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 13px;
  font-size: 12px;
  color: var(--text-dim);
}

.field input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text);
}

.field input::placeholder { color: var(--text-faint); }

.form-error {
  margin: 4px 0 10px;
  font-size: 12.5px;
  color: var(--danger);
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
  .brand-sub { max-width: 60vw; }
  .photo-frame, .compare-wrap { width: calc(100% - 70px); }
  .nav-arrow { width: 38px; height: 38px; }
  .nav-arrow-left { left: 8px; }
  .nav-arrow-right { right: 8px; }
  .bottombar { flex-wrap: wrap; }
  .meta { min-width: 0; }
}
