/* ==========================================================================
   MASAR — base layer: design tokens, reset, typography, app chrome.
   Every layout rule uses logical properties so dir="rtl" flips cleanly.
   ========================================================================== */

:root {
  /* ── palette (shared contract with the panels layer) ── */
  --bg: #05080f;
  --panel: rgba(10, 16, 28, .82);
  --accent: #22d3ee;
  --accent-2: #7c8cff;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #fb4d5d;
  --text: #e6edf7;
  --muted: #8b98ad;

  /* ── surfaces ── */
  --panel-solid: #080d18;
  --panel-2: rgba(14, 22, 38, .72);
  --hairline: rgba(120, 150, 200, .14);
  --hairline-soft: rgba(120, 150, 200, .08);
  --hairline-strong: rgba(120, 150, 200, .26);
  --panel-border: 1px solid var(--hairline);
  --blur: blur(14px);
  --shadow: 0 24px 60px -28px rgba(0, 0, 0, .92), 0 2px 12px -6px rgba(0, 0, 0, .7);
  --shadow-sm: 0 10px 26px -16px rgba(0, 0, 0, .9);
  --glow-accent: 0 0 0 1px rgba(34, 211, 238, .28), 0 0 22px -6px rgba(34, 211, 238, .45);

  /* ── radii ── */
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --radius-pill: 999px;

  /* ── 8px spacing rhythm ── */
  --sp-h: 4px;
  --sp-1: 8px;
  --sp-2: 16px;
  --sp-3: 24px;
  --sp-4: 32px;
  --sp-5: 40px;

  /* ── type ── */
  --font-display: 'Space Grotesk', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --font-text: 'Inter', 'IBM Plex Sans Arabic', system-ui, sans-serif;
  --font-ar: 'IBM Plex Sans Arabic', 'Inter', system-ui, sans-serif;
  --fs-micro: 10px;
  --fs-tiny: 11px;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 16px;
  --fs-lg: 19px;
  --fs-xl: 24px;
  --fs-2xl: 30px;

  /* ── chrome metrics ── */
  --topbar-h: 60px;
  --rail-w: 88px;
  --gutter: 16px;

  --ease: cubic-bezier(.4, .12, .18, 1);
  --ease-out: cubic-bezier(.16, .84, .28, 1);

  color-scheme: dark;
}

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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-text);
  font-size: var(--fs-base);
  font-feature-settings: 'cv05' 1, 'ss01' 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
}

html[lang='ar'] body { font-family: var(--font-ar); }

h1, h2, h3, h4, p, figure { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

a { color: inherit; }

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

::selection { background: rgba(34, 211, 238, .3); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(120, 150, 200, .2);
  border-radius: var(--radius-pill);
}
::-webkit-scrollbar-thumb:hover { background: rgba(120, 150, 200, .34); }

/* ── shared primitives ─────────────────────────────────────────────────── */
.glass {
  background: var(--panel);
  border: var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
}

.num {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

.eyebrow {
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding-inline: var(--sp-2);
  background: linear-gradient(180deg, rgba(5, 8, 15, .94) 0%, rgba(5, 8, 15, .72) 68%, rgba(5, 8, 15, 0) 100%);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.topbar::after {
  content: '';
  position: absolute;
  inset-block-end: 0;
  inset-inline: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(124, 140, 255, .22) 18%, rgba(34, 211, 238, .22) 52%, transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  min-width: 0;
}

.brand__mark {
  inline-size: 30px;
  block-size: 30px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: radial-gradient(120% 120% at 30% 12%, rgba(34, 211, 238, .3), rgba(124, 140, 255, .16) 55%, rgba(10, 16, 28, .1));
  border: 1px solid rgba(34, 211, 238, .3);
  box-shadow: 0 0 18px -6px rgba(34, 211, 238, .55), inset 0 0 12px -6px rgba(34, 211, 238, .7);
}
.brand__mark svg { display: block; }

.brand__text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }

.brand__line {
  display: flex;
  align-items: baseline;
  gap: 7px;
  line-height: 1;
}

.brand__word {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: 700;
  letter-spacing: .26em;
  padding-inline-end: 2px;
  background: linear-gradient(92deg, #eaf3ff 8%, var(--accent) 58%, var(--accent-2) 104%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand__sep { color: rgba(120, 150, 200, .34); font-size: var(--fs-xs); }

.brand__ar {
  font-family: var(--font-ar);
  font-size: var(--fs-md);
  font-weight: 600;
  color: #cbd8ec;
  letter-spacing: .02em;
}

.brand__sub {
  font-size: var(--fs-micro);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__spacer { flex: 1 1 auto; }

.topbar__tools {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

/* ── honesty badge ── */
.badge-modeled {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding-inline: 11px;
  border-radius: var(--radius-pill);
  background: rgba(251, 191, 36, .07);
  border: 1px solid rgba(251, 191, 36, .26);
  color: #f4d78b;
  font-size: var(--fs-tiny);
  font-weight: 600;
  letter-spacing: .06em;
  white-space: nowrap;
  cursor: help;
}
.badge-modeled__dot {
  inline-size: 6px;
  block-size: 6px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 9px 1px rgba(251, 191, 36, .8);
  flex: none;
}

/* ── segmented control (day type) ── */
.seg {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius-pill);
  background: rgba(10, 16, 28, .7);
  border: var(--panel-border);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

.seg__btn {
  height: 26px;
  padding-inline: 13px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-tiny);
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--muted);
  white-space: nowrap;
  transition: color .18s var(--ease), background-color .18s var(--ease);
}
.seg__btn:hover { color: var(--text); }
.seg__btn[aria-pressed='true'] {
  color: #04121a;
  background: linear-gradient(180deg, #4fe0f5, var(--accent));
  box-shadow: 0 0 16px -4px rgba(34, 211, 238, .7);
}

/* ── icon / ghost buttons ── */
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  min-inline-size: 32px;
  padding-inline: 12px;
  border-radius: var(--radius-pill);
  background: rgba(10, 16, 28, .7);
  border: var(--panel-border);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  color: var(--text);
  font-size: var(--fs-tiny);
  font-weight: 600;
  letter-spacing: .06em;
  transition: border-color .18s var(--ease), background-color .18s var(--ease), color .18s var(--ease);
}
.btn-ghost:hover {
  border-color: rgba(34, 211, 238, .4);
  background: rgba(16, 26, 44, .82);
}
.btn-ghost svg { flex: none; opacity: .8; }

.btn-lang__glyph { font-family: var(--font-ar); font-size: var(--fs-xs); }

/* ==========================================================================
   Left rail
   ========================================================================== */
.rail {
  position: fixed;
  inset-block-start: calc(var(--topbar-h) + var(--gutter));
  inset-inline-start: var(--gutter);
  z-index: 35;
  inline-size: var(--rail-w);
  padding: var(--sp-1) 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--panel);
  border: var(--panel-border);
  border-radius: var(--radius);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow);
}

.rail__btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding-block: 9px 8px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  transition: color .16s var(--ease), background-color .16s var(--ease);
}
.rail__btn:hover { color: var(--text); background: rgba(120, 150, 200, .07); }

.rail__btn svg {
  inline-size: 21px;
  block-size: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: filter .16s var(--ease);
}

.rail__label {
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: .05em;
  line-height: 1.1;
  text-align: center;
}

.rail__btn[aria-current='true'] {
  color: var(--accent);
  background: linear-gradient(90deg, rgba(34, 211, 238, .14), rgba(34, 211, 238, .04) 70%, transparent);
}
.rail__btn[aria-current='true'] svg { filter: drop-shadow(0 0 6px rgba(34, 211, 238, .7)); }
.rail__btn[aria-current='true']::before {
  content: '';
  position: absolute;
  inset-block: 8px;
  inset-inline-start: -6px;
  inline-size: 3px;
  border-start-end-radius: 3px;
  border-end-end-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 12px 1px rgba(34, 211, 238, .8);
}

.rail__sep {
  height: 1px;
  margin: 6px 8px;
  background: var(--hairline-soft);
}

/* ==========================================================================
   Splash / loading experience
   ========================================================================== */
.splash {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 90% at 50% 42%, rgba(14, 30, 54, .55), transparent 62%),
    radial-gradient(80% 60% at 78% 84%, rgba(124, 140, 255, .12), transparent 70%),
    var(--bg);
  transition: opacity .7s var(--ease), visibility .7s var(--ease);
}
.splash[hidden] { display: grid; }              /* fade instead of snap */
.splash.is-gone { opacity: 0; visibility: hidden; pointer-events: none; }

.splash__inner {
  inline-size: min(430px, 84vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  text-align: center;
}

.splash__mark {
  inline-size: 62px;
  block-size: 62px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: radial-gradient(120% 120% at 30% 12%, rgba(34, 211, 238, .28), rgba(124, 140, 255, .14) 55%, rgba(10, 16, 28, .1));
  border: 1px solid rgba(34, 211, 238, .3);
  box-shadow: 0 0 46px -12px rgba(34, 211, 238, .8), inset 0 0 20px -10px rgba(34, 211, 238, .9);
  animation: mark-breathe 3.6s var(--ease) infinite;
}

@keyframes mark-breathe {
  0%, 100% { box-shadow: 0 0 46px -12px rgba(34, 211, 238, .8), inset 0 0 20px -10px rgba(34, 211, 238, .9); }
  50%      { box-shadow: 0 0 62px -10px rgba(34, 211, 238, 1), inset 0 0 26px -10px rgba(34, 211, 238, 1); }
}

.splash__word {
  font-family: var(--font-display);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: .42em;
  padding-inline-start: .42em;
  background: linear-gradient(92deg, #eaf3ff, var(--accent) 62%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.splash__ar {
  font-family: var(--font-ar);
  font-size: var(--fs-lg);
  color: #b9c8de;
  letter-spacing: .06em;
  margin-block-start: 2px;
}
.splash__sub {
  font-size: var(--fs-xs);
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-block-start: var(--sp-1);
}

.splash__progress { inline-size: 100%; display: flex; flex-direction: column; gap: 10px; }

.load-row { display: flex; flex-direction: column; gap: 6px; }
.load-row__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  font-size: var(--fs-tiny);
  color: var(--muted);
  letter-spacing: .04em;
}
.load-row__pct { font-family: var(--font-display); font-variant-numeric: tabular-nums; color: #c6d3e6; }
.load-row__bar {
  block-size: 3px;
  border-radius: var(--radius-pill);
  background: rgba(120, 150, 200, .12);
  overflow: hidden;
}
.load-row__fill {
  display: block;
  block-size: 100%;
  inline-size: 0%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  box-shadow: 0 0 12px -2px rgba(34, 211, 238, .9);
  transition: inline-size .22s var(--ease-out);
}
.load-row.is-done .load-row__fill { background: linear-gradient(90deg, var(--good), var(--accent)); }

.splash__hint {
  font-size: var(--fs-tiny);
  color: rgba(139, 152, 173, .74);
  letter-spacing: .08em;
  min-block-size: 16px;
  transition: opacity .3s var(--ease);
}
.splash__hint kbd {
  font-family: var(--font-display);
  font-size: var(--fs-micro);
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid var(--hairline);
  background: rgba(120, 150, 200, .08);
}

.splash__error {
  font-size: var(--fs-xs);
  color: var(--bad);
  line-height: 1.5;
  max-inline-size: 40ch;
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* ==========================================================================
   Narrow viewports — keep the demo composed rather than broken
   ========================================================================== */
@media (max-width: 1180px) {
  :root { --rail-w: 62px; }
  .rail__label { display: none; }
  .rail__btn { padding-block: 11px; }
  .brand__sub { display: none; }
}

@media (max-width: 820px) {
  :root { --topbar-h: 54px; }
  .badge-modeled span { display: none; }
  .badge-modeled { padding-inline: 9px; }
}
