/* Marta Shahbazi archive: quiet, readable, works from 320px phones to desktops.
   No web fonts and no external requests: everything works offline. */

:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --ink: #22201c;
  --ink-2: #57534b;
  --muted: #857f74;
  --rule: #e7e2d8;
  --accent: #4d5e57;
  --accent-soft: #e8edea;
  --note: #7d5a33;
  --note-soft: #f6efe5;
  --shadow: 0 1px 2px rgba(34, 32, 28, .04), 0 4px 18px rgba(34, 32, 28, .05);

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --column: 46rem;        /* reading width of the text */
  --page: 150rem;         /* the whole layout; fills the screen up to very wide monitors */
  --gutter: clamp(.9rem, 1.6vw, 1.5rem);
  --bar-h: calc(3.05rem + env(safe-area-inset-top));  /* height of the sticky top bar */
  --search-h: 4.85rem;    /* height of the sticky search row below it (wide screens) */
  --radius: 10px;
}

/* Light/dark follows the system unless the reader picks one with the button in the top bar
   (data-theme on <html>, stored in localStorage "nasi-theme"). color-scheme also reaches
   the saved pages in their iframes. */
:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161514;
    --surface: #1e1d1b;
    --ink: #ece8e1;
    --ink-2: #bdb7ac;
    --muted: #8d877c;
    --rule: #2f2d29;
    --accent: #a9bdb3;
    --accent-soft: #24302b;
    --note: #d9b48a;
    --note-soft: #2c251d;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #161514;
  --surface: #1e1d1b;
  --ink: #ece8e1;
  --ink-2: #bdb7ac;
  --muted: #8d877c;
  --rule: #2f2d29;
  --accent: #a9bdb3;
  --accent-soft: #24302b;
  --note: #d9b48a;
  --note-soft: #2c251d;
  --shadow: none;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-padding-top: 4.5rem; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 1rem/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; width: 100%; max-width: var(--page); margin: 0 auto; padding: 0 var(--gutter) 4rem; outline: none; }

a { color: var(--accent); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

button, input, select { font: inherit; color: inherit; }

.skip { position: absolute; left: -999px; top: .5rem; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: .5rem; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ------------------------------------------------------------ top bar */

.bar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--rule);
  padding-top: env(safe-area-inset-top);
}
.bar-inner {
  max-width: var(--page); margin: 0 auto; padding: .7rem var(--gutter);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.bar-left { display: flex; align-items: baseline; gap: 1rem; min-width: 0; }
.brand { font: 500 1.06rem/1 var(--serif); color: var(--ink); text-decoration: none; letter-spacing: .01em; white-space: nowrap; }
.bar-stats { display: none; font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 700px) { .bar-stats { display: inline; } }
@media (max-width: 430px) { .brand { font-size: .94rem; line-height: 1.2; letter-spacing: 0; } }

.bar-right { display: flex; align-items: center; gap: .5rem; flex: none; }
.theme {
  display: grid; place-items: center; width: 1.95rem; height: 1.95rem; padding: 0; cursor: pointer;
  border: 1px solid var(--rule); border-radius: 999px; background: var(--surface); color: var(--muted);
}
.theme:hover { color: var(--ink); }
.theme svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
/* the icon shows the mode a click switches to: a moon in light mode, a sun in dark mode */
.theme .sun { display: none; }
:root[data-theme="dark"] .theme .sun { display: block; }
:root[data-theme="dark"] .theme .moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme .sun { display: block; }
  :root:not([data-theme="light"]) .theme .moon { display: none; }
}

.lang { display: flex; border: 1px solid var(--rule); border-radius: 999px; padding: 2px; background: var(--surface); }
.lang button {
  border: 0; background: none; cursor: pointer; padding: .2rem .65rem; border-radius: 999px;
  font-size: .75rem; letter-spacing: .08em; color: var(--muted);
}
.lang button[aria-pressed="true"] { background: var(--accent); color: var(--bg); }

/* ------------------------------------------------------------ home */

.hero { text-align: center; padding: 1.5rem 0 1rem; }
.eyebrow {
  margin: 0 0 .9rem; font-size: .72rem; letter-spacing: .22em; text-transform: uppercase; color: var(--muted);
}
.hero h1 { margin: 0; font: 400 clamp(2.3rem, 8vw, 3.4rem)/1.08 var(--serif); letter-spacing: -.01em; }
.hero .rule { width: 2.5rem; height: 1px; background: var(--accent); margin: 1rem auto; opacity: .6; border: 0; }
.lead { margin: 0 auto; font: 400 1.08rem/1.65 var(--serif); color: var(--ink-2); }

/* the search box with the archive's size and date: one row, sticky under the top bar */
.searchrow {
  position: sticky; top: var(--bar-h); z-index: 4; background: var(--bg);
  display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1.5rem; padding: .7rem 0;
}
.searchrow.in-cat { padding-top: 1.1rem; }
.stats { margin: 0; font-size: .85rem; color: var(--muted); }
.searchrow .stats { flex: 1 1 100%; text-align: center; }
.searchrow .search { flex: 1 1 100%; }
@media (min-width: 700px) {
  .searchrow { justify-content: center; }
  .searchrow .stats { display: none; }  /* shown in the top bar instead */
  .searchrow .search { flex: 0 1 72rem; }
  .search input { padding: .95rem 3rem .95rem 3.2rem; font-size: 1.1rem; }
  .search svg { left: 1.1rem; width: 1.25rem; height: 1.25rem; }
}

.tools { padding: .2rem 0 .25rem; }

.search { position: relative; }
.search svg { position: absolute; left: .95rem; top: 50%; transform: translateY(-50%); width: 1.1rem; height: 1.1rem; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; padding: .85rem 2.6rem .85rem 2.7rem; border: 1px solid var(--rule); border-radius: 999px;
  background: var(--surface); box-shadow: var(--shadow); font-size: 1rem; /* 16px: no zoom on iOS */
  -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--muted); }
.search input:focus { outline: none; border-color: var(--accent); }
.search input::-webkit-search-cancel-button { display: none; }
.search .clear {
  position: absolute; right: .45rem; top: 50%; transform: translateY(-50%);
  border: 0; background: none; cursor: pointer; color: var(--muted); width: 2rem; height: 2rem; border-radius: 50%;
  font-size: 1.2rem; line-height: 1;
}
.search .clear:hover { background: var(--accent-soft); color: var(--ink); }

.chips {
  display: flex; gap: .4rem; overflow-x: auto; padding: .85rem var(--gutter) .55rem; margin: 0 calc(-1 * var(--gutter));
  scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; scroll-snap-align: start; display: inline-flex; align-items: baseline; gap: .4rem;
  padding: .38rem .85rem; border: 1px solid var(--rule); border-radius: 999px; background: var(--surface);
  color: var(--ink-2); text-decoration: none; font-size: .88rem; white-space: nowrap; cursor: pointer;
}
.chip:hover { border-color: var(--muted); text-decoration: none; }
.chip .n { font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip[aria-current="true"], .chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip[aria-current="true"] .n, .chip[aria-pressed="true"] .n { color: inherit; opacity: .7; }
.chips.sub { padding-top: 0; }
.chips.sub .chip { font-size: .8rem; padding: .25rem .7rem; }

.listhead {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  font-size: .82rem; color: var(--muted); padding: .35rem 0 .2rem; border-bottom: 1px solid var(--rule);
}
.divider { display: none; }
.listhead select {
  border: 0; background: none; color: var(--ink-2); font-size: .82rem; cursor: pointer; padding: .25rem 0;
  text-align: right;
}

.group { margin: 0; padding: 1.6rem 0 .35rem; font: 500 .74rem/1 var(--sans); letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.card {
  display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: start;
  padding: 1.05rem 0; border-bottom: 1px solid var(--rule); color: inherit; text-decoration: none;
}
.card:hover .card-title { color: var(--accent); }
.card:hover { text-decoration: none; }
.card-meta { font-size: .8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .15rem .5rem; }
.card-meta .src { color: var(--ink-2); font-weight: 500; }
.card-meta > * + *::before { content: "·"; margin-right: .5rem; color: var(--rule); }
.card-title { margin: .25rem 0 .3rem; font: 500 1.14rem/1.35 var(--serif); color: var(--ink); transition: color .15s; overflow-wrap: anywhere; }
.card-summary {
  margin: 0; color: var(--ink-2); font-size: .92rem; line-height: 1.55; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.card-flags { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .55rem; }
.flag { font-size: .7rem; letter-spacing: .04em; padding: .1rem .5rem; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }
.flag.note { background: var(--note-soft); color: var(--note); }
.thumb { width: 4.5rem; height: 4.5rem; border-radius: 8px; object-fit: cover; background: var(--rule); margin-top: .3rem; }

.more { display: block; margin: 2rem auto 0; padding: .65rem 1.6rem; border: 1px solid var(--rule); border-radius: 999px; background: var(--surface); cursor: pointer; color: var(--ink-2); }
.more:hover { border-color: var(--muted); color: var(--ink); }

.empty { text-align: center; color: var(--muted); padding: 3rem 0; }
.empty button { margin-top: .8rem; border: 0; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; }

/* ------------------------------------------------------------ item */

.back {
  display: inline-flex; align-items: center; gap: .4rem; margin: 1.5rem 0 0; font-size: .88rem; color: var(--ink-2);
  text-decoration: none; padding: .3rem .1rem;
}
.back:hover { color: var(--accent); text-decoration: none; }

.item-head { padding: 1.6rem 0 1.4rem; border-bottom: 1px solid var(--rule); }
.item-head .eyebrow { margin-bottom: .7rem; }
.item-head h1 { margin: 0; font: 400 clamp(1.6rem, 5.4vw, 2.3rem)/1.22 var(--serif); letter-spacing: -.005em; overflow-wrap: anywhere; }
.item-meta { margin: .9rem 0 0; color: var(--ink-2); font-size: .9rem; display: flex; flex-wrap: wrap; gap: .2rem .55rem; }
.item-meta > * + *::before { content: "·"; margin-right: .55rem; color: var(--muted); }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 1.2rem 0 0; }
.tabs { display: inline-flex; gap: .25rem; padding: 3px; border-radius: 999px; background: var(--accent-soft); }
.tab { border: 0; background: none; padding: .35rem .95rem; border-radius: 999px; cursor: pointer; font-size: .85rem; color: var(--accent); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.ext { font-size: .85rem; display: inline-flex; align-items: center; gap: .3rem; padding: .35rem .4rem; margin-left: auto; }

.notice { margin: 1.4rem 0 0; padding: .85rem 1rem; border-radius: var(--radius); background: var(--note-soft); color: var(--note); font-size: .9rem; }

.media { margin: 1.5rem 0 0; }
.media video { width: 100%; max-height: 75vh; border-radius: var(--radius); background: #000; display: block; }
.media.portrait video { max-width: 22rem; margin: 0 auto; }
.media audio { width: 100%; }
.media img { max-width: 100%; border-radius: var(--radius); display: block; margin: 0 auto 1rem; max-height: 16rem; }

.source-note { margin: 1.6rem 0 0; font-size: .8rem; color: var(--muted); font-style: italic; }

.prose { font: 400 1.13rem/1.75 var(--serif); color: var(--ink); overflow-wrap: break-word; }
.prose p { margin: 1.05em 0; }
.prose h2, .prose h3, .prose h4, .prose h5, .prose h6 { font-family: var(--serif); font-weight: 500; line-height: 1.3; margin: 1.8em 0 .5em; }
.prose h2 { font-size: 1.35rem; } .prose h3 { font-size: 1.2rem; } .prose h4, .prose h5, .prose h6 { font-size: 1.05rem; }
.prose blockquote { margin: 1.4em 0; padding: 0 0 0 1.1rem; border-left: 2px solid var(--accent); color: var(--ink-2); font-style: italic; }
.prose ul, .prose ol { padding-left: 1.3rem; }
.prose li { margin: .3em 0; }
.prose hr { border: 0; border-top: 1px solid var(--rule); margin: 2em 0; }
.prose table { width: 100%; border-collapse: collapse; font: .9rem/1.45 var(--sans); display: block; overflow-x: auto; }
.prose td { border-bottom: 1px solid var(--rule); padding: .4rem .6rem .4rem 0; vertical-align: top; }
.prose mark { background: color-mix(in srgb, var(--accent) 22%, transparent); color: inherit; border-radius: 2px; padding: 0 .1em; }

.frame { margin: 1.5rem 0 0; }
.frame iframe { width: 100%; height: 78vh; height: 78dvh; border: 1px solid var(--rule); border-radius: var(--radius); background: #fff; display: block; }
.frame p { font-size: .8rem; color: var(--muted); margin: .6rem 0 0; }

.item-main .prose, .item-main .source-note, .item-main .notice { max-width: var(--column); }

.record { margin: 2.6rem 0 0; border-top: 1px solid var(--rule); padding-top: 1rem; font-size: .88rem; }
.record h2 { margin: 0; padding: .3rem 0; font: 500 .72rem/1.4 var(--sans); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.record dl { display: grid; grid-template-columns: minmax(7rem, auto) 1fr; gap: .45rem 1rem; margin: .9rem 0 0; }
.record dt { color: var(--muted); }
.record dd { margin: 0; color: var(--ink-2); overflow-wrap: anywhere; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 2.4rem 0 0; }
.pager a {
  display: block; padding: .9rem 1rem; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--surface); color: inherit; text-decoration: none; min-width: 0;
}
.pager a:hover { border-color: var(--muted); }
.pager small { display: block; font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.pager span { display: block; margin-top: .25rem; font: 500 .95rem/1.35 var(--serif); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager .next { text-align: right; grid-column: 2; }

/* ------------------------------------------------------------ about */

.about h1 { font: 400 2rem/1.2 var(--serif); margin: 2.5rem 0 1rem; }
.about h2 { font: 500 1.15rem/1.3 var(--serif); margin: 2rem 0 .5rem; }
.about p, .about li { color: var(--ink-2); }
.about code { font-size: .88em; background: var(--accent-soft); padding: .05em .35em; border-radius: 4px; }

/* ------------------------------------------------------------ footer */

.foot {
  border-top: 1px solid var(--rule); color: var(--muted); font-size: .8rem; text-align: center;
  padding: 1.6rem 1.25rem calc(1.6rem + env(safe-area-inset-bottom));
}
.foot a { color: var(--ink-2); }

.loading { text-align: center; color: var(--muted); padding: 2rem 0; font-size: .9rem; }

@media (min-width: 700px) {
  .thumb { width: 5.5rem; height: 5.5rem; }
  .card-title { font-size: 1.22rem; }
}

/* ------------------------------------------------------------ wide screens */

@media (min-width: 760px) {
  /* two or more columns of cards */
  .list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 21rem), 1fr)); column-gap: 2.25rem; }
  .list > li { min-width: 0; }
  .list .card { height: 100%; }
}

@media (min-width: 1100px) {
  /* lists: search and filters in a sticky sidebar, then a line (.divider) that resizes it
     when dragged (--side, set by app.js) and closes/opens it with its round handle */
  .browse { display: grid; grid-template-columns: var(--side, 16.5rem) 3rem minmax(0, 1fr); align-items: start; }
  .browse.closed { grid-template-columns: 0 3rem minmax(0, 1fr); }
  .browse.closed .tools { visibility: hidden; overflow: hidden; height: 0; }
  .divider { display: block; align-self: stretch; position: relative; cursor: col-resize; touch-action: none; outline-offset: -2px; }
  .divider::before {
    content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 1px; transform: translateX(-50%);
    background: var(--rule); transition: background .15s, width .15s;
  }
  .divider:hover::before, .divider.dragging::before { width: 3px; background: var(--accent); }
  .browse.closed .divider { cursor: default; }
  .browse.closed .divider:hover::before { width: 1px; background: var(--rule); }
  .divider-handle {
    position: sticky; top: calc(var(--bar-h) + var(--search-h) + 1rem); z-index: 2;
    display: grid; place-items: center; width: 2.4rem; height: 2.4rem; margin: 0 auto; padding: 0;
    border: 1px solid var(--rule); border-radius: 50%; background: var(--surface); color: var(--ink-2);
    box-shadow: var(--shadow); cursor: pointer; transition: border-color .15s, color .15s;
  }
  .divider-handle:hover { border-color: var(--accent); color: var(--accent); }
  .divider-handle svg { width: 1.35rem; height: 1.35rem; }
  .browse .tools {
    position: sticky; top: calc(var(--bar-h) + var(--search-h) + .5rem); padding: 0; background: none;
    max-height: calc(100vh - var(--bar-h) - var(--search-h) - 1rem); overflow-y: auto; scrollbar-width: thin;
  }
  .browse .chips { flex-direction: column; overflow: visible; margin: 0; padding: 1.1rem 0 0; gap: .2rem; }
  .browse .chips.sub { padding-top: 1.1rem; margin-top: .9rem; border-top: 1px solid var(--rule); }
  .browse .chip {
    justify-content: space-between; border-color: transparent; background: none; border-radius: 8px;
    padding: .42rem .75rem; font-size: .92rem; text-align: left;
  }
  .browse .chip:hover { background: var(--accent-soft); }
  .browse .chip[aria-current="true"], .browse .chip[aria-pressed="true"] { background: var(--ink); }
  .browse .chips.sub .chip { font-size: .86rem; padding: .32rem .75rem; }
  .browse .results .listhead { padding-top: 0; }
  .results .group:first-child { padding-top: 1.2rem; }

  /* items: record and previous/next in a sidebar, saved pages as tall as the window */
  .item-layout { display: grid; grid-template-columns: minmax(0, 1fr) 19rem; gap: 3.5rem; align-items: start; }
  .item-side { position: sticky; top: calc(3.05rem + env(safe-area-inset-top) + 1.5rem); padding-top: 1.6rem;
    max-height: calc(100vh - 5rem); overflow-y: auto; scrollbar-width: thin; }
  .item-side .record { margin: 0; border-top: 0; padding-top: 0; }
  .item-side .record dl { grid-template-columns: 1fr; gap: .1rem; }
  .item-side .record dd { margin-bottom: .7rem; }
  .item-side .pager { grid-template-columns: 1fr; gap: .6rem; margin-top: 1.6rem; }
  .item-side .pager .next { grid-column: 1; text-align: left; }
  .item-side .pager span { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .frame iframe { height: calc(100vh - 9rem); height: calc(100dvh - 9rem); }
  .media video { max-height: calc(100vh - 10rem); }
  .prose { font-size: 1.18rem; }
  /* the text keeps a readable line length, centred; saved pages, PDFs and videos use the full width */
  .item-main .item-head, .item-main .actions, .item-main .notice, .item-main .source-note, .item-main .prose {
    max-width: 48rem; margin-left: auto; margin-right: auto;
  }
  .item-main .actions { margin-top: 1.2rem; }
  .item-main .notice { margin-top: 1.4rem; }
  .item-main .source-note { margin-top: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

@media print {
  .bar, .tools, .actions, .pager, .foot, .back { display: none; }
  body { background: #fff; color: #000; }
}
