/* NORIA School design tokens + bespoke components.
   Direction: "Heritage school". Parchment paper, forest green, antique brass, oxblood,
   crests and italic serifs. Token names follow shadcn/ui (globals.css), so they port
   1:1 to Next.js + Tailwind v4. The NORIA wordmark and fonts come from
   landing_page/NORIA_Website_Proposal.html. */

/* Cascade layers: our element defaults beat Tailwind preflight, and Tailwind utilities
   beat our component classes, so utility overrides work as they do with shadcn. */
@layer theme, base, noria-base, components, utilities;

:root {
  /* Brand (legacy names kept so screens keep working: indigo = forest, lilac = pale brass) */
  --night: #0F1D15;
  --indigo: #16301F;
  --indigo-2: #1F3D2B;
  --violet: #2F5A43;
  --lilac: #DCC089;
  --ivory: #F4EDDC;
  --brass: #8C6A2E;
  --oxblood: #7E2230;
  --forest: #1F3D2B;

  /* shadcn-style semantic tokens (light: parchment) */
  --background: #F1E9D8;
  --foreground: #211F18;
  --card: #FAF5EA;
  --card-foreground: #211F18;
  --popover: #FFFBF3;
  --muted: #E8DFCB;
  --muted-foreground: #6E6550;
  --primary: #1F3D2B;
  --primary-foreground: #F6EFDD;
  --accent: #7E5E25;
  --accent-soft: #EFE3C4;
  --accent-foreground: #FFF8EA;
  --border: rgba(66, 50, 22, 0.14);
  --border-strong: rgba(66, 50, 22, 0.26);
  --ring: #7E5E25;

  /* States (semantic, separate from the accent) */
  --success: #36703F;      /* mastery */
  --success-soft: #DDE7D2;
  --warning: #A0621A;
  --warning-soft: #F3E2C3;
  --danger: #8E2533;
  --danger-soft: #F2DAD8;
  --info: #34597A;
  --info-soft: #DCE4EA;

  /* Houses */
  --house-falcon: #8E2533;
  --house-lion: #A57A2C;
  --house-eagle: #2E4F6E;
  --house-wolf: #3E5B45;

  --shadow-soft: 0 1px 2px rgba(66, 50, 22, 0.05), 0 10px 24px -14px rgba(66, 50, 22, 0.22);
  --shadow-lift: 0 2px 4px rgba(66, 50, 22, 0.06), 0 26px 48px -22px rgba(66, 50, 22, 0.38);
  --hero-grad: radial-gradient(ellipse 90% 70% at 100% 0%, rgba(214, 178, 108, 0.30) 0%, rgba(214, 178, 108, 0.08) 45%, rgba(214, 178, 108, 0) 70%),
               radial-gradient(ellipse 70% 60% at 0% 100%, rgba(126, 34, 48, 0.28) 0%, rgba(126, 34, 48, 0) 65%),
               linear-gradient(160deg, #0F1D15 0%, #16301F 55%, #1F3D2B 100%);
  /* Paper grain (inline SVG noise) */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .27 0 0 0 0 .12 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");

  --font-display: "Cormorant Garamond", "Noto Naskh Arabic", Georgia, serif;
  --font-body: "Jost", "IBM Plex Sans Arabic", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;

  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --background: #0E1611;
    --foreground: #EFE7D4;
    --card: #152019;
    --card-foreground: #EFE7D4;
    --popover: #1A271F;
    --muted: #1E2B22;
    --muted-foreground: #ABA38B;
    --primary: #E3C98F;
    --primary-foreground: #14271C;
    --accent: #D6B676;
    --accent-soft: rgba(214, 182, 118, 0.14);
    --accent-foreground: #14271C;
    --border: rgba(239, 231, 212, 0.10);
    --border-strong: rgba(239, 231, 212, 0.20);
    --ring: #D6B676;
    --success: #8CC393; --success-soft: rgba(140, 195, 147, 0.14);
    --warning: #E6B566; --warning-soft: rgba(230, 181, 102, 0.14);
    --danger: #E68C95;  --danger-soft: rgba(230, 140, 149, 0.14);
    --info: #96B8D6;    --info-soft: rgba(150, 184, 214, 0.14);
    --house-falcon: #E68C95; --house-lion: #DDBA74; --house-eagle: #96B8D6; --house-wolf: #9CC3A2;
    --brass: #D6B676;
    --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.55);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.3), 0 24px 48px -20px rgba(0, 0, 0, 0.75);
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 .95 0 0 0 0 .85 0 0 0 .035 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #0E1611;
  --foreground: #EFE7D4;
  --card: #152019;
  --card-foreground: #EFE7D4;
  --popover: #1A271F;
  --muted: #1E2B22;
  --muted-foreground: #ABA38B;
  --primary: #E3C98F;
  --primary-foreground: #14271C;
  --accent: #D6B676;
  --accent-soft: rgba(214, 182, 118, 0.14);
  --accent-foreground: #14271C;
  --border: rgba(239, 231, 212, 0.10);
  --border-strong: rgba(239, 231, 212, 0.20);
  --ring: #D6B676;
  --success: #8CC393; --success-soft: rgba(140, 195, 147, 0.14);
  --warning: #E6B566; --warning-soft: rgba(230, 181, 102, 0.14);
  --danger: #E68C95;  --danger-soft: rgba(230, 140, 149, 0.14);
  --info: #96B8D6;    --info-soft: rgba(150, 184, 214, 0.14);
  --house-falcon: #E68C95; --house-lion: #DDBA74; --house-eagle: #96B8D6; --house-wolf: #9CC3A2;
  --brass: #D6B676;
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.55);
  --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.3), 0 24px 48px -20px rgba(0, 0, 0, 0.75);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 .95 0 0 0 0 .85 0 0 0 .035 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Arabic: swap the type pairing, keep the hierarchy */
[dir="rtl"] {
  --font-display: "Noto Naskh Arabic", "Cormorant Garamond", serif;
  --font-body: "IBM Plex Sans Arabic", "Jost", sans-serif;
}

/* Page ground is unlayered on purpose: the Artifact viewer injects an unlayered
   off-white body reset, which would otherwise beat our layered body rule and leave
   dark-theme text on a light ground. */
html body {
  background-color: var(--background);
  background-image: var(--grain);
  color: var(--foreground);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
}

@layer noria-base {
/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background-color: var(--background);
  background-image: var(--grain);
  color: var(--foreground);
  font-family: var(--font-body);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, .display { font-family: var(--font-display); font-weight: 500; line-height: 1.08; letter-spacing: -0.01em; text-wrap: balance; margin: 0; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3, [dir="rtl"] .display { letter-spacing: 0; line-height: 1.35; }
p { margin: 0; }
.num, .tabular { font-variant-numeric: tabular-nums lining-nums; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--accent-soft); }
h1 em, h2 em, h3 em, .display em { font-style: italic; font-weight: 500; }

}

@layer components {
/* ---------- Bespoke components (map to React components later) ---------- */

/* <Eyebrow> */
.eyebrow {
  font-family: var(--font-body);
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--accent);
}
[dir="rtl"] .eyebrow { letter-spacing: 0; font-size: 12.5px; }

/* <Wordmark> — redrawn NORIA logo, stroke follows currentColor */
.wordmark svg { display: block; height: 100%; width: auto; }

/* <Hairline> */
.hairline { height: 1px; background: var(--border); border: 0; margin: 0; }

/* <Chip> / <Badge> */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding-inline: 10px;
  border-radius: 999px;
  font-size: 12px; font-weight: 500; letter-spacing: 0.01em;
  background: var(--muted); color: var(--muted-foreground);
  white-space: nowrap;
}
.chip svg { width: 13px; height: 13px; }
.chip-accent  { background: var(--accent-soft);  color: var(--accent); }
.chip-success { background: var(--success-soft); color: var(--success); }
.chip-warning { background: var(--warning-soft); color: var(--warning); }
.chip-danger  { background: var(--danger-soft);  color: var(--danger); }
.chip-info    { background: var(--info-soft);    color: var(--info); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

/* <Button> */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding-inline: 18px; border-radius: 999px;
  font: 500 14px/1 var(--font-body); letter-spacing: 0.01em;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  transition: transform .15s ease, background-color .2s ease, box-shadow .2s ease, border-color .2s ease;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--primary-foreground); box-shadow: var(--shadow-soft); }
.btn-primary:hover { box-shadow: var(--shadow-lift); }
.btn-accent { background: var(--accent); color: var(--accent-foreground); }
.btn-ghost { background: transparent; color: var(--foreground); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--muted); }
.btn-quiet { background: transparent; color: var(--muted-foreground); }
.btn-quiet:hover { color: var(--foreground); background: var(--muted); }
.btn-lg { height: 48px; padding-inline: 24px; font-size: 15px; }
.btn-sm { height: 32px; padding-inline: 12px; font-size: 13px; }
.btn-icon { width: 40px; padding: 0; }

/* <Card> — used by role, not everywhere */
.surface { background: var(--card); color: var(--card-foreground); border: 1px solid var(--border); border-radius: var(--radius); }
.surface-raised { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-soft); }

/* <Progress> */
.meter { height: 6px; border-radius: 999px; background: var(--muted); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.meter.success > i { background: var(--success); }
.meter.warning > i { background: var(--warning); }

/* <MasteryRing> — set --p (0–100) */
.ring {
  --p: 60; --size: 44px; --track: var(--muted); --fill: var(--accent);
  width: var(--size); height: var(--size); border-radius: 50%;
  background: conic-gradient(var(--fill) calc(var(--p) * 1%), var(--track) 0);
  display: grid; place-items: center; flex: none;
}
.ring::after { content: ""; width: calc(var(--size) - 8px); height: calc(var(--size) - 8px); border-radius: 50%; background: var(--card); grid-area: 1 / 1; }
.ring > span { grid-area: 1 / 1; z-index: 1; font-size: 11px; font-weight: 500; font-variant-numeric: tabular-nums; }

/* <AIDisclosure> — persistent label required by spec §5.3 */
.ai-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 500; letter-spacing: 0.04em;
  color: var(--accent); background: var(--accent-soft);
  padding: 4px 10px; border-radius: 999px;
}
.ai-label svg { width: 12px; height: 12px; }

/* Brand hero surface (always dark indigo, both themes) */
.hero-surface { background: var(--grain), var(--hero-grad); color: var(--ivory); }
.hero-surface em { color: var(--lilac); }

/* <Crest> — shield with the NORIA star (injected by noria.js into [data-crest]) */
[data-crest] svg { display: block; width: 100%; height: 100%; }

/* <Flourish> — brass rule with a centred lozenge, for section openings */
.flourish { display: flex; align-items: center; gap: 10px; color: var(--accent); }
.flourish::before, .flourish::after { content: ""; flex: 1; height: 1px; background: currentColor; opacity: .45; }
.flourish > i { width: 7px; height: 7px; transform: rotate(45deg); border: 1px solid currentColor; flex: none; }

/* Italic serif lede, used for greetings and quiet asides */
.lede { font-family: var(--font-display); font-style: italic; font-size: 1.2em; line-height: 1.35; }
[dir="rtl"] .lede { font-style: normal; }
.hero-surface .eyebrow { color: var(--lilac); }

/* Geometric star (8-point, from the brand proposal) as a watermark */
.star-mark { position: absolute; pointer-events: none; opacity: .5; aspect-ratio: 1; }
[data-star] svg { display: block; width: 100%; height: 100%; }

/* ---------- Prototype dock (injected by noria.js) ---------- */
.proto-dock {
  position: fixed; z-index: 90;
  inset-inline-end: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 4px;
  padding: 5px; border-radius: 999px;
  background: color-mix(in srgb, var(--popover) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid var(--border); box-shadow: var(--shadow-lift);
  font-size: 12.5px;
}
.proto-dock a, .proto-dock button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding-inline: 12px; border-radius: 999px;
  border: 0; background: transparent; color: var(--foreground);
  font: 500 12.5px/1 var(--font-body); cursor: pointer; text-decoration: none;
}
.proto-dock a:hover, .proto-dock button:hover { background: var(--muted); }
.proto-dock svg { width: 15px; height: 15px; }
.proto-dock .sep { width: 1px; height: 18px; background: var(--border); }
.proto-dock [aria-pressed="true"] { background: var(--primary); color: var(--primary-foreground); }
.proto-dock .lang-ar { font-family: "IBM Plex Sans Arabic", sans-serif; }

/* Motion */
@keyframes rise { from { opacity: .001; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.rise { animation: rise .6s cubic-bezier(.2, .7, .2, 1) both; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* Scrollbars */
.scroll-quiet { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
}
