:root {
  --bg: #0f0f14;
  --bg2: #171722;
  --bg3: #1f1f2e;
  --line: #2a2a3c;
  --fg: #ececf2;
  --muted: #9a9ab0;
  --accent: #7c5cff;
  --accent2: #ff5c8a;
  --ok: #3ddc84;
  --warn: #ffb020;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: var(--bg3); border-radius: 10px; padding: 10px 14px; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { background: #3a1d28; color: #ff8ba7; }
button.small { padding: 6px 10px; font-size: 14px; border-radius: 8px; }
input[type=text], input[type=search], input[type=date], input[type=time], input[type=url], input[type=number], select, textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
label.field { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { margin-top: 4px; color: var(--fg); font-size: 16px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* Layout */
#app { min-height: 100vh; }
header.top { position: sticky; top: 0; z-index: 5; background: rgba(15,15,20,.9); backdrop-filter: blur(12px); padding: 12px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
header.top h1 { font-size: 18px; flex: 1; }
main { padding: 14px 16px calc(84px + var(--safe-b)); max-width: 900px; margin: 0 auto; }
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: rgba(23,23,34,.96); backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); z-index: 5; }
nav.tabs button { flex: 1; background: none; border-radius: 0; padding: 8px 2px 8px; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav.tabs button .ico { font-size: 20px; }
nav.tabs button.active { color: var(--fg); }
nav.tabs button .badge { position: absolute; margin-left: 28px; margin-top: -2px; background: var(--accent2); color: #fff; font-size: 10px; border-radius: 10px; padding: 0 5px; font-weight: 700; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; background: var(--bg3); border: 2px solid var(--line); flex: none; }
.avatar.sm { width: 24px; height: 24px; font-size: 13px; border-width: 1.5px; }

/* Cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card { background: var(--bg2); border-radius: var(--radius); overflow: hidden; cursor: pointer; border: 1px solid var(--line); position: relative; display: flex; flex-direction: column; transition: transform .1s; }
.card:active { transform: scale(.98); }
.poster { aspect-ratio: 2/3; background: var(--bg3) center/cover no-repeat; position: relative; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 36px; }
.poster .top-left { position: absolute; top: 6px; left: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.poster .top-right { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.poster .bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 20px 8px 6px; background: linear-gradient(transparent, rgba(0,0,0,.85)); display: flex; justify-content: space-between; align-items: flex-end; gap: 4px; }
.card .body { padding: 8px 10px 10px; }
.card .title { font-weight: 600; font-size: 14px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: rgba(0,0,0,.55); color: #fff; backdrop-filter: blur(4px); white-space: nowrap; }
.chip.prov { color: #fff; }
.chip.rent { opacity: .75; }
.chip.date { background: var(--accent); }
.chip.prio { background: var(--warn); color: #000; }
.chip.both { background: var(--accent2); }
.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; background: var(--bg3); font-size: 13px; border: 1px solid var(--line); cursor: pointer; white-space: nowrap; }
.pill.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.pills { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.pills::-webkit-scrollbar { display: none; }
.rating-badge { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 700; color: #ffd166; }
.avatars { display: inline-flex; }
.avatars .avatar.sm + .avatar.sm { margin-left: -8px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 48px; margin-bottom: 8px; }

/* Sections */
.section { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.section h3 { margin-bottom: 10px; }
.list-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; cursor: pointer; }
.list-item:last-child { border-bottom: 0; }
.thumb { width: 44px; height: 66px; border-radius: 6px; background: var(--bg3) center/cover; flex: none; }
.thumb.lg { width: 70px; height: 105px; }

/* Search */
.searchbar { display: flex; gap: 8px; margin-bottom: 12px; }
.searchbar input { flex: 1; font-size: 17px; }
.result { display: flex; gap: 12px; padding: 12px; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.result .info { flex: 1; min-width: 0; }
.result .plot { font-size: 13px; color: var(--muted); margin: 4px 0 8px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.result .thumb { width: 60px; height: 90px; }

/* Sheet / modal */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); } }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 94vh; overflow-y: auto; border-radius: 20px 20px 0 0; border-top: 1px solid var(--line); animation: up .2s; padding-bottom: calc(20px + var(--safe-b)); }
@media (min-width: 720px) { .overlay { align-items: center; } .sheet { border-radius: 20px; max-height: 90vh; } }
.sheet .hero { position: relative; display: flex; gap: 14px; padding: 16px; background: linear-gradient(var(--bg3), var(--bg)); }
.sheet .hero .poster { width: 110px; flex: none; border-radius: 10px; font-size: 28px; }
.sheet .hero h2 { font-size: 20px; }
.sheet .close { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; border-radius: 50%; padding: 0; background: rgba(0,0,0,.5); font-size: 18px; }
.sheet .content { padding: 0 16px; }
.sheet .block { padding: 12px 0; border-top: 1px solid var(--line); }
.sheet .block h3 { margin-bottom: 8px; }
.stream { display: flex; flex-wrap: wrap; gap: 6px; }
.stream .chip { font-size: 13px; padding: 5px 10px; }
.stream .chip.mine { outline: 2px solid var(--ok); }
.scores { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.scores button { padding: 8px 0; font-weight: 700; background: var(--bg3); }
.scores button.on { background: var(--accent); color: #fff; }
.scores button.below { opacity: .6; }
.user-rating { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.comment { display: flex; gap: 10px; padding: 8px 0; }
.comment .bubble { background: var(--bg2); border-radius: 12px; padding: 8px 12px; flex: 1; }
.comment .meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.status-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.status-row button.on { background: var(--accent); color: #fff; }
.status-row button.on.watched { background: #1f6b43; }
.status-row button.on.dropped { background: #5a2a2a; }

/* Who */
.who { display: grid; gap: 12px; padding: 40px 20px; max-width: 420px; margin: 0 auto; text-align: center; }
.who button.person { display: flex; align-items: center; gap: 14px; padding: 16px; font-size: 18px; background: var(--bg2); border: 1px solid var(--line); }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.stat { background: var(--bg3); border-radius: 12px; padding: 12px; text-align: center; }
.stat .num { font-size: 24px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--muted); }
.bar { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 4px 0; }
.bar .fill { height: 10px; border-radius: 5px; background: var(--accent); }

/* Suggest */
.pick { display: flex; gap: 12px; padding: 12px; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; cursor: pointer; }
.pick.first { border-color: var(--accent); }
.pick .reason { font-size: 14px; color: var(--muted); margin-top: 4px; }

/* Calendar strip */
.cal { display: flex; flex-direction: column; gap: 8px; }
.cal .day { display: flex; gap: 12px; align-items: center; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.cal .day.today { border-color: var(--accent); }
.cal .day.past { opacity: .6; }
.cal .date { width: 54px; text-align: center; flex: none; }
.cal .date b { display: block; font-size: 20px; line-height: 1; }
.cal .date span { font-size: 12px; color: var(--muted); text-transform: uppercase; }

/* Toast */
#toast { position: fixed; bottom: calc(76px + var(--safe-b)); left: 50%; transform: translateX(-50%); background: #fff; color: #000; padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }
#toast.err { background: #ff5c8a; color: #fff; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.toggle { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.toggle:last-child { border-bottom: 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.sources a { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.hidden { display: none !important; }
