/* Uses Telegram's theme variables (set by telegram-web-app.js) so it matches light/dark
   and the person's chosen colours. The fallbacks are for opening the page in a plain browser. */
:root {
  --bg: var(--tg-theme-bg-color, #17171c);
  --bg2: var(--tg-theme-secondary-bg-color, #22222a);
  --text: var(--tg-theme-text-color, #f2f2f5);
  --hint: var(--tg-theme-hint-color, #9a9aa8);
  --accent: var(--tg-theme-button-color, #6c8cff);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --radius: 16px;
  --pad: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── top bar ── */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 10px var(--pad) 8px;
  display: grid; gap: 10px;
}
#q {
  width: 100%; padding: 11px 14px; border: 0; border-radius: 12px;
  background: var(--bg2); color: var(--text); font: inherit;
}
#q::placeholder { color: var(--hint); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; border: 0; border-radius: 999px;
  background: var(--bg2); white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quick-btn { padding: 10px; border: 1px dashed var(--hint); border-radius: 12px; background: transparent; }

/* ── cards ── */
main { padding: 4px var(--pad) 0; }
.status { color: var(--hint); text-align: center; margin: 28px 0; }
.status:empty { display: none; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card {
  display: flex; flex-direction: column; text-align: left; padding: 0;
  border: 0; border-radius: var(--radius); background: var(--bg2); overflow: hidden;
  transition: transform .12s ease;
}
.card:active { transform: scale(.97); }
.card .body { padding: 10px 12px 12px; display: grid; gap: 6px; }
.card h3 { margin: 0; font-size: 15px; line-height: 1.25; }
.card .blurb {
  margin: 0; font-size: 13px; color: var(--hint);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

.art {
  --hue: 220;
  aspect-ratio: 16 / 10; display: grid; place-items: center; font-size: 42px;
  background: linear-gradient(135deg, hsl(var(--hue) 65% 48%), hsl(calc(var(--hue) + 35) 65% 28%));
  background-size: cover; background-position: center;
}
.art.tall { aspect-ratio: 16 / 8; font-size: 56px; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--hint) 22%, transparent); color: var(--hint); }

/* ── detail sheet ── */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
.panel {
  position: relative; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise .18s ease-out;
}
.panel .body { padding: 14px var(--pad) 18px; display: grid; gap: 12px; }
.panel h2 { margin: 0; font-size: 22px; line-height: 1.2; }
.panel .blurb { margin: 0; color: var(--text); font-size: 16px; }
.actions { display: grid; gap: 8px; margin-top: 4px; }
.primary, .secondary { padding: 13px; border: 0; border-radius: 12px; }
.primary { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.secondary { background: var(--bg2); }

@keyframes rise { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .panel { animation: none; } .card { transition: none; } }
