:root {
  --bg: #14110f;
  --surface: #1e1a17;
  --line: #352e29;
  --text: #f3ede7;
  --muted: #a99d93;
  --accent: #ff7a45;
  --accent-ink: #1a0d06;
  --error: #ff8a80;
  --radius: 14px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf6f1;
    --surface: #ffffff;
    --line: #e6ddd3;
    --text: #1d1814;
    --muted: #6f655d;
    --accent: #e85d24;
    --accent-ink: #ffffff;
    --error: #c62828;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
.wrap {
  max-width: 880px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.01em; }
.brand img { border-radius: 10px; }

.hero h1 {
  font-size: clamp(2rem, 7vw, 3.4rem);
  line-height: 1.04;
  letter-spacing: -0.035em;
  margin: 0 0 12px;
}
.sub { color: var(--muted); margin: 0 0 24px; max-width: 34ch; }

.input-row {
  display: flex;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 6px;
}
.input-row:focus-within { border-color: var(--accent); }
.input-row input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  padding: 10px 10px;
  outline: none;
}

button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 18px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  white-space: nowrap;
  transition: transform .08s ease, opacity .15s;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.small { padding: 10px 12px; }

.status { min-height: 1.5em; color: var(--muted); margin: 12px 4px 0; font-size: .95rem; }
.status.error { color: var(--error); }

#result { margin-top: 28px; }
.result-head {
  display: flex; gap: 16px; align-items: flex-start; justify-content: space-between;
  padding-bottom: 16px; border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.owner { font-weight: 700; margin: 0; }
.caption {
  color: var(--muted); margin: 4px 0 0; font-size: .92rem;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
@media (max-width: 480px) { .grid { grid-template-columns: 1fr 1fr; gap: 10px; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
}
.media { position: relative; aspect-ratio: 4 / 5; background: var(--line); }
.media img, .media video { width: 100%; height: 100%; object-fit: contain; display: block; }
.badge {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,.62); color: #fff;
  font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 99px;
}
.card a.dl {
  display: block; text-align: center; text-decoration: none;
  font-weight: 600; color: var(--text);
  padding: 11px; border-top: 1px solid var(--line);
}
.card a.dl:hover { color: var(--accent); }

.foot { color: var(--muted); font-size: .82rem; margin-top: 48px; text-align: center; }

.spinner {
  display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.diag { margin-top: 8px; color: var(--muted); }
.diag summary { cursor: pointer; font-size: .85rem; }
.diag pre {
  white-space: pre-wrap; word-break: break-word; font-size: .78rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin: 6px 0 0;
}
.badge.res { left: auto; right: 8px; font-weight: 600; text-transform: none; letter-spacing: 0; }
