:root {
  --bg: #0f0f0f;
  --card: #1a1a1a;
  --accent: #4f8ef7;
  --text: #e0e0e0;
  --muted: #888888;
  --border: #2a2a2a;
  --danger: #ff6961;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: max(18px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  position: relative;
}

.top-action {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 10;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(26, 26, 26, 0.92);
  color: var(--muted);
}

.center-panel,
.search-page,
.result-page {
  width: min(100%, 680px);
  margin: 0 auto;
}

.compact {
  min-height: calc(100vh - 80px);
  display: grid;
  place-content: center;
  gap: 24px;
}

.brand-header,
.section-header {
  text-align: center;
  padding: 48px 0 22px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  font-weight: 750;
}

.brand-header p,
.section-header p,
.target-photo p,
.hint-text,
.match-row small {
  color: var(--muted);
}

.search-form,
.login-form {
  display: grid;
  gap: 12px;
}

input {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 16px;
  color: var(--text);
  background: var(--card);
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 142, 247, 0.18);
}

button,
.primary-button,
.secondary-button {
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
}

button:active,
.primary-button:active,
.secondary-button:active,
.thumb:active,
.match-row:active {
  transform: scale(0.97);
}

.search-form button,
.login-form button,
.primary-button {
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.secondary-button {
  width: 100%;
  margin-top: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
}

.gallery-actions {
  display: grid;
  gap: 10px;
}

.gallery-actions .secondary-button {
  margin-top: 0;
}

.search-form.loading .button-label {
  display: none;
}

.spinner {
  display: none;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: white;
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

.search-form.loading .spinner {
  display: block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.empty-state,
.install-hint,
.flash {
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}

.flash-stack {
  width: min(100%, 680px);
  margin: 0 auto 12px;
}

.flash-error {
  color: var(--danger);
}

.back-link {
  display: inline-block;
  margin: 14px 0 18px;
  color: var(--muted);
  text-decoration: none;
}

.target-photo {
  display: grid;
  gap: 12px;
  text-align: center;
}

.target-photo h1 {
  font-size: 22px;
  overflow-wrap: anywhere;
}

.image-frame {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.image-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.fade-image,
.thumb img,
.match-row img {
  opacity: 0;
  transition: opacity 180ms ease;
}

.fade-image.loaded,
.thumb img.loaded,
.match-row img.loaded {
  opacity: 1;
}

.timeline {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
  padding: 4px 0;
}

.thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid transparent;
  background: var(--card);
  overflow: hidden;
  min-width: 0;
}

.thumb.active {
  border-color: var(--accent);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.media-badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  max-width: calc(100% - 8px);
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(15, 15, 15, 0.78);
  color: var(--text);
  font-size: 10px;
  line-height: 1.2;
}

.hint-text {
  margin-top: 14px;
  text-align: center;
  font-size: 14px;
}

.match-list {
  display: grid;
  gap: 10px;
}

.match-row {
  min-height: 76px;
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  text-decoration: none;
}

.match-row img {
  width: 58px;
  height: 58px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--bg);
}

.match-row strong,
.match-row small {
  display: block;
  overflow-wrap: anywhere;
}

.match-row small {
  margin-top: 4px;
}

.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;
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 32px;
  }

  .search-form {
    grid-template-columns: 1fr 118px;
  }

  .image-frame {
    aspect-ratio: 4 / 3;
  }

  .timeline {
    grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  }
}
