:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e2330;
  --border: #2a3142;
  --text: #e8eaef;
  --muted: #9aa3b5;
  --accent: #6ea8fe;
  --tof: #5b8def;
  --mof: #3ecf8e;
  --bof: #f0b429;
  --chip: #2a3142;
  --danger: #f07178;
  --radius: 12px;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100%;
}
body.modal-open,
body.filters-open { overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.mobile-header,
.sidebar-backdrop,
.sidebar-close { display: none; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 16px 40px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.sidebar-heading { display: flex; justify-content: space-between; gap: 12px; }
.brand {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
}
.brand-sub {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 20px;
}
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}
.stat {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}
.stat b { display: block; font-size: 18px; }
.stat span { color: var(--muted); font-size: 11px; }

.filter-group { margin-bottom: 16px; }
.filter-group label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 6px;
}
.filter-group input[type="text"],
.filter-group input[type="date"],
.filter-group select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}
.checks {
  max-height: 160px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 6px 8px;
}
.checks label {
  display: flex;
  gap: 8px;
  align-items: center;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  color: var(--text);
  margin: 4px 0;
  cursor: pointer;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}
.chip input { accent-color: var(--accent); }
.actions { display: flex; gap: 8px; margin-top: 12px; }
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}
.btn.primary {
  background: var(--accent);
  color: #0b1220;
  border-color: transparent;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.08); }

.main { padding: 20px 24px 60px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 16px;
}
.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
}
.topbar .meta { color: var(--muted); font-size: 13px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 320px;
}
.card:hover { border-color: #3d4660; }
.thumb {
  aspect-ratio: 16 / 10;
  background: #10131a;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card-author {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.card-author strong { color: var(--text); }
.card-text {
  font-size: 13px;
  line-height: 1.45;
  color: #d5dae6;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  font-size: 11px;
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  background: var(--panel-2);
}
.badge.TOF { color: var(--tof); border-color: #2f4f86; }
.badge.MOF { color: var(--mof); border-color: #1f6b4a; }
.badge.BOF { color: var(--bof); border-color: #7a5c12; }
.card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
}

.detail {
  max-width: 920px;
  margin: 0 auto;
}
.detail-back { margin-bottom: 14px; display: inline-block; }
.detail-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 14px;
}
.detail-content {
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 15px;
  margin: 0 0 20px;
}
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin-bottom: 20px;
}
.media-grid img, .media-grid embed {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b0e14;
}
.edit-form {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 8px;
}
.edit-form h3 { margin: 0 0 10px; font-size: 14px; }
.edit-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
  align-items: start;
  margin-bottom: 10px;
}
.edit-row label { color: var(--muted); font-size: 12px; padding-top: 8px; }
.edit-row textarea {
  width: 100%;
  min-height: 70px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
}
.empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  color: var(--muted);
}
.pager {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 22px;
}
.pager a, .pager span {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
}
.pager .disabled { opacity: 0.4; pointer-events: none; }

.card { cursor: pointer; color: inherit; text-decoration: none; }
.card:hover { text-decoration: none; }
.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.72);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; z-index: 50; overflow: auto;
}
.modal-bg.open { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); max-width: 840px; width: 100%;
  padding: 20px; position: relative;
}
.modal-close {
  position: absolute; top: 12px; right: 12px;
  border: 1px solid var(--border); background: var(--panel-2);
  color: var(--text); border-radius: 8px; padding: 4px 10px; cursor: pointer;
}
.pages-note {
  font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.4;
}

@media (max-width: 900px) {
  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--border);
    background: rgba(15, 17, 21, .94);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
  }
  .mobile-brand { font-size: 15px; font-weight: 650; }
  .mobile-count { margin-top: 2px; color: var(--muted); font-size: 12px; }
  .mobile-filter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 42px;
    padding: 8px 13px;
  }
  .filter-count {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--accent);
    color: #0b1220;
    font-size: 11px;
    font-weight: 650;
    line-height: 20px;
    text-align: center;
  }
  .layout { display: block; min-height: 0; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 70;
    width: min(90vw, 380px);
    height: 100dvh;
    padding: max(18px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
  }
  body.filters-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform .22s ease;
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    width: 100%;
    height: 100%;
    border: 0;
    background: rgba(0, 0, 0, .68);
    cursor: default;
  }
  body.filters-open .sidebar-backdrop { display: block; }
  .sidebar-heading { align-items: flex-start; }
  .sidebar-close {
    display: grid;
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-2);
    color: var(--text);
    font: 24px/1 var(--font);
    cursor: pointer;
  }
  .brand-sub { margin-bottom: 16px; }
  .checks { max-height: 190px; }
  .filter-group input[type="text"],
  .filter-group input[type="date"],
  .filter-group select { min-height: 44px; font-size: 16px; }
  .chip { min-height: 36px; padding: 7px 11px; }
  .actions {
    position: sticky;
    bottom: calc(-1 * max(28px, env(safe-area-inset-bottom)));
    z-index: 2;
    margin: 18px -16px 0;
    padding: 12px 16px max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: rgba(23, 26, 33, .96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }
  .actions .btn { min-height: 44px; }
  .actions .primary { flex: 1; }
  .main { padding: 18px 14px 48px; }
  .topbar { align-items: center; margin-bottom: 14px; }
  .topbar h1 { font-size: 18px; }
  .topbar .meta { font-size: 12px; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .card { min-height: 0; border-radius: 14px; }
  .thumb { aspect-ratio: 4 / 3; }
  .card-body { padding: 13px 14px 15px; gap: 9px; }
  .card-author { align-items: baseline; font-size: 12px; }
  .card-author strong { font-size: 14px; }
  .card-text { font-size: 14px; line-height: 1.5; -webkit-line-clamp: 4; }
  .card-foot { padding-top: 2px; }
  .badge { padding: 3px 8px; }
  .pager { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
  .pager a, .pager span { padding: 10px 8px; text-align: center; }
  .modal-bg {
    align-items: stretch;
    padding: 0;
    overflow: hidden;
    background: var(--bg);
  }
  .modal {
    max-width: none;
    min-height: 100dvh;
    height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 0;
    border-radius: 0;
    padding: max(68px, calc(env(safe-area-inset-top) + 58px)) 16px max(28px, env(safe-area-inset-bottom));
  }
  .modal-close {
    position: fixed;
    z-index: 2;
    top: max(10px, env(safe-area-inset-top));
    right: 12px;
    min-height: 42px;
    padding: 7px 13px;
    background: rgba(30, 35, 48, .96);
  }
  .detail-content { font-size: 15px; line-height: 1.6; }
  .media-grid { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .main { padding-inline: 10px; }
  .card { border-radius: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
