:root {
  --bg: #1a1a1a;
  --surface: #262626;
  --text: #f5f5f5;
  --muted: #a3a3a3;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --border: #404040;
  --danger: #ef4444;
  --high: #22c55e;
  --med: #eab308;
  --low: #f97316;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

header {
  padding: env(safe-area-inset-top, 1rem) 1rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  text-align: center;
}

main {
  padding: 1.5rem 1rem;
  max-width: 680px;
  margin: 0 auto;
}

section { margin-bottom: 2rem; }

.primary-btn, .secondary-btn {
  width: 100%;
  padding: 1.25rem;
  border-radius: 12px;
  border: none;
  font-size: 1.125rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 64px;
  touch-action: manipulation;
}

.primary-btn {
  background: var(--accent);
  color: white;
}
.primary-btn:active { background: var(--accent-hover); }

.secondary-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.hint, .observation {
  text-align: center;
  color: var(--muted);
  margin-top: 1rem;
  font-size: 0.9rem;
}

.observation {
  font-style: italic;
  margin: 0 0 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-radius: 8px;
  text-align: left;
}

#preview-img {
  width: 100%;
  border-radius: 12px;
  margin-bottom: 1rem;
  display: block;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 2rem auto 1rem;
  animation: spin 0.8s linear infinite;
}

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

#loading-section p, #error-section p {
  text-align: center;
  color: var(--muted);
}

#results-section h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }

#results-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.match-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.match-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.match-card .part {
  color: var(--accent);
  font-weight: 700;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 1.1rem;
}

.match-card .conf {
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #0a0a0a;
}
.match-card .conf.high { background: var(--high); }
.match-card .conf.med  { background: var(--med); }
.match-card .conf.low  { background: var(--low); }

.match-card h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.match-card .match-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.match-card .reasoning {
  margin: 0.5rem 0 0.75rem;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.4;
}

.match-card .page-img {
  width: 100%;
  border-radius: 8px;
  background: white;
  display: block;
}

.empty {
  list-style: none;
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

#error-section p { color: var(--danger); margin-bottom: 1rem; }
