:root {
  --bg: #17193F;
  --surface: #131433;
  --surface-2: #1E2050;
  --accent: #9C49E3;
  --accent-dark: #2E2868;
  --text: #FFFFFF;
  --muted: #C3C5E6;
  --line: #2E2868;
  --danger: #FF8A9B;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
body.noscroll { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
img { display: block; }

:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.btn {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 2px solid transparent;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.btn-primary { background: var(--accent); }
.btn-ghost { background: transparent; border-color: var(--accent-dark); color: var(--muted); }
.btn-big { min-height: 56px; padding: 0 28px; font-size: 18px; }
.btn:disabled { cursor: default; }

/* top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-t)) calc(16px + var(--safe-r)) 10px calc(16px + var(--safe-l));
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; letter-spacing: .2px; }
.brand img { border-radius: 8px; }
.user { display: flex; align-items: center; gap: 8px; min-width: 0; }
.user-name { color: var(--muted); max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user .btn { min-height: 44px; padding: 0 14px; font-size: 14px; }

/* tabs and filter */
.controls {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 6px calc(16px + var(--safe-r)) 12px calc(16px + var(--safe-l));
  border-bottom: 1px solid var(--line);
}
.tabs { display: flex; gap: 8px; }
.tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 48px;
  padding: 6px 8px;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--accent-dark);
  border-radius: 999px;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); }
.kinds {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-top: 10px;
  padding: 3px;
  background: var(--surface);
  border-radius: 999px;
}
.kind {
  min-height: 44px;
  font: inherit;
  font-weight: 700;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}
.kind[aria-pressed="true"] { background: var(--accent-dark); color: var(--text); }

/* list and cards */
.list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px calc(16px + var(--safe-r)) calc(96px + var(--safe-b)) calc(16px + var(--safe-l));
  max-width: 720px;
  margin: 0 auto;
}
.card {
  display: flex;
  gap: 14px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.poster {
  flex: none;
  align-self: flex-start;
  width: 92px;
  aspect-ratio: 2 / 3;
  height: auto;
  object-fit: cover;
  border-radius: 10px;
  background: var(--accent-dark);
}
.poster-empty { display: flex; align-items: center; justify-content: center; font-size: 28px; color: var(--muted); }
.card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.card-title { font-size: 18px; line-height: 1.25; overflow-wrap: anywhere; }
.year { color: var(--muted); font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-dark);
  font-size: 13px;
  line-height: 1.3;
}
.chip-label { color: var(--muted); }
.chip-value { font-weight: 800; }
.chip-value::after { content: " /5"; font-weight: 400; color: var(--muted); }
.noscore { font-size: 13px; color: var(--muted); }
.reason { font-size: 14px; color: var(--muted); }
.card-action { margin-top: auto; padding-top: 4px; }
.state { width: 100%; }
.state-ask { background: var(--accent); }
.state-done { background: transparent; border-color: var(--accent); color: var(--text); }
.state-plex { background: var(--accent-dark); color: var(--text); }

.empty { padding: 32px 8px; text-align: center; color: var(--muted); font-size: 17px; }
.retry { align-self: center; }

.skeleton .poster, .sk-line { background: linear-gradient(90deg, var(--accent-dark), var(--surface-2), var(--accent-dark)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
.sk-line { height: 14px; border-radius: 7px; width: 70%; }
.sk-wide { width: 90%; height: 20px; }
.sk-short { width: 40%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* floating search button */
.fab {
  position: fixed;
  right: calc(16px + var(--safe-r));
  bottom: calc(16px + var(--safe-b));
  z-index: 8;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .5);
}

/* search overlay */
.search {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  overflow-y: auto;
  padding-top: var(--safe-t);
}
.search-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  gap: 8px;
  padding: 12px calc(16px + var(--safe-r)) 12px calc(16px + var(--safe-l));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.search-bar input {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 16px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--accent-dark);
  border-radius: 999px;
}
.search-bar input::placeholder { color: var(--muted); }
.search-bar input:focus { border-color: var(--accent); outline: none; }

/* request sheet */
.sheet { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); }
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 520px;
  padding: 22px calc(20px + var(--safe-r)) calc(20px + var(--safe-b)) calc(20px + var(--safe-l));
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  border-top: 2px solid var(--accent);
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: rise .2s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet-panel h2 { font-size: 20px; }
.sheet-hint { color: var(--muted); }
.options { display: flex; flex-direction: column; gap: 8px; }
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 0 16px;
  background: var(--bg);
  border: 2px solid var(--accent-dark);
  border-radius: 14px;
  font-weight: 600;
  cursor: pointer;
}
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-dark); }
.option input { width: 22px; height: 22px; accent-color: var(--accent); }
.sheet-actions { display: flex; gap: 10px; margin-top: 4px; }
.sheet-actions .btn { flex: 1; }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 40;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 14px;
  background: #3A1C4D;
  border: 1px solid var(--danger);
  color: var(--text);
}

/* sign-in and offline */
.signin, .offline-box {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  text-align: center;
}
.signin h1 { font-size: 40px; }
.signin p, .offline-box p { color: var(--muted); max-width: 320px; }
.signin img, .offline-box img { border-radius: 24px; }
.signin-msg { min-height: 24px; }
.signin-msg a { color: #fff; font-weight: 700; }
.offline-box h1 { font-size: 26px; }

@media (min-width: 720px) {
  .controls { padding-left: max(16px, calc((100vw - 720px) / 2)); padding-right: max(16px, calc((100vw - 720px) / 2)); }
  .topbar { padding-left: max(16px, calc((100vw - 720px) / 2)); padding-right: max(16px, calc((100vw - 720px) / 2)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
