:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-muted: #eef1f4;
  --border: #d8dde3;
  --text: #171a1f;
  --muted: #626b76;
  --accent: #35558a;
  --accent-dark: #243b6b;
  --shadow: 0 1px 2px rgb(15 23 42 / 8%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.4;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 16px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--border);
  background: rgb(255 255 255 / 92%);
  backdrop-filter: blur(10px);
}

h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 720;
  letter-spacing: 0;
}

.app-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.sort-menu {
  position: relative;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 28px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1;
  padding: 0;
}

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

.sort-chevron {
  width: 9px;
  height: 9px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
}

.sort-button[aria-expanded="true"] .sort-chevron {
  transform: translateY(2px) rotate(225deg);
}

.sort-options {
  position: absolute;
  top: calc(100% + 1px);
  right: 0;
  z-index: 20;
  min-width: 190px;
  padding: 12px 0;
  border: 0;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 16px 32px rgb(15 23 42 / 14%);
}

.sort-options button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.96rem;
  line-height: 1.2;
  padding: 8px 18px;
  text-align: left;
}

.sort-options button:hover,
.sort-options button[aria-checked="true"] {
  background: var(--surface-muted);
}

main {
  padding: 18px clamp(12px, 3vw, 32px) 40px;
}

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

.card {
  overflow: hidden;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.thumbnail-link {
  display: block;
  background: var(--surface-muted);
  aspect-ratio: 3 / 4;
}

.thumbnail {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card-body {
  display: grid;
  gap: 6px;
  padding: 9px 10px 10px;
}

.card-title {
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  font-size: 0.96rem;
  font-weight: 700;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-title-link {
  display: block;
  overflow: hidden;
  color: var(--text);
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-title-link:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}

.metadata {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1;
}

.value-row {
  min-height: 30px;
  padding-top: 2px;
}

.value {
  color: var(--accent-dark);
  font-size: 1rem;
  font-weight: 760;
}

.grade {
  color: var(--muted);
  font-size: 0.72rem;
}

.sentinel {
  height: 48px;
}

.empty-state {
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

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

  main {
    padding-inline: 10px;
  }

  .app-header {
    min-height: 66px;
    padding-inline: 14px;
  }

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