:root {
  --bg: #0b0b0f;
  --panel: #15151d;
  --panel2: #1e1e28;
  --line: #2a2a36;
  --txt: #f2f2f5;
  --dim: #9a9aa8;
  --red: #e50914;
  --green: #22c55e;
  --gold: #f5c518;   /* IMDb */
  --rt: #fa5035;
  --mc: #66cc33;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--txt);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
#app { max-width: 960px; margin: 0 auto; padding: 0 12px 40px; }
.loading { text-align: center; color: var(--dim); padding: 80px 0; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 2px 10px; background: linear-gradient(var(--bg) 70%, transparent);
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand.big { font-size: 28px; }
.logo {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px;
  background: var(--red); color: #fff; font-weight: 900; font-size: 18px;
}
.brand.big .logo { width: 40px; height: 40px; font-size: 26px; border-radius: 10px; }
.hdr-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--panel); color: var(--txt); font-size: 18px; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:active { transform: scale(.94); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin: 4px 0 12px; }
.stats div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; text-align: center; }
.stats b { display: block; font-size: 22px; }
.stats span { color: var(--dim); font-size: 12px; }

/* Search + sort */
.search { display: flex; gap: 8px; margin-bottom: 10px; }
.search input {
  flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line);
  color: var(--txt); border-radius: 11px; padding: 11px 12px; font-size: 15px;
}
.search select {
  background: var(--panel); border: 1px solid var(--line); color: var(--txt);
  border-radius: 11px; padding: 0 10px; font-size: 14px;
}

/* Chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; margin-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line); color: var(--txt);
  border-radius: 999px; padding: 8px 13px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--red); border-color: var(--red); color: #fff; }
.chip .n { font-size: 12px; color: var(--dim); }
.chip.on .n { color: #ffd9db; }

/* Grid */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 820px) { .grid { grid-template-columns: repeat(5, 1fr); } }

.cardw { display: flex; flex-direction: column; }
.card {
  position: relative; border: 0; padding: 0; cursor: pointer; text-align: left;
  background: var(--panel2); border-radius: var(--radius); overflow: hidden; aspect-ratio: 2/3;
}
.card:active { transform: scale(.985); }
.poster { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--panel2); }
.poster.ph {
  display: grid; place-items: center; text-align: center; padding: 10px;
  color: var(--dim); font-size: 13px; font-weight: 600;
}
.card.seen .poster { filter: brightness(.55); }
.seenmark {
  position: absolute; top: 8px; right: 8px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--green); color: #06110a; font-weight: 900; display: grid; place-items: center; font-size: 15px;
}
.ratings { position: absolute; left: 6px; bottom: 6px; display: flex; gap: 5px; flex-wrap: wrap; }
.r {
  font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px;
  background: rgba(0,0,0,.72); backdrop-filter: blur(2px);
}
.r.imdb { color: var(--gold); } .r.rt { color: var(--rt); } .r.mc { color: var(--mc); }
.r.none { color: var(--dim); background: rgba(0,0,0,.55); font-weight: 600; }

.toggle {
  margin-top: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--txt);
  border-radius: 10px; padding: 7px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.toggle.on { background: rgba(34,197,94,.15); border-color: var(--green); color: var(--green); }
.cap { margin-top: 6px; font-size: 13px; line-height: 1.3; }
.cap .yr { color: var(--dim); }

/* Empty / messages */
.empty { color: var(--dim); text-align: center; padding: 40px 16px; }
.empty.pad { padding: 80px 16px; }
.banner { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--red); border-radius: 10px; padding: 10px 12px; margin: 6px 0; font-size: 14px; }
.banner.warn { border-left-color: var(--gold); color: #f3e0a6; }

/* Detail sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; }
.dsheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-width: 640px; margin: 0 auto; background: var(--panel);
  border-radius: 20px 20px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 88vh; overflow-y: auto;
  animation: up .2s ease;
}
@keyframes up { from { transform: translateY(20px); opacity: .6; } to { transform: none; opacity: 1; } }
.dgrip { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 2px auto 14px; }
.drow { display: flex; gap: 14px; }
.dposter { width: 108px; flex: 0 0 auto; aspect-ratio: 2/3; object-fit: cover; border-radius: 10px; background: var(--panel2); }
.dposter.ph { display: grid; place-items: center; text-align: center; color: var(--dim); font-size: 12px; padding: 8px; }
.dmeta h2 { margin: 2px 0 4px; font-size: 20px; line-height: 1.2; }
.dsub { color: var(--dim); font-size: 13px; margin-bottom: 8px; }
.dmeta .ratings { position: static; margin: 4px 0; }
.dtags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tag { font-size: 11px; color: var(--dim); border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px; }
.dov { color: #d4d4de; font-size: 14px; margin: 14px 0; }
.bigtoggle {
  width: 100%; border: 1px solid var(--red); background: var(--red); color: #fff;
  border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 700; cursor: pointer; margin-top: 4px;
}
.bigtoggle.on { background: rgba(34,197,94,.15); border-color: var(--green); color: var(--green); }
.dlinks { display: flex; gap: 10px; margin: 12px 0; }
.dlinks a { flex: 1; text-align: center; text-decoration: none; color: var(--txt); background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 11px; font-size: 14px; font-weight: 600; }
.dclose { width: 100%; background: transparent; border: 0; color: var(--dim); padding: 12px; font-size: 14px; cursor: pointer; }

/* Login */
.login { text-align: center; padding: 70px 20px; }
.login .tag { color: var(--dim); margin: 10px 0 30px; }
.login #gbtn { display: inline-block; min-height: 44px; }
.note { color: var(--dim); margin-top: 16px; font-size: 14px; }

/* Install */
.install {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom));
  background: var(--red); color: #fff; border: 0; border-radius: 999px; padding: 12px 22px;
  font-size: 15px; font-weight: 700; box-shadow: 0 6px 20px rgba(0,0,0,.4); cursor: pointer; z-index: 30;
}

/* Spinner + toast */
.spin { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--txt); border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 30px);
  background: #000; border: 1px solid var(--line); color: #fff; padding: 11px 16px;
  border-radius: 10px; font-size: 14px; max-width: 86%; text-align: center;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
