:root {
  --bg: #0f1412;
  --surface: #171e1b;
  --surface-2: #1d2622;
  --ink: #e9efea;
  --muted: #9aaba1;
  --line: rgba(233, 239, 234, 0.1);
  --accent: #c8f542;
  --accent-ink: #12180f;
  --danger: #ff7a6e;
  --ok: #5ddea0;
  --radius: 14px;
  --font: "Instrument Sans", system-ui, -apple-system, sans-serif;
  --pad: 20px;
  --tap: 44px;
  --top: 52px;
  --tab: calc(58px + env(safe-area-inset-bottom, 0px));
  --radius: 14px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) 0 env(safe-area-inset-left, 0);
}

[hidden] { display: none !important; }

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(600px 320px at 0% 0%, rgba(200,245,66,0.08), transparent 60%),
    var(--bg);
}

.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--accent);
  flex-shrink: 0;
}
.brand-name {
  font-weight: 650;
  letter-spacing: -0.02em;
}

/* ----- Login ----- */
.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--pad);
}
.login-card {
  width: min(100%, 380px);
  display: grid;
  gap: 12px;
  padding: 22px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.login-card h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}
.lede {
  margin: 0 0 4px;
  color: var(--muted);
}

/* ----- App shell ----- */
.app {
  min-height: 100dvh;
  padding-bottom: var(--tab);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--pad);
  background: rgba(15, 20, 18, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
}

.main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px var(--pad) 24px;
}

.panel { display: none; }
.panel.is-visible { display: block; }

.page-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  margin-bottom: 16px;
}
.page-head h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}
.page-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ----- Controls ----- */
.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 500;
}
.field input,
.field select,
.field textarea,
.toolbar input,
.inline-form input[type="text"] {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  padding: 10px 12px;
  outline: none;
}
.field textarea {
  min-height: 96px;
  resize: vertical;
  line-height: 1.4;
}
.field input:focus,
.field select:focus,
.field textarea:focus,
.toolbar input:focus {
  border-color: rgba(200, 245, 66, 0.45);
}
.help-box {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}
.help-box strong { color: var(--ink); font-weight: 650; }
.field input[type="file"] {
  padding: 10px;
  font-size: 0.88rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); width: 100%; }
.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  width: 100%;
}
.btn.text {
  background: transparent;
  color: var(--muted);
  min-height: 36px;
  padding: 0 8px;
  width: auto;
}
.btn.danger { color: var(--danger); border-color: rgba(255,122,110,0.35); }
.btn:disabled { opacity: 0.5; }
.btn:active { transform: scale(0.98); }

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: 1.2rem;
  cursor: pointer;
  flex-shrink: 0;
}

.stack { display: grid; gap: 12px; }
.stack.tight { gap: 10px; margin-top: 12px; }
.row-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.toast {
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  color: var(--muted);
  font-size: 0.9rem;
}
.toast.error {
  color: #ffd2cd;
  border-color: rgba(255,122,110,0.35);
  background: rgba(255,122,110,0.08);
}
.toast.ok {
  color: #c9ffe4;
  border-color: rgba(93,222,160,0.35);
  background: rgba(93,222,160,0.08);
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  font-weight: 500;
  cursor: pointer;
}
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ----- Library ----- */
.toolbar { margin-bottom: 12px; }

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
  margin-bottom: 12px;
}
.filter-platform { flex: 1 1 140px; min-width: 120px; }
.chip-toggle {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.85rem;
}
.btn.compact {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.85rem;
  width: auto;
}
.bulk-bar {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.bulk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.item { position: relative; }
.item.is-bulk { grid-template-columns: 36px 112px 1fr; }
.item-check {
  display: grid;
  place-items: center;
  padding-left: 8px;
}
.item-flags {
  position: absolute;
  top: 6px;
  left: 6px;
  display: flex;
  gap: 4px;
}
.flag-dot {
  font-size: 0.75rem;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 6px;
  background: rgba(0,0,0,0.55);
  color: var(--accent);
}
.item-actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}
.icon-mini {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}
.icon-mini.is-on,
.btn.ghost.is-on {
  color: var(--accent);
  border-color: rgba(200, 245, 66, 0.4);
  background: rgba(200, 245, 66, 0.1);
}

.cat-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.cat-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
  mask-image: linear-gradient(90deg, #000 85%, transparent);
}
.cat-scroll::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.chip.is-active {
  background: rgba(200, 245, 66, 0.16);
  border-color: rgba(200, 245, 66, 0.4);
  color: var(--ink);
}
.chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.chip .n {
  color: var(--muted);
  font-size: 0.75rem;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.inline-form input[type="color"] {
  width: 44px;
  height: 44px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}
.inline-form .btn { grid-column: 1 / -1; }

.list {
  display: grid;
  gap: 10px;
}
.item {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 12px;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.item:active { border-color: rgba(200, 245, 66, 0.35); }
.item-thumb {
  aspect-ratio: 16 / 10;
  background: #0a0f0d;
  position: relative;
}
.item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.item-body {
  padding: 10px 12px 10px 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}
.item-body h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.item-body .meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}
.item-body .tag {
  align-self: start;
  font-size: 0.7rem;
  color: var(--muted);
  background: rgba(255,255,255,0.05);
  padding: 2px 7px;
  border-radius: 999px;
}

.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 14px;
  justify-items: center;
}
.empty p { margin: 0; }
.empty .btn { width: auto; min-width: 160px; }

/* ----- Download result ----- */
.result {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.result-media {
  aspect-ratio: 16 / 9;
  background: #0a0f0d;
}
.result-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.result-body { padding: 14px; }
.result-body h2 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.platform-tag {
  margin: 0 0 6px;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: rgba(200, 245, 66, 0.12);
  color: var(--accent);
}
.item-body .platform {
  font-size: 0.68rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent);
}

.job {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.job-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}
.bar {
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  overflow: hidden;
}
#job-bar {
  height: 100%;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: var(--accent);
  transition: transform 0.2s var(--ease);
}
.job-result { margin: 10px 0 0; color: var(--ok); font-size: 0.9rem; }
.job-result a { color: var(--accent); }

/* ----- Settings ----- */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.seg-btn {
  min-height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn.is-active {
  background: var(--accent);
  color: var(--accent-ink);
}
.settings-pane { display: none; }
.settings-pane.is-visible { display: block; }

.user-list { display: grid; gap: 8px; }
.user-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  display: grid;
  gap: 10px;
}
.user-card strong { font-size: 0.95rem; }
.user-card .muted { color: var(--muted); font-size: 0.8rem; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: rgba(200,245,66,0.12);
  color: var(--accent);
  margin-right: 4px;
}
.badge.muted {
  background: rgba(255,255,255,0.06);
  color: var(--muted);
}
.badge.off {
  background: rgba(255,122,110,0.12);
  color: var(--danger);
}
.card {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.form-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

/* ----- Tab bar ----- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: var(--tab);
  padding: 8px 8px max(8px, env(safe-area-inset-bottom, 0px));
  background: rgba(15, 20, 18, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 12px;
  -webkit-tap-highlight-color: transparent;
}
.tab svg { width: 22px; height: 22px; }
.tab.is-active {
  color: var(--accent);
  background: transparent;
}
.tab.is-active svg {
  filter: drop-shadow(0 0 6px rgba(200, 245, 66, 0.35));
}

/* ----- Player sheet ----- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  align-items: end;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
}
.sheet-panel {
  position: relative;
  max-height: 92dvh;
  overflow: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.3;
}
#player {
  width: 100%;
  max-height: 40dvh;
  background: #000;
  display: block;
}
.sheet-body {
  padding: 14px;
  display: grid;
  gap: 12px;
}

/* ----- Queue ----- */
.queue-list { display: grid; gap: 10px; }
.queue-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  display: grid;
  gap: 8px;
  cursor: default;
}
.queue-item[data-queue-done] { cursor: pointer; }
.queue-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  word-break: break-all;
}
.queue-actions { margin-top: 4px; }
.qbar {
  height: 100%;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: var(--accent);
  transition: transform 0.2s var(--ease);
}

/* ----- Notifications ----- */
.notif-btn { position: relative; }
.notif-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.65rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  line-height: 1;
}
.notif-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: min(340px, calc(100vw - 24px));
  max-height: 60dvh;
  overflow: auto;
  z-index: 40;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
}
.notif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--surface);
}
.notif-list { display: grid; }
.notif-item {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.notif-item.unread { background: rgba(200, 245, 66, 0.06); }
.notif-item strong { font-size: 0.9rem; }
.notif-item span { color: var(--muted); font-size: 0.82rem; }

/* ----- Cookie sites ----- */
.cookies-sites { display: grid; gap: 10px; }
.cookie-site {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  display: grid;
  gap: 8px;
}
.hint { color: var(--muted); font-size: 0.78rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Desktop */
@media (min-width: 860px) {
  .app { padding-bottom: 0; }
  .tabbar { display: none; }

  .topbar {
    max-width: 960px;
    margin: 0 auto;
    position: sticky;
  }
  .topbar::after {
    content: "";
    /* spacer for desktop nav injected via flex */
  }
  .main {
    max-width: 960px;
    padding: 24px 20px 48px;
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 24px;
  }
  /* Keep panels full width in single-column flow; use simpler desktop nav in topbar via JS class */
  .main { display: block; }

  .page-head h1 { font-size: 1.6rem; }
  .list {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
  .item { grid-template-columns: 1fr; }
  .item.is-bulk { grid-template-columns: 36px 1fr; }
  .item-thumb { aspect-ratio: 16 / 9; }
  .item-body { padding: 12px; }

  .btn.primary, .btn.ghost { width: auto; }
  .row-actions { justify-content: start; }
  #inspect-form .btn,
  #profile-form .btn,
  #settings-form .btn { width: auto; }

  .sheet {
    place-items: center;
    padding: 24px;
  }
  .sheet-panel {
    width: min(840px, 100%);
    border-radius: 16px;
    max-height: 90vh;
  }
  #player { max-height: 56vh; }

  /* Desktop top nav */
  .topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 16px;
  }
  .desktop-nav {
    display: flex;
    justify-content: center;
    gap: 6px;
  }
  .desktop-nav .tab {
    flex-direction: row;
    gap: 8px;
    min-height: 36px;
    padding: 0 12px;
    font-size: 0.88rem;
  }
  .desktop-nav .tab svg { width: 16px; height: 16px; }
}
