*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --bg: #f5f2ee;
    --surface: #ece8e1;
    --paper: #fdfbf8;
    --border: #dcd6cd;
    --green: #1d6b46;
    --red: #a33d32;
    --text: #20251f;
    --text-dim: #51574f;
    --text-muted: #64675e;
    --serif: 'Playfair Display', Georgia, serif;
    --sans: 'Inter', system-ui, -apple-system, sans-serif;
    --arabic: 'Noto Naskh Arabic', 'Geeza Pro', serif;
}
html { scroll-behavior: smooth; scrollbar-gutter: stable; }
body { font-family: var(--sans); background: var(--bg); color: var(--text); min-height: 100vh; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
a { color: var(--green); text-underline-offset: 4px; }
a:hover { text-decoration-thickness: 2px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0 !important; margin: -1px !important; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 3px solid var(--green); outline-offset: 4px; }
#storyName:focus, #galleryFallback:focus, #memorialStory:focus, #aboutArchive:focus { outline: none; }
.skip-link { position: absolute; top: 12px; left: 12px; z-index: 80; padding: 12px 16px; background: #fff; border-radius: 6px; transform: translateY(-180%); }
.skip-link:focus { transform: translateY(0); }

/* A quiet masthead keeps the stories within the first screen. */
.site-nav { max-width: 1328px; margin: 0 auto; padding: 18px 24px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.site-wordmark { color: var(--text); font-family: var(--serif); font-weight: 700; font-size: 1rem; text-decoration: none; }
.nav-links { display: flex; align-items: center; gap: 24px; font-size: 0.8rem; }
.nav-links > a { min-height: 44px; display: inline-flex; align-items: center; color: var(--text-dim); }
.pdf-access-button { border: 1px solid var(--border); border-radius: 999px; padding: 9px 16px; text-decoration: none; }
.pdf-access-button:hover { background: var(--surface); }
.hero { text-align: center; max-width: 820px; padding: 24px 24px 30px; margin: 0 auto; }
.hero-title { font-family: var(--serif); font-size: clamp(2.45rem, 5.2vw, 4.25rem); font-weight: 700; letter-spacing: -0.035em; line-height: 1.13; margin-bottom: 18px; }
.hero-divider { width: 34px; height: 2px; background: var(--green); margin: 0 auto 16px; }
.hero-arabic { font-family: var(--arabic); font-size: clamp(1.15rem, 2vw, 1.5rem); color: var(--red); line-height: 1.7; margin-bottom: 10px; }
.hero-english { font-size: 0.95rem; color: var(--text-dim); line-height: 1.7; max-width: 590px; margin: 0 auto; }

/* A quiet count and ordering control introduce the archive. */
#galleryFallback { max-width: 1328px; margin: 0 auto; padding: 0 24px 64px; }
.gallery-tools { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin: 0 0 20px; padding-top: 12px; border-top: 1px solid var(--border); }
.sort-group { display: flex; align-items: center; gap: 12px; }
.gallery-tools label { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; }
#storySort { width: 150px; min-height: 44px; padding: 10px 13px; color: var(--text); border: 1px solid #aaa99f; border-radius: 8px; background: var(--paper); font-size: 0.85rem; }
#storySort { padding-right: 28px; cursor: pointer; }
#storySort:disabled { opacity: 0.65; }
.result-count { min-height: 1.5em; font-size: 0.8rem; color: var(--text-muted); }
.gallery-message { max-width: 640px; margin: 24px auto; padding: 20px; text-align: center; line-height: 1.7; color: var(--text-dim); }
.message-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 18px; margin-top: 16px; }
#staticStoryList ul { columns: 3 200px; list-style: none; }
#staticStoryList li { break-inside: avoid; padding: 10px; line-height: 1.5; }

/* Names remain visible; original photographs fit within their frames. */
#imageGrid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: stretch; gap: 26px 22px; }
.image-container { min-width: 0; overflow: hidden; border-radius: 10px; border: 1px solid var(--border); background: var(--paper); display: flex; flex-direction: column; color: var(--text); text-decoration: none; transition: border-color 160ms, box-shadow 160ms; }
.image-container:hover { border-color: #9caa98; box-shadow: 0 5px 18px #1b30200b; }
.portrait-frame { display: block; aspect-ratio: 1; overflow: hidden; background: #e8e3db; }
.portrait-frame img { width: 100%; height: 100%; object-fit: contain; display: block; }
.name-overlay { display: block; font-family: var(--serif); font-size: 1.05rem; font-weight: 700; line-height: 1.4; padding: 14px 16px 16px; overflow-wrap: anywhere; }
.name-arabic { font-family: var(--arabic); font-weight: 400; font-size: 1.1rem; display: block; color: var(--text-dim); line-height: 1.6; }
.image-container > .name-arabic { padding: 0 16px 14px; margin-top: -8px; }
.image-fallback { object-fit: contain !important; }

/* Native modal and continuous reading. */
.modal-dialog { inset: 0; margin: auto; padding: 0; width: min(960px, calc(100% - 40px)); max-width: none; max-height: calc(100dvh - 40px); border: 1px solid var(--border); border-radius: 16px; background: var(--paper); color: var(--text); box-shadow: 0 24px 80px #0005; overflow: auto; }
.modal-dialog:not([open]) { display: none; }
.modal-dialog::backdrop { background: #131a13bf; backdrop-filter: blur(4px); }
.modal-layout { display: grid; grid-template-columns: 40% minmax(0, 1fr); max-height: calc(100dvh - 42px); }
.modal-image-panel { background: #e5dfd5; display: flex; align-items: center; justify-content: center; min-height: 0; }
.modal-image-panel img { width: 100%; height: 100%; max-height: calc(100dvh - 42px); object-fit: contain; display: block; }
.modal-text-panel { min-width: 0; min-height: 0; overflow-y: auto; padding: 40px 30px 22px; overscroll-behavior: contain; }
.modal-name { font-family: var(--serif); font-size: 1.7rem; font-weight: 700; margin-bottom: 18px; line-height: 1.25; padding-right: 20px; overflow-wrap: anywhere; }
.modal-name .name-arabic { margin-top: 10px; }
.modal-bio, .story-page-bio { color: var(--text-dim); font-size: 0.95rem; line-height: 1.85; }
.modal-bio p, .story-page-bio p { margin-bottom: 1em; }
.modal-close { position: absolute; top: 10px; right: 10px; background: var(--paper); border: 1px solid #babdb0; color: var(--text); width: 44px; height: 44px; border-radius: 50%; cursor: pointer; font-size: 18px; display: grid; place-items: center; z-index: 1; }
.modal-close:hover { background: var(--surface); }
.text-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 44px; padding: 10px 14px; border: 1px solid #78947e; border-radius: 7px; background: transparent; color: var(--green); cursor: pointer; font-size: 0.8rem; font-weight: 500; line-height: 1.3; text-decoration: none; }
.text-button:hover:not(:disabled) { background: #eaf0e8; }
.text-button:disabled { color: #73766d; border-color: var(--border); opacity: 0.65; cursor: default; }
.story-actions { display: flex; gap: 12px 18px; align-items: center; flex-wrap: wrap; margin-top: 20px; font-size: 0.8rem; }
.share-status { min-height: 1.5em; margin-top: 8px; color: var(--text-dim); font-size: 0.8rem; line-height: 1.5; }
.story-sources { margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 0.78rem; color: var(--text-muted); line-height: 1.7; overflow-wrap: anywhere; }
.story-sources p { margin-bottom: 5px; }
.story-sources ul { list-style: none; padding: 0; }
.story-sources li { margin-bottom: 7px; }
.story-sources a { text-decoration-thickness: 1px; }
.story-navigation { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; padding-top: 20px; border-top: 1px solid var(--border); }
.story-position { color: var(--text-muted); font-size: 0.72rem; text-align: center; line-height: 1.4; }
.story-navigation .text-button { padding: 10px; }

/* Full story pages are readable without JavaScript and print cleanly. */
.memorial-story { max-width: 1220px; padding: 24px 32px 48px; margin: 0 auto; }
.back-link { display: inline-block; font-size: 0.83rem; margin: 0 0 24px; text-decoration: none; min-height: 30px; }
.story-page-layout { display: grid; grid-template-columns: minmax(0, 42%) minmax(0, 1fr); align-items: start; gap: 48px; }
.story-page-portrait { position: sticky; top: 24px; background: var(--surface); border-radius: 12px; overflow: hidden; }
.story-page-portrait img { width: 100%; height: auto; max-height: 76dvh; object-fit: contain; display: block; }
.eyebrow { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.13em; text-transform: uppercase; color: var(--green); margin-bottom: 14px; }
.story-page-content h1 { font-family: var(--serif); font-size: clamp(1.9rem, 3.4vw, 2.8rem); font-weight: 700; line-height: 1.18; letter-spacing: -0.02em; overflow-wrap: anywhere; margin-bottom: 22px; }
.story-page-content > .name-arabic { font-size: 1.6rem; margin: -8px 0 24px; }
.story-page-bio { font-size: 1rem; line-height: 1.9; }
.archive-context { color: var(--text-muted); font-size: 0.75rem; line-height: 1.7; margin-top: 12px; }
.story-page-navigation { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: start; gap: 24px; margin-top: 48px; border-top: 1px solid var(--border); padding-top: 24px; }
.story-page-navigation a { display: flex; flex-direction: column; gap: 8px; max-width: 320px; font-size: 0.9rem; line-height: 1.6; min-height: 44px; text-decoration: none; }
.story-page-navigation a span { font-size: 0.75rem; color: var(--text-muted); }
.next-story { text-align: right; }
.next-story a { margin-left: auto; }
.story-page-navigation .story-position { padding-top: 5px; }
.story-page-footer { padding: 30px 24px 36px; border-top: 1px solid var(--border); background: var(--surface); text-align: center; font-size: 0.8rem; line-height: 1.8; color: var(--text-dim); }
.story-page-footer p { font-family: var(--serif); font-size: 1rem; margin-bottom: 10px; }

/* Collection notes and a clear corrections route. */
.about-page { max-width: 790px; margin: 0 auto; padding: 42px 24px 64px; }
.about-page h1 { font-family: var(--serif); font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1.15; letter-spacing: -0.025em; margin-bottom: 24px; }
.about-page p { font-size: 0.98rem; line-height: 1.85; color: var(--text-dim); margin-bottom: 16px; }
.about-page .eyebrow { font-size: 0.72rem; color: var(--green); }
.about-page .about-intro { font-size: 1.15rem; }
.about-page .about-arabic { font-family: var(--arabic); font-size: 1.6rem; color: var(--red); margin: 24px 0 36px; }
.about-page section { scroll-margin-top: 24px; padding-top: 28px; margin-top: 30px; border-top: 1px solid var(--border); }
.about-page h2 { font-family: var(--serif); font-size: 1.6rem; margin-bottom: 16px; }
.return-to-stories { margin-top: 24px; }
.site-footer { background: var(--surface); border-top: 1px solid var(--border); padding: 44px 24px; }
.footer-content { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); max-width: 1000px; margin: 0 auto; gap: 60px; }
.footer-section h3 { font-family: var(--serif); font-size: 1rem; color: var(--text); margin-bottom: 14px; }
.footer-section p { color: var(--text-muted); font-size: 0.8rem; line-height: 1.8; margin-bottom: 8px; }
.footer-arabic { font-family: var(--arabic); font-size: 1.1rem !important; color: var(--red) !important; }
.footer-section ul { list-style: none; display: flex; flex-direction: column; gap: 14px; }
.footer-section li a { font-size: 0.8rem; }
@media (max-width: 999px) {
    #imageGrid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px 16px; }
    .story-page-layout { gap: 30px; }
    .story-navigation { flex-wrap: wrap; }
    .story-navigation .story-position { order: 3; width: 100%; }
}
@media (max-width: 640px) {
    .site-nav { padding: 12px 16px; gap: 12px; }
    .site-wordmark { font-size: 0.85rem; }
    .nav-links { gap: 12px; font-size: 0.72rem; }
    .pdf-access-button { padding: 7px 10px; }
    .hero { padding: 18px 20px 24px; }
    .hero-title { margin-bottom: 16px; }
    .hero-divider { margin-bottom: 12px; }
    .hero-arabic { line-height: 1.65; margin-bottom: 9px; }
    .hero-english { font-size: 0.87rem; }
    #galleryFallback { padding: 0 16px 44px; }
    .gallery-tools { gap: 12px; margin-bottom: 16px; }
    .sort-group { gap: 8px; }
    .gallery-tools label { font-size: 0.72rem; }
    #storySort { width: 120px; font-size: 0.8rem; }
    #imageGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
    .image-container { border-radius: 8px; }
    .name-overlay { font-size: 0.9rem; padding: 10px 11px 12px; }
    .image-container > .name-arabic { font-size: 1rem; padding: 0 11px 12px; }
    .modal-dialog { margin: auto 0 0; width: 100%; max-height: 94dvh; border-radius: 16px 16px 0 0; }
    .modal-layout { grid-template-columns: 1fr; grid-template-rows: minmax(120px, 29dvh) minmax(0, 1fr); max-height: 94dvh; }
    .modal-image-panel img { max-height: 29dvh; }
    .modal-text-panel { padding: 24px 20px max(24px, env(safe-area-inset-bottom)); }
    .modal-name { font-size: 1.4rem; padding-right: 0; margin-bottom: 14px; }
    .modal-bio { font-size: 0.91rem; }
    .story-navigation .text-button { font-size: 0.75rem; }
    .story-actions { gap: 12px; }
    .memorial-story { padding: 18px 20px 32px; }
    .story-page-layout { grid-template-columns: 1fr; gap: 28px; }
    .story-page-portrait { position: static; }
    .story-page-portrait img { max-height: 55dvh; }
    .story-page-content h1 { font-size: 2rem; }
    .story-page-bio { font-size: 0.95rem; }
    .story-page-navigation { gap: 14px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); margin-top: 32px; }
    .story-page-navigation .story-position { grid-column: 1 / -1; grid-row: 2; }
    .story-page-navigation a { font-size: 0.82rem; }
    .about-page { padding: 28px 20px 44px; }
    .footer-content { grid-template-columns: 1fr; gap: 26px; }
    .site-footer { padding: 32px 20px; }
}
@media (max-width: 360px) {
    .site-nav { flex-wrap: wrap; }
    .nav-links { margin-left: auto; }
    .gallery-tools { align-items: flex-start; }
    .sort-group { flex-wrap: wrap; justify-content: flex-end; max-width: 140px; }
}
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media print {
    body { background: #fff; color: #000; }
    .site-nav, .skip-link, .back-link, .story-actions, .share-status, .story-page-navigation, .story-page-footer { display: none !important; }
    .memorial-story { max-width: none; padding: 0; }
    .story-page-layout { display: block; }
    .story-page-portrait { position: static; float: left; width: 32%; margin: 0 24px 16px 0; background: #fff; }
    .story-page-portrait img { max-height: 280px; }
    .story-page-content h1 { font-size: 24pt; }
    .story-page-bio { font-size: 11pt; line-height: 1.6; }
    .story-page-content { overflow: visible; }
    a { color: #000; }
    .story-sources, .archive-context { clear: both; }
}
