/* Components for the two themes. Uses the variables from tokens.css only. RTL first. */

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body.site {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color .25s ease, color .25s ease;
}
body.site main { padding: 0; flex: 1 0 auto; }
body.site a { color: inherit; }
body.site img { max-width: 100%; }

.wrap { width: 100%; max-width: 1200px; margin-inline: auto; padding-inline: 20px; }
.wrap-narrow { width: 100%; max-width: 760px; margin-inline: auto; padding-inline: 20px; }

.skip-link {
  position: absolute; inset-inline-start: 12px; top: -60px; z-index: 100;
  background: var(--accent); color: var(--on-accent); padding: 10px 16px; font-weight: 700;
}
.skip-link:focus { top: 12px; }

:where(a, button, input, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

/* ---------- top bar + masthead ---------- */
.topbar { background: var(--topbar-bg); color: var(--topbar-ink); font-size: 14px; }
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; }
.topbar-date { display: flex; gap: 8px; flex-wrap: wrap; }
.topbar-date .sep { opacity: .5; }

.theme-toggle {
  appearance: none; cursor: pointer;
  background: transparent; color: inherit;
  border: 1px solid currentColor; border-radius: 999px;
  padding: 3px 14px; font: inherit; font-size: 13px; line-height: 1.6;
}
.theme-toggle:hover { background: rgba(255, 255, 255, .12); }
.theme-toggle .when-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .when-light { display: none; }
:root[data-theme="dark"] .theme-toggle .when-dark { display: inline; }

.masthead { background: var(--bg); border-bottom: var(--rule-width) solid var(--rule); }
.masthead-in { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 14px; }
.brand { text-decoration: none; display: flex; align-items: baseline; gap: 14px; }
.brand-name { font-family: var(--font-display); font-size: clamp(40px, 7vw, 68px); line-height: 1; }
.brand-sub { font-size: 14px; color: var(--muted); max-width: 18ch; line-height: 1.4; }
@media (max-width: 560px) { .brand-sub { display: none; } }

.search { display: flex; align-items: stretch; border: var(--rule-width) solid var(--rule); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.search input { border: 0; background: transparent; color: inherit; padding: 8px 12px; font: inherit; font-size: 15px; width: 170px; min-width: 0; }
.search input::placeholder { color: var(--muted); }
.search button { border: 0; background: var(--accent); color: var(--on-accent); padding: 0 14px; cursor: pointer; font: inherit; font-weight: 700; }
@media (max-width: 560px) { .search input { width: 100px; } }

.catnav { border-top: var(--rule-width) solid var(--rule); }
.catnav-in { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-block: 8px; }
.catnav-in::-webkit-scrollbar { display: none; }
.catnav a {
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  text-decoration: none; padding: 6px 14px; font-weight: 600; font-size: 15px;
  border: 1px solid transparent; border-radius: var(--radius);
}
.catnav a:hover, .catnav a[aria-current="page"] { border-color: var(--rule); }
.catnav .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--accent)); display: inline-block; }

/* ---------- shared bits ---------- */
.kicker {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-ui); font-weight: 700; font-size: 14px; letter-spacing: .02em;
  text-decoration: none;
}
.kicker .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--accent)); }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 56px 0 24px; padding-bottom: 10px; border-bottom: var(--rule-width) solid var(--rule); }
.section-head h2 { font-family: var(--font-display); font-weight: 400; font-size: clamp(28px, 4vw, 40px); margin: 0; line-height: 1.2; }
:root[data-theme="dark"] .section-head h2 { font-weight: 700; }

.btn-read {
  display: inline-block; text-decoration: none; font-weight: 700;
  background: var(--accent); color: var(--on-accent);
  padding: 10px 22px; border: var(--rule-width) solid var(--ink); border-radius: var(--radius);
}
:root[data-theme="dark"] .btn-read { border-color: transparent; }
.btn-read:hover { box-shadow: var(--shadow-hover); }

/* ---------- cover (post image or letter cover) ---------- */
.cover { position: relative; overflow: hidden; aspect-ratio: 16 / 10; background: var(--c, var(--accent)); color: var(--on-c, #101010); isolation: isolate; }
.cover > img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-letter {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: "Aref Ruqaa", var(--font-display); font-weight: 700;
  font-size: clamp(160px, 38cqw, 420px); line-height: .9;
  transform: translate(-8%, 8%) scale(1.25);
  color: rgba(0, 0, 0, .86);
}
.cover { container-type: inline-size; }
.cover-ink { display: none; }
:root[data-theme="dark"] .cover { background: #07080d; border-radius: var(--radius-card); }
:root[data-theme="dark"] .cover-ink {
  display: block; position: absolute; inset: -20%; z-index: -1; filter: blur(28px);
  background:
    radial-gradient(40% 45% at 28% 30%, var(--c) 0%, transparent 70%),
    radial-gradient(45% 50% at 74% 72%, var(--c2, var(--plum)) 0%, transparent 70%);
  opacity: .85;
}
:root[data-theme="dark"] .cover-letter { color: #f1ebdd; text-shadow: 0 0 28px var(--c), 0 0 70px var(--c); transform: none; font-size: clamp(120px, 34cqw, 340px); }

/* ---------- post cards ---------- */
.grid { display: grid; gap: 40px 32px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.post-card { background: var(--surface); position: relative; display: flex; flex-direction: column; border: var(--rule-width) solid var(--rule); border-radius: var(--radius-card); overflow: hidden; transition: transform .2s ease, box-shadow .2s ease; }
.post-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-3px); }
@media (prefers-reduced-motion: reduce) { .post-card, .post-card:hover { transition: none; transform: none; } }
.post-card .cover { border-radius: 0; }
.post-card-body { padding: 18px 20px 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.post-card h3 { font-family: var(--font-display); font-weight: 400; font-size: 26px; line-height: 1.35; margin: 0; }
:root[data-theme="dark"] .post-card h3 { font-weight: 700; }
.post-card h3 a { text-decoration: none; }
.post-card h3 a::after { content: ""; position: absolute; inset: 0; }   /* whole card is the link */
.post-card p { margin: 0; color: var(--muted); font-size: 15.5px; line-height: 1.8; }
.post-card-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; position: relative; z-index: 2; }
.post-meta { display: flex; gap: 14px; flex-wrap: wrap; }
.post-meta span { display: inline-flex; gap: 5px; align-items: center; }

/* ---------- share ---------- */
.share { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.share a, .share button {
  appearance: none; cursor: pointer; text-decoration: none; font: inherit; font-size: 14px; font-weight: 600;
  color: var(--ink); background: transparent; border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 5px 12px; line-height: 1.5;
}
.share a:hover, .share button:hover { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.share [hidden] { display: none; }
.share-pop { position: relative; }
.share-pop summary { list-style: none; cursor: pointer; font-weight: 600; font-size: 14px; border: 1px solid var(--rule); border-radius: var(--radius); padding: 3px 12px; }
.share-pop summary::-webkit-details-marker { display: none; }
.share-pop .share { position: absolute; inset-inline-end: 0; bottom: calc(100% + 8px); z-index: 5; width: max-content; max-width: 260px; background: var(--surface); border: var(--rule-width) solid var(--rule); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow-card); }

/* ---------- hero (home) ---------- */
.hero { position: relative; background: var(--hero-bg); color: var(--hero-ink); border-bottom: var(--rule-width) solid var(--rule); overflow: hidden; isolation: isolate; }
.hero .ink { display: none; position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; }
:root[data-theme="dark"] .hero .ink { display: block; }
.hero-in { display: grid; grid-template-columns: 1.1fr .9fr; gap: 48px; align-items: center; padding-block: 56px; }
@media (max-width: 860px) { .hero-in { grid-template-columns: 1fr; padding-block: 32px; gap: 28px; } }
.hero h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(36px, 6vw, 72px); line-height: 1.25; margin: 14px 0 16px; }
:root[data-theme="dark"] .hero h1 { font-weight: 700; }
.hero h1 a { text-decoration: none; }
.hero p { font-size: 19px; line-height: 1.9; max-width: 46ch; margin: 0 0 22px; }
.hero-cover { display: block; text-decoration: none; }
.hero-cover .cover { box-shadow: var(--shadow-card); border: var(--rule-width) solid var(--ink); aspect-ratio: 4 / 3; }
:root[data-theme="dark"] .hero-cover .cover { border-color: var(--hairline); }
.hero .btn-read { background: var(--hero-ink); color: var(--hero-bg); }
:root[data-theme="dark"] .hero .btn-read { background: var(--accent); color: var(--on-accent); }
.hero .kicker { background: var(--hero-ink); color: var(--hero-bg); padding: 2px 12px; border-radius: var(--radius); }
:root[data-theme="dark"] .hero .kicker { background: transparent; color: var(--accent); padding: 0; }

/* ---------- this week ---------- */
.week { display: grid; grid-template-columns: 1.4fr 1fr; gap: 32px; }
.week-side { display: grid; gap: 32px; align-content: start; }
@media (max-width: 860px) { .week { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  :root[data-theme="dark"] .week { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 16px; padding-bottom: 12px; }
  :root[data-theme="dark"] .week > *, :root[data-theme="dark"] .week-side > * { flex: 0 0 82%; scroll-snap-align: start; }
  :root[data-theme="dark"] .week-side { display: contents; }
}
.week .post-card.large h3 { font-size: clamp(30px, 4vw, 44px); }
.week .post-card.large .cover { aspect-ratio: 16 / 9; }

/* ---------- quote band ---------- */
.quote-band { margin-top: 64px; background: var(--surface-2); border-block: var(--rule-width) solid var(--rule); }
.quote-band-in { padding-block: 48px; text-align: center; }
.quote-band blockquote { margin: 0 auto; max-width: 30ch; font-family: var(--font-display); font-size: clamp(26px, 4.4vw, 44px); line-height: 1.6; }
:root[data-theme="dark"] .quote-band blockquote { font-weight: 700; color: var(--accent); }
.quote-band cite { display: block; margin-top: 16px; font-style: normal; font-family: var(--font-ui); font-size: 15px; color: var(--muted); }

/* ---------- most read ---------- */
.most-read { list-style: none; margin: 0; padding: 0; counter-reset: rank; display: grid; gap: 0; }
.most-read li { display: grid; grid-template-columns: 84px 1fr auto; gap: 18px; align-items: center; padding: 16px 0; border-bottom: 1px solid var(--hairline); }
.most-read .rank { font-family: "Aref Ruqaa", var(--font-display); font-weight: 700; font-size: 64px; line-height: 1; color: transparent; -webkit-text-stroke: 2px var(--ink); text-align: center; }
:root[data-theme="dark"] .most-read .rank { -webkit-text-stroke: 1.5px var(--accent); }
.most-read a { text-decoration: none; font-family: var(--font-display); font-size: 24px; line-height: 1.4; }
:root[data-theme="dark"] .most-read a { font-weight: 700; }
.most-read a:hover { text-decoration: underline; }
.most-read .views { color: var(--muted); font-size: 14px; white-space: nowrap; }
@media (max-width: 560px) { .most-read li { grid-template-columns: 56px 1fr; } .most-read .views { display: none; } .most-read .rank { font-size: 44px; } }

/* ---------- category + search + 404 ---------- */
.page-head { padding-block: 40px 28px; background: var(--c, var(--accent)); color: var(--on-c, var(--on-accent)); border-bottom: var(--rule-width) solid var(--rule); }
:root[data-theme="dark"] .page-head { background: transparent; color: var(--ink); position: relative; overflow: hidden; isolation: isolate; }
:root[data-theme="dark"] .page-head::before { content: ""; position: absolute; inset: -40% -10% auto auto; width: 60%; aspect-ratio: 1; background: radial-gradient(closest-side, var(--c), transparent 70%); opacity: .35; filter: blur(30px); z-index: -1; }
.page-head h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(36px, 6vw, 64px); line-height: 1.2; margin: 0 0 8px; }
:root[data-theme="dark"] .page-head h1 { font-weight: 700; }
.page-head p { margin: 0; max-width: 60ch; font-size: 18px; }
.page-body { padding-block: 40px 24px; }
.empty { text-align: center; padding: 64px 0; color: var(--muted); }
.error-page { text-align: center; padding-block: 88px; }
.error-page .code { font-family: "Aref Ruqaa", var(--font-display); font-weight: 700; font-size: clamp(110px, 24vw, 240px); line-height: 1; color: transparent; -webkit-text-stroke: 3px var(--ink); }
:root[data-theme="dark"] .error-page .code { -webkit-text-stroke-color: var(--accent); }

/* ---------- article ---------- */
.post-head { background: var(--c, var(--accent)); color: var(--on-c, var(--on-accent)); border-bottom: var(--rule-width) solid var(--rule); padding-block: 48px 40px; }
.post-head h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(34px, 6vw, 62px); line-height: 1.3; margin: 14px 0 18px; }
.post-head .post-meta { color: inherit; font-size: 15px; opacity: .9; }
.post-head .kicker { background: var(--on-c, var(--ink)); color: var(--c, var(--bg)); padding: 2px 12px; border-radius: var(--radius); }
:root[data-theme="dark"] .post-head { background: transparent; color: var(--ink); text-align: center; padding-block: 64px 28px; border-bottom: 0; }
:root[data-theme="dark"] .post-head h1 { font-weight: 700; }
:root[data-theme="dark"] .post-head .post-meta { justify-content: center; color: var(--muted); }
:root[data-theme="dark"] .post-head .kicker { background: transparent; color: var(--c); padding: 0; }

.post-grid { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 56px; padding-block: 40px 24px; align-items: start; }
@media (max-width: 960px) { .post-grid { grid-template-columns: minmax(0, 1fr); gap: 24px; } }
.post-cover { margin: 0 0 32px; }
.post-cover .cover { aspect-ratio: 16 / 9; border: var(--rule-width) solid var(--rule); box-shadow: var(--shadow-card); }
:root[data-theme="dark"] .post-cover .cover { border: 0; }

.prose { font-family: var(--font-body); font-size: var(--body-size); line-height: var(--body-leading); max-width: 38em; }
.prose p { margin: 0 0 1.1em; }
.prose h2, .prose h3, .prose h4 { font-family: var(--font-display); font-weight: 400; line-height: 1.4; margin: 1.6em 0 .5em; scroll-margin-top: 80px; }
:root[data-theme="dark"] .prose h2, :root[data-theme="dark"] .prose h3, :root[data-theme="dark"] .prose h4 { font-weight: 700; }
.prose h2 { font-size: 1.7em; } .prose h3 { font-size: 1.4em; } .prose h4 { font-size: 1.2em; }
.prose a { color: var(--link); text-underline-offset: 4px; }
.prose img { max-width: 100%; height: auto; display: block; margin-inline: auto; }
.prose figure { margin: 1.6em 0; }
.prose figcaption { text-align: center; font-family: var(--font-ui); font-size: 15px; color: var(--muted); margin-top: 8px; }
.prose blockquote {   /* pull quote */
  margin: 1.6em 0; padding: .4em 1.2em; font-family: var(--font-display); font-size: 1.35em; line-height: 1.7;
  border-inline-start: 6px solid var(--accent); width: auto; background: transparent; font-style: normal; color: inherit;
}
:root[data-theme="dark"] .prose blockquote { font-weight: 700; color: var(--accent); }
.prose pre { direction: ltr; text-align: left; overflow-x: auto; background: var(--surface-2); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 1em; font-size: 15px; line-height: 1.6; }
.prose code { font-size: .85em; }
.prose hr { border: 0; border-top: var(--rule-width) solid var(--rule); margin: 2em 0; }
.prose ul, .prose ol { padding-inline-start: 1.6em; margin: 0 0 1.1em; }

.post-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 36px; padding-top: 18px; border-top: var(--rule-width) solid var(--rule); font-family: var(--font-ui); }
.post-actions form { margin: 0; }
.pill {
  appearance: none; cursor: pointer; font: inherit; font-size: 15px; font-weight: 600; color: inherit; text-decoration: none;
  background: transparent; border: 1px solid var(--rule); border-radius: 999px; padding: 6px 16px; display: inline-flex; gap: 8px; align-items: center;
}
.pill:hover { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.pill[disabled] { opacity: .6; cursor: default; }

.post-side { position: sticky; top: 24px; display: grid; gap: 28px; font-family: var(--font-ui); font-size: 15px; }
@media (max-width: 960px) { .post-side { position: static; } }
.post-side h4 { margin: 0 0 10px; font-size: 14px; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.toc ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; border-inline-start: 2px solid var(--hairline); }
.toc a { display: block; text-decoration: none; padding: 2px 12px; color: var(--muted); }
.toc a:hover, .toc a[aria-current="true"] { color: var(--ink); }
.toc a[aria-current="true"] { box-shadow: inset 3px 0 0 var(--accent); }
.toc li.h3 a { padding-inline-start: 26px; font-size: 14px; }

.reading-modes { display: none; }
:root[data-theme="dark"] .reading-modes { display: block; }
.reading-modes .seg { display: flex; border: 1px solid var(--rule); border-radius: 999px; overflow: hidden; }
.reading-modes button { flex: 1; appearance: none; border: 0; background: transparent; color: inherit; cursor: pointer; font: inherit; font-size: 13px; padding: 6px 4px; }
.reading-modes button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 700; }

/* dark reading modes */
:root[data-theme="dark"] body[data-reading="focus"] .post-side,
:root[data-theme="dark"] body[data-reading="focus"] .topbar,
:root[data-theme="dark"] body[data-reading="focus"] .masthead,
:root[data-theme="dark"] body[data-reading="focus"] footer.site-footer,
:root[data-theme="dark"] body[data-reading="focus"] #comments { opacity: .12; transition: opacity .3s; }
:root[data-theme="dark"] body[data-reading="focus"] .post-side:hover,
:root[data-theme="dark"] body[data-reading="focus"] #comments:hover { opacity: 1; }
:root[data-theme="dark"] body[data-reading="focus"] .post-grid { grid-template-columns: minmax(0, 1fr); justify-items: center; }
:root[data-theme="dark"] body[data-reading="warm"] { --bg: #17100a; --surface: #20160d; --surface-2: #2a1d11; --ink: #ecdcba; --muted: #bba98a; --accent: #f0c27a; }

.progress-ring { position: fixed; inset-inline-start: 18px; bottom: 18px; z-index: 40; width: 54px; height: 54px; background: var(--surface); border-radius: 50%; box-shadow: var(--shadow-card); display: grid; place-items: center; }
.progress-ring svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.progress-ring circle { fill: none; stroke-width: 4; }
.progress-ring .track { stroke: var(--hairline); }
.progress-ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .1s linear; }
.progress-ring span { font-family: var(--font-ui); font-size: 12px; font-weight: 700; }

/* ---------- comments ---------- */
.comments { padding-block: 8px 56px; }
.comments h3 { font-family: var(--font-display); font-weight: 400; font-size: 32px; margin: 32px 0 20px; }
:root[data-theme="dark"] .comments h3 { font-weight: 700; }
.comment { background: var(--surface); border: var(--rule-width) solid var(--rule); border-radius: var(--radius-card); padding: 16px 20px; margin-bottom: 16px; }
.comment header { display: flex; justify-content: space-between; gap: 12px; font-weight: 700; font-size: 15px; }
.comment header time { color: var(--muted); font-weight: 400; }
.comment p { margin: 8px 0 0; white-space: pre-line; }
.comments form { background: var(--surface); border: var(--rule-width) solid var(--rule); border-radius: var(--radius-card); padding: 20px; display: grid; gap: 14px; }
.comments label { font-weight: 600; font-size: 15px; display: grid; gap: 6px; }
.comments input[type=text], .comments textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px 12px; width: 100%;
}
.comments .hp { position: absolute; inset-inline-start: -10000px; }
.flash { background: var(--surface-2); border: 1px solid var(--rule); padding: 10px 16px; margin: 16px 0; border-radius: var(--radius); }

/* ---------- footer ---------- */
footer.site-footer { background: var(--footer-bg); color: var(--footer-ink); margin-top: 72px; padding-block: 48px 28px; border-top: var(--rule-width) solid var(--rule); }
.footer-grid { display: grid; grid-template-columns: 1.6fr 1fr 1fr; gap: 40px; }
@media (max-width: 860px) { .footer-grid { grid-template-columns: 1fr; gap: 28px; } }
.site-footer h4 { font-family: var(--font-display); font-weight: 400; font-size: 24px; margin: 0 0 12px; color: var(--accent); }
.site-footer p { margin: 0; font-size: 15px; line-height: 1.9; opacity: .9; }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.site-footer a { text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }
.footer-social { display: flex; gap: 14px; }
.footer-social img { width: 26px; height: 26px; filter: invert(1); opacity: .9; }
.footer-copy { margin-top: 32px; padding-top: 16px; border-top: 1px solid rgba(255, 255, 255, .15); font-size: 13px; opacity: .7; }

/* auth page keeps its own form markup; give it the new surface */
body.site .login-page, body.site .auth-wrap { color: var(--ink); }

@media print {
  .topbar, .masthead, .post-side, .progress-ring, .site-footer, .comments, .post-actions { display: none !important; }
  body.site { background: #fff; color: #000; }
}
