:root {
  --canvas: #f4efe5;
  --paper: #fffdf8;
  --ink: #17324a;
  --muted: #61717e;
  --line: #d9d1c3;
  --accent: #2f6b9a;
  --accent-ink: #fff;
  --danger: #b42318;
  --success: #1e7a4d;
  --warning: #946200;
  --radius: 1.25rem;
  --radius-sm: 0.8rem;
  --shadow: 0 18px 55px rgb(36 55 70 / 0.10);
}

body {
  background-image: radial-gradient(circle at 12% 3%, rgb(47 107 154 / 0.12), transparent 28rem),
    linear-gradient(90deg, transparent 49.8%, rgb(23 50 74 / 0.03) 50%, transparent 50.2%);
}

main {
  width: min(1160px, calc(100% - 32px));
  margin: auto;
  padding-top: clamp(2rem, 5vw, 4rem);
  padding-bottom: 5rem;
}

.hero {
  display: grid;
  grid-template-columns: 1.25fr 0.75fr;
  align-items: end;
  gap: clamp(2rem, 5vw, 5rem);
  padding-bottom: 2rem;
}
.hero h1 {
  margin: 0;
  font-family: Georgia, serif;
  font-weight: 500;
  font-size: clamp(2.4rem, 5vw, 3.8rem);
  line-height: 1.05;
}
.hero h1 em {
  color: var(--accent);
  font-weight: 500;
}
.hero-copy {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

/* Exam Chips Bar (Mobile-First Touch Ergonomics) */
.exam-chips-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 25px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.exam-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transition: all 0.15s ease;
}
.exam-chip:hover {
  border-color: var(--accent);
  background: #eaf3f9;
  color: var(--accent);
}
.exam-chip:active {
  transform: scale(0.97);
}
.exam-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.library {
  display: grid;
  grid-template-columns: minmax(14rem, 18rem) 1fr;
  gap: 1.25rem;
  align-items: start;
}
.filter-panel, .shelf, .ethics-note {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgb(255 253 248 / 0.95);
  box-shadow: var(--shadow);
}
.filter-panel {
  position: sticky;
  top: 1rem;
  display: grid;
  gap: 0.9rem;
  padding: 1.25rem;
}
.filter-panel h2 {
  margin: 0 0 0.4rem;
  font-size: 1.35rem;
}
.filter-panel label {
  display: flex;
  flex-direction: column;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.filter-panel input, .filter-panel select {
  margin-top: 4px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  font-size: 1rem; /* 16px to prevent iOS Safari auto-zoom */
  font-weight: 600;
  color: var(--ink);
  touch-action: manipulation;
}

.shelf {
  min-width: 0;
  padding: clamp(1.2rem, 3vw, 2rem);
}
.shelf-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}
.shelf-header h2 {
  margin: 0;
  font-size: 1.6rem;
}
.shelf-header output {
  color: var(--accent);
  font-weight: 850;
}

.rights-key {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 1rem 0 1.3rem;
}
.rights-key span {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 99rem;
  padding: 0.25rem 0.65rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  background: white;
}
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.dot-orig { background: #1e7a4d; }
.dot-open { background: #2f6b9a; }
.dot-official { background: #d97706; }
.dot-demo { background: #6b7280; }

.resource-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.resource-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: white;
  padding: 1.25rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.resource-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(23, 50, 74, 0.08);
}
.resource-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.resource-meta span {
  border: 1px solid var(--line);
  border-radius: 99rem;
  padding: 0.2rem 0.55rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  background: #f8f9fa;
}

.cut-off-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 8px;
  border-radius: 6px;
  background: #fef3c7;
  border: 1px solid #fde68a;
  color: #92400e;
  font-size: 0.72rem;
  font-weight: 700;
}

.resource-card h3 {
  margin: 0.75rem 0 0.45rem;
  font-size: 1.15rem;
  line-height: 1.35;
}
.resource-card p.card-desc {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.provenance {
  margin-top: auto;
  border-top: 1px dashed var(--line);
  padding-top: 0.75rem;
}
.provenance p {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.85rem;
}
.card-actions > * {
  flex: 1;
}

.resource-action {
  display: inline-grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 0.65rem;
  background: var(--accent);
  padding: 0.5rem 0.85rem;
  color: white;
  font-size: 0.84rem;
  font-weight: 750;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, transform 0.15s ease;
}
.resource-action:hover {
  background: #1e4a6d;
}
.resource-action:active {
  transform: scale(0.97);
}

.resource-action-govt {
  display: inline-grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid #bae6fd;
  border-radius: 0.65rem;
  background: #f0f9ff;
  padding: 0.5rem 0.85rem;
  color: #0369a1;
  font-size: 0.82rem;
  font-weight: 700;
  text-decoration: none;
  text-align: center;
  touch-action: manipulation;
  transition: all 0.15s ease;
}
.resource-action-govt:hover {
  background: #e0f2fe;
  border-color: #7dd3fc;
  color: #0284c7;
}

/* In-Portal Document & PDF Reader Modal */
.paper-viewer-dialog {
  width: min(920px, calc(100% - 1.5rem));
  max-height: 90vh;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
  box-shadow: 0 25px 70px rgba(15, 23, 42, 0.25);
  overflow: hidden;
}
.paper-viewer-dialog::backdrop {
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
}
.viewer-shell {
  display: flex;
  flex-direction: column;
  height: 85vh;
  max-height: 850px;
}
.viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}
.viewer-header-info h2 {
  margin: 4px 0 2px;
  font-size: 1.15rem;
  font-family: Georgia, serif;
  color: var(--ink);
}
.viewer-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e0f2fe;
  color: #0369a1;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}
#viewer-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.viewer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.viewer-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}
.viewer-btn--official {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  color: #0284c7;
}
.viewer-btn--official:hover {
  background: #e0f2fe;
}
.viewer-btn--close {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
}
.viewer-btn--close:hover {
  background: #e2e8f0;
}
.viewer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f8fafc;
}
.doc-reader-text {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 20px;
  color: #1e293b;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 100%;
  margin: 0;
}
.pdf-frame-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.pdf-notice-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: #f1f5f9;
  border-radius: 8px 8px 0 0;
  font-size: 0.78rem;
  color: #475569;
}
.btn-external-pdf {
  font-weight: 750;
  color: #0284c7;
  text-decoration: none;
}
.pdf-iframe {
  flex: 1;
  width: 100%;
  min-height: 550px;
  border: 1px solid #cbd5e1;
  border-radius: 0 0 8px 8px;
  background: white;
}
.portal-info-box {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px 15px;
}
.portal-info-card {
  max-width: 550px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.04);
}
.portal-icon {
  font-size: 2.2rem;
  margin-bottom: 10px;
}
.portal-info-card h3 {
  margin: 0 0 8px;
  font-size: 1.2rem;
  color: #0f172a;
}
.portal-info-card p {
  color: #475569;
  font-size: 0.88rem;
  line-height: 1.55;
  margin: 0 0 14px;
}
.portal-meta-details {
  background: #f8fafc;
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  font-size: 0.8rem;
  color: #334155;
}
.portal-meta-details p {
  margin: 4px 0;
}
.preview-only {
  opacity: 0.55;
  cursor: not-allowed;
  background: #e2e8f0;
  color: #64748b;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 1rem;
  padding: 2.5rem;
  text-align: center;
  color: var(--muted);
}

.ethics-note {
  margin-top: 1.5rem;
  padding: clamp(1.3rem, 4vw, 2.5rem);
}
.ethics-note h2 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}
.ethics-note p {
  margin: 0;
  max-width: 60rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
}

/* Modal Dialog */
dialog {
  width: min(38rem, calc(100% - 2rem));
  border: 0;
  border-radius: 1.2rem;
  padding: 2rem;
  color: var(--ink);
  box-shadow: 0 30px 90px rgb(15 32 48 / 0.35);
}
dialog::backdrop {
  background: rgb(10 29 44 / 0.62);
  backdrop-filter: blur(4px);
}
.dialog-close {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  background: transparent;
  border: none;
  color: var(--ink);
  font-size: 1.5rem;
  cursor: pointer;
  touch-action: manipulation;
}
.detail-facts {
  display: grid;
  grid-template-columns: 8rem 1fr;
  gap: 0.65rem 1rem;
  margin: 1.5rem 0;
  font-size: 0.85rem;
}
.detail-facts dt {
  color: var(--muted);
  font-weight: 700;
}
.detail-facts dd {
  margin: 0;
  color: var(--ink);
  font-weight: 600;
}

/* Available Papers & Answer Keys inside Details Dialog */
.detail-papers-section {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px dashed var(--line);
}
.detail-papers-heading {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
  font-family: Georgia, serif;
  color: var(--ink);
}
.detail-papers-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.paper-item-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  flex-wrap: wrap;
}
.paper-item-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 170px;
}
.paper-item-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  width: fit-content;
}
.paper-item-title {
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink);
  font-weight: 700;
}
.paper-item-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.btn-view-sm {
  min-height: 40px;
  padding: 6px 14px;
  font-size: 0.82rem;
  border-radius: 8px;
}
.btn-govt-sm {
  min-height: 40px;
  padding: 6px 14px;
  font-size: 0.8rem;
  border-radius: 8px;
}
.btn-card-details {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.88rem;
}

/* Monetization Slot */
.ad-slot {
  margin: 35px 0 25px;
}
.ad-container {
  position: relative;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: #fafbfc;
  padding: 22px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.ad-badge {
  position: absolute;
  top: -10px;
  left: 20px;
  background: var(--accent);
  color: white;
  font-size: 0.65rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}
.ad-placeholder {
  display: flex;
  width: 100%;
  justify-content: space-between;
  align-items: center;
  gap: 15px;
}
.ad-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
}
.ad-cta {
  padding: 8px 16px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-size: 0.82rem;
  font-weight: 750;
  white-space: nowrap;
}

.site-footer {
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.6;
}

/* Responsive Media Queries */
@media (max-width: 52rem) {
  .hero, .library {
    grid-template-columns: 1fr;
  }
  .filter-panel {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .filter-panel > div, .filter-panel > button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 38rem) {
  main {
    padding-top: 15px;
    width: min(100% - 1.25rem, 1160px);
  }
  .hero {
    padding-bottom: 1rem;
    gap: 10px;
  }
  .hero h1 {
    font-size: clamp(1.35rem, 5.2vw, 1.7rem);
    line-height: 1.22;
    text-wrap: pretty;
  }
  .resource-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .resource-card {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }
  .card-actions {
    flex-direction: column;
    width: 100%;
    gap: 6px;
  }
  .card-actions > * {
    width: 100%;
  }
  .viewer-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }
  .viewer-actions {
    width: 100%;
    justify-content: space-between;
  }
  .viewer-body {
    padding: 12px;
  }
  .filter-panel {
    grid-template-columns: 1fr;
  }
  .shelf-header {
    align-items: start;
    flex-direction: column;
  }
  .detail-facts {
    grid-template-columns: 1fr;
  }
  .ad-placeholder {
    flex-direction: column;
    align-items: flex-start;
  }
}
