:root {
  --bg: #f6f1e9;
  --surface: #fffdf9;
  --surface-2: #efe8dc;
  --line: #e2d8c8;
  --text: #221c14;
  --muted: #7a6f60;
  --accent: #e2531f;
  --accent-ink: #ffffff;
  --accent-soft: #fbe3d8;
  --want: #e2531f;
  --watching: #c98a0b;
  --watched: #2f8a5b;
  --danger: #c0352b;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 6px 20px rgba(60, 40, 10, .06);
  --radius: 14px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120e;
    --surface: #1f1b16;
    --surface-2: #2a251e;
    --line: #362f26;
    --text: #f3ece1;
    --muted: #a5998a;
    --accent: #ff7043;
    --accent-ink: #1a0f08;
    --accent-soft: #3a2218;
    --want: #ff7043;
    --watching: #f2b84b;
    --watched: #5ccf93;
    --danger: #ff6b5e;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; }
small { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; font-weight: 400; }
.muted { color: var(--muted); }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font: 700 21px/1 var(--display); letter-spacing: -.01em; }
.brand-lg { font-size: 30px; justify-content: center; }
.brand-mark {
  width: 26px; height: 20px; border-radius: 5px; position: relative;
  background: var(--accent); box-shadow: inset 0 0 0 3px var(--accent), inset 0 0 0 6px var(--bg);
}
.brand-mark::after { content: ""; position: absolute; left: 7px; right: 7px; bottom: -5px; height: 3px; border-radius: 2px; background: var(--accent); }
.brand-lg .brand-mark { width: 34px; height: 26px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: 15px;
  transition: transform .08s ease, background .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-block { width: 100%; }
.btn-danger-ghost { border-color: transparent; background: transparent; color: var(--danger); padding: 0 8px; }
.btn[disabled] { opacity: .6; pointer-events: none; }
.icon-btn { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; font-size: 14px; color: var(--muted); }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 600; font-size: 14px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- forms ---------- */
label, .field { display: block; font-weight: 600; font-size: 14px; margin: 0 0 16px; }
fieldset.field { border: 0; padding: 0; min-width: 0; }
legend, .field-label { padding: 0; margin-bottom: 6px; display: block; }
input:not([type=radio]), select, textarea {
  display: block; width: 100%; margin-top: 6px;
  padding: 11px 13px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 400; font-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
.form-error { color: var(--danger); font-size: 14px; min-height: 1em; margin: 0 0 8px; }
.note { background: var(--accent-soft); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }

/* segmented control */
.seg { display: flex; background: var(--surface-2); border-radius: 999px; padding: 4px; gap: 4px; margin-bottom: 18px; }
.seg > button, .seg > label { flex: 1; margin: 0; }
.seg > button {
  border: 0; background: transparent; padding: 9px 10px; border-radius: 999px; font-weight: 600; color: var(--muted);
}
.seg > button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg-sm { margin: 0; }
.seg label input { position: absolute; opacity: 0; pointer-events: none; }
.seg label span {
  display: block; text-align: center; padding: 8px 6px; border-radius: 999px; color: var(--muted); font-weight: 600; cursor: pointer;
}
.seg label input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg label input:focus-visible + span { outline: 2px solid var(--accent); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-sub { text-align: center; color: var(--muted); margin: 10px 0 26px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner { max-width: 1100px; margin: 0 auto; padding: 12px 16px 6px; display: flex; align-items: center; gap: 12px; }
.topbar-inner .brand { margin-right: auto; }
.user-btn { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); padding: 4px 12px 4px 4px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; text-transform: uppercase; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 210px; z-index: 20;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px;
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 12px; border-radius: 8px; font-size: 15px; }
.menu button:hover { background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

.tabs { max-width: 1100px; margin: 0 auto; padding: 0 8px; display: flex; gap: 4px; }
.tabs button {
  flex: 0 0 auto; border: 0; background: none; padding: 12px 12px 13px; font-weight: 650; font-size: 15px; color: var(--muted);
  border-bottom: 3px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--tab-color, var(--accent)); }
.tabs [data-tab="want"] { --tab-color: var(--want); }
.tabs [data-tab="watching"] { --tab-color: var(--watching); }
.tabs [data-tab="watched"] { --tab-color: var(--watched); }
.count { font-weight: 500; font-size: 13px; color: var(--muted); margin-left: 2px; }

/* ---------- content ---------- */
.content { max-width: 1100px; margin: 0 auto; padding: 16px 16px 110px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
@media (max-width: 600px) {
  .toolbar .search { flex: 1 1 100%; }
  .toolbar select { flex: 1 1 0; max-width: none; }
}
.search { position: relative; flex: 1; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input { margin: 0; padding-left: 38px; border-radius: 999px; }
.toolbar select { width: auto; margin: 0; border-radius: 999px; padding-right: 30px; }

.tag-filter { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; scrollbar-width: none; }
.tag-filter::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 5px 12px; font-size: 14px; font-weight: 500; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .n { color: var(--muted); font-size: 12px; }
.chip[aria-pressed="true"] .n { color: inherit; opacity: .7; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .cards { grid-template-columns: repeat(3, 1fr); } }

.card {
  display: grid; grid-template-columns: 76px 1fr; gap: 14px; align-items: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow); cursor: pointer; position: relative;
  transition: transform .12s ease, border-color .15s;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.card:active { transform: scale(.99); }
.poster {
  width: 76px; aspect-ratio: 2 / 3; border-radius: 8px; object-fit: cover; background: var(--surface-2);
}
.poster-blank {
  display: grid; place-items: center; font: 700 26px/1 var(--display); color: #fff;
  background: linear-gradient(150deg, hsl(var(--h) 55% 48%), hsl(calc(var(--h) + 40) 50% 30%));
}
.card-body { min-width: 0; }
.card-title { font: 700 18px/1.2 var(--display); margin: 2px 0 4px; overflow-wrap: anywhere; }
.card-meta { font-size: 13.5px; color: var(--muted); }
.card-meta .svc { color: var(--text); font-weight: 600; }
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.tag { font-size: 12.5px; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text); }
.card-notes { font-size: 13.5px; color: var(--muted); margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.mini {
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 600;
}
.mini.go-watched { border-color: color-mix(in srgb, var(--watched) 50%, var(--line)); color: var(--watched); }
.mini.go-watching { border-color: color-mix(in srgb, var(--watching) 50%, var(--line)); color: var(--watching); }
.rating { color: var(--watching); letter-spacing: 1px; font-size: 14px; }
.rating .off { color: var(--line); }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty strong { display: block; color: var(--text); font: 700 22px/1.2 var(--display); margin-bottom: 6px; }
.empty .btn { margin-top: 18px; }

.fab {
  position: fixed; right: 18px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 15;
  width: 60px; height: 60px; border-radius: 50%; border: 0; font-size: 32px; line-height: 1;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.add-desktop { display: none; }
@media (min-width: 760px) {
  .add-desktop { display: inline-flex; }
  .fab { display: none; }
  .content { padding-bottom: 60px; }
}
@media (max-width: 420px) { .user-name { display: none; } .user-btn { padding: 3px; } }

/* ---------- dialogs ---------- */
dialog.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--text);
  width: min(560px, 100%); max-height: min(92vh, 900px); border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog.sheet-sm { width: min(420px, 100%); }
dialog::backdrop { background: rgba(10, 8, 5, .55); }
dialog.sheet > form, dialog.sheet > div { display: flex; flex-direction: column; max-height: inherit; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 10px; }
.sheet-head h2 { margin: 0; font: 700 22px/1.2 var(--display); }
.sheet-body { padding: 8px 20px 4px; overflow-y: auto; }
.sheet-foot { display: flex; gap: 8px; align-items: center; padding: 12px 20px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.spacer { flex: 1; }
@media (max-width: 600px) {
  dialog.sheet {
    margin: auto 0 0; width: 100%; max-width: 100%; max-height: 94vh; border-radius: 20px 20px 0 0;
  }
}

/* lookup results */
.lookup { list-style: none; margin: -10px 0 16px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; max-height: 300px; overflow-y: auto; background: var(--bg); }
.lookup li button { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center; width: 100%; text-align: left; border: 0; background: none; padding: 6px; border-radius: 8px; }
.lookup li button:hover, .lookup li button:focus-visible { background: var(--surface-2); }
.lookup img, .lookup .ph { width: 40px; height: 56px; border-radius: 4px; object-fit: cover; background: var(--surface-2); }
.lookup .t { font-weight: 600; font-size: 15px; }
.lookup .m { font-size: 13px; color: var(--muted); }
.lookup .hint { padding: 8px; font-size: 13px; color: var(--muted); }

.picked { display: flex; gap: 14px; align-items: center; background: var(--surface-2); border-radius: 12px; padding: 10px; margin-bottom: 16px; }
.picked > div { flex: 1; min-width: 0; }
.picked .link { display: inline-block; margin-top: 6px; }
.picked img { flex: 0 0 70px; width: 70px; aspect-ratio: 2/3; object-fit: cover; border-radius: 6px; background: var(--line); }
.picked-title { font: 700 18px/1.2 var(--display); }

.watched-only { display: none; }
form[data-status="watched"] .watched-only { display: block; }

.stars { display: flex; gap: 2px; margin-top: 6px; }
.stars button { border: 0; background: none; font-size: 28px; line-height: 1; padding: 2px; color: var(--line); }
.stars button.on { color: var(--watching); }

.tag-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px;
  border: 1px solid var(--line); border-radius: 10px; padding: 6px; background: var(--surface);
}
.tag-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-input input { flex: 1; min-width: 140px; border: 0; margin: 0; padding: 5px 6px; box-shadow: none !important; background: transparent; }
.tag-input .tag { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; padding: 4px 6px 4px 10px; font-weight: 500; }
.tag-input .tag button { border: 0; background: none; padding: 0 4px; color: var(--muted); font-size: 15px; line-height: 1; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag-suggest .chip { font-size: 13px; padding: 3px 10px; color: var(--muted); }
.tag-suggest .chip::before { content: "+"; }

.summary { margin: 0 0 14px; font-size: 14px; color: var(--muted); }
.summary summary { cursor: pointer; font-weight: 600; color: var(--text); }

.user-list { list-style: none; margin: 0 0 16px; padding: 0; }
.user-list li { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.user-list .who { flex: 1; min-width: 140px; }
.user-list .who b { display: block; }
.user-list .who span { font-size: 13px; color: var(--muted); }
.user-list .mini.danger { color: var(--danger); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast button { border: 0; background: none; color: var(--accent); font-weight: 700; margin-left: 10px; pointer-events: auto; }
@media (min-width: 760px) { .toast { bottom: 28px; } }

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

/* ---------- shared list ---------- */
.small { font-size: 12.5px; font-weight: 400; }
.card-by { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.people { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
.person {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600;
  padding: 2px 8px 2px 2px; border-radius: 999px; background: var(--surface-2);
}
.person .tick { color: var(--watched); font-size: 11px; }
.person.watching .tick { color: var(--watching); }
.mini-avatar {
  width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  background: hsl(var(--h) 55% 45%); color: #fff; font-size: 11px; font-weight: 700; text-transform: uppercase;
}
.rating.sm { font-size: 11px; letter-spacing: 0; }
.added-line { margin: -4px 0 14px; font-size: 13.5px; color: var(--muted); }
.others { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; font-weight: 400; font-size: 13.5px; }
.others li { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.user-list .avatar { flex: 0 0 auto; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; }
.badge.want { background: var(--accent-soft); color: var(--want); }
.badge.watching { background: color-mix(in srgb, var(--watching) 18%, transparent); color: var(--watching); }
.mini.go-want { border-color: color-mix(in srgb, var(--want) 50%, var(--line)); color: var(--want); }
.empty-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.tabs { overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs [data-tab="all"] { --tab-color: var(--text); }
#status-seg span { font-size: 14px; padding: 8px 4px; }
@media (max-width: 600px) {
  .tabs { padding: 0 4px; gap: 0; }
  .tabs button { flex: 1 1 auto; padding: 12px 4px 13px; font-size: 14px; }
  .tabs .count { font-size: 12px; }
}
.tabs button { white-space: nowrap; }
@media (max-width: 360px) {
  .tabs button { font-size: 12.5px; padding: 12px 2px 13px; }
  .tabs .count { font-size: 11px; margin-left: 0; }
}
