:root {
  --bg: #0e0f11;
  --surface: #17181b;
  --surface-raised: #1f2024;
  --line: #2a2c31;
  --text: #f2f2f3;
  --text-dim: #a1a1aa;
  --text-faint: #71717a;
  --cta: #f4f4f5;
  --cta-text: #111113;
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f4f5;
    --surface: #ffffff;
    --surface-raised: #f4f4f5;
    --line: #e4e4e7;
    --text: #18181b;
    --text-dim: #52525b;
    --text-faint: #a1a1aa;
    --cta: #18181b;
    --cta-text: #fafafa;
    --danger: #dc2626;
    --ok: #16a34a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 880px;
  margin: 0 auto;
  padding: 20px 16px;
}
.wordmark { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; text-decoration: none; letter-spacing: -0.01em; }
.wordmark .mark { width: 30px; height: 30px; border-radius: 8px; }
.brand-icon { display: block; width: 88px; height: 88px; border-radius: 22px; margin: 0 0 20px; }
#account { display: flex; align-items: center; gap: 12px; color: var(--text-dim); font-size: 14px; min-width: 0; }
#account .email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { max-width: 880px; margin: 0 auto; padding: 8px 16px 64px; }
h1 { font-size: 28px; line-height: 1.2; letter-spacing: -0.02em; margin: 16px 0 6px; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin: 36px 0 12px; }
p.lede { color: var(--text-dim); margin: 0 0 24px; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); font-size: 13px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
}
.narrow { max-width: 420px; margin: 48px auto 0; }

.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}
.row.link { text-decoration: none; }
.row.link:hover { background: var(--surface-raised); }
.row.disabled .row-main { opacity: 0.5; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--text-dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.logo {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  background: var(--surface-raised); object-fit: contain;
  display: grid; place-items: center; font-weight: 700; color: var(--text-dim);
}

label { display: block; font-size: 13px; color: var(--text-dim); margin: 0 0 6px; }
input[type="text"], input[type="email"], input[type="url"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}
input:focus { border-color: var(--text-dim); }
input.code { font-size: 24px; letter-spacing: 0.3em; text-align: center; font-variant-numeric: tabular-nums; }
.field { margin-bottom: 16px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }

button, a.button {
  font: inherit;
  display: inline-block;
  text-decoration: none;
  font-weight: 600;
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-raised);
  white-space: nowrap;
}
button:hover { filter: brightness(1.15); }
button:disabled { opacity: 0.5; cursor: default; filter: none; }
button.primary, a.button.primary { background: var(--cta); color: var(--cta-text); }
button.danger { color: var(--danger); }
button.small { padding: 6px 12px; font-size: 13px; }
button.icon { padding: 6px 10px; font-size: 14px; line-height: 1; }
button.link { background: none; padding: 0; color: var(--text-dim); font-weight: 500; text-decoration: underline; }
.full { width: 100%; }

.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background 0.15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--text-dim); outline-offset: 2px; }

.choice { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface-raised); margin-bottom: 8px; cursor: pointer; }
.choice input { margin: 0; }

.error { color: var(--danger); font-size: 14px; margin: 8px 0 0; min-height: 1.5em; }
.empty { color: var(--text-dim); padding: 24px; text-align: center; background: var(--surface); border-radius: var(--radius); }
.reveal { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; background: var(--surface-raised); border-radius: 8px; padding: 10px; margin-top: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.big-code { font-size: 30px; font-weight: 700; letter-spacing: 0.12em; text-align: center; margin: 4px 0 16px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--cta); color: var(--cta-text); padding: 10px 18px; border-radius: 999px;
  font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 560px) {
  .row { flex-wrap: wrap; }
  .row-actions { width: 100%; justify-content: flex-end; }
  h1 { font-size: 24px; }
}

.mt { margin-top: 12px; }
.grow { flex: 1; }
.danger-text { color: var(--danger); }
.choice .grow input { margin-top: 8px; }

/* Drag to reorder */
.grip {
  flex-shrink: 0;
  width: 22px;
  height: 36px;
  padding: 0;
  border-radius: 6px;
  background-color: transparent;
  background-image: radial-gradient(circle, var(--text-faint) 1.7px, transparent 2px);
  background-size: 9px 9px;
  background-position: center;
  cursor: grab;
  touch-action: none;
}
.grip:hover { background-image: radial-gradient(circle, var(--text-dim) 1.7px, transparent 2px); filter: none; }
.grip:focus-visible { outline: 2px solid var(--text-dim); outline-offset: 2px; }
.sorting { user-select: none; -webkit-user-select: none; }
.sorting .grip { cursor: grabbing; }
.row.dragging {
  position: relative;
  z-index: 2;
  background: var(--surface-raised);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* Profile pictures */
.avatar { width: 44px; height: 44px; border-radius: 10px; flex-shrink: 0; object-fit: cover; background: var(--surface-raised); }
.avatar.large { width: 56px; height: 56px; border-radius: 12px; }
.avatar.monogram { display: grid; place-items: center; font-weight: 700; color: #fff; }
.avatar.large.monogram { font-size: 20px; }
.title-with-avatar { display: flex; align-items: center; gap: 16px; min-width: 0; }
.title-with-avatar h1 { margin: 0; }

/* Profile tabs */
.tabs { display: flex; gap: 4px; margin: 24px 0 0; border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 10px 16px; text-decoration: none; color: var(--text-dim); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--text); }
.mt-lg { margin-top: 24px; }
.flush { margin: 0; }

/* Rows that wrap a panel under themselves */
.row.wrap { flex-wrap: wrap; }
.row.wrap > .config-panel, .row.wrap > .disclosure, .row.wrap > .list.nested { flex-basis: 100%; }
.row.compact { padding: 10px 14px; }
.config-panel { display: flex; flex-direction: column; gap: 10px; padding-top: 8px; }
.config-panel[hidden], .disclosure[hidden] { display: none; }
.disclosure { margin: 8px 0; }
.list.nested { margin-top: 6px; padding-left: 12px; border-left: 2px solid var(--line); }
.tile-row { background: var(--surface-raised); }
.badge { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; color: var(--text-dim); background: var(--surface-raised); vertical-align: 2px; }
.tile-row .badge { background: var(--surface); }
.tile-thumb { width: 64px; height: 36px; border-radius: 6px; object-fit: cover; flex-shrink: 0; background: var(--surface); }
.tile-thumb.poster { width: 32px; height: 48px; }
.tile-thumb.square { width: 40px; height: 40px; }
.tile-thumb.placeholder { display: grid; place-items: center; font-size: 10px; color: var(--text-faint); }
select, textarea {
  font: inherit; color: var(--text); background: var(--surface-raised); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
textarea { width: 100%; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.small-text { font-size: 13px; color: var(--text-dim); }
.picker { display: flex; flex-direction: column; gap: 12px; max-height: 360px; overflow: auto; }
.picker-group { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.picker-group legend { font-weight: 600; margin-bottom: 4px; }

/* Filters */
.filter-group { margin-top: 24px; }
.filter-group h3 { font-size: 15px; margin: 0 0 8px; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 6px; font-size: 13px; font-weight: 600; border: 1px solid transparent; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.two-up { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.preview { padding: 4px 0; }
/* Name on the left, badge at the right end of the row, beside the switch. */
.badge-with-name { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; }
.badge-image { height: 26px; width: auto; max-width: 160px; object-fit: contain; display: block; }

/* A button that opens a panel turns white only while that panel is open. */
button[aria-expanded="true"] { background: var(--cta); color: var(--cta-text); }

/* Poster preview */
.poster-preview { display: grid; grid-template-columns: repeat(3, minmax(0, 160px)); gap: 16px; }
.poster-preview figure { margin: 0; }
.poster-frame { aspect-ratio: 2 / 3; border-radius: 10px; overflow: hidden; background: var(--surface); display: grid; place-items: center; }
.poster-frame.loading { background: linear-gradient(90deg, var(--surface) 0%, var(--surface-raised) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.poster-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster-preview figcaption { margin-top: 6px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Rows never grow past the page: the text column takes what's left (and
   truncates), and when the buttons don't fit beside a readable title they
   wrap onto their own line inside the row. */
.row-main { flex: 1 1 220px; min-width: 0; }
.row-actions { flex-wrap: wrap; justify-content: flex-end; }
.row.wrap > .row-actions { margin-left: auto; }
.list, .list.nested { min-width: 0; }
.tile-row .row-actions { gap: 4px; }

/* Space between Add Widget (and its form) and the first widget. */
#app > .disclosure + .list, #app > .spread + .list, #app > .disclosure:not([hidden]) { margin-top: 16px; }
.hidden-widget > .row-main, .hidden-widget > .grip { opacity: 0.5; }

/* More air between widgets (each a group of collections) and between filter groups. */
.list:has(> .widget) { gap: 20px; }
.filter-group { margin-top: 40px; }
.filter-group + .filter-group { padding-top: 8px; }

/* A row of section buttons (Add Filter, Import…) reads from the left; only
   buttons at the end of a list row sit right. */
.row-actions.toolbar { justify-content: flex-start; }

#app > .row-actions.toolbar + .disclosure, #app > .row-actions.toolbar ~ .list { margin-top: 16px; }

input[type="search"] {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-raised);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; outline: none;
}
input[type="search"]:focus { border-color: var(--text-dim); }
.picker-group[hidden], label.check[hidden] { display: none; }

/* Dialogs (Rename, Delete…) */
dialog.modal {
  width: min(440px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
dialog.modal h3 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
dialog.modal p { margin: 0; }
dialog.modal input, dialog.modal textarea { width: 100%; }
dialog.modal textarea { font-size: 12px; word-break: break-all; }
dialog.modal[open] { animation: modal-in 0.14s ease-out; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
button.danger-solid { background: var(--danger); color: #fff; }
@keyframes modal-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
