:root,
html[data-theme="dark"] {
  --bg: #1b1d21;
  --surface: #25282e;
  --surface-hover: #2d3139;
  --surface-elevated: #22252b;
  --border: #323741;
  --border-strong: #4a5160;
  --text: #e8eaef;
  --text-secondary: #a5abb6;
  --text-muted: #8b92a1;
  --accent: #a2c5f7;
  --accent-text: #111827;
  --accent-soft: rgba(162, 197, 247, 0.12);
  --badge-bg: rgba(162, 197, 247, 0.12);
  --badge-border: rgba(162, 197, 247, 0.28);
  --shadow-dialog: 0 24px 64px rgba(0, 0, 0, 0.55);
}

html[data-theme="light"] {
  --bg: #f5f5f7;
  --surface: #e9eaee;
  --surface-hover: #dfe3eb;
  --surface-elevated: #ffffff;
  --border: #cfd3dc;
  --border-strong: #b4bccb;
  --text: #222732;
  --text-secondary: #4c5363;
  --text-muted: #626a79;
  --accent: #245a9c;
  --accent-text: #ffffff;
  --accent-soft: rgba(36, 90, 156, 0.1);
  --badge-bg: rgba(36, 90, 156, 0.09);
  --badge-border: rgba(36, 90, 156, 0.25);
  --shadow-dialog: 0 20px 52px rgba(17, 24, 39, 0.18);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

html:has(dialog[open]) {
  overflow: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 64px;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.container {
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 28px;
}

/* Header */
.site-header {
  background: var(--bg);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-top: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  border-radius: 8px;
}

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

.brand-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.brand-name {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.header-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.header-stats strong {
  color: var(--text);
  font-weight: 600;
}

.header-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.icon-btn:hover {
  background: var(--surface);
  color: var(--text);
}

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

.lang-btn {
  width: auto;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-color: var(--border);
  background: var(--surface);
}

html[data-theme="dark"] .ic-theme-moon { display: none; }
html[data-theme="light"] .ic-theme-sun { display: none; }

/* Latest updates strip */
.recent {
  padding: 28px 0 10px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
}

.recent-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 16px;
}

.recent-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  border-radius: 12px;
}

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

.recent-art {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  object-fit: cover;
  background: var(--surface);
  display: block;
  transition: transform 0.15s ease, outline-color 0.15s ease;
  outline: 2px solid transparent;
  outline-offset: 2px;
}

.recent-card:hover .recent-art {
  outline-color: var(--accent);
}

.recent-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.recent-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.recent-ver {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.recent-meta > span:last-child {
  white-space: nowrap;
  flex-shrink: 0;
}

.recent-meta > span:last-child::before {
  content: "· ";
}

/* Main library toolbar */
.library {
  padding-top: 34px;
}

.library-head {
  margin-bottom: 14px;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 26px;
}

.platform-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.platform-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 96px;
  height: 52px;
  padding: 0 18px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.platform-tab:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.platform-tab[aria-selected="true"] {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.platform-tab .tab-count {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.72;
  font-variant-numeric: tabular-nums;
}

.category-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.pill-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.pill-btn[aria-pressed="true"] {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.pill-count {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.search-sort-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 280px;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text-muted);
  transition: border-color 0.14s ease;
}

.search-box:focus-within {
  border-color: var(--accent);
}

.search-box input {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 10px 8px;
  outline: none;
  color: var(--text);
  font-size: 14px;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

.search-kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--bg);
}

.sort-wrap select {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  cursor: pointer;
}

.sort-wrap select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.meta-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-top: -4px;
}

.sync-group {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.result-count,
.last-synced {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.sync-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.sync-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--accent);
}

.sync-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.sync-btn.is-syncing svg {
  animation: dk-spin 0.8s linear infinite;
}

@keyframes dk-spin {
  to { transform: rotate(360deg); }
}

/* Catalog groups & borderless artwork tiles */
.catalog-groups {
  display: flex;
  flex-direction: column;
  gap: 36px;
}

.group-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.group-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.group-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.group-count {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 20px 18px;
}

.project-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  border-radius: 12px;
}

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

.card-art-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color 0.14s ease;
}

.project-card:hover .card-art-wrap {
  outline-color: var(--accent);
}

.card-art {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 3px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  background: rgba(17, 20, 26, 0.82);
  color: #e8eaef;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.card-version {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-stars {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  color: var(--text-secondary);
}

.card-stars svg {
  color: var(--accent);
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--text-muted);
}

.empty-state button {
  margin-top: 12px;
}

/* Native Project Detail Dialog */
.project-dialog {
  width: min(620px, calc(100vw - 24px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--surface-elevated);
  color: var(--text);
  box-shadow: var(--shadow-dialog);
  overflow: auto;
}

.project-dialog::backdrop {
  background: rgba(10, 12, 16, 0.72);
}

.dialog-shell {
  padding: 20px 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.dialog-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-category {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.dialog-close {
  width: 32px;
  height: 32px;
  border-color: var(--border);
  background: var(--surface);
}

.dialog-hero {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.dialog-artwork {
  width: 112px;
  height: 112px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

.dialog-intro {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.dialog-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.dialog-platforms {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.platform-chip {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--badge-bg);
  border: 1px solid var(--badge-border);
  color: var(--accent);
}

.dialog-summary {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.dialog-meta-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 11px 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-variant-numeric: tabular-nums;
}

.meta-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-label {
  font-size: 11px;
  color: var(--text-muted);
}

.meta-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.dialog-note {
  padding: 11px 13px;
  border-radius: 8px;
  border: 1px solid var(--badge-border);
  background: var(--accent-soft);
}

.note-title {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 3px;
}

.note-body {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn-primary:hover {
  opacity: 0.92;
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.dialog-assets {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.assets-heading {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.assets-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.asset-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--text-secondary);
}

.asset-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.dialog-notes {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 9px 12px;
}

.notes-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  list-style: none;
}

.notes-toggle::-webkit-details-marker {
  display: none;
}

.dialog-notes[open] .notes-toggle svg {
  transform: rotate(180deg);
}

.notes-body {
  margin: 9px 0 2px;
  padding-top: 9px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: pre-line;
}

.dialog-foot {
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

/* Responsive Breakpoints */
@media (max-width: 1000px) {
  .recent-strip {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    padding-bottom: 6px;
  }

  .recent-card {
    flex: 0 0 138px;
    scroll-snap-align: start;
  }

  .card-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .header-inner {
    flex-wrap: wrap;
  }

  .header-divider {
    display: none;
  }

  .card-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .container {
    padding: 0 16px;
  }

  .card-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px 10px;
  }

  .card-title {
    font-size: 12.5px;
  }

  .dialog-hero {
    flex-direction: column;
  }

  .dialog-artwork {
    width: 88px;
    height: 88px;
  }

  .dialog-meta-strip {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 350px) {
  .card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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