/* ==========================================================================
   theApps — Design tokens
   Two named themes sharing one brand hue (emerald/green):
     - Default (no class needed)  : "Evergreen Dusk" — deep forest-night calm
     - body.theme-light           : "Sage Morning"    — soft mint-paper daylight

   Every color used anywhere in this project MUST be one of the tokens below.
   Never hard-code a hex value inside a component rule — see
   docs/UNIVERSAL_DESIGN_PLAYBOOK.md §3.

   Note the two-tier accent: --accent is the bright brand emerald, safe as an
   icon/border/fill color (with dark text on top) in both themes. --accent-ink
   is what text/links use when sitting directly on the page background —
   bright emerald fails contrast on a light/mint page, so in "Sage Morning"
   --accent-ink is a deeper forest green that still reads unmistakably "green"
   while passing WCAG AA (~5:1) for normal text.
   ========================================================================== */

:root {
  /* Layered backgrounds */
  --bg-page: #0b1210;
  --bg-surface: #101915;
  --bg-elevated: #16211b;
  --bg-overlay: rgba(6, 10, 8, 0.72);

  /* Brand accent (emerald) */
  --accent: #2fbf83;
  --accent-hover: #4ee0ac;
  --accent-ink: #34d399;
  --accent-ink-hover: #5fe6b5;
  --accent-dim: rgba(52, 211, 153, 0.14);
  --accent-contrast-text: #0b1210;

  /* Semantic status */
  --success: #4ade80;
  --success-dim: rgba(74, 222, 128, 0.14);
  --warning: #facc15;
  --warning-dim: rgba(250, 204, 21, 0.14);
  --danger: #f87171;
  --danger-dim: rgba(248, 113, 113, 0.14);
  --info: #38bdf8;
  --info-dim: rgba(56, 189, 248, 0.14);

  /* Extended palette — one hover/accent identity per category */
  --tool-blue: #60a5fa;
  --tool-purple: #a78bfa;
  --tool-amber: #fbbf24;
  --tool-rose: #fb7185;
  --tool-teal: #2dd4bf;

  /* Text */
  --text-1: #eef5f0;
  --text-2: #9fb3a8;
  --text-3: #66796e;

  /* Borders / shadows */
  --border: #223028;
  --border-subtle: #182420;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);

  /* Per-component */
  --navbar-bg: #0d1512;
  --card-bg: var(--bg-surface);
  --modal-bg: var(--bg-elevated);
  --modal-hdr-bg: var(--bg-surface);
  --input-bg: #0d1512;
  --input-border: var(--border);
  --toolbar-btn-bg: #16211b;
  --scrollbar-thumb: #2c3d34;
  --scrollbar-track: transparent;

  color-scheme: dark;
}

body.theme-light {
  /* Layered backgrounds */
  --bg-page: #f6faf7;
  --bg-surface: #eef6f0;
  --bg-elevated: #ffffff;
  --bg-overlay: rgba(10, 30, 20, 0.35);

  /* Brand accent */
  --accent: #2fbf83;
  --accent-hover: #24a873;
  --accent-ink: #167a4d;
  --accent-ink-hover: #0f5c3a;
  --accent-dim: rgba(22, 122, 77, 0.1);
  --accent-contrast-text: #0b1210;

  /* Semantic status */
  --success: #1e8449;
  --success-dim: rgba(30, 132, 73, 0.1);
  --warning: #92720a;
  --warning-dim: rgba(146, 114, 10, 0.1);
  --danger: #c23b32;
  --danger-dim: rgba(194, 59, 50, 0.1);
  --info: #1d6fa5;
  --info-dim: rgba(29, 111, 165, 0.1);

  /* Extended palette */
  --tool-blue: #1d6fa5;
  --tool-purple: #6e4fd1;
  --tool-amber: #7a5c00;
  --tool-rose: #c23572;
  --tool-teal: #0b6f68;

  /* Text */
  --text-1: #16211b;
  --text-2: #4c5c51;
  --text-3: #7c8b81;

  /* Borders / shadows */
  --border: #dcebe0;
  --border-subtle: #e8f3ec;
  --shadow-sm: 0 2px 8px rgba(20, 60, 40, 0.1);
  --shadow-md: 0 8px 24px rgba(20, 60, 40, 0.14);
  --shadow-lg: 0 24px 60px rgba(20, 60, 40, 0.2);

  /* Per-component */
  --navbar-bg: #f2f9f4;
  --card-bg: var(--bg-surface);
  --modal-bg: var(--bg-elevated);
  --modal-hdr-bg: #eef6f0;
  --input-bg: #ffffff;
  --input-border: var(--border);
  --toolbar-btn-bg: #ffffff;
  --scrollbar-thumb: #cfe3d6;
  --scrollbar-track: transparent;

  color-scheme: light;
}

/* ==========================================================================
   Base / reset
   ========================================================================== */

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-page);
  color: var(--text-1);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  transition: background-color 0.25s ease, color 0.25s ease;
}

p {
  color: var(--text-2);
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-1);
}

a {
  color: var(--accent-ink);
}

a:hover {
  color: var(--accent-ink-hover);
}

code, pre, .mono {
  font-family: "JetBrains Mono", "Consolas", monospace;
}

button {
  font-weight: 600;
}

hr {
  border-color: var(--border);
  opacity: 1;
}

::selection {
  background: var(--accent-dim);
  color: var(--text-1);
}

/* Consistent, visible keyboard-focus ring everywhere (accessibility) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* ==========================================================================
   Layout
   ========================================================================== */

.page-shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 96px 16px 48px;
}

.visually-hidden-focusable-skip {
  position: absolute;
  left: -9999px;
  top: 0;
}
.visually-hidden-focusable-skip:focus {
  left: 16px;
  top: 8px;
  z-index: 2000;
  background: var(--accent);
  color: var(--accent-contrast-text);
  padding: 8px 14px;
  border-radius: 8px;
}

/* ==========================================================================
   Scrollbar
   ========================================================================== */

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 6px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
