html.browse-light body,
body.light-mode {
  --color-primary: #4257b2;
  --color-primary-light: #f0f3ff;
  --color-primary-dark: #3a4b99;
  --color-bg: #f6f7fb;
  --color-bg-secondary: #ffffff;
  --color-card-bg: #ffffff;
  --color-text-primary: #303545;
  --color-text-secondary: #586380;
  --color-border: #e4e7eb;
  --shadow-md: 0 4px 12px rgba(48,53,69,0.1);
}

body.browse-page {
  user-select: text;
  -webkit-user-select: text;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text-primary);
}

body.browse-page header,
body.browse-page footer,
body.browse-page header *,
body.browse-page footer * {
  user-select: none;
  -webkit-user-select: none;
}

.browse-page [hidden] { display: none !important; }

.browse-shell {
  max-width: 1200px;
  margin: auto;
  padding: 0 clamp(1rem, 3vw, 2.5rem);
  position: relative;
}

.browse-header {
  position: relative;
  min-height: 88px;
  margin-top: 0.5rem;
}

/* Header row lines up with the rest of TNQ: items centered ~51px from the top */
.header-logo {
  position: absolute;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.header-logo img {
  width: 142px;
  max-height: 40px;
  object-fit: contain;
}

.quick-nav-cluster {
  position: absolute;
  left: 0;
  top: 25px;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 20;
}

.home-link-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  text-align: center;
}

.home-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--color-text-primary);
  text-decoration: none;
  box-shadow: none;
  transition: all 0.2s ease;
}

.home-button:hover {
  color: var(--color-primary);
  background-color: var(--color-card-bg);
  transform: none;
}

.home-icon svg {
  width: 22px;
  height: 22px;
  display: block;
  fill: currentColor;
}

.home-tooltip {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translate(-50%, -4px);
  padding: 0.2rem 0.55rem;
  border-radius: 8px;
  background: var(--color-card-bg);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  font-size: 0.72rem;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
}

#theme-toggle-button {
  position: absolute;
  right: 0;
  top: 24px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  padding: 8px;
  color: var(--color-text-primary);
  background: transparent;
  cursor: pointer;
  z-index: 20;
}

#theme-toggle-button:hover {
  color: var(--color-primary);
  background-color: var(--color-card-bg);
}

#theme-toggle-button svg {
  width: 22px;
  height: 22px;
  display: block;
}

.eyebrow { margin: 0 0 .7rem; color: var(--color-primary); letter-spacing: .18em; font-size: .72rem; font-weight: 900; }
.catalog { padding: clamp(1.25rem, 3vw, 2.25rem) 0 3.5rem; }
.catalog-heading { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 1.5rem; }
.catalog-heading .eyebrow { color: var(--color-primary); }
.catalog h1 { font-size: clamp(1.8rem, 3vw, 2.3rem); letter-spacing: -.04em; margin: 0 0 .3rem; }
.muted { color: var(--color-text-secondary); margin: 0; font-size: .9rem; }
.catalog-create { color: var(--color-primary); text-decoration: none; font-size: .9rem; font-weight: 800; white-space: nowrap; padding-bottom: 5px; }
.catalog-create:hover { text-decoration: underline; }

.filter-bar { display: grid; grid-template-columns: minmax(220px, 1fr) 180px 180px; gap: .75rem; margin-bottom: 1.5rem; }
/* Fields come from Shared/ui.css; these fields sit on the page, so they use the raised background */
.filter-bar { --tnq-field-bg: var(--color-bg-secondary); }
.search-field .tnq-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  margin-left: 6px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M3 3L13 13M13 3L3 13' stroke='%238a93b8' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") center / 14px 14px no-repeat;
  cursor: pointer;
}
.search-field .tnq-input::-ms-clear { display: none; }
.select-wrap { position: relative; display: block; min-width: 0; }
.select-wrap > span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--tnq-muted); font-size: .8rem; font-weight: 800; pointer-events: none; }
.select-wrap .tnq-select { padding-left: 54px; font-weight: 600; }

.set-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.set-card { min-width: 0; min-height: 265px; display: flex; flex-direction: column; padding: 1.35rem; border: 1px solid var(--color-border); border-radius: 20px; background: var(--color-bg-secondary); box-shadow: var(--shadow-md); cursor: pointer; transition: border-color 0.15s ease, transform 0.15s ease; }
.set-card:hover { border-color: var(--color-primary); transform: translateY(-2px); }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.card-badge { color: var(--color-primary); background: var(--color-primary-light); border-radius: 7px; padding: .3rem .45rem; font-size: .58rem; letter-spacing: .09em; font-weight: 900; }
.card-count { color: var(--color-text-secondary); font-size: .75rem; font-weight: 700; white-space: nowrap; }
.set-card h3 { font-size: 1.17rem; line-height: 1.3; margin: 1.1rem 0 .45rem; overflow-wrap: anywhere; }
.card-description { color: var(--color-text-secondary); font-size: .86rem; line-height: 1.5; margin: 0 0 1rem; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.card-tags { display: flex; flex-wrap: wrap; gap: .35rem; margin: auto 0 1.15rem; }
.card-tags span { border: 1px solid var(--color-border); color: var(--color-text-secondary); border-radius: 30px; padding: .24rem .55rem; font-size: .7rem; font-weight: 700; }
.set-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
/* Card and "Show more" buttons use the shared .main-action-button / .secondary-action-button */
.preview-button, .study-button, .load-more { font-size: .86rem; padding: .6rem 1rem; }
.study-button:disabled { cursor: wait; }

html.browse-preview-open { overflow: hidden; }
.set-preview { width: min(720px, calc(100% - 2rem)); max-width: none; max-height: 90vh; max-height: 90dvh; padding: 0; margin: auto; border: 1px solid var(--color-border); border-radius: var(--border-radius-card); background: var(--color-bg-secondary); color: var(--color-text-primary); box-shadow: var(--shadow-lg); overflow: hidden; }
.set-preview[open] { display: flex; flex-direction: column; animation: shared-modal-enter .2s ease both; }
.set-preview::backdrop { background: rgba(0, 0, 0, .6); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.preview-header { position: relative; flex: none; padding: 1.75rem 3.75rem 1.25rem 1.75rem; border-bottom: 1px solid var(--color-border); max-height: 40vh; max-height: 40dvh; overflow-y: auto; }
.preview-header h2 { margin: 0 0 .6rem; font-size: 1.5rem; line-height: 1.3; overflow-wrap: anywhere; }
.preview-header p { margin: 0; color: var(--color-text-secondary); font-size: .9rem; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.preview-close { position: absolute; top: 1rem; right: 1rem; display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--color-text-secondary); font-size: 1.75rem; cursor: pointer; }
.preview-close:hover { background: var(--color-primary-light); color: var(--color-text-primary); }
.preview-body { padding: 1.25rem 1.75rem 1.75rem; overflow-y: auto; overscroll-behavior: contain; }
.preview-status { margin: 0; color: var(--color-text-secondary); line-height: 1.6; }
.preview-columns, .preview-entry { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 1.5rem; }
.preview-columns { padding-bottom: .65rem; color: var(--color-text-secondary); font-size: .75rem; font-weight: 700; }
.preview-terms { margin: 0; }
.preview-entry { padding: 1rem 0; border-top: 1px solid var(--color-border); font-size: .9rem; line-height: 1.6; }
.preview-entry dt { font-weight: 700; }
.preview-entry dd { margin: 0; color: var(--color-text-secondary); }
.preview-entry dt, .preview-entry dd { white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 520px) {
  .preview-header { padding: 1.25rem 3.5rem 1rem 1.25rem; }
  .preview-body { padding: 1rem 1.25rem 1.25rem; }
  .preview-columns { display: none; }
  .preview-entry { grid-template-columns: 1fr; gap: .35rem; }
}
@media (prefers-reduced-motion: reduce) {
  .set-preview[open] { animation: none; }
}

.catalog-message { border: 1px dashed var(--color-border); border-radius: 20px; padding: 3rem 1.5rem; text-align: center; background: var(--color-bg-secondary); color: var(--color-text-secondary); }
.catalog-message p { margin: 0; }
.catalog-message a { display: inline-block; color: var(--color-primary); font-weight: 800; margin-top: .8rem; }
.more-wrap { text-align: center; margin-top: 1.75rem; }


.browse-footer {
  padding: 2rem 0 2.5rem;
  margin-top: 4rem;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  text-align: center;
}

.browse-footer p {
  margin: 0 0 0.75rem;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
}

.browse-footer .footer-link {
  color: inherit;
}

@media (max-width: 900px) {
  .set-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 670px) {
  .browse-header { min-height: 105px; flex-wrap: wrap; gap: .2rem 1rem; padding: .75rem 0; }
  .header-logo, #theme-toggle-button { top: 16px; }
  .quick-nav-cluster { top: 17px; }
  .brand img { width: 150px; }
  .top-links { order: 3; width: 100%; justify-content: space-between; gap: .5rem; margin: .2rem 0 0; }
  .top-links a { font-size: .8rem; }
  .theme-toggle { margin-left: auto; }
  .filter-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .search-field { grid-column: 1 / -1; }
  .set-grid { grid-template-columns: 1fr; }
  .set-card { min-height: 235px; }
}
@media (max-width: 430px) {
  .catalog-heading { align-items: start; }
  .catalog-create { font-size: .78rem; }
  .select-wrap > span { left: 12px; font-size: .72rem; }
  .select-wrap .tnq-select { padding-left: 46px; padding-right: 36px; background-position: right 13px center; font-size: .85rem; }
}
