/* ==========================================================================
   Base: reset, typography, focus, links, selection, scrollbars, motion
   ========================================================================== */

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

html {
  font-size: calc(var(--font-scale, 1) * 100%);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-padding-top: calc(var(--topbar-h) + var(--space-4));
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  font-weight: var(--fw-regular);
  line-height: var(--lh-normal);
  color: var(--text);
  background: var(--canvas);
  font-feature-settings: "kern" 1;
  font-optical-sizing: auto;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

[data-theme] { color: var(--text); }

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: -0.005em;
  color: var(--text);
  text-wrap: balance;
}
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); font-weight: var(--fw-semibold); }
h4 { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
h5, h6 { font-size: var(--fs-md); font-weight: var(--fw-semibold); }

p { margin: 0 0 var(--space-3); text-wrap: pretty; }
p:last-child { margin-bottom: 0; }

ul, ol { margin: 0; padding-inline-start: var(--space-6); }
li + li { margin-top: var(--space-1); }
.list-reset { list-style: none; margin: 0; padding: 0; }
.list-reset > li + li { margin-top: 0; }

small { font-size: var(--fs-sm); }
strong, b { font-weight: var(--fw-semibold); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-6) 0; }

img, svg, video, canvas { display: block; max-width: 100%; }
img, video { height: auto; }
svg { flex-shrink: 0; }
iframe { border: 0; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
textarea { resize: vertical; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }
table { border-collapse: collapse; border-spacing: 0; }
[hidden] { display: none !important; }

/* Inputs that are inherently LTR keep LTR text but align to the RTL edge */
input[type="email"], input[type="url"], input[type="tel"], input[dir="ltr"], textarea[dir="ltr"] {
  direction: ltr;
  text-align: right;
}
input[type="email"]:placeholder-shown, input[type="url"]:placeholder-shown, input[type="tel"]:placeholder-shown {
  direction: rtl;
}

code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.92em; }
code {
  padding: 0.1em 0.4em;
  border-radius: var(--radius-xs);
  background: var(--surface-3);
  direction: ltr;
  unicode-bidi: isolate;
}
pre {
  margin: 0;
  padding: var(--space-4);
  overflow: auto;
  border-radius: var(--radius-md);
  background: var(--ink);
  color: #E6EAF4;
  direction: ltr;
  text-align: left;
  line-height: 1.55;
}
pre code { background: none; padding: 0; color: inherit; }
kbd {
  display: inline-block;
  padding: 0.05em 0.45em;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  background: var(--surface);
  font-size: 0.82em;
  line-height: 1.4;
}

mark {
  background: var(--mark);
  color: var(--mark-text);
  border-radius: 3px;
  padding: 0 1px;
}

/* ---- Links ---------------------------------------------------------- */
a {
  color: var(--primary-text);
  text-decoration: none;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
  transition: color var(--dur-1) var(--ease-out);
}
a:hover { text-decoration: underline; }
.link-muted { color: var(--text-muted); }
.link-muted:hover { color: var(--text); }

:root[data-highlight-links="true"] a:not(.btn):not(.nav-item):not(.bottom-nav__item) {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  background: var(--link-highlight);
  border-radius: 2px;
  outline: 1px dashed currentColor;
  outline-offset: 1px;
}
:root[data-highlight-links="true"] .nav-item,
:root[data-highlight-links="true"] .bottom-nav__item,
:root[data-highlight-links="true"] a.btn {
  outline: 2px dashed var(--warning);
  outline-offset: 1px;
}

/* ---- Focus ---------------------------------------------------------- */
:focus { outline: none; }
:focus-visible {
  outline: var(--focus-width) solid var(--focus-color);
  outline-offset: var(--focus-offset);
}
[tabindex="-1"]:focus-visible { outline: none; }
main[tabindex="-1"]:focus-visible, h1[tabindex="-1"]:focus-visible { outline: none; }

/* ---- Selection ------------------------------------------------------ */
::selection { background: var(--selection); }

/* ---- Scrollbars ----------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--scrollbar-hover); }

/* ---- Utilities ------------------------------------------------------ */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.tabular-nums, .num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.ltr { direction: ltr; unicode-bidi: isolate; }
.bidi { unicode-bidi: isolate; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.line-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.text-sm { font-size: var(--fs-sm); }
.text-xs { font-size: var(--fs-xs); }
.text-lg { font-size: var(--fs-lg); }
.fw-medium { font-weight: var(--fw-medium); }
.fw-semibold { font-weight: var(--fw-semibold); }
.fw-bold { font-weight: var(--fw-bold); }
.text-center { text-align: center; }
.text-end { text-align: end; }
.text-success { color: var(--success-text); }
.text-danger { color: var(--danger-text); }
.text-warning { color: var(--warning-text); }
.text-primary { color: var(--primary-text); }
.mono { font-family: var(--font-mono); }

.skip-link {
  position: fixed;
  top: var(--space-3);
  inset-inline-start: var(--space-3);
  z-index: var(--z-skip);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-input);
  background: var(--primary);
  color: var(--on-primary);
  font-weight: var(--fw-semibold);
  box-shadow: var(--shadow-lg);
  transform: translateY(-160%);
  transition: transform var(--dur-2) var(--ease-out);
}
.skip-link:focus, .skip-link:focus-visible { transform: translateY(0); text-decoration: none; }

.noscript {
  margin: var(--space-8) auto;
  max-width: 520px;
  padding: var(--space-6);
  border-radius: var(--radius-card);
  background: var(--warning-soft);
  color: var(--warning-text);
  text-align: center;
  font-weight: var(--fw-semibold);
}

/* ---- Motion --------------------------------------------------------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* Page entrance — opacity only (see .page in layout.css: no transform on fixed-bar ancestors). */
@keyframes page-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes scale-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
:root[data-reduce-motion="true"] *,
:root[data-reduce-motion="true"] *::before,
:root[data-reduce-motion="true"] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

/* Readable-font mode: a touch more air between letters, words and lines */
:root[data-readable-font="true"] body {
  letter-spacing: 0.012em;
  word-spacing: 0.06em;
  line-height: var(--lh-relaxed);
}

@media print {
  body { background: #fff; color: #000; }
  .no-print, .sidebar, .topbar, .bottom-nav, .mobile-header, .toast-host { display: none !important; }
  .shell, .shell__main { display: block !important; padding: 0 !important; }
}
