:root {
  /* Palette — light (default) */
  --canvas: #FAFAF9;
  --canvas-2: #F5F5F4;
  --card: #FFFFFF;
  --ink: #111827;
  --ink-2: #4B5563;
  --ink-3: #9CA3AF;
  --border: #E5E7EB;
  --border-strong: #D1D5DB;

  --teal: #0D9488;        /* runtime / active */
  --teal-ink: #134E4A;
  --teal-bg: #F0FDFA;

  --indigo: #6366F1;      /* static */
  --indigo-ink: #3730A3;
  --indigo-bg: #EEF2FF;

  --danger: #B91C1C;
  --danger-bg: #FEF2F2;
  --warn: #92400E;
  --success: #065F46;

  /* Spacing / radii */
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 16px;
  --shadow-xs: 0 1px 2px rgba(17,24,39,.04);
  --shadow-sm: 0 1px 2px rgba(17,24,39,.06), 0 1px 1px rgba(17,24,39,.03);
  --shadow-md: 0 4px 12px rgba(17,24,39,.06), 0 2px 4px rgba(17,24,39,.04);
  --shadow-lg: 0 12px 40px rgba(17,24,39,.10), 0 4px 12px rgba(17,24,39,.06);

  --font-ui: 'Inter', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --ease: cubic-bezier(.2,.7,.2,1);

  /* Theme transition — applied via <html class="theme-ready"> after init script runs */
  color-scheme: light;
}

[data-theme="dark"] {
  /* Palette — dark */
  --canvas: #0B0F13;
  --canvas-2: #111821;
  --card: #1A2130;
  --ink: #F5F5F4;
  --ink-2: #9CA3AF;
  --ink-3: #6B7280;
  --border: #2A3441;
  --border-strong: #3A4757;

  --teal: #2DD4BF;
  --teal-ink: #5EEAD4;
  --teal-bg: #042F2E;

  --indigo: #818CF8;
  --indigo-ink: #C7D2FE;
  --indigo-bg: #1E1B4B;

  --danger: #F87171;
  --danger-bg: #2D1313;
  --warn: #FBBF24;
  --success: #34D399;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.35);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.40), 0 1px 1px rgba(0,0,0,.25);
  --shadow-md: 0 4px 12px rgba(0,0,0,.45), 0 2px 4px rgba(0,0,0,.30);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.55), 0 4px 12px rgba(0,0,0,.40);

  color-scheme: dark;
}

/* Theme transitions only AFTER the init script sets .theme-ready — prevents a flash
   of animated recolor when the stored-theme is applied on first paint. */
html.theme-ready,
html.theme-ready body,
html.theme-ready .card,
html.theme-ready .btn,
html.theme-ready input,
html.theme-ready select,
html.theme-ready .site-header,
html.theme-ready .app-header,
html.theme-ready .project-view,
html.theme-ready table.errors thead th,
html.theme-ready table.errors tbody td {
  transition: background-color .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.55;
}

a {
  color: var(--teal);
  text-decoration: none;
  transition: color .15s var(--ease);
}
a:hover { color: var(--teal-ink); }

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
}

h1 { font-size: 48px; line-height: 1.1; letter-spacing: -0.03em; }
h2 { font-size: 32px; line-height: 1.15; }
h3 { font-size: 22px; line-height: 1.3; }
h4 { font-size: 17px; line-height: 1.4; }

p { margin: 0; }

code, pre, .mono { font-family: var(--font-mono); }
code { font-size: 0.9em; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--r);
  border: 1px solid transparent;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: all .15s var(--ease);
  text-decoration: none;
  background: var(--card);
  color: var(--ink);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.btn-primary:hover { background: #000; color: white; }

.btn-accent {
  background: var(--teal);
  color: white;
  border-color: var(--teal);
}
.btn-accent:hover { background: var(--teal-ink); color: white; }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--card); }

.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-lg { padding: 14px 22px; font-size: 16px; }

/* ---------- Forms ---------- */
.input, input[type="email"], input[type="password"], input[type="text"] {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  font-family: var(--font-ui);
  font-size: 15px;
  background: var(--card);
  color: var(--ink);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.input:focus, input:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(13,148,136,.15);
}

.label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  margin-bottom: 6px;
}

/* ---------- Cards / panels ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Overlay (replaces confirm()) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(17,24,39,.4);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ease);
}
.overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
.overlay .dialog {
  width: 400px;
  max-width: 90vw;
  background: var(--card);
  border-radius: var(--r-lg);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  transform: translateY(8px);
  transition: transform .2s var(--ease);
}
.overlay.visible .dialog { transform: translateY(0); }
.overlay .dialog h3 { margin-bottom: 10px; }
.overlay .dialog p { color: var(--ink-2); margin-bottom: 18px; }
.overlay .actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Utility ---------- */
.container {
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 0 24px;
}
.container-narrow { max-width: 720px; }

.muted { color: var(--ink-2); }
.tiny  { font-size: 13px; color: var(--ink-3); }
.center { text-align: center; }
.flex { display: flex; gap: 12px; align-items: center; }
.flex-col { display: flex; flex-direction: column; gap: 12px; }

.stack-4  > * + * { margin-top: 4px; }
.stack-8  > * + * { margin-top: 8px; }
.stack-12 > * + * { margin-top: 12px; }
.stack-16 > * + * { margin-top: 16px; }
.stack-24 > * + * { margin-top: 24px; }
.stack-40 > * + * { margin-top: 40px; }

.pill {
  display: inline-flex;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 999px;
  background: var(--indigo-bg);
  color: var(--indigo-ink);
  border: 1px solid rgba(99,102,241,.2);
}
.pill.teal { background: var(--teal-bg); color: var(--teal-ink); border-color: rgba(13,148,136,.2); }

/* ---------- Typography shades ---------- */
.kicker {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  font-weight: 600;
  color: var(--teal);
}

/* Scrollbar polish */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--r);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--ink-2);
  cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--border-strong);
}
.theme-toggle svg {
  width: 16px;
  height: 16px;
}
.theme-toggle .sun { display: none; }
.theme-toggle .moon { display: block; }
[data-theme="dark"] .theme-toggle .sun { display: block; }
[data-theme="dark"] .theme-toggle .moon { display: none; }
