/* ==================================================================
   Thư viện đề thi THPT - giao diện trang chủ
   Chỉ dùng cho index.html. Các file đề giữ CSS riêng để không bị ảnh hưởng.
   ================================================================== */

:root {
  --bg: #eef2f8;
  --card: #ffffff;
  --ink: #172033;
  --muted: #5b6577;
  --line: #dbe2ee;
  --brand: #4338ca;
  --brand-dark: #312e81;
  --brand-soft: #eef0ff;
  --ok: #15803d;
  --ok-soft: #e8f7ee;
  --warn: #b45309;
  --warn-soft: #fff6e5;
  --shadow: 0 10px 30px rgba(23, 32, 51, .08);
  --shadow-lg: 0 18px 44px rgba(23, 32, 51, .14);
  --radius: 18px;
  --accent: var(--brand);
  --accent-soft: var(--brand-soft);
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}

h1, h2, h3, p, dl, dd, dt { margin: 0; }
a { color: inherit; }

.wrap {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding-left: 20px;
  padding-right: 20px;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 10px;
  background: #fff;
  color: var(--brand);
  font-weight: 800;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: top .15s;
}
.skip-link:focus { top: 12px; }

/* ---------------- Hero ---------------- */
.hero {
  position: relative;
  overflow: hidden;
  color: #fff;
  background:
    radial-gradient(900px 420px at 88% -10%, rgba(129, 140, 248, .55), transparent 62%),
    radial-gradient(700px 380px at 0% 110%, rgba(14, 165, 233, .30), transparent 60%),
    linear-gradient(135deg, #312e81 0%, #4338ca 52%, #4f46e5 100%);
  padding: 40px 0 30px;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .16;
  background-image:
    linear-gradient(rgba(255, 255, 255, .35) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .35) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, .8), transparent 78%);
  -webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, .8), transparent 78%);
}
.hero .wrap { position: relative; z-index: 1; }

.hero-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 58px;
  height: 58px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .28);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25);
  font-size: .74rem;
  font-weight: 900;
  letter-spacing: .06em;
}
.eyebrow {
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: #c7d2fe;
}
.hero h1 {
  margin-top: 4px;
  font-size: clamp(1.65rem, 4vw, 2.35rem);
  line-height: 1.15;
  letter-spacing: -.02em;
}

.hero-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.hero-stats .stat {
  min-width: 84px;
  padding: 8px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .22);
  backdrop-filter: blur(4px);
}
.hero-stats dt {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: #c7d2fe;
}
.hero-stats dd {
  margin-top: 1px;
  font-size: 1.15rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.lede {
  max-width: 720px;
  margin-top: 18px;
  color: #e0e7ff;
  font-size: .98rem;
}

/* ---------------- Search ---------------- */
.searchbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
  padding: 5px 8px 5px 16px;
  background: #fff;
  color: var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255, 255, 255, .6);
  transition: box-shadow .15s;
}
.searchbar:focus-within {
  box-shadow: 0 0 0 4px rgba(199, 210, 254, .55), var(--shadow-lg);
}
.search-icon { flex: none; color: var(--muted); }
#search {
  flex: 1;
  min-width: 0;
  padding: 11px 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}
#search:focus { outline: none; }
#search::-webkit-search-cancel-button { display: none; }
.clear-search {
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 9px;
  background: #eef1f7;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}
.clear-search:hover { background: #e2e7f1; color: var(--ink); }

/* ---------------- Subject filters ---------------- */
.filters {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.filter {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 7px 15px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .3);
  background: rgba(255, 255, 255, .10);
  color: #eef2ff;
  font: inherit;
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.filter:hover { background: rgba(255, 255, 255, .2); }
.filter[aria-pressed="true"] {
  background: #fff;
  border-color: #fff;
  color: var(--brand-dark);
}
.filter .n {
  font-size: .74rem;
  font-weight: 900;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .18);
}
.filter[aria-pressed="true"] .n { background: var(--brand-soft); color: var(--brand); }

/* ---------------- Main / results ---------------- */
main.wrap { padding-top: 26px; padding-bottom: 40px; }

.result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.result-count {
  color: var(--muted);
  font-size: .86rem;
  font-weight: 600;
}

.subject {
  margin-bottom: 34px;
  scroll-margin-top: 16px;
}
.subject-head {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  margin-bottom: 14px;
}
.subject-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(67, 56, 202, .12);
  font-size: 1.2rem;
  font-weight: 900;
}
.subject-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  font-size: 1.22rem;
  letter-spacing: -.01em;
}
.subject-count {
  font-size: .76rem;
  font-weight: 800;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 9px;
}
.subject-desc {
  margin-top: 3px;
  color: var(--muted);
  font-size: .88rem;
}

.exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 15px;
}

.exam-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: transform .16s, box-shadow .16s, border-color .16s;
}
.exam-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 18px;
  bottom: 18px;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--accent);
  opacity: .85;
}
.exam-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: #c7d2fe;
}
.exam-card:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}
.exam-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.exam-subject {
  font-size: .74rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--accent);
}
.exam-mode {
  font-size: .72rem;
  font-weight: 800;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid #bbebc9;
}
.exam-mode.exam { background: var(--warn-soft); color: var(--warn); border-color: #f0d6a4; }
.exam-title {
  font-size: 1.1rem;
  line-height: 1.3;
  letter-spacing: -.01em;
}
.exam-desc {
  color: var(--muted);
  font-size: .88rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.exam-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}
.chip {
  font-size: .76rem;
  font-weight: 700;
  color: var(--muted);
  background: #f4f6fb;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
}
.exam-open {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: .84rem;
  font-weight: 800;
  color: var(--accent);
}
.exam-open .arrow { transition: transform .16s; }
.exam-card:hover .exam-open .arrow { transform: translateX(3px); }

.subject-empty {
  border: 1.5px dashed #c9d3e6;
  border-radius: var(--radius);
  padding: 20px;
  color: var(--muted);
  font-size: .9rem;
  background: rgba(255, 255, 255, .45);
}
.subject-empty b { color: var(--ink); }

/* ---------------- Empty / info / footer ---------------- */
.empty {
  padding: 34px 22px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.empty-title { font-size: 1.1rem; font-weight: 800; margin-bottom: 4px; }
.empty p { color: var(--muted); font-size: .9rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 18px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: #f4f6fb; }
.btn.small { min-height: 36px; padding: 6px 14px; font-size: .86rem; }
.empty .btn { margin-top: 14px; }

.info {
  margin-top: 10px;
  padding: 26px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.info h2 { font-size: 1.15rem; letter-spacing: -.01em; }
.info-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 22px;
  margin-top: 16px;
}
.info h3 { font-size: .93rem; margin-bottom: 4px; }
.info p { color: var(--muted); font-size: .87rem; }

.offline-note {
  margin-top: 20px;
  padding: 10px 14px;
  border-radius: 11px;
  background: #f4f6fb;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: .82rem;
}
.offline-note[data-state="ready"] { background: var(--ok-soft); border-color: #b8e5c6; color: #166534; }
.offline-note[data-state="limited"] { background: var(--warn-soft); border-color: #f6d9a8; color: #7c4a03; }

.footer {
  padding: 24px 0 34px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .5);
  color: var(--muted);
  font-size: .82rem;
}
.footer p + p { margin-top: 4px; }
.footer strong { color: var(--ink); }

.noscript {
  margin: 20px auto;
  padding: 14px 18px;
  background: var(--warn-soft);
  border: 1px solid #f6d9a8;
  border-radius: 12px;
}

.update-toast {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 14px;
  width: calc(100% - 32px);
  max-width: 440px;
  padding: 12px 14px 12px 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  font-size: .88rem;
  font-weight: 700;
}
.update-toast[hidden] { display: none; }
.update-toast button { margin-left: auto; flex: none; }

@media (max-width: 860px) {
  .info-grid { grid-template-columns: 1fr; gap: 16px; }
}

@media (max-width: 620px) {
  .wrap { padding-left: 14px; padding-right: 14px; }
  .hero { padding: 28px 0 24px; }
  .brand-mark { width: 50px; height: 50px; border-radius: 14px; font-size: .68rem; }
  .hero-stats { width: 100%; }
  .hero-stats .stat { flex: 1 1 0; min-width: 0; text-align: center; padding: 7px 8px; }
  .hero-stats dd { font-size: 1.05rem; }
  .lede { margin-top: 14px; font-size: .92rem; }
  .searchbar { margin-top: 18px; }
  main.wrap { padding-top: 20px; }
  .subject { margin-bottom: 28px; }
  .exam-grid { grid-template-columns: 1fr; }
  .exam-card { padding: 17px 17px 16px; }
  .info { padding: 20px 18px; }
  .footer { font-size: .78rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}
