:root {
  color-scheme: dark;
  --bg: #0b0812;
  --panel: #17111f;
  --panel-soft: #21182c;
  --text: #f5f1fa;
  --muted: #aaa0b8;
  --line: rgba(255,255,255,.1);
  --accent: #a78bfa;
  --accent-2: #f472b6;
  --shadow: 0 22px 60px rgba(0,0,0,.28);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f4f9;
  --panel: #ffffff;
  --panel-soft: #f0ebf5;
  --text: #21172d;
  --muted: #71667d;
  --line: rgba(39,24,55,.12);
  --shadow: 0 18px 45px rgba(40,24,58,.1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  min-height: 100vh;
  margin: 0;
  padding: 26px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0, color-mix(in srgb, var(--accent) 17%, transparent), transparent 30rem),
    radial-gradient(circle at 100% 12%, color-mix(in srgb, var(--accent-2) 13%, transparent), transparent 28rem),
    var(--bg);
}

button, input, select { font: inherit; }
a { color: inherit; }
.shell { width: min(1160px, 100%); margin: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 900; text-decoration: none; letter-spacing: -.02em; }
.brand-mark { display: grid; place-items: center; width: 36px; aspect-ratio: 1; border-radius: 11px; color: #170d20; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.theme-toggle, .button { padding: 10px 14px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); background: var(--panel); font-weight: 750; text-decoration: none; cursor: pointer; }
.theme-toggle:hover, .button:hover { background: var(--panel-soft); }
.button.primary { border-color: transparent; color: #160d20; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.hero { padding: clamp(58px, 10vw, 110px) 0 48px; }
.eyebrow { margin: 0 0 12px; color: var(--accent); font-size: 12px; font-weight: 900; letter-spacing: .18em; text-transform: uppercase; }
h1 { max-width: 900px; margin: 0; font-size: clamp(42px, 7vw, 78px); line-height: .98; letter-spacing: -.055em; }
.lede { max-width: 690px; margin: 20px 0 0; color: var(--muted); font-size: 17px; line-height: 1.65; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.section-head h2 { margin: 0; font-size: 24px; }
.count { color: var(--muted); font-size: 14px; }
.category-grid, .item-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.category-card, .item-card { position: relative; min-width: 0; border: 1px solid var(--line); border-radius: 20px; background: color-mix(in srgb, var(--panel) 90%, transparent); box-shadow: var(--shadow); overflow: hidden; }
.category-card { min-height: 215px; padding: 23px; text-decoration: none; transition: transform .2s ease, border-color .2s ease; }
.category-card:hover { transform: translateY(-4px); border-color: color-mix(in srgb, var(--card-accent) 55%, var(--line)); }
.category-icon { display: grid; place-items: center; width: 54px; aspect-ratio: 1; margin-bottom: 35px; border-radius: 15px; background: color-mix(in srgb, var(--card-accent) 22%, var(--panel)); font-size: 26px; }
.category-card h3 { margin: 0 0 7px; font-size: 22px; }
.category-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.category-arrow { position: absolute; top: 24px; right: 24px; color: var(--muted); font-size: 20px; }
.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) auto auto auto; gap: 10px; margin-bottom: 12px; }
.control { width: 100%; min-width: 155px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; outline: none; color: var(--text); background: var(--panel); }
.shuffle-button, .view-toggle { display: grid; place-items: center; width: 43px; min-width: 43px; padding: 0; font-size: 20px; line-height: 1; }
.shuffle-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.control:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 16%, transparent); }
.results-meta { display: flex; justify-content: space-between; gap: 16px; min-height: 34px; color: var(--muted); font-size: 14px; }
.item-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.item-grid.table-view { display: block; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.collection-table { width: 100%; min-width: 800px; border-collapse: collapse; }
.collection-table thead { color: #fff; background: #07040c; }
.collection-table th, .collection-table td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.collection-table th { font-size: 14px; white-space: nowrap; }
.collection-table tbody tr:hover { background: var(--panel-soft); }
.collection-table tbody tr:last-child td { border-bottom: 0; }
.collection-table .table-title { color: color-mix(in srgb, var(--accent) 72%, var(--text)); font-size: 15px; font-weight: 650; }
.collection-table .table-details { color: var(--muted); }
.collection-table .table-actions { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.table-person { white-space: nowrap; }
.table-person-inner { display: inline-flex; align-items: center; gap: 9px; }
.table-flag { display: inline-flex; align-items: center; min-width: 25px; }
.table-flag img.emoji { width: 1.45em; height: 1.45em; }
.table-name { color: color-mix(in srgb, var(--accent) 78%, var(--text)); font-family: Georgia, "Times New Roman", serif; font-size: 19px; font-weight: 500; letter-spacing: .01em; }
.table-lifetime { font-weight: 750; white-space: nowrap; }
.table-resource { color: var(--muted); }
.table-sort { display: inline-flex; align-items: center; gap: 7px; padding: 0; border: 0; color: inherit; background: transparent; font: inherit; font-weight: 800; cursor: pointer; }
.table-sort::after { content: "↕"; color: #9ca3af; }
.table-sort[data-direction="ascending"]::after { content: "↑"; color: #fff; }
.table-sort[data-direction="descending"]::after { content: "↓"; color: #fff; }
.item-grid.portrait-view { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.portrait-card { position: relative; min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); transition: transform .2s ease, border-color .2s ease; }
.portrait-card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--accent) 48%, var(--line)); }
.portrait-image-wrap { position: relative; height: 178px; overflow: hidden; background: var(--panel-soft); }
.portrait-image { width: 100%; height: 100%; object-fit: cover; object-position: center 22%; filter: saturate(.82) contrast(1.04); transition: transform .35s ease, filter .35s ease; }
.portrait-card:hover .portrait-image { transform: scale(1.035); filter: saturate(1) contrast(1.02); }
.portrait-badges { position: absolute; inset: auto 10px 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.portrait-badge { padding: 5px 8px; border: 1px solid rgba(255,255,255,.16); border-radius: 999px; color: #fff; background: rgba(8,5,12,.72); backdrop-filter: blur(8px); font-size: 11px; }
.portrait-flag img.emoji { width: 1.15em; height: 1.15em; vertical-align: -.15em; }
.portrait-copy { padding: 14px; }
.portrait-copy h2 { margin: 0 0 7px; color: color-mix(in srgb, var(--accent) 72%, var(--text)); font-family: Georgia, "Times New Roman", serif; font-size: 18px; font-weight: 500; line-height: 1.15; }
.portrait-focus { min-height: 38px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.portrait-actions { display: flex; align-items: center; gap: 7px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.portrait-source { margin-left: auto; color: var(--muted); font-size: 11px; text-decoration: none; }
.portrait-source:hover { color: var(--text); }
.compact-table-page .hero { padding: 32px 0 24px; }
.compact-table-page .hero .eyebrow { margin-bottom: 6px; }
.compact-table-page .hero h1 { font-size: clamp(32px, 5vw, 48px); letter-spacing: -.035em; }
.compact-table-page .hero .lede { margin-top: 10px; font-size: 15px; }
.compact-table-page .collection-table th,
.compact-table-page .collection-table td { padding: 9px 13px; font-size: 13px; }
.compact-table-page .table-name { font-size: 16px; }
.compact-table-page .table-flag img.emoji { width: 1.2em; height: 1.2em; }
.compact-table-page .toolbar { margin-bottom: 8px; }
.collection-page .hero { padding: 34px 0 26px; }
.collection-page .hero .eyebrow { margin-bottom: 6px; font-size: 11px; }
.collection-page .hero h1 { font-size: clamp(32px, 5vw, 48px); letter-spacing: -.035em; }
.collection-page .hero .lede { max-width: 620px; margin-top: 10px; font-size: 14px; line-height: 1.5; }
.item-card { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 12px; padding: 13px; border-radius: 16px; }
.item-icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 13px; background: var(--item-color, var(--panel-soft)); font-size: 22px; }
.book-cover-frame { position: relative; overflow: hidden; color: rgba(255,255,255,.92); }
.book-cover-frame::before { content: ""; position: absolute; inset: 0 auto 0 7px; width: 1px; background: rgba(255,255,255,.28); }
.book-cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.book-group-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.book-group-card { display: grid; grid-template-columns: 43px minmax(0, 1fr); grid-template-rows: auto auto; gap: 2px 11px; min-height: 92px; padding: 15px; border: 1px solid var(--line); border-radius: 16px; color: inherit; background: var(--panel); box-shadow: var(--shadow); text-decoration: none; transition: transform .18s ease, border-color .18s ease; }
.book-group-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 52%, var(--line)); }
.book-group-icon { display: grid; grid-row: 1 / 3; place-items: center; align-self: center; width: 43px; height: 57px; border-radius: 5px 9px 9px 5px; color: #241402; background: linear-gradient(145deg, #fbbf24, #d97706); box-shadow: inset 4px 0 rgba(255,255,255,.2), 0 6px 15px rgba(0,0,0,.22); font-size: 19px; }
.book-group-card h2 { align-self: end; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.book-group-card > span:last-child { align-self: start; color: var(--muted); font-size: 12px; }
.book-groups-back { white-space: nowrap; }
.item-copy { min-width: 0; }
.item-card h2 { margin: 1px 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; }
.song-card { display: block; min-height: 78px; cursor: pointer; transition: transform .18s ease, border-color .18s ease, background .18s ease; }
.song-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--accent) 48%, var(--line)); background: var(--panel-soft); }
.song-card:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; }
.song-card h2 { margin: 2px 0 5px; }
.item-meta, .item-summary { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.item-summary { display: -webkit-box; margin-top: 9px; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.actions .button { padding: 6px 9px; font-size: 12px; }
.youtube { color: #ffb2b2; }
.youtube.icon-only { display: inline-grid; place-items: center; width: 34px; height: 32px; padding: 0; }
.youtube-icon { display: block; font-size: 11px; line-height: 1; }
.empty, .error { padding: 60px 20px; border: 1px dashed var(--line); border-radius: 18px; color: var(--muted); text-align: center; }
.pagination { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 26px; }
.page-button { min-width: 39px; height: 39px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--panel); font-weight: 800; cursor: pointer; }
.page-button[aria-current="page"] { border-color: transparent; color: #170d20; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.page-button:disabled { opacity: .35; cursor: not-allowed; }
dialog { width: min(650px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 22px; color: var(--text); background: var(--panel); box-shadow: 0 40px 120px rgba(0,0,0,.55); }
dialog::backdrop { background: rgba(5,3,9,.78); backdrop-filter: blur(7px); }
.dialog-head { display: flex; justify-content: space-between; gap: 20px; padding: 23px 25px 18px; border-bottom: 1px solid var(--line); }
.dialog-actions { display: flex; align-items: center; gap: 8px; }
.dialog-head h2 { margin: 0 0 5px; }
.dialog-head p { margin: 0; color: var(--muted); }
.close { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; color: var(--text); background: var(--panel-soft); font-size: 21px; cursor: pointer; }
.detail-body { max-height: 62vh; margin: 0; padding: 25px; overflow-y: auto; color: var(--text); font-family: Georgia, serif; font-size: 17px; line-height: 1.8; white-space: pre-wrap; }
footer { padding: 42px 0 14px; color: var(--muted); text-align: center; font-size: 13px; }
code { padding: 2px 6px; border-radius: 6px; background: var(--panel-soft); }

@media (max-width: 820px) {
  .category-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .item-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .book-group-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .item-grid.portrait-view { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  body { padding: 18px 14px; }
  .topbar { align-items: center; }
  .hero { padding-top: 42px; }
  .category-grid { grid-template-columns: 1fr; }
  .item-grid { grid-template-columns: 1fr; }
  .book-group-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .book-group-card { min-height: 78px; padding: 11px; }
  .item-grid.portrait-view { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { grid-template-columns: minmax(0, 1fr) 43px 43px; }
  .toolbar #search, .toolbar #filter:not([hidden]) { grid-column: 1 / -1; }
  .toolbar .shuffle-button { grid-column: 2; }
  .toolbar .view-toggle { grid-column: 3; }
  .section-head { align-items: start; flex-direction: column; gap: 6px; }
  .results-meta { font-size: 12px; }

  .item-grid.table-view { display: block; }
  .table-wrap { overflow: visible; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
  .collection-table { display: block; min-width: 0; }
  .collection-table thead { display: none; }
  .collection-table tbody { display: grid; gap: 10px; }
  .collection-table tr { display: block; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); box-shadow: 0 8px 24px rgba(0,0,0,.12); }
  .collection-table td,
  .compact-table-page .collection-table td { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 10px; align-items: start; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 12px; white-space: normal; }
  .collection-table td::before { content: attr(data-label); color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
  .collection-table .table-actions { display: grid; grid-template-columns: 104px minmax(0, 1fr); }
  .collection-table .table-actions > * { grid-column: 2; }
  .collection-table .table-title, .compact-table-page .table-name { font-size: 14px; }
  .collection-table tbody tr:last-child td:not(:last-child) { border-bottom: 1px solid var(--line); }
  .collection-table tbody tr td:last-child { border-bottom: 0; }

  .dialog-head { padding: 18px; }
  .dialog-head h2 { font-size: 20px; }
  .detail-body { padding: 20px 18px; font-size: 16px; line-height: 1.7; }
}

@media (max-width: 420px) {
  .item-grid.portrait-view { gap: 9px; }
  .portrait-image-wrap { height: 145px; }
  .portrait-copy { padding: 11px; }
  .portrait-copy h2 { font-size: 16px; }
  .portrait-focus { min-height: 48px; font-size: 11px; }
  .portrait-badges { inset: auto 7px 7px; }
  .portrait-badge { padding: 4px 6px; font-size: 9px; }
}
