/* ==========================================================================
   Codalla Design System — base layer.  Requires tokens.css.
   Direction-aware (LTR + RTL), theme-aware (light + dark), logical properties only.
   ========================================================================== */

/* ---- Direction & script ------------------------------------------------- */
:root {
  --ds-dir-sign: 1;                                  /* +1 LTR, -1 RTL — for canvas math, translateX, gradients */
  --ds-font-ui: var(--ds-font-ui-en);
  --ds-leading-body: var(--ds-font-leading-normal);
  --ds-btn-pad-x: 10px;                                /* 0.7x internal padding: compact titles */
}
:root[dir="rtl"] {
  --ds-dir-sign: -1;
  --ds-font-ui: var(--ds-font-ui-ar);
  --ds-leading-body: var(--ds-font-leading-relaxed);  /* Arabic needs more air */
  --ds-btn-pad-x: 7px;                                 /* 0.7x internal padding: Walk rule */
}
:root:lang(ckb), :root:lang(ku) { --ds-font-ui: var(--ds-font-ui-ku); }
:root[dir="rtl"][lang^="tk"] { --ds-font-ui: var(--ds-font-ui-en); }   /* Turkmen is Latin, even if hosted in an RTL shell */

/* Inline foreign-script runs keep their own face and rhythm */
:lang(ar):not(:root) { font-family: var(--ds-font-ui-ar); line-height: var(--ds-font-leading-relaxed); }
:lang(ckb):not(:root), :lang(ku):not(:root) { font-family: var(--ds-font-ui-ku); line-height: var(--ds-font-leading-relaxed); }
:lang(en):not(:root), :lang(tk):not(:root) { font-family: var(--ds-font-ui-en); }

/* ---- Document ----------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--ds-bg-base); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--ds-bg-wash);
  background-attachment: fixed;
  color: var(--ds-text-primary);
  font-family: var(--ds-font-ui);
  font-size: var(--ds-font-size-md);
  line-height: var(--ds-leading-body);
  font-weight: var(--ds-font-weight-regular);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
.ds-no-wash { background: var(--ds-bg-base); }
::selection { background: var(--ds-selection); }
img, svg, video, canvas { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Arabic never gets tracking (breaks letter joining). Only Latin caps labels do. */
:lang(ar), :lang(ckb), :lang(ku), [dir="rtl"] { letter-spacing: 0; }

/* ---- Focus (every interactive element, both themes) --------------------- */
:focus-visible { outline: 2px solid var(--ds-focus-ring); outline-offset: 2px; border-radius: var(--ds-radius-xs); }
:focus:not(:focus-visible) { outline: none; }

/* ---- Scrollbars (Walk) -------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--ds-surface-active) transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--ds-surface-active); border-radius: 6px; }

/* ---- Typography roles --------------------------------------------------- */
.ds-display { font-family: var(--ds-font-display); font-weight: 400; line-height: var(--ds-font-leading-tight); }
:root[dir="rtl"] .ds-display, :lang(ar).ds-display { line-height: 1.5; }        /* Ruqaa has deep descenders */
.ds-h1 { font-size: var(--ds-font-size-3xl); font-weight: 700; line-height: var(--ds-font-leading-tight); letter-spacing: var(--ds-font-tracking-tight); }
.ds-h2 { font-size: var(--ds-font-size-2xl); font-weight: 700; line-height: var(--ds-font-leading-tight); letter-spacing: var(--ds-font-tracking-tight); }
.ds-h3 { font-size: var(--ds-font-size-xl);  font-weight: 700; line-height: var(--ds-font-leading-snug); }
.ds-h4 { font-size: var(--ds-font-size-lg);  font-weight: 700; line-height: var(--ds-font-leading-snug); }
.ds-body { font-size: var(--ds-font-size-md); line-height: var(--ds-leading-body); }
.ds-body-sm { font-size: var(--ds-font-size-sm); line-height: var(--ds-leading-body); }
.ds-meta { font-size: var(--ds-font-size-xs); color: var(--ds-text-muted); line-height: var(--ds-font-leading-snug); }
.ds-label { font-size: var(--ds-font-size-2xs); font-weight: 700; color: var(--ds-text-secondary); }
.ds-label:lang(en), .ds-label:lang(tk) { text-transform: uppercase; letter-spacing: var(--ds-font-tracking-caps); }
.ds-prose { max-inline-size: var(--ds-size-prose-max); }
.ds-mono, code, kbd, pre { font-family: var(--ds-font-mono); }
.ds-text-secondary { color: var(--ds-text-secondary); } .ds-text-muted { color: var(--ds-text-muted); }

/* ---- Bidi helpers ------------------------------------------------------- */
/* Code, paths, URLs, model ids, emails: always LTR, isolated, even inside Arabic. */
.ds-ltr, code, kbd, pre, samp { direction: ltr; unicode-bidi: isolate; }
.ds-ltr-block, pre { text-align: left; }
.ds-rtl { direction: rtl; unicode-bidi: isolate; }
/* Numbers: Western digits by default, tabular, never reordered by neighbours. */
.ds-num { font-family: var(--ds-font-numerals); font-variant-numeric: tabular-nums lining-nums; unicode-bidi: isolate; direction: ltr; display: inline-block; }
/* Directional icons (arrows, chevrons, back/forward, send, reply, indent) mirror in RTL. */
[dir="rtl"] .ds-flip, .ds-flip:dir(rtl) { transform: scaleX(-1); }

/* ---- Layout primitives (logical) ---------------------------------------- */
.ds-stack { display: flex; flex-direction: column; gap: var(--ds-space-4); }
.ds-row { display: flex; align-items: center; gap: var(--ds-space-3); }
.ds-row--between { justify-content: space-between; }
.ds-container { inline-size: 100%; max-inline-size: var(--ds-size-content-max); margin-inline: auto; padding-inline: var(--ds-space-4); }
.ds-scroll { overflow: auto; min-block-size: 0; }            /* every region scrolls itself; the page does not */
.ds-sr-only { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.ds-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ds-safe-top { padding-block-start: env(safe-area-inset-top); }
.ds-safe-bottom { padding-block-end: env(safe-area-inset-bottom); }
.ds-safe-x { padding-inline: max(var(--ds-space-4), env(safe-area-inset-left), env(safe-area-inset-right)); }

/* ---- Motion ------------------------------------------------------------- */
@keyframes ds-fade-in { from { opacity: 0 } to { opacity: 1 } }
@keyframes ds-rise { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }
@keyframes ds-pop { from { opacity: 0; transform: scale(0.96) } to { opacity: 1; transform: none } }
@keyframes ds-spin { to { transform: rotate(360deg) } }
@keyframes ds-pulse { 0%, 100% { opacity: 1 } 50% { opacity: 0.4 } }
@keyframes ds-shimmer { from { background-position: calc(var(--ds-dir-sign) * -200%) 0 } to { background-position: calc(var(--ds-dir-sign) * 200%) 0 } }
@keyframes ds-wash-drift { 0%, 100% { transform: translate(0, 0) scale(1) } 50% { transform: translate(calc(var(--ds-dir-sign) * 2.5%), 2%) scale(1.03) } }
.ds-enter { animation: ds-rise var(--ds-duration-slow) var(--ds-ease-out) both; }
.ds-enter-pop { animation: ds-pop var(--ds-duration-base) var(--ds-ease-out) both; }
@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; }
}
