/* Design tokens: one place for every colour, size and radius. Dark is the default; light is a first-class choice.
   The palette is taken from ysimon.info (ink/teal/seafoam, Inter, pill buttons, 14/20/28 px radii). */
:root {
  color-scheme: dark;
  --bg: #05242a;
  --surface: #0a3239;
  --surface-2: #0f3f47;
  --text: #e9f5f2;
  --muted: #9fbcbf;
  --line: rgb(98 182 164 / 0.22);
  --accent: #62b6a4;
  --accent-text: #062f35;
  --accent-soft: #0e4a50;
  --accent-ink: #8fd6c6;
  --mark: rgba(255, 196, 0, 0.42);
  --shadow: 0 10px 30px rgb(0 0 0 / 0.35);
  --hero: linear-gradient(135deg, #073f47 0%, #05303a 55%, #05242a 100%);
  --reader-bg: #03171a;
  --r-s: 10px;
  --r-m: 14px;
  --r-l: 20px;
  --r-xl: 28px;
  --pill: 999px;
  --tap: 44px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Noto Sans Hebrew", "Arial Hebrew", Arial, sans-serif;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4fbf8;
  --surface: #ffffff;
  --surface-2: #e8f4ef;
  --text: #062f35;
  --muted: #476870;
  --line: rgb(6 47 53 / 0.14);
  --accent: #028090;
  --accent-text: #ffffff;
  --accent-soft: #dff6ef;
  --accent-ink: #0d5c63;
  --shadow: 0 12px 34px rgb(6 47 53 / 0.12);
  --hero: linear-gradient(135deg, #dff6ef 0%, #f4fbf8 70%);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font); }
img { max-width: 100%; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }

.skip { position: absolute; inset-inline-start: 8px; inset-block-start: -60px; background: var(--surface); padding: 8px 12px; border-radius: var(--r-s); z-index: 50; }
.skip:focus { inset-block-start: 8px; }

/* ---------- header */
.site-header { position: sticky; inset-block-start: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-block-size: 56px; padding-inline: max(14px, calc((100% - 1180px) / 2)); background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(10px); border-block-end: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 750; letter-spacing: -0.01em; min-block-size: var(--tap); min-inline-size: 0; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark { flex: none; display: grid; place-items: center; inline-size: 36px; block-size: 36px; border-radius: 12px; border: 1.5px solid var(--accent); color: var(--accent); }
.header-tools { display: flex; align-items: center; gap: 4px; flex: none; }
.site-link { display: none; color: var(--accent-ink); font-size: 0.88rem; font-weight: 650; text-decoration: none; padding-inline: 10px; }
.site-link:hover { text-decoration: underline; }
@media (min-width: 720px) { .site-link { display: inline-block; } }
body.is-reader .site-header { display: none; }

.icon-btn, .text-btn { display: inline-grid; place-items: center; min-inline-size: var(--tap); min-block-size: var(--tap); padding: 0 12px; border: 0; border-radius: var(--pill);
  background: transparent; color: inherit; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.icon-btn:hover, .text-btn:hover { background: var(--surface-2); }
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }

.btn { min-block-size: var(--tap); padding: 0 20px; border: 1px solid var(--line); border-radius: var(--pill); background: var(--surface); color: inherit; font: inherit; font-weight: 750; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }

main { padding: 14px max(14px, calc((100% - 1180px) / 2)) 40px; }
.notice { color: var(--muted); padding: 16px 0; }
.notice:empty { display: none; }
.error-detail { font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; word-break: break-all; }

/* ---------- home: a compact hero, then a shelf where every year is one small block */
.hero { display: grid; gap: 10px 28px; align-items: center; padding: 18px 18px; background: var(--hero); border: 1px solid var(--line); border-radius: var(--r-xl); }
.hero-text { min-inline-size: 0; }
.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 0.74rem; font-weight: 900; letter-spacing: 0.14em; text-transform: uppercase; }
.hero h1 { margin: 0; font-size: clamp(1.45rem, 3.4vw, 2.1rem); line-height: 1.15; letter-spacing: -0.02em; font-weight: 800; }
.lede { margin: 4px 0 0; color: var(--muted); font-size: 0.98rem; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 0.84rem; }
@media (min-width: 900px) { .hero { grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); padding: 20px 26px; } }
.searchbox { position: relative; display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
.searchbox-icon { position: absolute; inset-inline-start: 16px; inset-block-start: 12px; color: var(--muted); pointer-events: none; }
.searchbox input[type="search"] { flex: 1 1 200px; min-inline-size: 0; min-block-size: var(--tap); padding-inline: 44px 14px; border: 1px solid var(--line); border-radius: var(--pill); background: var(--surface); color: inherit; font: inherit; }
.searchbox select { min-block-size: var(--tap); padding-inline: 14px; border: 1px solid var(--line); border-radius: var(--pill); background: var(--surface); color: inherit; font: inherit; }
.searchbox input:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* Columns pack the year blocks tightly (a year with four issues does not stretch its neighbours), so the whole library needs the least scrolling. */
.shelf { columns: 340px; column-gap: 10px; margin-block-start: 14px; }
.year-block { break-inside: avoid; margin-block-end: 10px; display: grid; grid-template-columns: 2.6rem minmax(0, 1fr); gap: 8px; align-items: start; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); }
.year-block h2 { margin: 0; padding-block-start: 4px; font-size: 1.02rem; font-weight: 850; letter-spacing: 0.01em; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.specials-block { column-span: all; grid-template-columns: minmax(0, 1fr); }
.specials-block h2 { padding: 0 2px 2px; }
.covers { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 10px; }
.specials-block .covers { grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); }

/* Phone: no boxes. Every year becomes one small tile in a single run of covers (4 per row). */
@media (max-width: 639px) {
  main { padding-block-start: 10px; }
  .hero { padding: 12px 14px; gap: 8px; border-radius: var(--r-l); }
  .hero h1 { font-size: 1.25rem; }
  .lede, .hint { display: none; }
  .shelf { columns: auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .year-block { display: contents; }
  .covers { display: contents; }
  .year-block h2 { display: grid; place-items: center; aspect-ratio: 2 / 3; padding: 0; border-radius: var(--r-s); background: var(--accent-soft); font-size: 0.95rem; }
  .specials-block { display: grid; grid-column: 1 / -1; grid-template-columns: minmax(0, 1fr); gap: 8px; margin-block-start: 6px; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); }
  .specials-block h2 { display: block; aspect-ratio: auto; background: none; padding: 0 2px; font-size: 1rem; place-items: unset; }
  .specials-block .covers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
}
.card { position: relative; display: flex; flex-direction: column; gap: 4px; text-decoration: none; border-radius: var(--r-s); transition: transform 0.15s, box-shadow 0.15s; }
.card:hover { transform: translateY(-2px); }
.card:hover .card-cover { box-shadow: var(--shadow); border-color: var(--accent); }
.card-cover { position: relative; display: block; aspect-ratio: 2 / 3; border-radius: var(--r-s); overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); transition: box-shadow 0.15s, border-color 0.15s; }
.card-cover img { display: block; inline-size: 100%; block-size: 100%; object-fit: cover; }
.card-cover img.is-wide { object-fit: contain; }
.badge { position: absolute; inset-inline-start: 4px; inset-block-end: 4px; min-inline-size: 22px; padding: 1px 7px; border-radius: var(--pill); background: var(--accent); color: var(--accent-text);
  font-size: 0.78rem; font-weight: 850; line-height: 1.45; text-align: center; box-shadow: 0 1px 4px rgb(0 0 0 / 0.4); }
.cover-placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; block-size: 100%; padding: 6px; text-align: center; color: var(--accent-ink);
  background: linear-gradient(160deg, var(--accent-soft), var(--surface-2)); }
.cover-placeholder small { color: var(--muted); font-size: 0.66rem; line-height: 1.2; }
.card-caption { padding: 0 2px; font-size: 0.78rem; line-height: 1.3; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- search results */
.results-head { max-inline-size: 760px; }
.results-title { margin: 20px 0 8px; font-size: 1.15rem; font-weight: 600; }
.hits { list-style: none; margin: 8px 0 0; padding: 0; max-inline-size: 860px; display: flex; flex-direction: column; gap: 10px; }
.hit-link { display: flex; gap: 14px; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); text-decoration: none; }
.hit-link:hover { border-color: var(--accent); }
.hit-thumb { flex: none; inline-size: 72px; block-size: 108px; object-fit: cover; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--line); }
.hit-thumb-text { display: grid; place-items: center; color: var(--muted); font-size: 1.6rem; }
.hit-body { display: flex; flex-direction: column; gap: 2px; min-inline-size: 0; }
.hit-title { font-weight: 600; }
.hit-where { color: var(--muted); font-size: 0.88rem; }
.hit-snippet { display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin-block-start: 4px; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.more { padding: 20px 0; }

/* ---------- text-only issue and articles */
.issue-head { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.issue-cover { inline-size: 160px; height: auto; border-radius: var(--r-m); box-shadow: var(--shadow); }
.issue-head h1 { margin: 6px 0 8px; }
.crumb { color: var(--muted); text-decoration: none; font-size: 0.92rem; }
.crumb:hover { color: var(--accent-ink); }
.article-list { max-inline-size: 760px; padding: 0; margin: 28px 0 0; list-style: none; display: flex; flex-direction: column; }
.article-list li { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; padding: 12px 4px; border-block-end: 1px solid var(--line); }
.article-main { display: flex; flex-direction: column; gap: 2px; min-inline-size: 0; }
.article-preview { color: var(--muted); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.article-list a { text-decoration: none; font-weight: 550; }
.article-list a:hover { color: var(--accent-ink); }
.article-list small { color: var(--muted); white-space: nowrap; }
.article { max-inline-size: 70ch; margin-inline: auto; font-size: 1.08rem; line-height: 1.75; }
.article h1 { line-height: 1.25; letter-spacing: -0.01em; }
.article p { margin: 0 0 1em; }

/* ---------- reader */
.reader { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--reader-bg); color: #e9ebef; }
.reader-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-block-size: 52px; padding-inline: 8px; background: var(--surface); color: var(--text); border-block-end: 1px solid var(--line); }
.bar-start, .bar-end { display: flex; align-items: center; gap: 2px; min-inline-size: 0; flex: 1; }
.bar-end { justify-content: flex-end; }
.reader-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-center { display: flex; align-items: center; gap: 6px; }
.page-input { inline-size: 64px; min-block-size: 36px; text-align: center; border: 1px solid var(--line); border-radius: var(--r-s); background: var(--surface-2); color: inherit; font: inherit; }
.page-of { color: var(--muted); font-size: 0.92rem; white-space: nowrap; }
.hit-group { display: inline-flex; align-items: center; gap: 0; }
.hit-info { font-size: 0.85rem; color: var(--muted); min-inline-size: 3.2em; text-align: center; }
.only-wide { display: none; }
@media (min-width: 900px) { .only-wide { display: inline-grid; } }
@media (max-width: 640px) { .reader-title, .page-of { display: none; } }

.reader-main { position: relative; flex: 1; min-block-size: 0; display: flex; }
.stage { flex: 1; min-inline-size: 0; container-type: size; display: grid; place-items: center; overflow: hidden; touch-action: none; user-select: none; outline: none; }
.stage.is-zoomed { cursor: grab; }
.spread { display: flex; align-items: center; justify-content: center; transform-origin: 50% 50%; }
.leaf { position: relative; margin: 0; aspect-ratio: var(--ar); block-size: min(100cqh, calc(100cqw / (var(--n, 1) * var(--ar, 0.66)))); background: #fff; box-shadow: 0 2px 18px rgb(0 0 0 / 0.45); }
.leaf img { display: block; inline-size: 100%; block-size: 100%; pointer-events: none; }
.marks { position: absolute; inset: 0; pointer-events: none; }
.mark { position: absolute; background: var(--mark); mix-blend-mode: multiply; border-radius: 2px; box-shadow: 0 0 0 1px rgb(255 160 0 / 0.55); }
.nav { position: absolute; inset-block-start: 50%; transform: translateY(-50%); z-index: 3; inline-size: 48px; block-size: 72px; background: rgb(0 0 0 / 0.38); color: #fff; border-radius: var(--r-s); opacity: 0.55; transition: opacity 0.15s; }
.nav:hover, .nav:focus-visible { opacity: 1; background: rgb(0 0 0 / 0.6); }
.nav-prev { inset-inline-start: 8px; }
.nav-next { inset-inline-end: 8px; }
@media (max-width: 640px) { .nav { inline-size: 36px; block-size: 56px; } }

.text-panel { position: absolute; inset-block: 0; inset-inline-end: 0; z-index: 4; inline-size: min(440px, 100%); overflow: auto; padding: 16px 18px 40px; background: var(--surface); color: var(--text); border-inline-start: 1px solid var(--line); box-shadow: var(--shadow); }
.text-panel h2 { margin: 12px 0 6px; font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.page-text { white-space: pre-wrap; line-height: 1.7; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 8px 10px; background: var(--surface); border-block-start: 1px solid var(--line); color: var(--text); }
.thumb { flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 3px; border: 2px solid transparent; border-radius: var(--r-s); background: transparent; color: inherit; font-size: 0.75rem; cursor: pointer; position: relative; }
.thumb img { display: block; block-size: 96px; inline-size: auto; border-radius: 3px; border: 1px solid var(--line); }
.thumb.is-current { border-color: var(--accent); }
.thumb.has-hit::after { content: ""; position: absolute; inset-block-start: 6px; inset-inline-end: 6px; inline-size: 10px; block-size: 10px; border-radius: 50%; background: #ffc400; box-shadow: 0 0 0 2px var(--surface); }

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