:root {
  --bg: oklch(0.985 0.005 240);
  --surface: oklch(0.995 0.003 240);
  --text: oklch(0.22 0.02 260);
  --text-muted: oklch(0.55 0.02 260);
  --border: oklch(0.9 0.01 260);
  --accent: oklch(0.55 0.14 250);
  --accent-hover: oklch(0.5 0.15 250);
  --accent-fg: oklch(0.99 0.005 250);
  --warn: oklch(0.62 0.14 45);
  --warn-bg: oklch(0.96 0.05 55);
  --warn-border: oklch(0.78 0.11 55);
  --warn-text: oklch(0.35 0.09 55);
  --ok: oklch(0.5 0.14 155);
  --err: oklch(0.5 0.18 25);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-move: cubic-bezier(0.77, 0, 0.175, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Geist", ui-sans-serif, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
}

.masthead { margin-bottom: 3rem; }

.masthead-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-links {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}
.header-links a {
  color: var(--text-muted);
  display: inline-flex;
  transition: color 160ms var(--ease-out);
}
.header-links a:hover { color: var(--accent); }
.header-links svg { width: 19px; height: 19px; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}
.brand-mark {
  display: inline-flex;
  width: 22px;
  height: 22px;
  color: var(--accent);
  cursor: default;
  user-select: none;
}
.brand-mark svg {
  width: 100%;
  height: 100%;
  display: block;
}
.brand-text {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  text-decoration: none;
}

.tagline {
  margin: 0.4rem 0 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  max-width: 44ch;
}

h1 {
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0 0 0.75rem;
}

.body {
  color: var(--text-muted);
  max-width: 55ch;
  margin-bottom: 1.75rem;
}

.upload-card { margin-bottom: 3rem; }

.uploader {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.drop-zone {
  position: relative;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 2.25rem 1.5rem;
  background: var(--surface);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  transition: border-color 200ms var(--ease-out), background 200ms var(--ease-out);
}

.drop-zone:hover {
  border-color: var(--accent);
  background: oklch(0.98 0.008 250);
}

.drop-zone:focus-within {
  border-color: var(--accent);
  outline: 2px solid oklch(0.55 0.14 250 / 0.25);
  outline-offset: 2px;
}

.drop-zone input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-label { font-weight: 500; }
.drop-hint { color: var(--text-muted); font-size: 0.85rem; }

.preview-img {
  max-width: 100%;
  max-height: 180px;
  border-radius: 8px;
  object-fit: contain;
}
.drop-zone.has-preview { padding-top: 1.25rem; }
.drop-zone.has-preview .drop-hint { display: none; }

.form-error {
  color: var(--err);
  font-size: 0.85rem;
  margin: 0;
}

.primary-btn {
  position: relative;
  background: var(--accent);
  color: var(--accent-fg);
  border: none;
  padding: 0.85rem 1.5rem;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: transform 160ms var(--ease-out), background 200ms var(--ease-out);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: scale(0.97); }
.primary-btn:focus-visible {
  outline: 2px solid var(--accent-fg);
  outline-offset: 2px;
}
.primary-btn[disabled] { cursor: wait; opacity: 0.85; }

.btn-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid oklch(0.99 0.005 250 / 0.35);
  border-top-color: var(--accent-fg);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
.primary-btn.is-loading .btn-spinner { display: inline-block; }
.primary-btn.is-loading .btn-label { opacity: 0.7; }

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

.samples { margin-bottom: 3rem; }
.samples h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }

.sample-group { margin-top: 1.25rem; }
.sample-group-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 0.5rem;
}

.sample-thumbs {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.sample-thumb {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: none;
  cursor: pointer;
  width: 76px;
  height: 76px;
  transition: border-color 160ms var(--ease-out), transform 160ms var(--ease-out);
}
.sample-thumb:hover { border-color: var(--accent); transform: scale(1.03); }
.sample-thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sample-thumb.is-loading { opacity: 0.5; cursor: wait; }
.sample-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sample-credit {
  margin-top: 1.25rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.error-card { margin-bottom: 3rem; }
.error-card h1 { color: var(--err); }

.result-card { margin-bottom: 3rem; }

.eyebrow {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 0.5rem;
}

.prediction {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}

.confidence {
  margin: 0.35rem 0 2rem;
  color: var(--text-muted);
}

.conf-num {
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 1.4rem;
  color: var(--text);
  font-weight: 500;
}

.conf-unit { margin-left: 0.25rem; }

.low-conf-banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  color: var(--warn-text);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin: 0 0 2rem;
  font-size: 0.9rem;
  line-height: 1.5;
}
.low-conf-banner strong { color: oklch(0.28 0.1 55); }

.gradcam {
  margin: 0 0 2.5rem;
  padding: 0;
}
.gradcam img {
  display: block;
  width: 100%;
  max-width: 480px;
  border-radius: 12px;
  border: 1px solid var(--border);
}
.gradcam figcaption {
  margin-top: 0.65rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  max-width: 55ch;
}

.top3 { margin-top: 2rem; }

.top3 h2 {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  margin: 0 0 0.75rem;
}

.top3-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.top3-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 0.4rem 0.75rem;
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.cls-name { grid-column: 1; grid-row: 1; font-size: 0.95rem; }
.cls-prob {
  grid-column: 2;
  grid-row: 1;
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.cls-bar-wrap {
  grid-column: 1 / -1;
  grid-row: 2;
  height: 3px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.cls-bar {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 400ms var(--ease-move);
}

.back {
  display: inline-block;
  margin-top: 2rem;
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  transition: opacity 160ms var(--ease-out);
}
.back:hover { opacity: 0.7; }

.disclaimer {
  border-top: 1px solid var(--border);
  padding-top: 1.5rem;
  margin-top: 2.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  max-width: 60ch;
}

.colophon {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
}
.colophon p { margin: 0.25rem 0; }
.colophon a {
  color: var(--text-muted);
  text-decoration: underline;
  text-decoration-color: var(--border);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.colophon a:hover { color: var(--accent); text-decoration-color: var(--accent); }

.icon-inline {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* Debug page */
.debug-card { margin-bottom: 3rem; }

.debug-status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1.5rem 0 2rem;
}
.status-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
}
.status-label {
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}
.status-value {
  font-family: "Geist Mono", ui-monospace, monospace;
  color: var(--text);
}
.status-value.ok { color: var(--ok); }
.status-value.err { color: var(--err); }

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  margin: 1rem 0 2rem;
}
.log-table thead th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
}
.log-table tbody td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.log-time { color: var(--text-muted); white-space: nowrap; }
.log-level {
  font-weight: 500;
  white-space: nowrap;
}
.log-message {
  color: var(--text);
  word-break: break-word;
}
.log-error .log-level, .log-critical .log-level { color: var(--err); }
.log-warning .log-level { color: var(--warn); }
.log-info .log-level { color: var(--text-muted); }
.log-debug .log-level { color: var(--text-muted); opacity: 0.7; }

@media (max-width: 600px) {
  .container { padding: 2rem 1rem 3rem; }
  .prediction { font-size: 1.6rem; }
  .log-table { font-size: 0.72rem; }
  .log-table thead th, .log-table tbody td { padding: 0.35rem 0.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
