/* My Daily Knowledge design system: an editorial, academic look. Tokens first; components use only the tokens.
   Logical properties (margin-inline, padding-inline-start, inset-inline) keep Arabic right-to-left layouts correct. */
:root {
  --navy: #10243A; --emerald: #176B58; --sage: #A5C7B5; --gold: #C6A667; --ivory: #F8F6F0; --white: #FFFFFF;
  --slate: #243746; --muted: #64748B; --stone: #E5E7E3;
  --emerald-deep: #11523F; --sage-soft: #E7F0EA; --gold-soft: #F4ECDA; --danger: #9B2C2C; --danger-soft: #FBEAEA; --warn-soft: #FFF6E0;
  --bg: var(--ivory); --surface: var(--white); --text: var(--slate); --heading: var(--navy); --line: var(--stone); --accent: var(--emerald);
  --serif-head: 'Libre Baskerville', Georgia, 'Times New Roman', serif;
  --serif: 'Source Serif 4', 'Source Serif Pro', Georgia, 'Times New Roman', serif;
  --sans: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  --radius: 10px; --radius-sm: 6px; --shadow: 0 1px 2px rgba(16, 36, 58, .06), 0 8px 24px rgba(16, 36, 58, .06);
  --wrap: 1160px; --read: 720px;
}
:lang(ar) { --serif-head: 'Noto Naskh Arabic', 'Geeza Pro', 'Segoe UI', Tahoma, serif; --serif: 'Noto Naskh Arabic', 'Geeza Pro', 'Segoe UI', Tahoma, serif; --sans: 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif; }
:lang(zh-CN) { --serif-head: 'Noto Serif SC', 'Songti SC', serif; --serif: 'Noto Serif SC', 'Songti SC', serif; --sans: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif; }
:lang(hi) { --serif-head: 'Noto Serif Devanagari', 'Kohinoor Devanagari', serif; --serif: 'Noto Serif Devanagari', 'Kohinoor Devanagari', serif; --sans: 'Noto Sans Devanagari', 'Nirmala UI', sans-serif; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--sans); text-rendering: optimizeLegibility; }
img, svg { max-width: 100%; }
a { color: var(--accent); text-underline-offset: .18em; }
a:hover { color: var(--emerald-deep); }
h1, h2, h3, h4 { font-family: var(--serif-head); color: var(--heading); line-height: 1.25; margin: 0 0 .5em; font-weight: 700; }
h1 { font-size: clamp(2rem, 4.2vw, 3.1rem); letter-spacing: -.01em; }
h2 { font-size: clamp(1.45rem, 2.6vw, 2rem); }
h3 { font-size: 1.15rem; }
p { margin: 0 0 1em; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 3px; }
.skip { position: absolute; inset-inline-start: 8px; top: 8px; background: var(--navy); color: #fff; padding: 8px 12px; z-index: 100; clip-path: inset(50%); white-space: nowrap; }
.skip:focus { clip-path: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { max-width: var(--wrap); margin-inline: auto; padding-inline: 20px; }
.narrow { max-width: var(--read); margin-inline: auto; padding-inline: 20px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.eyebrow { font: 600 .78rem/1.2 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin-bottom: .75rem; }
:lang(ar) .eyebrow, :lang(zh-CN) .eyebrow, :lang(hi) .eyebrow { letter-spacing: 0; text-transform: none; }
.lead { font: 1.2rem/1.6 var(--serif); color: var(--slate); max-width: 60ch; }
.center { text-align: center; }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.between { justify-content: space-between; }
.grid { display: grid; gap: 20px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.section { padding-block: 72px; }
.section.alt { background: var(--white); border-block: 1px solid var(--line); }
.section.dark { background: var(--navy); color: #E9EEF0; }
.section.dark h2, .section.dark h3 { color: #fff; }
.rule { border: 0; border-top: 1px solid var(--line); margin: 32px 0; }
.ornament { display: inline-block; color: var(--gold); }

/* Header and footer */
.site-head { background: var(--ivory); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.nav { display: flex; align-items: center; gap: 18px; min-height: 64px; }
.logo { display: inline-flex; align-items: center; gap: 10px; font: 700 1.15rem var(--serif-head); color: var(--navy); text-decoration: none; white-space: nowrap; }
.logo svg { width: 34px; height: 34px; flex: none; }
@media (max-width: 420px) { .logo { font-size: 1.02rem; gap: 8px; } .logo svg { width: 30px; height: 30px; } }
.nav-links { display: flex; gap: 18px; margin-inline-start: auto; align-items: center; }
.nav-links a { color: var(--slate); text-decoration: none; font-size: .95rem; }
.nav-links a:hover, .nav-links a[aria-current] { color: var(--accent); }
.nav-links a.btn, .nav-links a.btn:hover { color: #fff; }
.btn.nav-toggle { display: none; margin-inline-start: auto; }
@media (max-width: 900px) {
  .btn.nav-toggle { display: inline-flex; }
  .nav-links { display: none; position: absolute; inset-inline: 0; top: 64px; background: var(--ivory); flex-direction: column; align-items: stretch; padding: 12px 20px 20px; border-bottom: 1px solid var(--line); gap: 4px; }
  .nav-links.open { display: flex; }
  .nav-links a { padding: 10px 0; }
}
.site-foot { background: var(--navy); color: #C9D3DC; padding-block: 48px 32px; margin-top: 0; font-size: .92rem; }
.site-foot a { color: #E9EEF0; text-decoration: none; }
.site-foot a:hover { text-decoration: underline; }
.site-foot .logo { color: #fff; }
.site-foot .logo svg > circle:first-child { stroke: var(--gold); stroke-width: 1; }
.foot-grid { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 28px; }
.foot-grid ul { list-style: none; margin: 0; padding: 0; }
.foot-grid li { margin-bottom: 8px; }
.foot-grid h3 { color: #fff; font: 600 .82rem var(--sans); letter-spacing: .06em; text-transform: uppercase; }
@media (max-width: 760px) { .foot-grid { grid-template-columns: 1fr 1fr; } .foot-grid > :first-child { grid-column: 1 / -1; } }

/* Language menu */
.lang-menu { position: relative; }
.lang-menu summary { list-style: none; cursor: pointer; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: .88rem; background: var(--white); }
.lang-menu summary::-webkit-details-marker { display: none; }
.lang-menu ul { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); list-style: none; margin: 0; padding: 6px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 170px; z-index: 30; }
.lang-menu button { display: block; width: 100%; text-align: start; border: 0; background: none; padding: 8px 10px; border-radius: var(--radius-sm); font: inherit; cursor: pointer; color: var(--slate); }
.lang-menu button:hover, .lang-menu button[aria-current] { background: var(--sage-soft); color: var(--emerald-deep); }

/* Buttons and forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 20px; border-radius: var(--radius-sm); border: 1px solid transparent; background: var(--emerald); color: #fff; font: 600 .95rem/1.2 var(--sans); text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s, color .15s; }
.btn:hover { background: var(--emerald-deep); color: #fff; }
.btn.secondary { background: var(--white); color: var(--navy); border-color: var(--line); }
.btn.secondary:hover { border-color: var(--navy); color: var(--navy); }
.btn.gold { background: var(--gold); color: var(--navy); }
.btn.gold:hover { background: #B59455; }
.btn.ghost { background: none; color: var(--slate); border-color: transparent; }
.btn.ghost:hover { background: var(--stone); color: var(--navy); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 7px 12px; font-size: .85rem; }
.btn.large { padding: 14px 26px; font-size: 1.02rem; }
.btn[disabled], .btn[aria-disabled='true'] { opacity: .5; cursor: not-allowed; }
label { display: block; font-weight: 600; font-size: .9rem; color: var(--navy); margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.hint { font-size: .84rem; color: var(--muted); margin-top: 4px; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], input[type=time], input[type=url], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #CDD2CC; border-radius: var(--radius-sm); background: var(--white); color: var(--slate); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--sage); border-color: var(--emerald); }
textarea { min-height: 96px; resize: vertical; }
.error { color: var(--danger); font-size: .9rem; }
.notice { padding: 12px 16px; border-radius: var(--radius-sm); background: var(--sage-soft); color: var(--emerald-deep); border: 1px solid #C9DDD0; }
.notice.warn { background: var(--warn-soft); color: #6B4E0F; border-color: #EBD9A8; }
.notice.error { background: var(--danger-soft); color: var(--danger); border-color: #EBC5C5; }

/* Cards, chips, badges */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.card.raised { box-shadow: var(--shadow); }
.card h3 { margin-bottom: .35em; }
.card-link { display: block; text-decoration: none; color: inherit; transition: border-color .15s, transform .15s; }
.card-link:hover { border-color: var(--sage); transform: translateY(-1px); color: inherit; }
.field-icon { width: 40px; height: 40px; border-radius: 9px; background: var(--sage-soft); color: var(--emerald); display: inline-flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.field-icon svg { width: 22px; height: 22px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid #CDD2CC; border-radius: 999px; background: var(--white); color: var(--slate); font: 500 .9rem var(--sans); cursor: pointer; user-select: none; }
.chip:hover { border-color: var(--emerald); }
.chip[aria-pressed='true'], .chip.on { background: var(--emerald); border-color: var(--emerald); color: #fff; }
.chip .x { font-weight: 700; opacity: .8; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font: 600 .74rem/1.6 var(--sans); background: var(--stone); color: var(--slate); }
.badge.green { background: var(--sage-soft); color: var(--emerald-deep); }
.badge.gold { background: var(--gold-soft); color: #7A5B1E; }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.navy { background: var(--navy); color: #fff; }
.pill-steps { display: flex; gap: 6px; flex-wrap: wrap; }
.progress { height: 8px; background: var(--stone); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--emerald); border-radius: inherit; }

/* Selectable option cards (onboarding) */
.options { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.option { position: relative; text-align: start; display: block; width: 100%; padding: 16px; border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--white); cursor: pointer; font: inherit; color: inherit; }
.option:hover { border-color: var(--sage); }
.option[aria-pressed='true'], .option[aria-checked='true'] { border-color: var(--emerald); background: #F3F8F5; box-shadow: inset 0 0 0 1px var(--emerald); }
.option strong { display: block; color: var(--navy); margin-bottom: 4px; }
.option .muted { font-size: .88rem; }
.option .tick { position: absolute; top: 12px; inset-inline-end: 12px; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid #CDD2CC; }
.option[aria-pressed='true'] .tick, .option[aria-checked='true'] .tick { background: var(--emerald); border-color: var(--emerald); box-shadow: inset 0 0 0 4px #fff; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; background: var(--white); }
.table th, .table td { text-align: start; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font: 600 .78rem var(--sans); letter-spacing: .04em; text-transform: uppercase; color: var(--muted); background: #FBFAF6; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.stat { padding: 18px; }
.stat b { display: block; font: 700 1.7rem/1.1 var(--serif-head); color: var(--navy); }
.stat span { color: var(--muted); font-size: .86rem; }

/* Article reader (rendered by api/_lib/article.js in web mode) */
.article { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(22px, 5vw, 56px); }
.article-head h1 { font-size: clamp(1.9rem, 3.6vw, 2.6rem); }
.article-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; color: var(--muted); font-size: .9rem; margin-bottom: 18px; }
.article-summary { font: italic 1.18rem/1.6 var(--serif); color: var(--slate); border-inline-start: 3px solid var(--gold); padding: 6px 0 6px 18px; padding-inline-start: 18px; margin: 18px 0 26px; }
.prose { font: 1.12rem/1.78 var(--serif); color: var(--slate); max-width: var(--read); }
.prose h2 { font-size: 1.45rem; margin-top: 2em; scroll-margin-top: 80px; }
.prose h3 { font-size: 1.15rem; margin-top: 1.5em; }
.prose ul, .prose ol { padding-inline-start: 1.3em; }
.prose li { margin-bottom: .35em; }
.prose .cite { font: 600 .7rem var(--sans); vertical-align: super; }
.prose .cite a { text-decoration: none; margin-inline-start: 1px; }
.prose .kind { font: 600 .72rem var(--sans); letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-inline-end: 6px; }
.prose .kind-interpretation, .prose .kind-contested { border-inline-start: 3px solid var(--sage); padding-inline-start: 14px; }
.prose dl.concepts dt { font-weight: 700; color: var(--navy); margin-top: .8em; }
.prose dl.concepts dd { margin: 0 0 .4em; }
.prose .equation { font: 1.05rem/1.6 'Cambria Math', 'STIX Two Math', Georgia, serif; background: var(--ivory); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 14px; margin: 1em 0 .5em; overflow-x: auto; }
.prose ol.references { font: .9rem/1.55 var(--sans); color: var(--muted); }
.prose ol.references a { word-break: break-all; }
.prose .disclaimer { font: .9rem/1.55 var(--sans); background: var(--ivory); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; color: var(--muted); }
.prose .next { background: var(--sage-soft); border-radius: var(--radius-sm); padding: 14px 16px; }
.toc { position: sticky; top: 84px; font-size: .9rem; }
.toc a { display: block; padding: 4px 0; color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--accent); }

/* Knowledge map (homepage) */
.map { display: grid; gap: 14px; }
.map-node { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); font-weight: 600; color: var(--navy); }
.map-node small { display: block; font-weight: 400; color: var(--muted); }
.map-node .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); flex: none; }
.map-link { width: 2px; height: 14px; background: var(--sage); margin-inline-start: 36px; }

/* Modal and toast */
.modal { position: fixed; inset: 0; background: rgba(16, 36, 58, .45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--white); border-radius: var(--radius); max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; padding: 22px; box-shadow: var(--shadow); }
.modal-card.wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.modal-head h2 { font-size: 1.25rem; margin: 0; }
.toast { position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 18px; border-radius: var(--radius-sm); z-index: 60; box-shadow: var(--shadow); max-width: 90vw; }
[dir='rtl'] .toast { transform: translateX(50%); }
.toast.error { background: var(--danger); }

/* App shell (dashboard, admin) */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 64px); }
.side { background: var(--white); border-inline-end: 1px solid var(--line); padding: 20px 12px; }
.side a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: var(--radius-sm); color: var(--slate); text-decoration: none; font-size: .95rem; }
.side a:hover { background: var(--ivory); }
.side a[aria-current] { background: var(--sage-soft); color: var(--emerald-deep); font-weight: 600; }
.side svg { width: 18px; height: 18px; flex: none; }
.main { padding: 28px clamp(16px, 3vw, 40px); min-width: 0; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: flex; overflow-x: auto; gap: 4px; padding: 8px; border-inline-end: 0; border-bottom: 1px solid var(--line); position: sticky; top: 64px; z-index: 10; }
  .side a { white-space: nowrap; }
}
.empty { text-align: center; padding: 40px 20px; color: var(--muted); border: 1px dashed #CDD2CC; border-radius: var(--radius); background: var(--white); }
.skeleton { background: linear-gradient(90deg, var(--stone), #F0F1EE, var(--stone)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-sm); min-height: 18px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.steps-bar { display: flex; gap: 4px; margin-bottom: 24px; }
.steps-bar span { flex: 1; height: 4px; border-radius: 2px; background: var(--stone); }
.steps-bar span.done { background: var(--emerald); }
.steps-bar span.now { background: var(--gold); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media print { .site-head, .site-foot, .no-print, .side { display: none !important; } .article { border: 0; padding: 0; } body { background: #fff; } }
