/* ── Design Tokens ── */
:root {
  color-scheme: dark;
  --ink: #F5F5F5;
  --muted: rgba(245, 245, 245, 0.68);
  --faint: rgba(245, 245, 245, 0.42);
  --glass: rgba(15, 16, 17, 0.48);
  --glass-strong: rgba(15, 16, 17, 0.72);
  --line: rgba(255, 255, 255, 0.2);
  --line-focus: rgba(255, 255, 255, 0.7);
  --focus: rgba(244, 191, 110, 0.78);
  --font-serif: "Cormorant Garamond", Georgia, serif;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.theme-light {
  color-scheme: light;
  background:
    radial-gradient(circle at 18% 12%, rgba(229, 220, 198, 0.44), transparent 26rem),
    radial-gradient(circle at 82% 8%, rgba(182, 204, 225, 0.34), transparent 24rem),
    #e8e0d6;
  --ink: #1A1A1A;
  --muted: rgba(26, 26, 26, 0.72);
  --faint: rgba(26, 26, 26, 0.45);
  --glass: rgba(255, 255, 255, 0.52);
  --glass-strong: rgba(255, 255, 255, 0.74);
  --line: rgba(0, 0, 0, 0.18);
  --line-focus: rgba(0, 0, 0, 0.6);
}

/* ── Reset ── */
* { box-sizing: border-box; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(circle at 18% 12%, rgba(89, 74, 61, 0.28), transparent 26rem),
    radial-gradient(circle at 82% 8%, rgba(61, 75, 84, 0.24), transparent 24rem),
    #0b0c0d;
  color: var(--ink);
  font-family: var(--font-sans);
  overflow-x: hidden;
}

button, input { font: inherit; }
a { color: inherit; }

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

/* ── App Shell Grid ── */
.app-shell {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding: clamp(0.85rem, 2vw, 1.5rem);
  gap: 0.85rem;
}

/* ── Topbar: Perfectly Aligned Editorial Navigation ── */
.topbar {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 24px;
  width: 100%;
  padding: 0.2rem 0;
}

.identity {
  max-width: 32rem;
  flex-shrink: 0;
}

.kicker,
.city-name,
.city-stats,
.updated-at,
.quiet-note,
.status-message {
  margin: 0;
}

.kicker {
  font-family: var(--font-serif);
  font-size: clamp(2rem, 4vw, 3.7rem);
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1;
}

h1 {
  max-width: 31rem;
  margin: 0.12rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 400;
}

/* ── Shared Input + Button Baseline (32px plane) ── */
.search-row,
.secondary-search,
.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-row {
  flex: 1 1 auto;
  min-width: 14rem;
  max-width: 28rem;
}

.secondary-search {
  min-width: 12rem;
}

.search-row input,
.secondary-search input {
  min-width: 0;
  flex: 1;
  height: 32px;
  border: none;
  border-bottom: 1px solid var(--line);
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  padding: 6px 0;
  transition: border-color 0.3s ease;
}

.search-row input:focus,
.secondary-search input:focus {
  border-bottom-color: var(--line-focus);
}

.search-row input::placeholder,
.secondary-search input::placeholder {
  color: var(--faint);
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 500;
}

button {
  height: 32px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  padding: 0;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.3s ease, color 0.3s ease, transform 180ms ease;
}

button:hover {
  border-bottom-color: var(--line-focus);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
.compare-toggle:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.control-row {
  margin-left: auto;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.compare-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 32px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 0;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.compare-toggle input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--ink);
}

/* ── Gallery ── */
.gallery {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.85rem;
  min-height: 0;
}

.gallery.is-comparing {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.portrait-panel {
  position: relative;
  min-height: min(70svh, 52rem);
  overflow: hidden;
  background: #efe9dc;
  isolation: isolate;
  outline: 1px solid transparent;
  outline-offset: -1px;
  transition: outline-color 180ms ease;
}

.portrait-panel.is-active {
  outline-color: var(--line);
}

.canvas-host,
.canvas-host canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.canvas-host {
  position: absolute;
  inset: 0;
  cursor: crosshair;
}

/* ── Portrait Metadata (City name, stats, time) ── */
.portrait-meta {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: calc(100% - 40px);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  z-index: 3;
  gap: 1rem;
  pointer-events: none;
}

.city-name {
  font-family: var(--font-serif);
  font-size: clamp(1.9rem, 4vw, 4.4rem);
  font-weight: 500;
  line-height: 0.95;
  color: var(--ink);
  text-wrap: balance;
  transition: opacity 500ms ease, letter-spacing 500ms ease, transform 500ms ease, filter 500ms ease, color 0.4s ease;
}

.city-stats {
  margin-top: 0.45rem;
  color: var(--muted);
  font-size: 0.88rem;
  transition: opacity 500ms ease, letter-spacing 500ms ease, transform 500ms ease, filter 500ms ease, color 0.4s ease;
}

.updated-at {
  max-width: 16rem;
  color: var(--faint);
  font-size: 0.78rem;
  text-align: right;
  transition: opacity 500ms ease, letter-spacing 500ms ease, transform 500ms ease, filter 500ms ease, color 0.4s ease;
}

.portrait-meta.is-drifting .city-name,
.portrait-meta.is-drifting .city-stats,
.portrait-meta.is-drifting .updated-at {
  opacity: 0;
  letter-spacing: 0.16em;
  transform: translateX(0.9rem);
  filter: blur(2px);
}

/* ── Status Message Toast ── */
.status-message {
  position: absolute;
  z-index: 5;
  top: clamp(1rem, 2vw, 1.5rem);
  left: clamp(1rem, 2vw, 1.5rem);
  max-width: min(28rem, calc(100% - 2rem));
  color: var(--muted);
  background: var(--glass-strong);
  border-left: 1px solid var(--line);
  padding: 0.75rem 0.9rem;
  opacity: 0;
  transform: translateY(-0.35rem);
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}

.status-message.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Transition Overlay ── */
.portrait-panel.is-transitioning::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background: rgba(7, 8, 9, 0.45);
  animation: crossfade 700ms ease both;
  pointer-events: none;
}

/* ── Legend / Footer Bar (Glassmorphism) ── */
.quiet-note {
  z-index: 2;
  font-size: 0.78rem;
  text-align: right;
  background: rgba(15, 15, 25, 0.45);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 12px 24px;
  color: rgba(255, 255, 255, 0.6);
}

body.theme-light .quiet-note {
  background: rgba(255, 255, 255, 0.5);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  color: rgba(0, 0, 0, 0.55);
}

.legend {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 1rem;
}

.legend li {
  font-size: 0.72rem;
}

.legend strong {
  font-weight: 500;
}

/* ── Keyframes ── */
@keyframes crossfade {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ── Responsive: Tablet ── */
@media (max-width: 980px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .search-row {
    max-width: none;
  }

  .control-row {
    margin-left: 0;
    justify-content: flex-start;
  }

  .gallery.is-comparing {
    grid-template-columns: 1fr;
  }

  .portrait-panel {
    min-height: 43svh;
  }
}

/* ── Responsive: Mobile ── */
@media (max-width: 620px) {
  .app-shell {
    padding: 0.7rem;
  }

  .search-row,
  .secondary-search,
  .control-row {
    width: 100%;
    flex-wrap: wrap;
  }

  .search-row input,
  .secondary-search input,
  .search-row button,
  .secondary-search button,
  #export-button,
  .compare-toggle {
    width: 100%;
  }

  .portrait-meta {
    align-items: start;
    flex-direction: column;
  }

  .updated-at {
    text-align: left;
  }

  .quiet-note {
    text-align: left;
  }
}
