:root {
  --bg: #0f1117; --surface: #181b24; --surface-2: #222634; --border: #2e3344;
  --text: #e8eaf0; --muted: #9097a8; --accent: #ff5c8a; --accent-2: #7c5cff; --gold: #ffc94d;
  --ok: #3ecf8e; --err: #ff6b6b; --radius: 12px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root { --bg: #f5f6fa; --surface: #fff; --surface-2: #eef0f6; --border: #dde0ea; --text: #1b1e27; --muted: #5f6678; color-scheme: light; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
code { font-family: ui-monospace, monospace; font-size: .9em; }
.muted { color: var(--muted); }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 18px; text-decoration: none; white-space: nowrap; }
.stats { flex: 1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view { max-width: 1400px; margin: 0 auto; padding: 20px; }

.btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--accent-2); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #fff; font-weight: 600; }
.btn:disabled { opacity: .6; cursor: wait; }
.btn[aria-pressed="true"] { color: var(--gold); border-color: var(--gold); }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 18px; }
.search { flex: 1 1 240px; min-width: 0; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
.search:focus, select:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.field { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
select { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.tile { display: flex; flex-direction: column; gap: 8px; text-decoration: none; }
.tile-media { position: relative; aspect-ratio: 2 / 3; border-radius: var(--radius); overflow: hidden; background: var(--surface-2);
  box-shadow: 0 4px 14px rgb(0 0 0 / .25); transition: transform .18s ease, box-shadow .18s ease; }
.tile:hover .tile-media, .tile:focus-visible .tile-media { transform: translateY(-4px); box-shadow: 0 10px 24px rgb(0 0 0 / .35); }
.cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-fallback, .hero-cover.cover-fallback { display: grid; place-items: center; font-size: 42px; font-weight: 800; color: #fff;
  background: linear-gradient(145deg, var(--ph), color-mix(in srgb, var(--ph) 40%, #000)); }
.ph-0 { --ph: #e85d75; } .ph-1 { --ph: #7c5cff; } .ph-2 { --ph: #2bb3a3; }
.ph-3 { --ph: #f2a541; } .ph-4 { --ph: #3d8bfd; } .ph-5 { --ph: #c065d6; }
.count-badge { position: absolute; bottom: 8px; right: 8px; background: rgb(0 0 0 / .75); color: #fff; font-weight: 700; font-size: 13px; padding: 3px 9px; border-radius: 999px; }
.tile-title { font-size: 14px; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.fav { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgb(0 0 0 / .55); color: #ffffff80; font-size: 17px; line-height: 1; }
.fav[aria-pressed="true"] { color: var(--gold); }
.fav-inline { position: static; width: 28px; height: 28px; background: transparent; color: var(--muted); margin-left: auto; }

.hero { display: flex; gap: 24px; align-items: flex-end; margin-bottom: 24px; }
.hero-cover { width: 160px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: var(--radius); box-shadow: 0 8px 24px rgb(0 0 0 / .35); flex-shrink: 0; }
.hero h1 { margin: 6px 0 4px; font-size: clamp(22px, 4vw, 34px); line-height: 1.15; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--text); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card { --ed: var(--muted); background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--ed); border-radius: var(--radius); padding: 12px 14px; }
.ed-1 { --ed: #8a93a6; } .ed-2 { --ed: #3ecf8e; } .ed-3 { --ed: #3d8bfd; } .ed-4 { --ed: #c065d6; }
.ed-5 { --ed: #f2a541; } .ed-6 { --ed: #ff5c8a; } .ed-7 { --ed: #2bb3a3; } .ed-8 { --ed: #ffc94d; }
.card-head { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.print { font-size: 18px; }
.edition { color: var(--ed); font-size: 14px; }
.card-name { margin: 6px 0 2px; font-size: 16px; }
.quality { color: var(--gold); letter-spacing: 2px; font-size: 14px; }
.card-meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 10px 0 6px; font-size: 13px; }
.card-meta dt { color: var(--muted); }
.card-meta dd { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; background: var(--surface-2); border-radius: 999px; padding: 2px 8px; }

.loading, .empty, .error { text-align: center; color: var(--muted); padding: 48px 0; }
.sentinel { height: 1px; }

.dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); max-width: 460px; width: calc(100% - 32px); padding: 22px; }
.dialog::backdrop { background: rgb(0 0 0 / .6); }
.dialog h2 { margin-top: 0; }
.dialog label { display: flex; flex-direction: column; gap: 6px; margin: 14px 0; font-size: 14px; }
.dialog input { padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.upload-result { min-height: 1.4em; font-size: 14px; }
.upload-result.ok { color: var(--ok); } .upload-result.err { color: var(--err); }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .stats { order: 3; flex-basis: 100%; }
  .view { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
  .hero { gap: 14px; }
  .hero-cover { width: 100px; }
  .cards { grid-template-columns: 1fr; }
}

/* ---------- v2: navegação, autenticação, tags, duplicadas, bandeja ---------- */
.logged-out .auth-only { display: none; }
.nav { display: flex; gap: 4px; }
.nav a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current] { color: var(--text); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--accent); }
.user-box { display: flex; align-items: center; gap: 10px; }
.btn-small { padding: 4px 10px; font-size: 13px; }
.link-btn { background: none; border: 0; color: var(--accent-2); cursor: pointer; font: inherit; padding: 0; }

.banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; max-width: 1400px; margin: 16px auto 0; padding: 12px 16px;
  border: 1px solid color-mix(in srgb, var(--gold) 50%, var(--border)); background: color-mix(in srgb, var(--gold) 12%, var(--surface)); border-radius: var(--radius); }
.banner > span { flex: 1 1 260px; }
.banner[hidden], .tray[hidden] { display: none; }

.auth-wrap { display: grid; place-items: center; min-height: 60vh; }
.auth-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { margin: 0; }
.auth-card p { margin: 0; }
.field-col { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field-col input { padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; }
.form-error { color: var(--err); min-height: 1.2em; font-size: 14px; }

.page-title { margin: 8px 0 4px; }
.toolbar-actions { margin-top: -6px; }
.tag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 16px; }
.tag-tile { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 14px; text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow-wrap: anywhere; }
.tag-tile:hover { border-color: var(--accent-2); }
.tag-untagged { display: inline-flex; min-width: 220px; margin-top: 12px; border-color: var(--accent); }
.tag-count { background: var(--surface-2); border-radius: 999px; padding: 2px 9px; font-weight: 700; font-size: 13px; }

.pick { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.card.selected { outline: 2px solid var(--accent); outline-offset: -1px; }
.card-series { display: block; color: var(--muted); font-size: 13px; text-decoration: none; margin-bottom: 2px; }
.card-series:hover { text-decoration: underline; }

.dup-list { display: flex; flex-direction: column; gap: 8px; }
.dup-group { display: grid; grid-template-columns: minmax(180px, 1fr) 2fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.dup-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dup-info a { font-size: 13px; text-decoration: none; }
.dup-cards { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-keep { background: color-mix(in srgb, var(--ok) 18%, var(--surface-2)); color: var(--ok); font-weight: 600; }
.chip-extra { border: 1px solid var(--border); color: var(--text); cursor: pointer; font: inherit; font-size: 12px; }
.chip-extra[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.tray { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--border); }
.tray-inner { max-width: 1400px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.tray-inner > span { flex: 1; }
body.has-tray .view { padding-bottom: 90px; }

.dialog-wide { max-width: 760px; }
.dialog-body { display: flex; flex-direction: column; gap: 14px; }
.dialog-title { display: flex; justify-content: space-between; align-items: center; }
.dialog-title h2 { margin: 0; }
.dialog .field-col { margin: 0; }
.dialog label[hidden] { display: none; }
.selected-preview { display: flex; flex-wrap: wrap; gap: 6px; max-height: 120px; overflow: auto; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); border-radius: 999px; padding: 6px 14px; cursor: pointer; font: inherit; }
.tab[aria-selected="true"] { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.command-output { display: flex; flex-direction: column; gap: 10px; }
.command-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.command textarea { width: 100%; resize: vertical; padding: 8px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font: 13px/1.4 ui-monospace, monospace; }
.settings summary { cursor: pointer; color: var(--muted); }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin: 10px 0; }
.check-row { flex-direction: row !important; align-items: flex-start; }

@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; }
  .nav { order: 4; flex-basis: 100%; overflow-x: auto; }
  .dup-group { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .user-box { margin-left: auto; }
  .user-box #user { display: none; }
  .brand span { display: none; }
}

/* ---------- galeria e perfil público ---------- */
.guest-only { display: none; }
.logged-out .guest-only { display: inline-block; }
.fav-static { display: grid; place-items: center; cursor: default; color: var(--gold); }
.fav-inline.fav-static { background: transparent; }
.card.is-fav { border-color: color-mix(in srgb, var(--gold) 60%, var(--border)); }
.collector-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; margin-top: 18px; }
.collector { display: flex; flex-direction: column; gap: 6px; padding: 14px; text-decoration: none; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); transition: transform .15s, border-color .15s; }
.collector:hover, .collector:focus-visible { transform: translateY(-3px); border-color: var(--accent-2); }
.collector-covers { display: flex; gap: 6px; min-height: 84px; align-items: center; }
.mini-cover { width: 56px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 6px; font-size: 18px; }
.collector-name { font-size: 18px; overflow-wrap: anywhere; }
.collector-fav { font-size: 13px; color: var(--gold); overflow-wrap: anywhere; }
@media (prefers-reduced-motion: reduce) { .collector { transition: none; } }
.viewing-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px; margin-bottom: 18px;
  padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent-2); border-radius: var(--radius); }
.viewing-title { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.viewing-title .back { margin: 0; }
.viewing-tabs { display: flex; gap: 4px; overflow-x: auto; }
.viewing-tabs a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.viewing-tabs a:hover { color: var(--text); background: var(--surface-2); }
.viewing-tabs a[aria-current] { color: var(--text); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--accent); }
.chip-fav { color: var(--gold); }

/* ---------- switch de visibilidade, wishlist ---------- */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--muted); }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch input:disabled { cursor: progress; }
.switch-track { width: 36px; height: 20px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
  position: relative; transition: background .15s; flex-shrink: 0; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked ~ .switch-track { background: color-mix(in srgb, var(--ok) 35%, var(--surface-2)); border-color: var(--ok); }
.switch input:checked ~ .switch-track::after { transform: translateX(16px); background: var(--ok); }
.switch input:focus-visible ~ .switch-track { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.switch:has(input:checked) .switch-label { color: var(--text); }
.switch[data-tooltip]:not([data-tooltip=""])::after { content: attr(data-tooltip); position: absolute; top: calc(100% + 10px); right: 0; z-index: 20;
  width: 280px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  box-shadow: 0 8px 24px rgb(0 0 0 / .35); font-size: 13px; line-height: 1.4; pointer-events: none; opacity: 0; transform: translateY(-4px);
  transition: opacity .15s, transform .15s; }
.switch:hover::after, .switch:focus-within::after { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .switch-track, .switch-track::after, .switch::after { transition: none; } }
.wish { width: 28px; height: 28px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; margin-left: auto; }
.wish:hover { color: var(--accent); }
.wish[aria-pressed="true"] { color: var(--accent); }
.wish + .fav-inline { margin-left: 0; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; text-align: center; }
.badge[hidden] { display: none; }
.fav-left { left: 6px; right: auto; }
.wish-series[aria-pressed="true"] { color: var(--accent); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hero-actions .wish-series[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.wish-section { margin: 24px 0 0; font-size: 18px; }
.interest { padding: 1px 7px; border-radius: 999px; font-size: 12px; font-weight: 700; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface-2)); cursor: help; }
.wish-badge { position: absolute; left: 6px; bottom: 6px; padding: 2px 8px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; }
.tile-sub { font-size: 12px; margin-top: -4px; }
.person-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-top: 12px; }
.person-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.person-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.person-name { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.wish-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip-wish { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); }
.chip-x { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; }
.chip-x:hover { color: var(--err); }

/* ---------- interessados nas suas cartas ---------- */
.person-grid-wide { grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); align-items: start; }
.person-info { display: flex; flex-direction: column; min-width: 0; }
.interest-person .person-head { justify-content: flex-start; align-items: center; gap: 12px; }
.avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.interest-list { display: flex; flex-direction: column; gap: 6px; }
.interest-anime, .interest-more { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.interest-anime > summary, .interest-more > summary { display: flex; align-items: center; gap: 10px; padding: 8px 10px; cursor: pointer; list-style: none; }
.interest-anime > summary::-webkit-details-marker, .interest-more > summary::-webkit-details-marker { display: none; }
.interest-anime > summary::after { content: "▾"; color: var(--muted); margin-left: 4px; transition: transform .15s; }
.interest-anime[open] > summary::after { transform: rotate(180deg); }
.interest-more > summary { color: var(--muted); font-size: 13px; justify-content: center; }
.interest-more[open] > summary { border-bottom: 1px solid var(--border); }
.interest-more > .interest-list { padding: 6px; }
.interest-cover { width: 34px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 5px; flex-shrink: 0; font-size: 11px; }
.interest-name { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count-pill { background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 9px; font-size: 12px; font-weight: 700; }
.interest-body { padding: 4px 10px 10px; display: flex; flex-direction: column; gap: 8px; }
.card-chip { display: inline-flex; flex-direction: column; align-items: flex-start; padding: 4px 9px; border-radius: 8px; background: var(--surface);
  border: 1px solid var(--border); line-height: 1.25; cursor: pointer; font: inherit; color: inherit; text-align: left; }
.card-chip:hover { border-color: var(--accent-2); }
.card-chip[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
.card-chip:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.card-chip-name { font-size: 13px; font-weight: 600; }
.card-chip small { font-size: 11px; }
.chip-code { font-size: 11px; color: var(--accent-2); }
.interest-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.person-head .btn { margin-left: auto; }
.interest-anime > summary:focus-visible, .interest-more > summary:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; border-radius: 10px; }
@media (prefers-reduced-motion: reduce) { .interest-anime > summary::after { transition: none; } }

/* ---------- faixa de ambiente (beta) ---------- */
.env-banner { position: sticky; top: 0; z-index: 30; padding: 6px 12px; text-align: center; font-size: 13px; font-weight: 700;
  color: #1b1e27; background: var(--gold); }
.env-banner[hidden] { display: none; }
