/* Design tokens — colors, spacing, typography, radii. Single source of visual constants.
   Elevation on dark = lighter surface levels + hairline borders (shadows barely read on dark);
   all text tokens are WCAG AA on every surface level they're used on. */
:root {
  /* color — surfaces (elevation ladder: bg → surface → surface-2 → surface-3) */
  --c-bg: #0f1115;
  --c-surface: #181b22;
  --c-surface-2: #1f232c;
  --c-surface-3: #262b36;
  --c-border: #2a3040;
  --c-border-strong: #3a4152;

  /* color — text (contrast on #0f1115: 15.9 / 9.0 / 7.4) */
  --c-text: #e8ecf4;
  --c-text-secondary: #aab4c5;
  --c-text-muted: #9aa3b2;

  /* color — accent (#5b8cff is 5.97:1 on bg — AA as text/icon; dark text on primary fills) */
  --c-primary: #5b8cff;
  --c-primary-hover: #7ea5ff;
  --c-primary-active: #4a7bf0;
  --c-on-primary: #0b1020;
  --c-danger: #ff5c6c;
  --c-danger-hover: #ff7280;
  --c-success: #45d18f;
  --c-focus: #9bc0ff;

  /* decorative gradient accent (never used as a text/background contrast pair) */
  --g-accent: linear-gradient(135deg, #5b8cff, #8f6bff);
  --g-glow: radial-gradient(ellipse 60% 50% at 50% 0%, rgba(91, 140, 255, 0.12), transparent 70%);

  /* spacing scale */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-8: 48px;
  --sp-10: 64px;

  /* typography */
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans Hebrew', 'Noto Sans Arabic', sans-serif;
  --fs-xs: 0.75rem;
  --fs-sm: 0.85rem;
  --fs-base: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.6rem;
  --fs-2xl: 2.25rem;
  --fs-3xl: clamp(2.25rem, 5vw, 3rem);

  /* radius + elevation */
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --shadow-overlay: 0 16px 48px rgba(0, 0, 0, 0.5);

  /* motion (interactive elements transition colors only — never `all`) */
  --transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

/* Base + shared BEM blocks. Layout uses logical properties so RTL mirrors automatically. */
/* tokens.css inlined above */

* { box-sizing: border-box; }

html, body, #root { height: 100%; }

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: 1.5;
}

a { color: var(--c-primary); transition: var(--transition); }
a:hover { color: var(--c-primary-hover); }

h1, h2, h3 { letter-spacing: -0.02em; line-height: 1.2; }

:focus-visible {
  outline: 2px solid var(--c-focus);
  outline-offset: 2px;
}

/* ---- layout ---- */
.app { display: flex; flex-direction: column; min-height: 100%; }
.app__main { flex: 1; width: 100%; max-width: 960px; margin-inline: auto; padding: var(--sp-5) var(--sp-4); }

/* ---- header ---- */
.header {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface);
  border-block-end: 1px solid var(--c-border);
}
.header__brand { font-weight: 700; font-size: var(--fs-lg); margin: 0; }
.header__nav { display: flex; align-items: center; gap: var(--sp-3); margin-inline-start: auto; flex-wrap: wrap; }
.header__link { color: var(--c-text-muted); text-decoration: none; padding: var(--sp-1) var(--sp-2); border-radius: var(--radius-sm); transition: var(--transition); }
.header__link:hover { color: var(--c-text); }
.header__link--active { color: var(--c-text); }

/* ---- buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface-2);
  color: var(--c-text);
  font: inherit;
  cursor: pointer;
  transition: var(--transition);
}
.btn:hover { border-color: var(--c-border-strong); background: var(--c-surface-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn--primary { background: var(--c-primary); border-color: var(--c-primary); color: var(--c-on-primary); font-weight: 600; }
.btn--primary:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }
.btn--primary:active:not(:disabled) { background: var(--c-primary-active); border-color: var(--c-primary-active); }
.btn--danger { color: var(--c-danger); border-color: transparent; background: transparent; }
.btn--danger:hover { background: rgba(255, 92, 108, 0.12); border-color: var(--c-danger); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--c-text-muted); }
.btn--ghost:hover { color: var(--c-text); background: var(--c-surface-2); }
.btn--sm { padding: var(--sp-1) var(--sp-3); font-size: var(--fs-sm); }
.btn--block { width: 100%; }

/* ---- form fields ---- */
.field { display: flex; flex-direction: column; gap: var(--sp-2); margin-block-end: var(--sp-4); }
/* Reusable thin modern scrollbar — add .scroll-thin to ANY scroll surface to theme its scrollbar. */
.scroll-thin { scrollbar-width: thin; scrollbar-color: var(--c-border) transparent; }
.scroll-thin::-webkit-scrollbar { width: 8px; }
.scroll-thin::-webkit-scrollbar-track { background: transparent; }
.scroll-thin::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 999px; }
.scroll-thin::-webkit-scrollbar-thumb:hover { background: var(--c-text-muted); }
/* History version list: cap the height and scroll inside the (shared) modal body so the panel stays
   within the viewport. padding-inline-end keeps the scrollbar off the row action buttons. The
   scrollbar theme comes from .scroll-thin (applied in the markup). */
.history-list { max-height: 50vh; overflow-y: auto; padding-inline-end: var(--sp-2); }
/* Shared-version status indicator (green) shown inline next to the version name. Status, not action. */
.history-shared { display: inline-flex; align-items: center; color: var(--c-success); margin-inline-start: var(--sp-2); vertical-align: middle; }
/* Note row action: outline icon by default; primary-coloured (with a filled dot) when the version
   HAS a note. Same specificity as .btn but declared later, so it wins the icon colour. */
.history-note--set { color: var(--c-primary); }
/* Note dialog: preserve the note's line breaks/spaces (plain text, React-escaped — never innerHTML),
   wrap long words. The textarea grows vertically; the live counter sits at the inline-end. */
.history-note-text { white-space: pre-wrap; word-break: break-word; }
.history-note-textarea { width: 100%; resize: vertical; min-block-size: 6rem; line-height: 1.5; }
.history-note-counter { display: block; margin-block-start: var(--sp-1); font-size: var(--fs-sm); color: var(--c-text-muted); text-align: end; }
.history-note-counter--warn { color: var(--c-text); }
.history-note-counter--limit { color: var(--c-danger); }
.field__label { font-size: var(--fs-sm); color: var(--c-text-muted); }
.field__input,
.field__select {
  padding: var(--sp-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-bg);
  color: var(--c-text);
  font: inherit;
}
.field__input, .field__select { transition: var(--transition), box-shadow 0.15s ease; }
.field__input:focus, .field__select:focus { border-color: var(--c-primary); outline: none; box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.25); }

/* ---- messages ---- */
.alert { padding: var(--sp-3); border-radius: var(--radius-sm); margin-block-end: var(--sp-4); font-size: var(--fs-sm); }
.alert--error { background: rgba(255, 92, 108, 0.12); color: var(--c-danger); border: 1px solid rgba(255, 92, 108, 0.4); }
.alert--success { background: rgba(69, 209, 143, 0.12); color: var(--c-success); border: 1px solid rgba(69, 209, 143, 0.4); }
.alert--info { background: var(--c-surface-2); color: var(--c-text-muted); border: 1px solid var(--c-border); }
.alert__text { margin: 0 0 var(--sp-2); }
/* Auto-dismissing status toast: opacity transitions to 0 when `--leaving` is applied (JS timer). */
.alert--toast { opacity: 1; transition: opacity 400ms ease; }
.alert--toast.alert--leaving { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .alert--toast { transition: none; } }

/* ---- auth card ---- */
.auth { position: relative; min-height: 100%; display: grid; place-items: center; padding: var(--sp-5); }
.auth__card { width: 100%; max-width: 380px; background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: var(--sp-6); box-shadow: var(--shadow); }
.auth__title { margin: 0 0 var(--sp-1); font-size: var(--fs-xl); }
.auth__subtitle { margin: 0 0 var(--sp-5); color: var(--c-text-muted); }
.auth__footer { margin-block-start: var(--sp-4); font-size: var(--fs-sm); color: var(--c-text-muted); text-align: center; }
/* Pin the language picker to the top (inline-end) corner, OUT of the centered grid flow, so it no
   longer floats above the card pushing it down. Shared by SignIn/SignUp/ForgotPassword. RTL-safe
   via logical inset properties. */
.auth__topbar { position: absolute; inset-block-start: 0; inset-inline-end: 0; display: flex; justify-content: flex-end; padding: var(--sp-3) var(--sp-4); }

/* ---- language switcher ---- */
.lang { display: inline-flex; align-items: center; gap: var(--sp-2); }
.lang__select { padding: var(--sp-1) var(--sp-2); background: var(--c-bg); color: var(--c-text); border: 1px solid var(--c-border); border-radius: var(--radius-sm); font: inherit; font-size: var(--fs-sm); }

/* ---- page heading ---- */
.page__head { display: flex; align-items: center; gap: var(--sp-3); margin-block-end: var(--sp-5); flex-wrap: wrap; }
.page__title { margin: 0; font-size: var(--fs-xl); }
/* "Which version am I on" status chip in the project header (read-only label, RTL-safe). */
.page__version { color: var(--c-text-muted); font-size: var(--fs-sm); padding: var(--sp-1) var(--sp-3); border: 1px solid var(--c-border); border-radius: var(--radius-sm); white-space: nowrap; }
.page__sub { color: var(--c-text-muted); margin-inline-start: auto; font-size: var(--fs-sm); }

/* ---- create row ---- */
.create { display: flex; gap: var(--sp-2); margin-block-end: var(--sp-5); }
.create__input { flex: 1; padding: var(--sp-3); border: 1px solid var(--c-border); border-radius: var(--radius-sm); background: var(--c-bg); color: var(--c-text); font: inherit; }

/* ---- project list ---- */
.projects { display: grid; gap: var(--sp-3); grid-template-columns: 1fr; list-style: none; padding: 0; margin: 0; }
.project-card {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  flex-wrap: wrap;
  transition: var(--transition);
}
.project-card:hover { background: var(--c-surface-2); border-color: var(--c-border-strong); }
.project-card__info { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.project-card__name { font-weight: 600; word-break: break-word; }
.project-card__meta { font-size: var(--fs-sm); color: var(--c-text-muted); }
.project-card__actions { display: flex; gap: var(--sp-2); margin-inline-start: auto; flex-wrap: wrap; }
/* History rows ONLY: stack the actions BELOW the name/date, flush to the (logical) start — directly
   under the text rather than pushed to the far end. Scoped to .history-list so the Dashboard's
   project cards (same .project-card class) keep their name-left / actions-right row layout. */
.history-list .project-card { flex-direction: column; align-items: flex-start; }
.history-list .project-card__actions { margin-inline-start: 0; }

/* ---- empty / loading states ---- */
.state { text-align: center; padding: var(--sp-8) var(--sp-4); color: var(--c-text-muted); }
.state__title { color: var(--c-text); font-size: var(--fs-lg); margin: 0 0 var(--sp-2); }

/* ---- settings ---- */
.panel { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: var(--sp-5); max-width: 460px; }
.panel + .panel { margin-block-start: var(--sp-4); }
.panel__title { margin: 0 0 var(--sp-4); font-size: var(--fs-lg); }

/* ---- embedded editor ---- */
.editor-frame { width: 100%; height: 72vh; min-height: 420px; border: 1px solid var(--c-border); border-radius: var(--radius); background: var(--c-bg); display: block; }
.share-badge { margin: 0; padding: var(--sp-1) var(--sp-3); }

/* ---- fluid editor route (/project/:id only) ---- */
/* Full-width + fill the viewport height beneath the header. `.app` is already a flex column
   (min-height:100%), so this is a pure flex-fill: the fluid main is a column, the Project
   <section> grows to fill it, and the editor iframe takes the remaining height (its base
   min-height:420px stays the floor on short viewports). The base .app__main / .editor-frame
   rules are untouched, so other routes and the public share view are unchanged. */
.app__main--full { max-width: none; padding: 0; display: flex; flex-direction: column; }
/* Compaction (A.1/B3 + S1): trim top, minimal 8px side gutter (keeps the toolbar + editor
   border off the viewport edge), bottom 0 so the iframe reaches the viewport edge. */
.app__main--full > section { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: var(--sp-3) var(--sp-2) 0; }
.app__main--full .page__head { margin-block-end: var(--sp-3); }
.app__main--full .editor-frame { flex: 1; height: auto; }
/* Trim the global header height on the editor route only (scoped via .app--fluid). */
.app--fluid .header { padding-block: var(--sp-2); }

/* Public share — standalone invalid/revoked page: full-bleed black, centered, NO app chrome. */
.share-error {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-5);
  background: #000;
  color: var(--c-text);
  text-align: center;
}
.share-error__msg { margin: 0; font-size: var(--fs-lg); }
.share-error__redirect { margin: 0; color: var(--c-text-muted); font-size: var(--fs-sm); }

/* ---- modal / dialog ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: rgba(8, 9, 12, 0.6);
  backdrop-filter: blur(4px);
}
.modal__panel {
  width: 100%;
  max-width: 420px;
  background: var(--c-surface-3);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
  padding: var(--sp-5);
  animation: modal-in 150ms ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) { .modal__panel { animation: none; } }
.modal__head { display: flex; align-items: flex-start; gap: var(--sp-3); margin-block-end: var(--sp-4); }
.modal__title { margin: 0; font-size: var(--fs-lg); }
.modal__close { margin-inline-start: auto; font-size: var(--fs-lg); line-height: 1; }
.modal__body { margin-block-end: var(--sp-5); }
.modal__text { margin: 0 0 var(--sp-3); color: var(--c-text-muted); }
.modal__input { width: 100%; margin-block-start: var(--sp-2); }
.modal__foot { display: flex; justify-content: flex-end; gap: var(--sp-2); flex-wrap: wrap; }

/* mobile-first is the default (single column); widen project grid on larger screens */
@media (min-width: 640px) {
  .projects { grid-template-columns: 1fr 1fr; }
}

/* Marketing-site-only styles (prerendered static pages on keyanima.com — see
   scripts/prerender-site.mjs, which concatenates tokens.css + app.css + this file into
   dist/site/site.css). NOT imported by the SPA. BEM; logical properties so RTL mirrors. */

/* No-JS language switcher: plain links between locale URLs. */
.site-lang { display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; list-style: none; margin: 0; padding: 0; }
.site-lang__link {
  color: var(--c-text-muted);
  text-decoration: none;
  font-size: var(--fs-sm);
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.site-lang__link:hover { color: var(--c-text); }
.site-lang__link[aria-current='true'] { color: var(--c-text); background: var(--c-surface-2); }

/* Marketing 404 page. */
.site-404 { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: var(--sp-8) var(--sp-4); gap: var(--sp-4); }
.site-404__code { font-size: var(--fs-3xl); margin: 0; color: var(--c-text-secondary); }
.site-404__title { font-size: var(--fs-xl); margin: 0; }
/* ---- public landing (/) ---- */
/* One dark page: sticky translucent nav, glow hero, feature grid, CTA band, small footer.
   All logical properties — mirrors automatically in RTL. Decorative gradients never carry text. */
.home { min-height: 100%; display: flex; flex-direction: column; background: var(--c-bg); }
.home__nav {
  position: sticky;
  inset-block-start: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(12px);
  border-block-end: 1px solid var(--c-border);
}
.home__brand { font-weight: 700; font-size: var(--fs-lg); margin: 0; color: var(--c-text); }
.home__brand-link { color: inherit; text-decoration: none; transition: var(--transition); }
.home__navlinks { display: flex; align-items: center; gap: var(--sp-3); margin-inline-start: auto; flex-wrap: wrap; }
.home__navlink { color: var(--c-text-muted); text-decoration: none; padding: var(--sp-1) var(--sp-2); border-radius: var(--radius-sm); transition: var(--transition); }
.home__navlink:hover { color: var(--c-text); }
.home__main { flex: 1; }
.home__hero {
  position: relative;
  text-align: center;
  padding: var(--sp-10) var(--sp-4) var(--sp-8);
  background: var(--g-glow);
}
.home__eyebrow {
  display: inline-block;
  font-size: var(--fs-sm);
  color: var(--c-primary);
  border: 1px solid var(--c-border-strong);
  border-radius: 999px;
  padding: var(--sp-1) var(--sp-3);
  margin-block-end: var(--sp-4);
  background: var(--c-surface);
}
.home__title { font-size: var(--fs-3xl); margin: 0 auto var(--sp-4); max-width: 22ch; }
.home__subtitle { color: var(--c-text-secondary); font-size: var(--fs-lg); max-width: 52ch; margin: 0 auto var(--sp-6); }
.home__cta { display: flex; gap: var(--sp-3); justify-content: center; flex-wrap: wrap; }
.home__section { max-width: 960px; margin-inline: auto; padding: var(--sp-8) var(--sp-4); }
.home__section-title { font-size: var(--fs-2xl); text-align: center; margin: 0 0 var(--sp-6); }
.home__features { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; list-style: none; padding: 0; margin: 0; }
.feature-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  transition: var(--transition);
}
.feature-card:hover { background: var(--c-surface-2); border-color: var(--c-border-strong); }
.feature-card__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 40px;
  block-size: 40px;
  border-radius: var(--radius);
  background: rgba(91, 140, 255, 0.12);
  color: var(--c-primary);
  font-size: var(--fs-lg);
  margin-block-end: var(--sp-3);
}
.feature-card__title { margin: 0 0 var(--sp-2); font-size: var(--fs-base); font-weight: 600; }
.feature-card__body { margin: 0; color: var(--c-text-muted); font-size: var(--fs-sm); }
.home__band {
  text-align: center;
  border-block: 1px solid var(--c-border);
  background: linear-gradient(135deg, rgba(91, 140, 255, 0.08), rgba(143, 107, 255, 0.08));
  padding: var(--sp-8) var(--sp-4);
}
.home__band-title { font-size: var(--fs-2xl); margin: 0 0 var(--sp-5); }
.home__footer { text-align: center; padding: var(--sp-6) var(--sp-4); color: var(--c-text-muted); font-size: var(--fs-sm); border-block-start: 1px solid var(--c-border); }
@media (min-width: 640px) {
  .home__features { grid-template-columns: 1fr 1fr 1fr; }
}

/* ---- documentation (/docs) ---- */
/* Single page, anchored sections, sticky TOC on wide screens (collapses above content on narrow).
   Grid + logical properties = automatic RTL mirroring; scroll-margin keeps anchors below the nav. */
.docs { display: grid; grid-template-columns: 1fr; gap: var(--sp-6); max-width: 960px; margin-inline: auto; padding: var(--sp-5) var(--sp-4) var(--sp-8); }
.docs__toc { align-self: start; }
.docs__toc-title { font-size: var(--fs-sm); color: var(--c-text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 0 0 var(--sp-3); }
.docs__toc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-1); }
.docs__toc-link {
  display: block;
  color: var(--c-text-muted);
  text-decoration: none;
  font-size: var(--fs-sm);
  padding: var(--sp-1) var(--sp-3);
  border-inline-start: 2px solid var(--c-border);
  transition: var(--transition);
}
.docs__toc-link:hover { color: var(--c-text); border-inline-start-color: var(--c-border-strong); }
.docs__content { min-width: 0; max-width: 72ch; }
.docs__title { font-size: var(--fs-2xl); margin: 0 0 var(--sp-2); }
.docs__lead { color: var(--c-text-secondary); margin: 0 0 var(--sp-6); }
.docs__section { scroll-margin-block-start: 80px; margin-block-end: var(--sp-6); }
.docs__section-title { font-size: var(--fs-lg); margin: 0 0 var(--sp-3); padding-block-end: var(--sp-2); border-block-end: 1px solid var(--c-border); }
.docs__text { color: var(--c-text-secondary); margin: 0 0 var(--sp-3); }
.docs__list { color: var(--c-text-secondary); margin: 0 0 var(--sp-3); padding-inline-start: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); }
.docs__kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--fs-xs);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border-strong);
  border-block-end-width: 2px;
  border-radius: var(--radius-sm);
  padding: 1px var(--sp-2);
  white-space: nowrap;
}
.docs__callout {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-inline-start: 3px solid var(--c-primary);
  border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-4);
  margin-block-end: var(--sp-3);
  color: var(--c-text-secondary);
  font-size: var(--fs-sm);
}
@media (min-width: 860px) {
  .docs { grid-template-columns: 200px 1fr; }
  .docs__toc { position: sticky; inset-block-start: 72px; }
}

