:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --bg2: var(--tg-theme-secondary-bg-color, #0e1621);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #7f91a4);
  --accent: var(--tg-theme-button-color, #5288c1);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --danger: #e5484d;
  --gold: #f5c518;
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: env(safe-area-inset-bottom); }

.top { position: sticky; top: 0; z-index: 5; background: var(--bg2);
  padding: 12px 16px 8px; border-bottom: 1px solid rgba(255,255,255,.06); }
h1 { margin: 0 0 10px; font-size: 20px; }
#search { width: 100%; padding: 10px 14px; border: 0; border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: 16px; outline: none; }
#search::placeholder { color: var(--hint); }
.tabs { display: flex; gap: 8px; margin-top: 10px; }
.tab { flex: 1; padding: 8px 0; border: 0; border-radius: 999px; background: var(--bg);
  color: var(--hint); font-size: 14px; cursor: pointer; }
.tab.active { background: var(--accent); color: var(--accent-text); }
.summary { margin-top: 8px; color: var(--hint); font-size: 13px; }

main { padding: 12px 16px 24px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 520px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(5, 1fr); } }

.card { position: relative; background: var(--bg); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; border: 0; padding: 0; text-align: left; color: inherit;
  transition: transform .12s; }
.card:active { transform: scale(.97); }
.poster { width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block; background: #223;
  }
.poster.empty { display: flex; align-items: center; justify-content: center; font-size: 42px; }
.badge { position: absolute; top: 8px; left: 8px; padding: 2px 8px; border-radius: 8px;
  background: rgba(0,0,0,.7); color: var(--gold); font-size: 13px; font-weight: 600; }
.info { padding: 8px 10px 10px; }
.title { font-weight: 600; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; min-height: 2.8em; }
.sub { color: var(--hint); font-size: 12px; margin-top: 4px; display: flex; justify-content: space-between; }

.status { text-align: center; color: var(--hint); margin: 32px 0; }

.sheet { position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.6);
  display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden], .toast[hidden], #delete-btn[hidden] { display: none; }
.sheet-card { width: 100%; max-width: 560px; background: var(--bg); border-radius: 18px 18px 0 0;
  display: flex; gap: 14px; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
#sheet-poster { width: 110px; border-radius: 10px; align-self: flex-start; background: #223; }
.sheet-body { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.sheet-body h2 { margin: 0; font-size: 18px; }
#sheet-meta { margin: 0; color: var(--hint); font-size: 14px; white-space: pre-line; }
button.danger, button.ghost { padding: 11px; border: 0; border-radius: var(--radius);
  font-size: 15px; cursor: pointer; }
button.danger { background: var(--danger); color: #fff; margin-top: auto; }
button.ghost { background: var(--bg2); color: var(--text); }
button:disabled { opacity: .5; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); max-width: 90%; background: #000c; color: #fff;
  padding: 10px 16px; border-radius: 999px; z-index: 20; font-size: 14px; text-align: center; }
