:root {
  --bg: #0d1220;
  --bg-2: #141b2e;
  --panel: #182036;
  --line: #26304d;
  --text: #e7ebf5;
  --muted: #8b95b2;
  --blue: #3d7bff;
  --red: #e5383b;
  --yellow: #f5c518;
  --green: #2fbf71;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, sans-serif;
}
a { color: #8fb3ff; text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { font-family: Rajdhani, sans-serif; letter-spacing: .02em; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 20px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ── Top bar ── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px;
  background: rgba(13, 18, 32, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--text); font: 700 20px Rajdhani, sans-serif; letter-spacing: .04em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-block; padding: 0 8px; margin-right: 6px; border-radius: 4px;
  background: linear-gradient(90deg, var(--blue) 0 33%, #fff 33% 66%, var(--red) 66%);
  color: #0d1220;
}
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: var(--muted); padding: 6px 12px; border-radius: 6px; font-weight: 500; }
.topbar nav a.on, .topbar nav a:hover { color: var(--text); background: var(--bg-2); text-decoration: none; }

.wrap { max-width: 1400px; margin: 0 auto; padding: 20px 24px 60px; }
.site-foot {
  max-width: 1400px; margin: 0 auto; padding: 18px 24px 28px;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; line-height: 1.6;
}
.site-foot p { margin: 0 0 4px; }
.source-link { display: inline-block; margin-top: 14px; font-size: 13.5px; }

/* ── Forms ── */
.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  padding: 14px; margin-bottom: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.filters label { display: flex; flex-direction: column; gap: 4px; min-width: 220px; }
.filters label.grow { flex: 1; }
.filters label > span { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
select, input[type=search] {
  height: 38px; padding: 0 10px; width: 100%;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; font: inherit;
}
select:focus, input:focus { outline: 2px solid var(--blue); outline-offset: -1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 38px; padding: 0 16px; border-radius: 7px; cursor: pointer;
  background: var(--bg-2); color: var(--text); border: 1px solid var(--line);
  font: 600 14px Inter, sans-serif;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; }
button.link { background: none; border: 0; color: #8fb3ff; cursor: pointer; font: inherit; padding: 0; }

.count { color: var(--muted); margin: 0 0 12px; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h2 { color: var(--text); }

/* ── Card list: filter panel + results ── */
.browse { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 24px; align-items: start; }
.fpanel {
  position: sticky; top: 66px; max-height: calc(100vh - 82px); overflow-y: auto;
  padding: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  scrollbar-width: thin;
}
.fpanel-top, .fpanel-foot, .fpanel-backdrop, .filter-toggle { display: none; }
.fld { display: flex; flex-direction: column; gap: 4px; }
.fld > span, .fhead span { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.fld-input { margin-top: 10px; }
.fhead { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 2px; padding-top: 14px; border-top: 1px solid var(--line); }
.fhead .link { font-size: 13px; }

.fgroup { padding: 12px 0; border-bottom: 1px solid var(--line); }
.fgroup:last-child { border-bottom: 0; }
.fgroup > h3, .fgroup > summary {
  display: flex; align-items: baseline; gap: 8px; margin: 0 0 9px;
  font: 600 14px Inter, sans-serif; letter-spacing: 0;
}
.fgroup small { font-size: 11px; font-weight: 400; color: var(--muted); }
.fgroup .badge { margin-left: auto; }
.fgroup.is-list > summary { margin: 0; cursor: pointer; list-style: none; }
.fgroup.is-list > summary::-webkit-details-marker { display: none; }
.fgroup.is-list > summary::after { content: "▾"; color: var(--muted); margin-left: 6px; transition: transform .15s; }
.fgroup.is-list:not(:has(.badge:not([hidden]))) > summary::after { margin-left: auto; }
.fgroup.is-list[open] > summary { margin-bottom: 9px; }
.fgroup.is-list[open] > summary::after { transform: rotate(180deg); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; min-width: 38px; justify-content: center;
  padding: 4px 12px; border-radius: 99px; font-size: 13px; font-weight: 500;
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  transition: background .12s, border-color .12s;
}
.chip:hover span { border-color: var(--muted); }
.chip input:checked + span { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--yellow); outline-offset: 2px; }
.dot-c { width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }

.mini { height: 32px !important; margin-bottom: 8px; font-size: 13px; }
.opt-list { max-height: 250px; overflow-y: auto; scrollbar-width: thin; }
.opt-row { display: flex; align-items: flex-start; gap: 8px; padding: 4px 2px; font-size: 13px; line-height: 1.35; cursor: pointer; }
.opt-row input { margin-top: 1px; flex: none; }
.opt-row small { margin-left: auto; padding-left: 8px; color: var(--muted); }
.opt-row:hover span { color: #fff; }

.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; background: var(--blue); color: #fff; font: 600 11px/18px Inter, sans-serif; text-align: center; }
.results-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.results-bar .count { margin: 0; }
.filter-toggle .badge { margin-left: 6px; }
.active-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.active-chips:empty { display: none; }
.achip {
  padding: 3px 10px; border-radius: 99px; cursor: pointer; font: 500 12.5px Inter, sans-serif;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
}
.achip small { color: var(--muted); }
.achip:hover { border-color: var(--red); }

/* ── Card grid ── */
.grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
}
.card {
  display: flex; flex-direction: column; width: 100%; padding: 0; text-align: left;
  background: none; border: 0; color: inherit; cursor: pointer; font: inherit;
}
.card img {
  width: 100%; height: auto; aspect-ratio: 0.717; object-fit: cover;
  border-radius: 8px; background: var(--bg-2);
  transition: transform .15s, box-shadow .15s;
}
.card:hover img, .card:focus-visible img { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,.5), 0 0 0 2px var(--blue); }
.card:focus-visible { outline: none; }
.card-meta { display: flex; justify-content: space-between; margin-top: 6px; font-size: 12px; }
.card-no { color: var(--muted); font-variant-numeric: tabular-nums; }
.rarity { color: var(--yellow); font-weight: 600; }
.card-name { font-weight: 500; font-size: 13.5px; line-height: 1.3; }

/* ── Detail dialog ── */
dialog {
  width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 24px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--text);
}
dialog::backdrop { background: rgba(5, 8, 15, .75); }
.close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: 0; color: var(--muted); font-size: 28px; cursor: pointer; line-height: 1;
}
.detail-body { display: grid; grid-template-columns: 300px 1fr; gap: 24px; }
.detail-body > img { width: 100%; border-radius: 10px; }
.detail-info h2 { font-size: 28px; margin: 2px 0 14px; }
.detail-info .card-no { margin: 0; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 0 0 14px; }
.stats dt, .stats dd { margin: 0; }
.stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stats dd { font: 600 18px Rajdhani, sans-serif; }
.effect { white-space: pre-line; background: var(--bg); border-radius: 8px; padding: 12px 14px; margin: 0 0 14px; }
.effect:empty { display: none; }
.more > div { display: contents; }
.more, .kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.more dt, .kv dt { color: var(--muted); }
.more dd, .kv dd { margin: 0; word-break: break-word; }

/* ── Admin ── */
.admin-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.admin-head h1 .muted { font-weight: 500; }
.subnav { display: flex; gap: 4px; }
.subnav a { padding: 6px 12px; border-radius: 6px; color: var(--muted); border: 1px solid var(--line); }
.subnav a.on { color: var(--text); background: var(--panel); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile span { display: block; font-size: 12px; color: var(--muted); }
.tile b { font: 700 26px Rajdhani, sans-serif; }
.tile b.sm { font-size: 17px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; overflow-x: auto; }
.admin-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }

.pkg-head { display: flex; justify-content: space-between; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.pkgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 4px 12px; margin: 8px 0; max-height: 260px; overflow-y: auto; }
.pkgs label, .opt { display: flex; gap: 8px; align-items: center; font-size: 13.5px; }
.opt { margin: 8px 0; }
.scrape-form .btn { margin-top: 10px; }
input[type=checkbox] { accent-color: var(--blue); width: 16px; height: 16px; }

.sched-title { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.sched-row { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 0; }
.sched-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.sched-row label:last-child { flex: 1; min-width: 200px; }
input[type=time] {
  height: 38px; padding: 0 10px; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; font: inherit;
}

.export-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.export-cols h3 { font: 600 16px Rajdhani, sans-serif; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.export-cols .btn { margin-top: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

.live { display: none; }
.live.is-running { display: block; }
.live-row { display: flex; align-items: center; gap: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.bar { height: 8px; background: var(--bg); border-radius: 4px; margin: 10px 0 6px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--green)); transition: width .4s; }
.live-stop { margin-top: 10px; }

.log { list-style: none; margin: 8px 0 0; padding: 10px 12px; background: var(--bg); border-radius: 8px; font: 12.5px/1.6 ui-monospace, Consolas, monospace; color: #a8d8a8; }
.log.full { max-height: 600px; overflow-y: auto; }
.log li.warn { color: var(--yellow); }
.log li.error { color: #ff7b7b; }
.log li.new { color: #7fd6ff; }
.log li.update { color: #ffb86b; }
.log:empty { display: none; }

.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.hist td { vertical-align: middle; white-space: nowrap; }
.thumb { width: 40px; height: 56px; object-fit: cover; border-radius: 4px; background: var(--bg); display: block; }

.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--bg-2); color: var(--muted); white-space: nowrap; vertical-align: middle; }
.pill.done { background: rgba(47,191,113,.15); color: var(--green); }
.pill.running { background: rgba(61,123,255,.18); color: #8fb3ff; }
.pill.stopped { background: rgba(245,197,24,.15); color: var(--yellow); }
.pill.error { background: rgba(229,56,59,.18); color: #ff7b7b; }
.pill.ev-new { background: rgba(61,123,255,.18); color: #8fb3ff; }
.pill.ev-data_changed { background: rgba(255,184,107,.16); color: #ffb86b; }
.pill.ev-image_new { background: rgba(47,191,113,.15); color: var(--green); }
.pill.ev-image_changed { background: rgba(229,56,59,.18); color: #ff7b7b; }

.events { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 8px 18px; }
.events li { display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.events img { width: 36px; height: 50px; object-fit: cover; border-radius: 3px; background: var(--bg); }

.card-admin { display: grid; grid-template-columns: 280px 1fr; gap: 20px; align-items: start; }
.card-admin > img { width: 100%; border-radius: 10px; position: sticky; top: 70px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.diff { margin-top: 8px; font-size: 13px; }
.diff th { width: 110px; text-transform: none; }
.diff .old { color: #ff9a9a; text-decoration: line-through; }
.diff .new { color: #9be7b7; }

@media (max-width: 900px) {
  .browse { grid-template-columns: 1fr; }
  .fpanel {
    position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(360px, 88vw);
    max-height: none; border-radius: 0; border-width: 0 1px 0 0; padding-top: 0;
    transform: translateX(-105%); transition: transform .2s ease;
  }
  .fpanel-top {
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; z-index: 1; margin: 0 -16px 12px; padding: 12px 16px;
    background: var(--panel); border-bottom: 1px solid var(--line); font: 700 18px Rajdhani, sans-serif;
  }
  .icon-btn { background: none; border: 0; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; }
  .fpanel-foot { display: block; position: sticky; bottom: 0; margin: 0 -16px; padding: 12px 16px; background: var(--panel); border-top: 1px solid var(--line); }
  .fpanel-foot .btn { width: 100%; }
  .filter-toggle { display: inline-flex; }
  body.filters-open { overflow: hidden; }
  body.filters-open .fpanel { transform: none; }
  body.filters-open .fpanel-backdrop { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(5, 8, 15, .7); }
  .admin-cols, .card-admin, .export-cols { grid-template-columns: 1fr; }
  .card-admin > img { position: static; max-width: 280px; }
}
@media (max-width: 640px) {
  .topbar, .wrap, .site-foot { padding-left: 16px; padding-right: 16px; }
  .filters label { min-width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(135px, 1fr)); gap: 12px; }
  .detail-body { grid-template-columns: 1fr; }
  .detail-body > img { max-width: 260px; margin: 0 auto; }
}
