/* AIOS Design System — Shatranj v1.0.0 Design Tokens
 * Unites Shatranj Obsidian & Muted Gold with Nordic Electric Sapphire accents
 */
:root,
[data-theme="dark"] {
  /* Shatranj Obsidian & Muted Gold Palette */
  --bg: #0B0D11;
  --bg-elev: #161A22;
  --bg-card: #161A22;
  --bg-surface-elevated: #1E2430;
  --bg-hover: #252C3A;
  --surface-soft: #1E2430;
  --panel: #161A22;
  --panel-elevated: #1E2430;

  --text: #EFE9DC;
  --fg: #EFE9DC;
  --text-secondary: #C8C2B6;
  --text-muted: #8B9BB0;
  --fg-muted: #8B9BB0;
  --fg-dim: #6F8197;

  --border: #2D3545;
  --border-subtle: rgba(111, 129, 151, 0.22);
  --border-strong: rgba(198, 161, 91, 0.38);

  --gold: #C6A15B;
  --accent-gold: #C6A15B;
  --accent: #38BDF8;
  --accent-hover: #60A5FA;
  --accent-soft: rgba(56, 189, 248, 0.12);
  --green: #4ADE80;
  --red: #F87171;
  --terminal-bg: #07090D;
  --terminal-text: #EFE9DC;
  --terminal-muted: #8B9BB0;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);

  /* Shatranj Chessboard Squares */
  --board-light: rgba(198, 161, 91, 0.14);
  --board-dark: #131720;

  /* Domain Accents */
  --accent-shah: #C6A15B;
  --accent-wazir: #60A5FA;
  --accent-hisn: #2DD4BF;
  --accent-faras: #818CF8;
  --accent-fil: #34D399;
  --accent-baydaq: #94A3B8;
  --accent-midan: #F59E0B;

  /* Typography */
  --font-serif: 'Newsreader', 'Iowan Old Style', Georgia, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-arabic: 'IBM Plex Sans Arabic', 'Noto Sans Arabic', 'Tahoma', sans-serif;

  /* Fluid Type Scale */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.3vw, 1.0625rem);
  --text-lg: clamp(1.125rem, 1rem + 0.5vw, 1.3rem);
  --text-xl: clamp(1.35rem, 1.1rem + 0.9vw, 1.75rem);
  --text-2xl: clamp(1.75rem, 1.3rem + 1.4vw, 2.4rem);
  --text-3xl: clamp(2.25rem, 1.5rem + 2.4vw, 3.4rem);

  --container-max: 1200px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --transition-fast: 140ms cubic-bezier(0.33, 0, 0.67, 1);
  --focus-ring: 2px solid var(--gold);
  --focus-offset: 2px;
}

[data-theme="light"] {
  --bg: #FAF9F5;
  --bg-elev: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-surface-elevated: #F3F1EA;
  --bg-hover: #EAE6DC;
  --surface-soft: #F3F1EA;
  --panel: #FFFFFF;
  --panel-elevated: #F3F1EA;

  --text: #141413;
  --fg: #141413;
  --text-secondary: #53524D;
  --text-muted: #73716B;
  --fg-muted: #73716B;
  --fg-dim: #73716B;

  --border: rgba(20, 20, 19, 0.12);
  --border-subtle: rgba(20, 20, 19, 0.08);
  --border-strong: rgba(20, 20, 19, 0.24);

  --gold: #8A6522;
  --accent-gold: #8A6522;
  --accent: #0F4C81;
  --accent-hover: #0A365C;
  --accent-soft: rgba(15, 76, 129, 0.08);
  --green: #15803D;
  --red: #B91C1C;
  --terminal-bg: #141413;
  --terminal-text: #F3F1EA;
  --terminal-muted: #9E9C95;
  --shadow: 0 6px 20px rgba(20, 20, 19, 0.08);

  --board-light: #EFE9DC;
  --board-dark: #DCD3BE;
}

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

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2 {
  font-family: var(--font-serif);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

h1 {
  font-size: var(--text-3xl);
  margin: 0 0 0.75rem;
}

h2 {
  font-size: var(--text-2xl);
  margin: 2rem 0 0.85rem;
}

h3 {
  font-size: 1.15rem;
  margin: 0 0 0.5rem;
}

.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 24px;
}

:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

code,
pre {
  font-family: var(--font-mono);
}

code {
  background: var(--surface-soft);
  padding: 0.15rem 0.4rem;
  border-radius: 5px;
  font-size: 0.86em;
  border: 1px solid var(--border-subtle);
}

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

/* WAEL AI OS Unified Stylesheet — Shatranj Obsidian & Gold + Editorial Layout */
.site-header {
  position: sticky;
  top: 0;
  z-index: 60;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
  position: relative;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; }
.brand-title { font-size: 0.98rem; letter-spacing: 0.03em; line-height: 1.15; }
.brand-sub { font-size: 0.65rem; color: var(--gold); letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; }

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}
.nav-link, .nav-drop-btn {
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: color var(--transition-fast), background var(--transition-fast);
}
.nav-link:hover, .nav-link.active, .nav-drop-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
  text-decoration: none;
}
.nav-drop { position: relative; }
.nav-drop-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 250px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.5rem;
  box-shadow: var(--shadow);
  z-index: 80;
}
.nav-drop:hover .nav-drop-menu,
.nav-drop:focus-within .nav-drop-menu { display: block; }
.nav-drop-menu a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
}
.nav-drop-menu a:hover { background: var(--bg-hover); text-decoration: none; }
.nav-drop-menu .meta { font-size: 0.75rem; color: var(--text-muted); }

.nav-actions { display: flex; align-items: center; gap: 0.5rem; }
.mobile-toggle { display: none; }

@media (max-width: 980px) {
  .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1.25rem;
    box-shadow: var(--shadow);
  }
  .site-nav.open { display: flex; }
  .mobile-toggle { display: inline-flex; }
  .nav-drop-menu { position: static; box-shadow: none; margin-top: 0.25rem; }
}

.main-content { padding: 2.25rem 24px 4.5rem; }

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 2rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.footer-domains { margin-top: 0.45rem; font-size: 0.8rem; }
.footer-links { display: flex; gap: 1rem; flex-wrap: wrap; }

/* Hero */
.hero {
  position: relative;
  padding: 3rem 0 2.5rem;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 2.25rem;
  background: radial-gradient(ellipse 70% 55% at 20% 0%, rgba(198, 161, 91, 0.09), transparent 70%),
              radial-gradient(ellipse 55% 45% at 85% 15%, rgba(56, 189, 248, 0.08), transparent 70%);
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.75rem;
}
.tagline {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  color: var(--gold);
  font-weight: 500;
  margin: 0 0 0.85rem;
}
.lead { font-size: 1.06rem; color: var(--text-secondary); max-width: 76ch; margin: 0 0 1.25rem; }

/* Grids & Cards */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.1rem 1.25rem;
}
.kpi-value {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--text);
  margin: 0.25rem 0;
}
.kpi-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gold); font-weight: 700; }
.kpi-sub { font-size: 0.82rem; color: var(--text-muted); }

/* Badges & Buttons */
.badge {
  display: inline-block;
  padding: 0.18rem 0.6rem;
  border-radius: var(--radius-pill);
  font-size: 0.73rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-surface-elevated);
  color: var(--text);
}
.badge-l4 { border-color: var(--green); color: var(--green); }
.badge-l2 { border-color: var(--accent); color: var(--accent); }
.badge-l1 { border-color: var(--gold); color: var(--gold); }
.badge-danger { border-color: var(--red); color: var(--red); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1.05rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.88rem;
  transition: background var(--transition-fast), transform var(--transition-fast);
}
.btn:hover { background: var(--bg-hover); text-decoration: none; }
.btn-primary { background: var(--gold); color: #0B0D11; border-color: var(--gold); }
.btn-primary:hover { opacity: 0.92; background: var(--gold); }
.btn-danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

/* Terminal Showcase */
.terminal-box {
  background: var(--terminal-bg);
  color: var(--terminal-text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem 1.15rem;
  overflow-x: auto;
}
.terminal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--terminal-muted);
}
.terminal-box pre {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--terminal-text);
  font-size: 0.82rem;
  line-height: 1.55;
}

pre {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.84rem;
}

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; display: block; overflow-x: auto; max-width: 100%; }
th, td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th { color: var(--text-muted); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* Interactive Component Explorer & Animated Flow */
.explorer-grid {
  display: grid;
  grid-template-columns: minmax(240px, 340px) 1fr;
  gap: 1.25rem;
  align-items: start;
}
@media (max-width: 860px) { .explorer-grid { grid-template-columns: 1fr; } }
.comp-tabs { display: flex; flex-direction: column; gap: 0.45rem; }
.comp-tab {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
}
.comp-tab:hover, .comp-tab.active {
  border-color: var(--gold);
  background: var(--bg-hover);
}
.comp-tab .ar { font-family: var(--font-arabic); color: var(--gold); font-size: 0.82rem; }

@keyframes flowDash {
  to { stroke-dashoffset: -24; }
}
.flow-line {
  stroke-dasharray: 6 6;
  animation: flowDash 1.4s linear infinite;
}
.flow-node rect { transition: stroke 0.2s ease, fill 0.2s ease; }
.flow-node.active rect { stroke: var(--gold); stroke-width: 2.5; }

/* Shatranj 8x8 Board */
.shatranj-layout {
  display: grid;
  grid-template-columns: minmax(300px, 540px) 1fr;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 900px) { .shatranj-layout { grid-template-columns: 1fr; } }
.chessboard {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  border: 2px solid var(--gold);
  border-radius: var(--radius-md);
  overflow: hidden;
  aspect-ratio: 1 / 1;
  box-shadow: var(--shadow);
}
.square {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(128, 128, 128, 0.12);
  cursor: pointer;
  padding: 2px;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  user-select: none;
  background: var(--board-light);
}
.square.dark { background: var(--board-dark); }
.square.highlighted {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
  background: rgba(198, 161, 91, 0.24);
}
.square .glyph { font-size: clamp(1rem, 2.2vw, 1.4rem); line-height: 1; }
.square .ar-label { font-family: var(--font-arabic); font-size: 0.65rem; color: var(--gold); }
.square .en-label { font-size: 0.58rem; color: var(--text-muted); font-weight: 700; }

.filter-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1.25rem;
}
.input {
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 0.9rem;
}
.hidden { display: none !important; }
