/* Design tokens and typography.
   Palette mirrors the iOS app: tinted cards on a grouped background,
   accent = Theme.accent (hue 0.60, sat 0.80, brightness 0.70). */

/* Arabic first — the browser falls back to the Latin cut for ASCII runs. */
@font-face {
  font-family: "Plex Arabic";
  src: url("../assets/fonts/plex-arabic-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200F, U+2066-2069;
}
@font-face {
  font-family: "Plex Arabic";
  src: url("../assets/fonts/plex-arabic-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
  unicode-range: U+0600-06FF, U+0750-077F, U+08A0-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200F, U+2066-2069;
}
@font-face {
  font-family: "Plex Arabic";
  src: url("../assets/fonts/plex-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Plex Arabic";
  src: url("../assets/fonts/plex-latin-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  /* Light is the default everywhere, regardless of the device's system setting.
     Dark is opt-in through the header toggle, which sets data-theme="dark". */
  color-scheme: light;

  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-sunken: rgba(120, 120, 128, 0.08);
  --text: #1c1c1e;
  --text-dim: #6c6c70;
  --text-faint: #9a9aa0;
  --border: rgba(120, 120, 128, 0.20);

  --accent: #245db3;
  --accent-soft: rgba(36, 93, 179, 0.10);
  --accent-line: rgba(36, 93, 179, 0.22);

  --green: #24864b;
  --green-soft: rgba(36, 134, 75, 0.14);
  --red: #c0392f;
  --red-soft: rgba(192, 57, 47, 0.13);
  --orange: #c56a12;
  --orange-soft: rgba(197, 106, 18, 0.13);
  --teal: #0f7d84;
  --teal-soft: rgba(15, 125, 132, 0.13);
  --purple: #6d3aa8;
  --purple-soft: rgba(109, 58, 168, 0.13);

  --radius-card: 22px;
  --radius-tile: 24px;
  --radius-inner: 12px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --shadow-card: 0 4px 14px rgba(0, 0, 0, 0.05);
  --shadow-tile: 0 5px 18px rgba(0, 0, 0, 0.07);

  --reading-width: 760px;
  --font: "Plex Arabic", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #000000;
    --surface: #1c1c1e;
    --surface-sunken: rgba(120, 120, 128, 0.18);
    --text: #f2f2f7;
    --text-dim: #a1a1a6;
    --text-faint: #6c6c70;
    --border: rgba(120, 120, 128, 0.32);

    --accent: #6ea3ea;
    --accent-soft: rgba(110, 163, 234, 0.16);
    --accent-line: rgba(110, 163, 234, 0.30);

    --green: #4fc47a;
    --green-soft: rgba(79, 196, 122, 0.18);
    --red: #ff6b5e;
    --red-soft: rgba(255, 107, 94, 0.18);
    --orange: #f0a04b;
    --orange-soft: rgba(240, 160, 75, 0.18);
    --teal: #3fc7cf;
    --teal-soft: rgba(63, 199, 207, 0.18);
    --purple: #b28ce8;
    --purple-soft: rgba(178, 140, 232, 0.18);

    --shadow-card: 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-tile: 0 5px 18px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

/* `display:flex` on a component beats the hidden attribute's default
   `display:none`, so hidden rows would still show as empty boxes. */
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

/* Numeric readouts must never reflow the page as digits change —
   this is the web form of the ResultRow jitter fixed in the iOS app.
   They are also Latin islands: without an explicit LTR isolate the surrounding
   Arabic reorders "30 m/s" into "m/s 30". */
.readout,
.slider-value,
.result-value {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  direction: ltr;
  unicode-bidi: isolate;
}

/* Latin islands: formulas, symbols, canvases. */
.ltr {
  direction: ltr;
  unicode-bidi: isolate;
}

a { color: inherit; text-decoration: none; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
