/* ==========================================================================
   CentiChess Design System — "Every move counts."
   Light-first theme with CSS custom properties
   ========================================================================== */

/* ---------- Color Palette & Custom Properties ---------- */
:root {
  /* Backgrounds */
  --bg-primary:    #FFFFFF;
  --bg-secondary:  #F5F5F7;
  --bg-card:       #FFFFFF;
  --bg-elevated:   #FAFAFB;

  /* Text */
  --text-primary:   #0B0B0D;
  --text-secondary: #6E6E73;
  --text-tertiary:  #8E8E93;
  --text-muted:     var(--text-tertiary);
  --text-inverse:   #FFFFFF;

  /* Accent (Centi Blue) */
  --accent:         #0A84FF;
  --accent-strong:  #0A84FF;
  --accent-fill:    #0066CC;
  --accent-hover:   #005FCC;
  --accent-pressed: #004FA8;
  --focus-ring:     rgba(10, 132, 255, 0.28);
  --accent-soft-bg: rgba(10, 132, 255, 0.10);
  --accent-hairline: rgba(10, 132, 255, 0.34);
  --ink-black:      #000000;

  /* Accent tints */
  --accent-tint-4:  rgba(10, 132, 255, 0.04);
  --accent-tint-8:  rgba(10, 132, 255, 0.08);
  --accent-tint-12: rgba(10, 132, 255, 0.12);
  --accent-tint-16: rgba(10, 132, 255, 0.16);

  /* Hover surfaces */
  --bg-hover:       var(--accent-tint-8);
  --bg-hover-strong: var(--accent-tint-12);

  /* Semantic colors */
  --success: #34C759;
  --danger:  #FF3B30;
  --warning: #FF9F0A;

  /* Category colors (marker-only) */
  --cat-play:    #FF9F0A;
  --cat-solve:   #22C3A6;
  --cat-study:   #5856D6;
  --cat-analyze: #AF52DE;
  --cat-review:  #34C759;
  --cat-meta:    #8E8E93;

  /* Borders & Surfaces */
  --border-subtle:  #E5E5EA;
  --border-medium:  #D1D1D6;
  --border-strong:  #C7C7CC;

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md:  0 6px 14px rgba(0, 0, 0, 0.12);
  --shadow-lg:  0 10px 28px rgba(0, 0, 0, 0.16);
  --shadow-xl:  0 18px 60px rgba(0, 0, 0, 0.18);
  --glow-accent: 0 0 22px rgba(10, 132, 255, 0.18);

  /* Journal surfaces */
  --paper:       #FFFFFF;
  --paper-2:     #FFFFFF;
  --ink:         #111111;
  --pencil:      #6E6E73;
  --rule-line:   rgba(17, 17, 17, 0.06);
  --margin-line: rgba(17, 17, 17, 0.10);
  --paper-grain-opacity: 0.04;

  /* Compatibility aliases (to be phased out) */
  --accent-primary: var(--accent);
  --accent-red:     var(--accent);
  --accent-blue:    var(--accent);
  --accent-green:   var(--success);
  --milestone-gold: var(--warning);
  --text-contrast:  var(--text-inverse);
  --glow-red:       var(--glow-accent);
  --glow-blue:      var(--glow-accent);
  --glow-green:     0 0 22px rgba(52, 199, 89, 0.18);
  --glow-gold:      0 0 22px rgba(255, 159, 10, 0.18);
  --red-tint-4:     var(--accent-tint-4);
  --red-tint-6:     rgba(10, 132, 255, 0.06);
  --red-tint-10:    rgba(10, 132, 255, 0.10);
  --red-tint-12:    var(--accent-tint-12);
  --red-tint-15:    rgba(10, 132, 255, 0.15);
  --red-tint-20:    rgba(10, 132, 255, 0.20);
  --red-tint-8:     var(--accent-tint-8);
  --red-tint-30:    rgba(10, 132, 255, 0.30);
  --shadow-red-sm:  0 2px 8px rgba(10, 132, 255, 0.2);
  --border:         var(--border-medium);
  --bg:             var(--bg-primary);
  --card-bg:        var(--bg-card);
  --bg-tertiary:    var(--bg-elevated);
  --flair-streak:   var(--accent);
  --flair-focus:    var(--accent);
  --goal-gray:      var(--text-tertiary);
  --goal-blue:      var(--accent);
  --goal-red:       var(--accent);
  --goal-deep-red:  var(--accent-pressed);
  --goal-green:     var(--success);
  --goal-gold:      var(--warning);
  --streak-ember:     var(--accent);
  --streak-flame:     var(--accent);
  --streak-full:      var(--accent-pressed);
  --streak-hot:       var(--accent-pressed);
  --streak-legendary: var(--warning);
  --phase-base:     var(--accent);
  --phase-build:    var(--warning);
  --phase-peak:     var(--danger);
  --phase-recovery: var(--success);
  --zone-deload:      var(--accent);
  --zone-maintaining: var(--success);
  --zone-building:    var(--warning);
  --zone-peak:        var(--danger);
  --status-completed: currentColor;
  --status-planned:   currentColor;
  --status-skipped:   #4B5563;
  --status-skipped-opacity: 0.45;

  /* Heatmap (single hue) */
  --heatmap-none: #F2F2F7;
  --heatmap-1:    rgba(10, 132, 255, 0.12);
  --heatmap-2:    rgba(10, 132, 255, 0.20);
  --heatmap-3:    rgba(10, 132, 255, 0.32);
  --heatmap-4:    rgba(10, 132, 255, 0.48);
  --heatmap-5:    rgba(10, 132, 255, 0.70);
  --heatmap-rest:    var(--heatmap-1);
  --heatmap-light:   var(--heatmap-2);
  --heatmap-medium:  var(--heatmap-3);
  --heatmap-high:    var(--heatmap-4);
  --heatmap-intense: var(--heatmap-5);

  /* Medal colors */
  --medal-silver: #8E8E93;
  --medal-bronze: #6E6E73;

  /* Warm/Cool temperature tinting */
  --bg-card-warm: hsl(36, 25%, 96%);
  --bg-card-cool: hsl(210, 20%, 97%);
  --bg-btn-warm:  hsl(36, 20%, 94%);
  --bg-btn-cool:  hsl(210, 15%, 95%);

  /* Typography */
  --font-display: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-serif:   'Lora', Georgia, 'Times New Roman', serif;
  --font-mono:    'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;

  /* Font sizes */
  --text-xs:   0.75rem;    /* 12px */
  --text-sm:   0.875rem;   /* 14px */
  --text-base: 1rem;       /* 16px */
  --text-lg:   1.125rem;   /* 18px */
  --text-xl:   1.25rem;    /* 20px */
  --text-2xl:  1.5rem;     /* 24px */
  --text-3xl:  1.875rem;   /* 30px */
  --text-4xl:  2.25rem;    /* 36px */
  --text-5xl:  3rem;       /* 48px */

  /* Spacing (8px grid) */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Border Radius */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast:   150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow:   500ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Dark Theme Override ---------- */
[data-theme="dark"] {
  --bg-primary:    #000000;
  --bg-secondary:  #111113;
  --bg-card:       #1C1C1E;
  --bg-elevated:   #2C2C2E;

  --text-primary:   #F5F5F7;
  --text-secondary: #A1A1A6;
  --text-tertiary:  #7C7C80;
  --text-muted:     var(--text-tertiary);
  --text-inverse:   #000000;

  --border-subtle:  #3A3A3C;
  --border-medium:  #48484A;
  --border-strong:  #5A5A5C;

  --shadow-sm:  0 1px 3px rgba(0, 0, 0, 0.40);
  --shadow-md:  0 6px 14px rgba(0, 0, 0, 0.55);
  --shadow-lg:  0 10px 28px rgba(0, 0, 0, 0.65);
  --shadow-xl:  0 18px 60px rgba(0, 0, 0, 0.75);
  --glow-accent: 0 0 22px rgba(10, 132, 255, 0.22);
  --accent-strong:  #0A84FF;
  --accent-soft-bg: rgba(10, 132, 255, 0.20);
  --accent-hairline: rgba(10, 132, 255, 0.46);
  --ink-black:      #F5F5F7;

  --paper:       #0F0F10;
  --paper-2:     #161618;
  --ink:         #F5F5F7;
  --pencil:      #A1A1A6;
  --rule-line:   rgba(245, 245, 247, 0.08);
  --margin-line: rgba(245, 245, 247, 0.14);
  --paper-grain-opacity: 0.03;

  --heatmap-none: #1C1C1E;
  --heatmap-1:    rgba(10, 132, 255, 0.16);
  --heatmap-2:    rgba(10, 132, 255, 0.24);
  --heatmap-3:    rgba(10, 132, 255, 0.36);
  --heatmap-4:    rgba(10, 132, 255, 0.52);
  --heatmap-5:    rgba(10, 132, 255, 0.74);

  --bg-hover:       rgba(10, 132, 255, 0.16);
  --bg-hover-strong: rgba(10, 132, 255, 0.22);
}

/* ---------- Base Reset & Body ---------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

/* Restore comfortable font size on mobile */
@media (max-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  font-family: var(--font-display);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---------- Selection ---------- */
::selection {
  background-color: var(--accent-tint-16);
  color: var(--text-primary);
}

::-moz-selection {
  background-color: var(--accent-tint-16);
  color: var(--text-primary);
}

/* ---------- Custom Scrollbar ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: var(--radius-full);
}

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

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-medium) var(--bg-secondary);
}

/* ---------- Typography Utilities ---------- */
.font-display { font-family: var(--font-display); }
.font-mono    { font-family: var(--font-mono); }

.text-xs   { font-size: var(--text-xs); }
.text-sm   { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg   { font-size: var(--text-lg); }
.text-xl   { font-size: var(--text-xl); }
.text-2xl  { font-size: var(--text-2xl); }
.text-3xl  { font-size: var(--text-3xl); }
.text-4xl  { font-size: var(--text-4xl); }
.text-5xl  { font-size: var(--text-5xl); }

.font-light    { font-weight: 300; }
.font-normal   { font-weight: 400; }
.font-medium   { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold     { font-weight: 700; }

/* ---------- Color Utilities ---------- */
.text-primary   { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted     { color: var(--text-muted); }
.text-accent    { color: var(--accent-red); }
.text-blue      { color: var(--accent-blue); }
.text-green     { color: var(--accent-green); }
.text-gold      { color: var(--milestone-gold); }
.text-danger    { color: var(--danger); }

.bg-primary   { background-color: var(--bg-primary); }
.bg-secondary { background-color: var(--bg-secondary); }
.bg-card      { background-color: var(--bg-card); }
.bg-elevated  { background-color: var(--bg-elevated); }
.bg-accent    { background-color: var(--accent-red); }
.bg-blue      { background-color: var(--accent-blue); }
.bg-green     { background-color: var(--accent-green); }
.bg-gold      { background-color: var(--milestone-gold); }
.bg-danger    { background-color: var(--danger); }

/* ---------- Border Utilities ---------- */
.border-subtle { border: 1px solid var(--border-subtle); }
.border-medium { border: 1px solid var(--border-medium); }
.border-strong { border: 1px solid var(--border-strong); }
.border-accent { border: 1px solid var(--accent-red); }

.border-t-subtle { border-top: 1px solid var(--border-subtle); }
.border-b-subtle { border-bottom: 1px solid var(--border-subtle); }
.border-l-accent { border-left: 3px solid var(--accent-red); }

/* ---------- Shadow Utilities ---------- */
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.shadow-xl { box-shadow: var(--shadow-xl); }

.glow-red    { box-shadow: var(--glow-red); }
.glow-blue   { box-shadow: var(--glow-blue); }
.glow-green  { box-shadow: var(--glow-green); }
.glow-gold   { box-shadow: var(--glow-gold); }

/* ---------- Border Radius Utilities ---------- */
.rounded-sm   { border-radius: var(--radius-sm); }
.rounded-md   { border-radius: var(--radius-md); }
.rounded-lg   { border-radius: var(--radius-lg); }
.rounded-xl   { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

/* ---------- Links ---------- */
a {
  color: var(--accent-strong);
  text-decoration: none;
  text-underline-offset: 2px;
  transition: color var(--transition-fast), text-decoration-color var(--transition-fast);
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
  text-decoration-color: var(--accent-hairline);
}
