:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #15171d;
  --muted: #697180;
  --line: #dfe3ea;
  --accent: #147e73;
  --accent-strong: #0b5f57;
  --danger: #b42318;
  --shadow: 0 12px 30px rgba(20, 30, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(20, 126, 115, 0.08), transparent 320px),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 48px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 26px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 42px;
  line-height: 1.05;
}

.stats {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.inlineStats {
  font-weight: 800;
}

.themeSelectWrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.selectShell {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.selectShell::after {
  content: "";
  position: absolute;
  right: 12px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  pointer-events: none;
  transform: translateY(-2px) rotate(45deg);
}

.themeSelectWrap select {
  appearance: none;
  min-height: 38px;
  min-width: 132px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(20, 30, 45, 0.06);
}

.themeSelectWrap select:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(20, 126, 115, 0.14);
}

.controls {
  display: grid;
  gap: 16px;
  padding: 18px;
  margin-bottom: 18px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
}

.search input,
.jumpForm input {
  min-width: 0;
  height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

.search button,
.pager button,
.actions a,
.actions button,
.ghost {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}

.segmented button {
  min-width: 78px;
  height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented .active {
  background: var(--ink);
  color: #fff;
}

.ghost {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

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

.styleBar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.styleBar span {
  font-weight: 800;
}

.styleBar button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.styleBar button.active {
  border-color: var(--accent);
  background: rgba(20, 126, 115, 0.1);
  color: var(--accent-strong);
}

.tag {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.tag.active {
  border-color: var(--accent);
  background: rgba(20, 126, 115, 0.1);
  color: var(--accent-strong);
}

.filterSummary {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

.summaryRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.status {
  min-height: 28px;
  color: var(--muted);
  font-size: 14px;
}

.status.error {
  color: var(--danger);
}

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

.grid[aria-busy="true"] {
  opacity: 0.68;
}

.card {
  display: grid;
  grid-template-rows: 168px minmax(220px, auto);
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.previewButton {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(45deg, #edf0f3 25%, transparent 25%) 0 0 / 22px 22px,
    linear-gradient(45deg, transparent 75%, #edf0f3 75%) 0 0 / 22px 22px,
    linear-gradient(45deg, transparent 75%, #edf0f3 75%) 11px 11px / 22px 22px,
    linear-gradient(45deg, #edf0f3 25%, #f8fafc 25%) 11px 11px / 22px 22px;
  cursor: pointer;
}

.sprite {
  --idle-distance: 576px;
  width: 96px;
  height: 104px;
  image-rendering: pixelated;
  background-repeat: no-repeat;
  background-size: 768px 936px;
  background-position: 0 0;
  animation: idleSprite 900ms steps(6) infinite;
}

.card:hover .sprite,
.previewButton:focus-visible .sprite {
  animation-duration: 560ms;
}

@keyframes idleSprite {
  from {
    background-position-x: 0;
  }
  to {
    background-position-x: calc(var(--idle-distance) * -1);
  }
}

.cardBody {
  display: grid;
  grid-template-rows: auto minmax(58px, 1fr) auto auto auto;
  gap: 10px;
  padding: 14px;
}

.titleRow {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
}

h2 {
  margin: 0;
  min-width: 0;
  font-size: 18px;
  line-height: 1.22;
  overflow-wrap: anywhere;
}

.version {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.desc {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.cardTags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 26px;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: #eef5f4;
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 12px;
}

.chip.muted {
  color: var(--muted);
  cursor: default;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.actions .copyInstall {
  grid-column: 1 / -1;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.actions .detail {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

#pageInfo {
  min-width: 150px;
  text-align: center;
  color: var(--muted);
}

.jumpForm {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.jumpForm input {
  width: 86px;
  height: 38px;
  text-align: center;
}

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

@media (max-width: 740px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 22px;
  }

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

  .topbar {
    align-items: flex-start;
  }

  .themeSelectWrap,
  .selectShell,
  .themeSelectWrap select {
    width: 100%;
  }

  h1 {
    font-size: 34px;
  }

  .search {
    grid-template-columns: 1fr;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    min-width: 0;
  }

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

  .card {
    grid-template-rows: 146px minmax(220px, auto);
  }

  .summaryRow,
  .detailTopbar {
    align-items: stretch;
    flex-direction: column;
  }

  .inlineStats {
    align-self: flex-start;
  }
}

@media (max-width: 480px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .pager {
    align-items: stretch;
    flex-direction: column;
  }

  #pageInfo,
  .jumpForm,
  .pager button {
    width: 100%;
  }

  .jumpForm {
    display: grid;
    grid-template-columns: auto 1fr auto;
  }

  .jumpForm input {
    width: 100%;
  }
}

.detailShell {
  width: min(1160px, calc(100% - 32px));
}

.backLink {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  margin-bottom: 18px;
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: none;
}

.detailTopbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.detailView {
  display: grid;
  gap: 34px;
}

.detailStyleBar {
  margin: -8px 0 18px;
}

.detailHero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 46%);
  gap: 42px;
  align-items: start;
  padding-bottom: 34px;
  border-bottom: 1px solid var(--line);
}

.detailCopy {
  min-width: 0;
}

.detailDescription {
  margin: 22px 0 24px;
  max-width: 680px;
  color: #344054;
  font-size: 22px;
  line-height: 1.55;
}

.detailStats {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.detailActions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
}

.primaryAction,
.secondaryAction,
.commandBox button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  text-decoration: none;
}

.secondaryAction {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.detailPreview {
  display: grid;
  place-items: center;
  min-height: 360px;
  border: 1px solid #cbe9e5;
  background:
    linear-gradient(#d9f0ed 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, #d9f0ed 1px, transparent 1px) 0 0 / 24px 24px,
    #eefaf8;
}

.detailSprite {
  width: 192px;
  height: 208px;
  image-rendering: pixelated;
  background-repeat: no-repeat;
  background-size: 1536px 1872px;
  background-position: 0 0;
  animation: detailIdleSprite 900ms steps(6) infinite;
}

@keyframes detailIdleSprite {
  from {
    background-position-x: 0;
  }
  to {
    background-position-x: -1152px;
  }
}

.installPanel {
  width: min(880px, 100%);
  margin: 0 auto;
}

.installPanel h2 {
  margin: 0 0 12px;
  font-size: 24px;
}

.installPanel p {
  color: #475467;
  font-size: 16px;
}

.installPanel code {
  border-radius: 5px;
  background: #fff7e6;
  color: #111827;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

.commandBox {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.commandBox > code {
  display: block;
  min-width: 0;
  padding: 18px;
  overflow-x: auto;
  border-radius: 6px;
  background: #101828;
  color: #fff;
  white-space: nowrap;
}

.commandBox button {
  border-color: #344054;
  background: #344054;
}

.enableTip {
  margin-top: 18px;
}

.animationPanel,
.spritesheetPanel {
  display: grid;
  gap: 18px;
}

.sectionTitleRow {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.sectionTitleRow h2 {
  margin: 0;
  font-size: 24px;
}

.sectionNote {
  color: var(--muted);
  font-size: 14px;
}

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

.stateCard {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.statePreview {
  display: grid;
  place-items: center;
  min-height: 138px;
  overflow: hidden;
  border: 1px solid #d7ece9;
  border-radius: 6px;
  background:
    linear-gradient(#e2f2ef 1px, transparent 1px) 0 0 / 18px 18px,
    linear-gradient(90deg, #e2f2ef 1px, transparent 1px) 0 0 / 18px 18px,
    #f5fbfa;
}

.stateSprite {
  width: 96px;
  height: 104px;
  image-rendering: pixelated;
  background-repeat: no-repeat;
  background-size: 768px 936px;
  background-position: 0 calc(var(--row) * -104px);
  animation-name: stateSprite;
  animation-iteration-count: infinite;
}

@keyframes stateSprite {
  from {
    background-position-x: 0;
  }
  to {
    background-position-x: calc(var(--distance) * -1);
  }
}

.stateTitle {
  font-weight: 800;
}

.stateMeta {
  color: var(--muted);
  font-size: 13px;
}

.sheetFrame {
  overflow: auto;
  max-height: 720px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #edf0f3 25%, transparent 25%) 0 0 / 24px 24px,
    linear-gradient(45deg, transparent 75%, #edf0f3 75%) 0 0 / 24px 24px,
    linear-gradient(45deg, transparent 75%, #edf0f3 75%) 12px 12px / 24px 24px,
    linear-gradient(45deg, #edf0f3 25%, #f8fafc 25%) 12px 12px / 24px 24px;
}

.sheetFrame img {
  display: block;
  width: min(100%, 768px);
  height: auto;
  margin: 0 auto;
  image-rendering: pixelated;
}

@media (max-width: 860px) {
  .detailHero {
    grid-template-columns: 1fr;
  }

  .detailPreview {
    min-height: 300px;
  }
}

@media (max-width: 560px) {
  .detailDescription {
    font-size: 18px;
  }

  .detailActions,
  .commandBox {
    grid-template-columns: 1fr;
  }

  .primaryAction,
  .secondaryAction,
  .commandBox button {
    width: 100%;
  }

  .sectionTitleRow {
    align-items: stretch;
    flex-direction: column;
  }

  .stateGrid {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 561px) and (max-width: 900px) {
  .stateGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Style 2: compact information desk */
:root[data-theme="compact"] {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #566274;
  --line: #d9dee8;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --shadow: 0 6px 18px rgba(20, 30, 45, 0.06);
}

:root[data-theme="compact"] body {
  background: var(--bg);
}

:root[data-theme="compact"] .shell {
  width: min(1480px, calc(100% - 24px));
  padding-top: 18px;
}

:root[data-theme="compact"] .topbar {
  align-items: center;
  margin-bottom: 14px;
}

:root[data-theme="compact"] h1 {
  font-size: 30px;
}

:root[data-theme="compact"] .controls {
  gap: 10px;
  padding: 12px;
  box-shadow: none;
}

:root[data-theme="compact"] .grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

:root[data-theme="compact"] .card {
  grid-template-rows: 118px minmax(190px, auto);
  border-radius: 6px;
}

:root[data-theme="compact"] .sprite {
  --idle-distance: 432px;
  width: 72px;
  height: 78px;
  background-size: 576px 702px;
}

:root[data-theme="compact"] .cardBody {
  gap: 7px;
  padding: 10px;
}

:root[data-theme="compact"] h2 {
  font-size: 15px;
}

:root[data-theme="compact"] .desc {
  -webkit-line-clamp: 2;
  font-size: 12px;
}

:root[data-theme="compact"] .actions {
  grid-template-columns: 1fr;
}

/* Style 3: showcase gallery */
:root[data-theme="showcase"] {
  --bg: #fbf7f1;
  --panel: #fffdf8;
  --ink: #201712;
  --muted: #735f52;
  --line: #ead9c8;
  --accent: #b85f2f;
  --accent-strong: #87441f;
  --shadow: 0 18px 38px rgba(89, 50, 25, 0.12);
}

:root[data-theme="showcase"] body {
  background:
    linear-gradient(180deg, rgba(184, 95, 47, 0.18), transparent 380px),
    var(--bg);
}

:root[data-theme="showcase"] .shell {
  width: min(1320px, calc(100% - 40px));
}

:root[data-theme="showcase"] .topbar {
  align-items: center;
  padding: 24px 0;
}

:root[data-theme="showcase"] h1 {
  font-size: 54px;
}

:root[data-theme="showcase"] .controls {
  padding: 22px;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
}

:root[data-theme="showcase"] .grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
}

:root[data-theme="showcase"] .card {
  grid-template-rows: 238px minmax(230px, auto);
}

:root[data-theme="showcase"] .sprite {
  --idle-distance: 864px;
  width: 144px;
  height: 156px;
  background-size: 1152px 1404px;
}

:root[data-theme="showcase"] .previewButton {
  background:
    linear-gradient(#ead9c8 1px, transparent 1px) 0 0 / 22px 22px,
    linear-gradient(90deg, #ead9c8 1px, transparent 1px) 0 0 / 22px 22px,
    #fff8ed;
}

:root[data-theme="showcase"] h2 {
  font-size: 22px;
}

/* Style 4: dark pixel lab */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1118;
  --panel: #121a24;
  --ink: #f4f7fb;
  --muted: #9aa7b8;
  --line: #263445;
  --accent: #34d399;
  --accent-strong: #6ee7b7;
  --danger: #fb7185;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
}

:root[data-theme="dark"] body {
  background:
    linear-gradient(180deg, rgba(52, 211, 153, 0.12), transparent 340px),
    radial-gradient(circle at top right, rgba(37, 99, 235, 0.12), transparent 300px),
    var(--bg);
}

:root[data-theme="dark"] .controls,
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .stateCard,
:root[data-theme="dark"] .commandBox {
  background: rgba(18, 26, 36, 0.92);
}

:root[data-theme="dark"] .search input,
:root[data-theme="dark"] .jumpForm input,
:root[data-theme="dark"] .themeSelectWrap select,
:root[data-theme="dark"] .segmented,
:root[data-theme="dark"] .tag,
:root[data-theme="dark"] .styleBar button,
:root[data-theme="dark"] .ghost,
:root[data-theme="dark"] .actions .copyInstall,
:root[data-theme="dark"] .actions .detail,
:root[data-theme="dark"] .secondaryAction {
  background: #0f1722;
  color: var(--ink);
}

:root[data-theme="dark"] .themeSelectWrap select {
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

:root[data-theme="dark"] .selectShell::after {
  border-color: var(--accent-strong);
}

:root[data-theme="dark"] .segmented .active {
  background: var(--accent);
  color: #06110d;
}

:root[data-theme="dark"] .styleBar button.active,
:root[data-theme="dark"] .tag.active {
  background: rgba(52, 211, 153, 0.16);
  color: var(--accent-strong);
}

:root[data-theme="dark"] .previewButton,
:root[data-theme="dark"] .sheetFrame {
  background:
    linear-gradient(45deg, #182232 25%, transparent 25%) 0 0 / 22px 22px,
    linear-gradient(45deg, transparent 75%, #182232 75%) 0 0 / 22px 22px,
    linear-gradient(45deg, transparent 75%, #182232 75%) 11px 11px / 22px 22px,
    linear-gradient(45deg, #182232 25%, #101823 25%) 11px 11px / 22px 22px;
}

:root[data-theme="dark"] .detailPreview,
:root[data-theme="dark"] .statePreview {
  background:
    linear-gradient(#21384a 1px, transparent 1px) 0 0 / 22px 22px,
    linear-gradient(90deg, #21384a 1px, transparent 1px) 0 0 / 22px 22px,
    #0d1722;
}

:root[data-theme="dark"] .detailDescription {
  color: #d3dbe7;
}

:root[data-theme="dark"] .installPanel code {
  background: #1c2a3a;
  color: #f4f7fb;
}

:root[data-theme="dark"] .commandBox > code {
  background: #050914;
}

@media (max-width: 1180px) {
  :root[data-theme="compact"] .grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  :root[data-theme="compact"] .grid,
  :root[data-theme="showcase"] .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 740px) {
  :root[data-theme="compact"] .grid,
  :root[data-theme="showcase"] .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  :root[data-theme="compact"] .grid,
  :root[data-theme="showcase"] .grid {
    grid-template-columns: 1fr;
  }
}
