:root {
  --bg: #0f1117;
  --panel: #1a1d29;
  --panel-2: #232735;
  --border: #2e3344;
  --text: #e7e9ee;
  --muted: #9aa0b0;
  --accent: #7c5cff;
  --accent-2: #ff5c8a;
  --star: #ffc83d;
  --danger: #ff5c5c;
  --radius: 14px;
  --cards-per-row: 4;
}
body.light {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #eceef3;
  --border: #d9dde6;
  --text: #1b1e28;
  --muted: #616877;
  --star: #e0a100;
}
/* Light-mode overrides for the few hardcoded dark fills */
body.light .rating .bar { background: #d3d7e0; }
body.light .decimal-row .bar { background: #dde0e8; }
body.light .rating .bar.preview { background: #f0d49a; }
body.light .decimal-row .bar.preview { background: #c9bdf3; }
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}
header {
  padding: 24px 20px 8px;
  text-align: center;
}
header h1 {
  margin: 0;
  font-size: 28px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
header p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.editable-name { cursor: pointer; }
.editable-name:hover { text-decoration: underline; }

.user-panel {
  position: absolute; top: 16px; right: 16px; z-index: 60;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  color: var(--muted); font-size: 13px; text-align: right;
}
.user-panel .user-line strong { color: var(--text); font-weight: 600; }
.user-panel button { padding: 6px 12px; font-size: 12px; }

/* Sign-in screen */
.authview { display: flex; align-items: center; justify-content: center; padding: 50px 20px; }
.authcard {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 24px;
  width: min(380px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.auth-h { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.auth-sub { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.auth-sub strong { color: var(--text); font-weight: 600; }
.auth-input {
  width: 100%; padding: 11px 13px; margin-bottom: 12px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 14px; outline: none;
}
.auth-input:focus { border-color: var(--accent); }
.authcard button.primary { width: 100%; }
.authcard button.ghost { width: 100%; margin-top: 10px; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 20px 60px; }

/* Add bar */
.add-bar {
  position: relative;
  display: flex;
  gap: 8px;
  margin: 20px auto 8px;
  max-width: 640px;
}
.add-bar input {
  flex: 1;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.add-bar input:focus { border-color: var(--accent); }
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  color: white;
  background: var(--accent);
  padding: 12px 18px;
  transition: transform .05s ease, opacity .2s ease;
}
button:hover { opacity: .9; }
button:active { transform: scale(.97); }
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 500;
  padding: 8px 12px;
}
button.ghost.active { color: var(--text); border-color: var(--accent); background: var(--panel-2); }

/* Search results dropdown */
.results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 20;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  max-height: 420px;
  overflow-y: auto;
}
.result {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.result:last-child { border-bottom: none; }
.result:hover { background: var(--panel-2); }
.result img { width: 42px; height: 60px; object-fit: cover; border-radius: 6px; flex-shrink: 0; background: var(--panel-2); }
.result .meta { min-width: 0; flex: 1; }
.result .meta .t { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result .meta .s { color: var(--muted); font-size: 12px; }
.result.added { cursor: default; opacity: .5; }
.result.added:hover { background: none; }
.result .added-tag {
  flex-shrink: 0; color: #3ddc84; font-size: 12px; font-weight: 700;
  border: 1px solid #3ddc84; border-radius: 999px; padding: 3px 9px;
}
.results .status { padding: 14px; color: var(--muted); font-size: 14px; text-align: center; }

/* Controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 18px 0 4px;
}
.controls .label { color: var(--muted); font-size: 13px; margin-right: 2px; }
.spacer { flex: 1; }
select {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
}
.list-filter {
  flex: 1 1 200px; min-width: 150px; max-width: 320px;
  padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--text); font-size: 13px; outline: none;
}
.list-filter:focus { border-color: var(--accent); }

.tagfilter-section { margin: 8px 0 16px; }
.tagfilter-head {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; user-select: none;
}
.tagfilter-head .chevron {
  color: var(--muted); font-size: 11px; transition: transform .15s ease;
}
.tagfilter-label { font-size: 13px; font-weight: 600; color: var(--text); }
.tagfilter-active { font-size: 12px; color: var(--accent); font-weight: 600; }
.tagfilter { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tagfilter-section.collapsed .chevron { transform: rotate(-90deg); }
.tagfilter-section.collapsed .tagfilter { display: none; }

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(var(--cards-per-row), minmax(0, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.card.dragging { opacity: .4; }
.card.dragover { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.card .poster { position: relative; aspect-ratio: 2/3; background: var(--panel-2); }
.card .poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .poster.clickable { cursor: pointer; }
.card .poster.clickable img { transition: opacity .15s ease; }
.card .poster.clickable:hover img { opacity: .82; }
.rank-badge {
  position: absolute; top: 8px; left: 8px;
  background: rgba(0,0,0,.65); backdrop-filter: blur(4px);
  color: #fff; font-weight: 700; font-size: 13px;
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.drag-handle {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,.55); border-radius: 8px;
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  cursor: grab; color: #fff; font-size: 14px; user-select: none;
}
.drag-handle:active { cursor: grabbing; }
.del {
  position: absolute; bottom: 8px; right: 8px;
  background: rgba(0,0,0,.55); border-radius: 8px;
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #fff; font-size: 16px; opacity: 0; transition: opacity .2s;
}
.card:hover .del { opacity: 1; }
.del:hover { background: var(--danger); }

.card .body { padding: 12px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card .title-row { display: flex; align-items: flex-start; gap: 8px; }
.card .title { font-weight: 600; font-size: 14px; flex: 1; min-width: 0; }
.card .year { color: var(--muted); font-size: 12px; font-weight: 400; }

/* "Who has this?" button on each card */
.compare-btn {
  flex-shrink: 0; background: var(--panel-2); border: 1px solid var(--border);
  color: var(--muted); border-radius: 8px; padding: 4px 7px;
  font-size: 13px; line-height: 1; font-weight: 600;
}
.compare-btn:hover { opacity: 1; border-color: var(--accent); color: var(--text); }

/* Status filter pills */
.statusfilter { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; }
.statusfilter .spill {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--muted); border-radius: 999px;
  padding: 5px 11px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.statusfilter .spill .dot { width: 8px; height: 8px; border-radius: 50%; }
.statusfilter .spill .cnt { color: var(--muted); font-weight: 500; }
.statusfilter .spill.active { color: var(--text); border-color: var(--text); background: var(--panel-2); }

/* Per-card status select */
.card .status-select {
  width: 100%; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2);
  color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer;
  border-left-width: 3px;
}

/* Airing badge on poster */
.airing-badge {
  position: absolute; bottom: 8px; left: 8px;
  background: rgba(61,220,132,.92); color: #06241a;
  font-size: 10px; font-weight: 800; letter-spacing: .3px;
  padding: 3px 7px; border-radius: 7px; display: flex; align-items: center; gap: 4px;
}
.airing-badge .pulse {
  width: 6px; height: 6px; border-radius: 50%; background: #06241a;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .35; } 50% { opacity: 1; } }
.card .broadcast { font-size: 11px; color: var(--muted); }
.card .broadcast .airing-txt { color: #3ddc84; font-weight: 600; }

.rating-wrap { display: flex; flex-direction: column; gap: 6px; }
.rating { display: flex; align-items: center; gap: 8px; }
.rating .bars { display: flex; gap: 3px; }
.rating .bar {
  width: 13px; height: 20px; border-radius: 3px;
  background: #353a4d; cursor: pointer;
  transition: background .08s ease, transform .08s ease;
}
.rating .bar:hover { transform: scaleY(1.12); }
.rating .bar.on { background: var(--star); }
.rating .bar.preview { background: #6b5a2a; }
.rating-num {
  color: var(--muted); font-size: 13px; font-weight: 600;
  min-width: 42px; text-align: right; font-variant-numeric: tabular-nums;
}
.rating-num.set { color: var(--star); }
.decimal-row .bar { background: #2f3445; }
.decimal-row .bar.on { background: var(--accent); }
.decimal-row .bar.preview { background: #3f3470; }
.dec-num { color: var(--muted); font-size: 12px; min-width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
.dec-num.set { color: var(--accent); }

/* Narrow cards (4+ per row): stack the rating bars vertically so the score
   isn't clipped. The two meters (whole + decimal) sit side by side. */
body.vertical-rating .rating-wrap { flex-direction: row; gap: 14px; align-items: flex-start; }
body.vertical-rating .rating { flex-direction: column; align-items: center; gap: 6px; }
body.vertical-rating .rating .bars { flex-direction: column-reverse; gap: 3px; }
body.vertical-rating .rating .bar { width: 26px; height: 9px; }
body.vertical-rating .rating .bar:hover { transform: scaleX(1.12); }
body.vertical-rating .rating-num,
body.vertical-rating .dec-num { min-width: 0; text-align: center; }

/* Tightest phone layout (3 per row): thinner vertical bars still. */
body.thin-rating .rating-wrap { gap: 9px; }
body.thin-rating .rating .bar { width: 15px; height: 7px; }
body.thin-rating .rating-num,
body.thin-rating .dec-num { font-size: 11px; }

.tags { display: none; flex-wrap: wrap; gap: 5px; margin-top: auto; }
body.show-tags .tags { display: flex; }
.tag {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 9px; font-size: 11px; color: var(--text);
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
}
.tag.filter-on { border-color: var(--accent); color: #fff; background: var(--accent); }
.tag .x { color: var(--muted); font-weight: 700; }
.tag .x:hover { color: var(--danger); }
.tag-add {
  background: transparent; border: 1px dashed var(--border);
  border-radius: 999px; padding: 3px 9px; font-size: 11px; color: var(--muted); cursor: pointer;
}
.tag-input {
  background: var(--panel-2); border: 1px solid var(--accent);
  border-radius: 999px; padding: 3px 9px; font-size: 11px; color: var(--text);
  outline: none; width: 90px;
}

#unratedSection { margin-top: 36px; }
.section-head {
  display: flex; align-items: baseline; gap: 10px;
  padding-top: 20px; margin-bottom: 14px;
  border-top: 1px solid var(--border);
  cursor: pointer; user-select: none;
}
.section-head .chevron {
  color: var(--muted); font-size: 11px; transition: transform .15s ease;
  align-self: center;
}
.section-title { font-size: 15px; font-weight: 700; color: var(--text); }
.section-count { font-size: 13px; color: var(--muted); font-weight: 600; }
.section-sub { font-size: 12px; color: var(--muted); }
#unratedSection.collapsed .chevron { transform: rotate(-90deg); }
#unratedSection.collapsed #unratedGrid { display: none; }
#unratedSection.collapsed .section-head { margin-bottom: 0; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; font-size: 15px; }

.settings-btn {
  position: absolute; top: 16px; left: 16px; z-index: 60;
  width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; font-size: 18px; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.settings-btn:hover { background: var(--panel-2); }

/* Friends button — circular, sits just right of the settings gear. */
.friends-btn { left: 62px; }
.friends-btn .badge { position: absolute; top: -4px; right: -4px; margin: 0; }

.settings-menu {
  position: absolute; top: 62px; left: 16px; z-index: 61;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: 14px 16px; min-width: 230px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
/* Friends popover: same card as settings, a touch wider and scrollable. */
.friends-menu { min-width: 300px; max-width: 340px; max-height: calc(100vh - 90px); overflow-y: auto; }
.friends-menu .panel-section:first-of-type { margin-top: 0; }
.settings-menu-title { font-size: 14px; font-weight: 700; margin-bottom: 14px; }
.settings-row { display: flex; flex-direction: column; gap: 8px; }
.settings-row .settings-label {
  font-size: 12px; color: var(--muted); font-weight: 600;
}
.settings-choices { display: flex; gap: 6px; }
.settings-choices button {
  flex: 1; padding: 7px 0; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.settings-choices button:hover { border-color: var(--accent); }
.settings-choices button.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.settings-row-inline {
  flex-direction: row; align-items: center; justify-content: space-between;
}
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border); transition: background .15s ease, border-color .15s ease;
}
.switch .track::before {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 999px; background: var(--muted);
  transition: transform .15s ease, background .15s ease;
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::before { transform: translateX(18px); background: #fff; }

.back-to-top {
  position: fixed; bottom: 24px; right: 24px; z-index: 60;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #fff; border: none;
  font-size: 20px; line-height: 1; cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.back-to-top.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.back-to-top:hover { filter: brightness(1.1); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 50;
  box-shadow: 0 8px 30px rgba(0,0,0,.5); opacity: 0; transition: opacity .25s; pointer-events: none;
  display: flex; align-items: center; gap: 14px;
}
.toast.show { opacity: 1; }
.toast.has-action { pointer-events: auto; }
.toast .undo-btn {
  background: transparent; border: none; color: var(--accent);
  font-weight: 700; font-size: 13px; cursor: pointer; padding: 2px 2px;
}
.toast .undo-btn:hover { text-decoration: underline; }

/* Friends button badge */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 2px;
  border-radius: 999px; background: var(--accent-2); color: #fff;
  font-size: 11px; font-weight: 800;
}

/* Viewing-a-friend banner */
.viewing-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 18px 0 4px; padding: 10px 14px;
  background: var(--panel-2); border: 1px solid var(--accent); border-radius: var(--radius);
  font-size: 14px;
}
.viewing-banner strong { font-weight: 700; }
.viewing-banner .ro-tag {
  margin-left: 6px; font-size: 11px; font-weight: 700; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px;
}

/* Read-only rating + status (friend's list) */
.rating-wrap.readonly .bar { cursor: default; }
.rating-wrap.readonly .bar:hover { transform: none; }
.status-view {
  align-self: flex-start; font-size: 12px; font-weight: 600;
  padding: 4px 9px; border-radius: 8px;
  border: 1px solid var(--border); border-left-width: 3px; background: var(--panel-2);
}

/* Friends panel */
.panel-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,.6);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto;
}
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); width: min(440px, 94vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  padding: 20px 22px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.panel-title { font-size: 18px; font-weight: 700; }
.panel-section { margin-top: 18px; }
.panel-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 8px; }
.friend-results { display: flex; flex-direction: column; gap: 6px; }
.friend-results:empty { display: none; }
.friend-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel-2);
}
.friend-name { font-weight: 600; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-actions { display: flex; gap: 6px; flex-shrink: 0; }
.friend-actions button { padding: 6px 12px; font-size: 12px; }
.friend-tag { font-size: 12px; color: var(--muted); font-weight: 600; padding: 6px 4px; }
.friend-empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }
#incomingList, #outgoingList, #friendsList { display: flex; flex-direction: column; gap: 6px; }

/* "Who has this?" compare modal */
.compare-body { display: flex; flex-direction: column; gap: 6px; }
.compare-count { font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.compare-meta { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.compare-status {
  font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 7px;
  border: 1px solid var(--border); border-left-width: 3px; background: var(--panel);
  color: var(--muted);
}
.compare-rating {
  font-size: 13px; font-weight: 700; color: var(--muted);
  font-variant-numeric: tabular-nums; min-width: 54px; text-align: right;
}
.compare-rating.set { color: var(--star); }
.friend-row.is-me { border-color: var(--accent); background: var(--panel); }
.friend-row.is-me .friend-name { color: var(--accent); }
