:root {
  --ink: #13211f;
  --muted: #63706b;
  --paper: #f7f3e8;
  --surface: #fffdf7;
  --teal: #0f5c5c;
  --teal-dark: #0a3738;
  --gold: #c89a3c;
  --rose: #b86f58;
  --line: rgba(19, 33, 31, 0.12);
  --shadow: 0 22px 70px rgba(10, 55, 56, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: "Tajawal", Arial, sans-serif;
  line-height: 1.7;
}

body.support-popup-lock {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

.support-popup {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 24, 24, 0.64);
  backdrop-filter: blur(7px);
}

.support-popup[hidden] {
  display: none;
}

.support-popup__card {
  width: min(680px, 100%);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  padding: clamp(22px, 4vw, 36px);
  border: 1px solid rgba(200, 154, 60, 0.35);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(15, 92, 92, 0.08), rgba(200, 154, 60, 0.1)),
    var(--surface);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.32);
  text-align: right;
}

.support-popup h2 {
  margin: 0 0 16px;
  color: var(--teal-dark);
  font-size: clamp(1.8rem, 5vw, 2.7rem);
}

.support-popup__text {
  display: grid;
  gap: 10px;
}

.support-popup__text p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.08rem);
  line-height: 1.9;
}

.support-popup__details {
  display: grid;
  gap: 12px;
  margin-top: 22px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.52);
}

.support-popup__details strong {
  color: var(--teal);
  font-weight: 800;
}

.support-popup__details p {
  margin: 4px 0 0;
  color: var(--ink);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.support-popup__actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-top: 20px;
}

.support-popup__button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--teal-dark);
  background: rgba(255, 255, 255, 0.78);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
}

.support-popup__button--primary {
  border-color: transparent;
  color: #211806;
  background: var(--gold);
  box-shadow: 0 14px 30px rgba(200, 154, 60, 0.26);
}

.support-popup__button:hover,
.support-popup__button:focus {
  transform: translateY(-1px);
}

.site-header {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px clamp(18px, 4vw, 56px);
  color: #fff;
  background: linear-gradient(180deg, rgba(8, 27, 27, 0.72), rgba(8, 27, 27, 0));
}

.brand,
.main-nav {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.brand-mark {
  display: block;
  width: 38px;
  height: 38px;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.34));
}

.main-nav {
  gap: 20px;
  font-size: 0.98rem;
  font-weight: 700;
}

.main-nav a {
  opacity: 0.9;
}

.main-nav a:hover,
.main-nav a:focus {
  opacity: 1;
}

.hero {
  position: relative;
  display: grid;
  min-height: 92vh;
  place-items: center;
  overflow: hidden;
  padding: 116px 18px 72px;
  color: #fff;
}

.hero-media,
.hero-overlay {
  position: absolute;
  inset: 0;
}

.hero-media {
  background-image: url("https://ik.imagekit.io/moadalhmre/libyan-digital-archive/assets/library-hero.webp?tr=w-1600,q-75,f-webp");
  background-position: center;
  background-size: cover;
  transform: scale(1.02);
}

.hero-overlay {
  background:
    radial-gradient(circle at 50% 48%, rgba(12, 44, 45, 0.18), rgba(8, 24, 24, 0.74) 66%),
    linear-gradient(180deg, rgba(7, 20, 20, 0.22), rgba(7, 20, 20, 0.78));
}

.hero-content {
  position: relative;
  z-index: 1;
  width: min(980px, 100%);
  text-align: center;
}

.eyebrow,
.section-kicker,
.book-meta {
  margin: 0 0 8px;
  color: var(--gold);
  font-weight: 800;
}

.libya-flag-mark {
  position: relative;
  display: inline-block;
  width: 1.55em;
  height: 1.05em;
  margin-right: 0.35em;
  overflow: hidden;
  border-radius: 2px;
  background: linear-gradient(180deg, #e70013 0 25%, #050505 25% 75%, #239e46 75% 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.42), 0 4px 10px rgba(0, 0, 0, 0.18);
  vertical-align: -0.16em;
}

.libya-flag-mark::before {
  position: absolute;
  top: 50%;
  left: 45%;
  width: 0.48em;
  height: 0.48em;
  border-radius: 999px;
  box-shadow: -0.11em 0 0 0.08em #fff;
  content: "";
  transform: translate(-50%, -50%);
}

.libya-flag-mark::after {
  position: absolute;
  top: 50%;
  left: 61%;
  color: #fff;
  content: "★";
  font-size: 0.34em;
  line-height: 1;
  transform: translate(-50%, -50%);
}

.hero h1 {
  max-width: 920px;
  margin: 0 auto;
  font-size: clamp(2.2rem, 6vw, 5.4rem);
  line-height: 1.12;
  letter-spacing: 0;
}

.hero h1 > span {
  display: block;
}

.intro {
  max-width: 720px;
  margin: 22px auto 0;
  color: rgba(255, 255, 255, 0.88);
  font-size: clamp(1rem, 2vw, 1.28rem);
}

.bubble-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  margin-top: 34px;
}

.bubble {
  display: inline-grid;
  min-width: 124px;
  min-height: 124px;
  place-items: center;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 999px;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.2);
  font-size: 1.16rem;
  font-weight: 800;
  backdrop-filter: blur(14px);
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.bubble:hover,
.bubble:focus {
  transform: translateY(-5px);
  border-color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.24);
}

.bubble-primary {
  background: rgba(200, 154, 60, 0.9);
  color: #211806;
}

.rights-notice {
  width: min(780px, 100%);
  margin: -28px auto 54px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 44px rgba(19, 33, 31, 0.08);
  color: var(--ink);
  text-align: right;
}

.rights-notice strong {
  display: block;
  margin-bottom: 6px;
  color: var(--gold);
  font-size: 1rem;
}

.rights-notice p {
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.75;
}

.rights-notice p + p {
  margin-top: 8px;
}

.rights-notice a {
  color: var(--teal);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.search-band,
.language-hub,
.book-grid,
.support-section,
.about {
  width: min(1180px, calc(100% - 36px));
  margin-inline: auto;
}

#languages,
#library,
#support,
#about {
  scroll-margin-top: 110px;
}

.language-hub {
  margin-top: 42px;
  padding: clamp(26px, 5vw, 48px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(15, 92, 92, 0.08), rgba(184, 111, 88, 0.08)),
    var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.language-hub[hidden] {
  display: none;
}

.search-band[hidden],
.book-grid[hidden] {
  display: none;
}

.language-hub h2 {
  margin-bottom: 10px;
}

.language-hub > p:last-of-type {
  color: var(--muted);
}

.language-bubbles {
  display: grid;
  gap: 16px;
  margin-top: 28px;
}

.language-bubbles-main {
  grid-template-columns: repeat(6, minmax(118px, 1fr));
  max-width: none;
  margin-inline: auto;
}

.language-bubbles-secondary {
  grid-template-columns: repeat(3, minmax(150px, 220px));
  justify-content: center;
}

.category-bubbles {
  grid-template-columns: repeat(6, minmax(112px, 1fr));
}

.language-subgroup {
  margin-top: 30px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 110px;
}

.language-subgroup[hidden] {
  display: none;
}

.language-subgroup h3 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 3vw, 1.65rem);
}

.language-bubble {
  position: relative;
  display: grid;
  min-height: 138px;
  place-items: center;
  overflow: hidden;
  padding: 18px;
  border-radius: 999px;
  color: #fff;
  box-shadow: 0 16px 38px rgba(19, 33, 31, 0.15);
  font-weight: 800;
  isolation: isolate;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.language-bubble::before {
  position: absolute;
  inset: 0;
  z-index: -2;
  content: "";
}

.language-bubble::after {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.2), rgba(0, 0, 0, 0.2));
  content: "";
}

.language-bubble:hover,
.language-bubble:focus,
.language-bubble.is-active {
  transform: translateY(-5px);
  box-shadow: 0 22px 52px rgba(19, 33, 31, 0.22);
}

.language-bubble span {
  display: inline-flex;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.28);
  line-height: 1.35;
}

.language-ar::before {
  background: linear-gradient(180deg, #e70013 0 28%, #050505 28% 72%, #239e46 72% 100%);
}

.language-libya::before {
  background: linear-gradient(180deg, #e70013 0 28%, #050505 28% 72%, #239e46 72% 100%);
}

.language-other::before {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.12) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1) 1px, transparent 1px),
    radial-gradient(circle at 28% 32%, rgba(200, 154, 60, 0.9) 0 8%, transparent 9%),
    radial-gradient(circle at 72% 68%, rgba(184, 111, 88, 0.86) 0 7%, transparent 8%),
    linear-gradient(135deg, #102d31, #0f5c5c 48%, #263b4d);
  background-size: 26px 26px, 26px 26px, auto, auto, auto;
}

.language-saudi::before {
  background: #006c35;
}

.language-saudi::after {
  background: radial-gradient(circle, rgba(255, 255, 255, 0.12), rgba(0, 0, 0, 0.16));
  content: "";
}

.language-saudi span {
  transform: none;
}

.language-ar span::before {
  margin-left: 8px;
  color: #fff;
  content: "☪";
}

.language-en::before {
  background:
    linear-gradient(90deg, transparent 0 38%, #fff 38% 44%, #c8102e 44% 56%, #fff 56% 62%, transparent 62% 100%),
    linear-gradient(180deg, transparent 0 36%, #fff 36% 43%, #c8102e 43% 57%, #fff 57% 64%, transparent 64% 100%),
    linear-gradient(32deg, transparent 0 42%, #fff 42% 49%, #c8102e 49% 53%, #fff 53% 60%, transparent 60% 100%),
    linear-gradient(148deg, transparent 0 42%, #fff 42% 49%, #c8102e 49% 53%, #fff 53% 60%, transparent 60% 100%),
    #012169;
}

.language-fr::before {
  background: linear-gradient(90deg, #0055a4 0 33.3%, #fff 33.3% 66.6%, #ef4135 66.6% 100%);
}

.language-it::before {
  background: linear-gradient(90deg, #009246 0 33.3%, #fff 33.3% 66.6%, #ce2b37 66.6% 100%);
}

.language-tr::before {
  background: #e30a17;
}

.language-tr span::before {
  margin-left: 8px;
  color: #fff;
  content: "☪";
}

.search-band {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 420px);
  gap: 24px;
  align-items: center;
  padding: 42px 0 24px;
}

h2,
h3,
p {
  margin-top: 0;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(1.75rem, 4vw, 2.65rem);
  line-height: 1.25;
}

.search-band p,
.book-card p,
.content-split p,
.about p {
  color: var(--muted);
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  outline: none;
}

.search-box input {
  height: 58px;
  padding: 0 18px;
  box-shadow: var(--shadow);
}

.search-box input:focus {
  border-color: var(--teal);
}

.book-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  padding: 20px 0 54px;
}

.book-card {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr;
  gap: 24px;
  align-items: start;
  min-height: 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 40px rgba(19, 33, 31, 0.08);
}

.empty-library {
  margin: 0;
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.75);
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.empty-library[hidden] {
  display: none;
}

.load-more-books {
  grid-column: 1 / -1;
  justify-self: center;
  min-width: 150px;
  padding: 12px 22px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, var(--teal), var(--ink));
  box-shadow: 0 10px 24px rgba(19, 33, 31, 0.16);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
}

.load-more-books[hidden] {
  display: none;
}

.book-cover {
  margin: 0;
  overflow: hidden;
  border-radius: 6px;
  background: #f6efe2;
  box-shadow: 0 14px 30px rgba(19, 33, 31, 0.16);
}

.book-cover img {
  display: block;
  width: 100%;
  height: auto;
  margin: 0;
  object-fit: initial;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.book-cover img.is-loaded {
  opacity: 1;
}

.book-cover-placeholder {
  display: grid;
  min-height: 280px;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, var(--teal), var(--rose));
  font-weight: 800;
}

.book-card h3 {
  display: none;
}

.book-card .book-meta {
  display: none;
}

.book-details {
  display: grid;
  gap: 12px;
}

.book-info {
  display: grid;
  gap: 8px;
  margin: 0;
}

.book-info div {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.book-info dt {
  color: var(--teal);
  font-weight: 800;
}

.book-info dd {
  margin: 0;
  color: var(--ink);
}

.book-summary {
  margin-bottom: 0;
}

.book-summary strong {
  color: var(--ink);
}

.download-btn,
.text-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border-radius: 8px;
  font-weight: 800;
}

.download-btn {
  grid-column: 2;
  border: 0;
  color: #fff;
  background: var(--teal);
  cursor: pointer;
}

.download-btn:hover,
.text-link:hover {
  background: var(--teal-dark);
  color: #fff;
}

.support-section {
  padding-bottom: 56px;
}

.support-panel,
.about {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 44px rgba(19, 33, 31, 0.08);
}

.support-panel {
  padding: clamp(22px, 4vw, 36px);
}

.support-contacts {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.support-contacts p {
  margin: 0;
  color: var(--ink);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.text-link {
  width: fit-content;
  padding: 0 18px;
  color: var(--teal);
  border: 1px solid var(--teal);
}

.about {
  margin-bottom: 54px;
  padding: clamp(24px, 5vw, 46px);
}

.support-panel .section-kicker,
.about .about-kicker {
  color: #c89a3c !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.is-hidden {
  display: none;
}

@media (max-width: 860px) {
  .site-header {
    position: static;
    z-index: auto;
    top: auto;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding: 14px 18px;
    background: linear-gradient(180deg, rgba(8, 27, 27, 0.96), rgba(10, 55, 56, 0.92));
  }

  .main-nav {
    width: 100%;
    justify-content: space-between;
    gap: 10px;
    font-size: 0.92rem;
  }

  .support-popup__card {
    max-height: calc(100svh - 28px);
    padding: 20px;
  }

  .support-popup__actions {
    grid-template-columns: 1fr;
  }

  .hero {
    min-height: 88vh;
    padding-top: 72px;
  }

  .hero-media {
    background-image: url("https://ik.imagekit.io/moadalhmre/libyan-digital-archive/assets/library-hero-mobile.webp?tr=w-850,q-70,f-webp");
    background-position: center center;
    background-size: cover;
  }

  #languages,
  #library,
  #support,
  #about {
    scroll-margin-top: 20px;
  }

  .bubble {
    min-width: 104px;
    min-height: 104px;
    font-size: 1rem;
  }

  .search-band,
  .language-bubbles,
  .category-bubbles {
    grid-template-columns: 1fr;
  }

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

  .book-card {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .download-btn {
    grid-column: auto;
  }

  .book-info div {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

@media (max-width: 520px) {
  .site-header {
    padding-inline: 14px;
  }

  .brand {
    width: 100%;
    font-size: 0.95rem;
    white-space: normal;
  }

  .brand span:last-child {
    line-height: 1.3;
  }

  .main-nav a {
    padding: 6px 0;
  }

  .hero h1 {
    max-width: 100%;
    font-size: 1.78rem;
    line-height: 1.22;
    overflow-wrap: anywhere;
  }

  .intro {
    max-width: 100%;
    font-size: 0.98rem;
  }

  .bubble-actions {
    display: grid;
    grid-template-columns: repeat(3, 88px);
    justify-content: center;
    gap: 10px;
  }

  .bubble {
    min-width: 88px;
    min-height: 88px;
    padding: 12px;
    font-size: 0.95rem;
  }
}
