:root {
  color-scheme: light;
  --canvas: #f5f7f6;
  --surface: #ffffff;
  --surface-muted: #eef2f0;
  --line: #dbe2df;
  --line-strong: #c6d1cd;
  --ink: #17201d;
  --ink-muted: #64706b;
  --teal: #0f766e;
  --teal-deep: #075d56;
  --teal-pale: #d9eeeb;
  --shadow: 0 18px 40px rgba(27, 43, 37, 0.08);
  --radius: 8px;
  font-family: "SF Pro Text", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.35);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 204px minmax(0, 1fr) 0;
  min-height: 100dvh;
}

.sidebar {
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
  padding: 28px 16px 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfb;
}

.brand-block {
  padding: 0 8px 28px;
}

.brand-kicker {
  margin: 0 0 6px;
  color: var(--ink-muted);
  font-size: 12px;
}

.brand-block h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 720;
  letter-spacing: 0;
}

.primary-nav {
  display: grid;
  gap: 4px;
}

.nav-item,
.settings-button {
  width: 100%;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-muted);
  padding: 10px 12px;
  text-align: left;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-item:hover,
.settings-button:hover {
  background: var(--surface-muted);
  color: var(--ink);
}

.nav-item:active,
.settings-button:active,
.outline-button:active,
.text-button:active {
  transform: translateY(1px);
}

.nav-item.is-active {
  background: var(--teal-pale);
  color: var(--teal-deep);
  font-weight: 700;
}

.storage-summary {
  margin-top: auto;
  padding: 18px 8px 20px;
}

.storage-summary p,
.storage-summary small {
  margin: 0;
  color: var(--ink-muted);
}

.storage-summary p {
  font-size: 12px;
}

.storage-summary strong {
  display: block;
  margin: 6px 0 10px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 15px;
}

.storage-summary strong span {
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 500;
}

.storage-scale {
  height: 6px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--line);
}

.storage-scale span {
  display: block;
  width: 45%;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.storage-summary small {
  display: block;
  margin-top: 8px;
  font-size: 11px;
}

.settings-button {
  margin-top: 4px;
}

.workspace {
  min-width: 0;
  padding: 28px clamp(20px, 3.2vw, 52px) 52px;
}

.topbar,
.collection-header,
.filter-row,
.panel-heading,
.card-title-line,
.topbar-actions,
.drawer-topline,
.drawer-head,
.drawer-data-row {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
}

.search-block {
  width: min(100%, 490px);
}

.search-block label,
.filter-group label {
  display: block;
  margin-bottom: 7px;
  color: var(--ink-muted);
  font-size: 12px;
  font-weight: 650;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

input {
  height: 42px;
  padding: 0 12px;
}

select {
  height: 38px;
  padding: 0 28px 0 10px;
}

.topbar-actions {
  gap: 12px;
  white-space: nowrap;
}

.sync-label {
  color: var(--ink-muted);
  font-size: 12px;
}

.outline-button,
.text-button {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
  transition: background 160ms ease, transform 160ms ease;
}

.outline-button:hover {
  background: var(--surface-muted);
}

.collection-header {
  padding: 36px 0 22px;
}

.collection-header h2,
.panel-heading h3,
.empty-state h3,
.drawer-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.collection-header h2 {
  font-size: 26px;
  font-weight: 740;
}

.collection-header p {
  margin: 6px 0 0;
  color: var(--ink-muted);
}

.filter-row {
  gap: 12px;
  padding: 16px 0 22px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.filter-group {
  width: min(154px, 100%);
}

.filter-group label {
  margin-bottom: 5px;
}

.sort-group {
  margin-left: auto;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(250px, 284px);
  gap: 34px;
  padding-top: 28px;
}

.panel-heading {
  justify-content: space-between;
  min-height: 30px;
  margin-bottom: 14px;
}

.panel-heading h3 {
  font-size: 15px;
  font-weight: 730;
}

.panel-heading span,
.panel-heading select {
  color: var(--ink-muted);
  font-size: 12px;
}

.panel-heading select {
  width: auto;
  height: 30px;
  padding: 0 25px 0 8px;
  border-color: transparent;
  background: transparent;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 14px;
}

.skeleton-card {
  min-height: 258px;
  border-radius: var(--radius);
  background: linear-gradient(110deg, #e6ece9 28%, #f4f7f5 44%, #e6ece9 60%);
  background-size: 240% 100%;
  animation: skeleton-shift 1.2s ease-in-out infinite;
}

@keyframes skeleton-shift {
  to {
    background-position: -140% 0;
  }
}

.game-card {
  min-width: 0;
}

.cover-button {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 7 / 9;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  color: #f9fffd;
  padding: 0;
  text-align: left;
  isolation: isolate;
  background: var(--cover-base, #1f3b36);
  box-shadow: 0 12px 26px rgba(35, 57, 49, 0.15);
  transition: transform 180ms cubic-bezier(0.16, 1, 0.3, 1), box-shadow 180ms ease;
}

.cover-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 18px 30px rgba(35, 57, 49, 0.2);
}

.cover-button::before,
.cover-button::after,
.cover-pattern {
  position: absolute;
  content: "";
  pointer-events: none;
}

.cover-button::before {
  right: -18%;
  bottom: 13%;
  width: 85%;
  height: 42%;
  transform: rotate(-28deg);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
}

.cover-button::after {
  top: 16%;
  left: 11%;
  width: 35%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
}

.cover-pattern {
  right: 9%;
  top: 10%;
  width: 56%;
  height: 74%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  transform: skewY(-18deg);
}

.cover-code,
.cover-title {
  position: absolute;
  z-index: 1;
  left: 13px;
  right: 13px;
}

.cover-code {
  top: 13px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
}

.cover-title {
  bottom: 14px;
  max-width: 80%;
  font-size: 18px;
  font-weight: 760;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.card-main {
  padding: 10px 2px 4px;
}

.card-title-line {
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-title-line h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
}

.state-mark {
  flex: 0 0 auto;
  margin-top: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
}

.state-mark.is-installed {
  background: var(--teal);
}

.state-mark.is-pending {
  background: #a4aca8;
}

.state-mark.is-missing {
  border: 1px solid #87908b;
  background: transparent;
}

.game-subtitle,
.card-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-subtitle {
  margin: 3px 0 0;
  color: var(--ink-muted);
  font-size: 12px;
}

.card-meta {
  margin-top: 8px;
  color: var(--ink-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 11px;
}

.insights-panel {
  display: grid;
  align-content: start;
  gap: 28px;
  padding-left: 24px;
  border-left: 1px solid var(--line);
}

.insight-section + .insight-section {
  padding-top: 26px;
  border-top: 1px solid var(--line);
}

.popular-list,
.recent-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.popular-list {
  counter-reset: rank;
}

.popular-list li,
.recent-entry {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 8px;
  min-height: 39px;
}

.popular-list li::before {
  content: counter(rank, decimal-leading-zero);
  counter-increment: rank;
  color: var(--ink-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 11px;
}

.popular-list .popular-unavailable {
  display: block;
  min-height: 0;
  color: var(--ink-muted);
  font-size: 13px;
}

.popular-list .popular-unavailable::before {
  display: none;
}

.popular-title,
.recent-entry strong {
  overflow: hidden;
  font-size: 13px;
  font-weight: 620;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.popular-value,
.recent-entry span {
  color: var(--ink-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 11px;
}

.quiet-note {
  margin: 12px 0 0;
  color: var(--ink-muted);
  font-size: 11px;
  line-height: 1.6;
}

.recent-list {
  display: grid;
  gap: 10px;
}

.recent-entry {
  grid-template-columns: 1fr auto;
  min-height: 26px;
}

.empty-state {
  padding: 62px 0;
  text-align: center;
}

.empty-state p {
  margin: 8px 0 16px;
  color: var(--ink-muted);
}

.empty-state.is-error h3 {
  color: var(--teal-deep);
}

.text-button {
  border-color: transparent;
  color: var(--teal-deep);
  font-weight: 700;
}

.details-drawer {
  position: sticky;
  top: 0;
  min-width: 0;
  height: 100dvh;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: #fbfcfb;
  box-shadow: -12px 0 32px rgba(27, 43, 37, 0.07);
  transition: box-shadow 180ms ease;
}

.app-shell:has(.details-drawer.is-open) {
  grid-template-columns: 204px minmax(0, 1fr) minmax(300px, 368px);
}

.drawer-empty {
  padding: 36px 28px;
  color: var(--ink-muted);
}

.drawer-empty p {
  margin: 0 0 5px;
  color: var(--ink);
  font-weight: 700;
}

.drawer-empty span {
  font-size: 12px;
}

.drawer-content {
  padding: 24px;
}

.drawer-topline {
  justify-content: space-between;
  margin-bottom: 28px;
}

.drawer-topline span {
  color: var(--ink-muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 11px;
}

.drawer-close {
  border: 0;
  border-radius: 6px;
  background: var(--surface-muted);
  color: var(--ink);
  padding: 7px 9px;
}

.drawer-head {
  align-items: flex-start;
  gap: 12px;
}

.drawer-cover {
  flex: 0 0 76px;
  aspect-ratio: 7 / 9;
  border-radius: 6px;
  background: var(--cover-base, #1f3b36);
}

.drawer-head h2 {
  font-size: 21px;
  line-height: 1.18;
}

.drawer-head p {
  margin: 5px 0 0;
  color: var(--ink-muted);
}

.drawer-section {
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}

.drawer-section h3 {
  margin: 0 0 13px;
  font-size: 13px;
}

.drawer-data-row {
  justify-content: space-between;
  gap: 16px;
  padding: 7px 0;
}

.drawer-data-row span {
  color: var(--ink-muted);
}

.drawer-data-row strong {
  max-width: 64%;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 12px;
  font-weight: 600;
  overflow-wrap: anywhere;
  text-align: right;
}

.source-link {
  color: var(--teal-deep);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.source-slot {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--ink-muted);
}

.source-slot strong {
  color: var(--ink);
  font-size: 13px;
}

.source-slot button {
  width: max-content;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
  color: #8d9893;
  padding: 7px 9px;
  cursor: not-allowed;
}

@media (max-width: 1180px) {
  .app-shell:has(.details-drawer.is-open) {
    grid-template-columns: 184px minmax(0, 1fr) minmax(292px, 330px);
  }

  .sidebar {
    padding-inline: 12px;
  }

  .content-grid {
    grid-template-columns: minmax(0, 1fr) 246px;
    gap: 24px;
  }
}

@media (max-width: 980px) {
  .app-shell,
  .app-shell:has(.details-drawer.is-open) {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .sidebar {
    align-items: center;
    padding: 24px 9px 16px;
  }

  .brand-block {
    padding: 0 0 24px;
  }

  .brand-kicker,
  .sidebar h1,
  .storage-summary,
  .settings-button {
    display: none;
  }

  .brand-block::before {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 8px;
    background: var(--teal);
    color: #fff;
    content: "库";
    font-weight: 800;
  }

  .nav-item {
    width: 52px;
    padding: 10px 4px;
    font-size: 11px;
    text-align: center;
  }

  .details-drawer {
    position: fixed;
    z-index: 2;
    right: 0;
    width: min(390px, 92vw);
    transform: translateX(100%);
    transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .details-drawer.is-open {
    transform: translateX(0);
  }
}

@media (max-width: 760px) {
  .app-shell,
  .app-shell:has(.details-drawer.is-open) {
    display: block;
  }

  .sidebar {
    display: flex;
    min-height: auto;
    flex-direction: row;
    justify-content: space-between;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand-block {
    padding: 0;
  }

  .primary-nav {
    display: flex;
    gap: 2px;
  }

  .nav-item {
    width: auto;
    padding: 8px 7px;
    font-size: 11px;
  }

  .nav-item:nth-child(3),
  .nav-item:nth-child(4) {
    display: none;
  }

  .workspace {
    padding: 20px 16px 40px;
  }

  .topbar,
  .collection-header {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    gap: 12px;
    padding-bottom: 20px;
  }

  .topbar-actions {
    justify-content: space-between;
  }

  .collection-header {
    gap: 16px;
    padding: 26px 0 18px;
  }

  .collection-header h2 {
    font-size: 23px;
  }

  .filter-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-group,
  .sort-group {
    width: auto;
    margin-left: 0;
  }

  .content-grid {
    display: block;
  }

  .game-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .insights-panel {
    grid-template-columns: 1fr;
    margin-top: 34px;
    padding: 26px 0 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .details-drawer {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
