/* =============================================================================
   FuzzyWorld Shared Design System
   
   This file contains design tokens and common base styles shared across
   all fuzzyworld.net sites (fuzzyworld.net, code.fuzzyworld.net, apps.fuzzyworld.net).
   
   Import this file before site-specific styles.
   ============================================================================= */

/* ---------------------------------------------------------------------
   Design Tokens: Colors
   --------------------------------------------------------------------- */

:root {
  /* Light mode (default) */
  --color-bg-primary: #ffffff;
  --color-bg-secondary: #f6f6f8;
  --color-bg-tertiary: #ffffff;
  --color-bg-hover: #eaeaf0;
  
  --color-fg-primary: #1d1d1f;
  --color-fg-secondary: #62626a;
  --color-fg-muted: #9a9aa2;
  
  --color-border-primary: #e1e1e6;
  --color-border-secondary: #c1c1c7;
  
  /* Accent colors */
  --color-accent: #0a58ca;
  --color-accent-soft: #e8f0fe;
  --color-accent-muted: #79b8ff;
  
  /* Semantic colors */
  --color-success: #116329;
  --color-success-bg: #e6f4ea;
  --color-error: #a40e26;
  --color-error-bg: #fdecea;
  --color-warning: #8250df;
  --color-warning-bg: #e8e8ea;
  
  /* Code syntax colors (light) */
  --color-hl-comment: #6a737d;
  --color-hl-keyword: #cf222e;
  --color-hl-string: #0a3069;
  --color-hl-number: #0550ae;
  --color-hl-function: #8250df;
  --color-hl-class: #953800;
  --color-hl-type: #116329;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg-primary: #111113;
    --color-bg-secondary: #1a1a1e;
    --color-bg-tertiary: #17171a;
    --color-bg-hover: #2a2a2f;
    
    --color-fg-primary: #e8e8ea;
    --color-fg-secondary: #9a9aa2;
    --color-fg-muted: #62626a;
    
    --color-border-primary: #2a2a2f;
    --color-border-secondary: #3e3e42;
    
    /* Accent colors */
    --color-accent: #79b8ff;
    --color-accent-soft: #16243a;
    --color-accent-muted: #bf8700;
    
    /* Semantic colors */
    --color-success: #7ee787;
    --color-success-bg: #12261a;
    --color-error: #ff9492;
    --color-error-bg: #2d1517;
    --color-warning: #c5a5ff;
    --color-warning-bg: #2a2a2f;
    
    /* Code syntax colors (dark) */
    --color-hl-comment: #8b949e;
    --color-hl-keyword: #ff7b72;
    --color-hl-string: #a5d6ff;
    --color-hl-number: #79c0ff;
    --color-hl-function: #d2a8ff;
    --color-hl-class: #ffa657;
    --color-hl-type: #7ee787;
  }
}

/* Force color scheme support */
:root {
  color-scheme: light dark;
}

/* ---------------------------------------------------------------------
   Design Tokens: Spacing
   --------------------------------------------------------------------- */

:root {
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;
  
  /* For grid gaps */
  --gap-sm: 0.75rem;
  --gap-md: 1rem;
  --gap-lg: 1.5rem;
}

/* ---------------------------------------------------------------------
   Design Tokens: Typography
   --------------------------------------------------------------------- */

:root {
  --font-family-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-family-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  
  --font-size-xs: 0.8rem;
  --font-size-sm: 0.9rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.1rem;
  --font-size-xl: 1.2rem;
  --font-size-2xl: 1.75rem;
  
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;
  
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.55;
}

/* ---------------------------------------------------------------------
   Design Tokens: Borders & Shadows
   --------------------------------------------------------------------- */

:root {
  --border-radius-sm: 4px;
  --border-radius-md: 6px;
  --border-radius-lg: 8px;
  --border-radius-full: 9999px;
  
  --box-shadow-sm: 0 1px 2px rgb(0 0 0 / 6%);
  --box-shadow-md: 0 4px 6px rgb(0 0 0 / 8%);
  
  /* No shadow in dark mode */
  --box-shadow: var(--box-shadow-sm);
}

@media (prefers-color-scheme: dark) {
  :root {
    --box-shadow: none;
  }
}

/* ---------------------------------------------------------------------
   Design Tokens: Transitions
   --------------------------------------------------------------------- */

:root {
  --transition-fast: 100ms ease;
  --transition-normal: 200ms ease;
  --transition-slow: 300ms ease;
}

/* ---------------------------------------------------------------------
   Base Styles
   --------------------------------------------------------------------- */

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  font-size: 16px;
}

body {
  margin: 0;
  background: var(--color-bg-primary);
  color: var(--color-fg-primary);
  font: var(--font-size-base)/var(--line-height-relaxed) var(--font-family-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Text selection */
::selection {
  background: var(--color-accent);
  color: var(--color-bg-primary);
}

/* Focus styles */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--border-radius-sm);
}

/* Links */
a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Images */
img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

/* Lists */
ul, ol {
  padding: 0;
  margin: 0;
}

/* Forms */
input, button, textarea, select {
  font: inherit;
}

/* Code */
code, kbd, samp, pre {
  font-family: var(--font-family-mono);
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  letter-spacing: -0.01em;
}

/* ---------------------------------------------------------------------
   Layout Utilities
   --------------------------------------------------------------------- */

.main-container {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 var(--spacing-md) var(--spacing-2xl);
}

/* Visually hidden but accessible */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Text utilities */
.text-muted { color: var(--color-fg-muted); }
.text-secondary { color: var(--color-fg-secondary); }
.text-success { color: var(--color-success); }
.text-error { color: var(--color-error); }
.text-warning { color: var(--color-warning); }

/* Truncate text */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Overflow wrap */
.overflow-wrap-anywhere {
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------------
   Spacing Utilities
   --------------------------------------------------------------------- */

.mt-xs { margin-top: var(--spacing-xs); }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mt-xl { margin-top: var(--spacing-xl); }

.mb-xs { margin-bottom: var(--spacing-xs); }
.mb-sm { margin-bottom: var(--spacing-sm); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }
.mb-xl { margin-bottom: var(--spacing-xl); }

/* ---------------------------------------------------------------------
   Card Component
   --------------------------------------------------------------------- */

.card {
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--box-shadow);
  padding: var(--spacing-md);
}

.card:hover {
  border-color: var(--color-accent);
}

/* ---------------------------------------------------------------------
   Button Component
   --------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-xs) var(--spacing-md);
  background: var(--color-accent);
  color: var(--color-bg-primary);
  border: none;
  border-radius: var(--border-radius-md);
  font: inherit;
  font-size: var(--font-size-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.btn:hover {
  background: var(--color-accent-muted);
}

.btn-secondary {
  background: var(--color-bg-secondary);
  color: var(--color-fg-primary);
  border: 1px solid var(--color-border-primary);
}

.btn-secondary:hover {
  background: var(--color-bg-hover);
}

/* ---------------------------------------------------------------------
   Badge Component
   --------------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: var(--spacing-xs) var(--spacing-sm);
  background: var(--color-bg-secondary);
  color: var(--color-fg-secondary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--border-radius-full);
  font-size: var(--font-size-xs);
}

.badge-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border-color: var(--color-success);
}

.badge-error {
  background: var(--color-error-bg);
  color: var(--color-error);
  border-color: var(--color-error);
}

.badge-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border-color: var(--color-warning);
}

/* ---------------------------------------------------------------------
   Table Styles
   --------------------------------------------------------------------- */

table {
  border-collapse: collapse;
  width: 100%;
}

td, th {
  padding: var(--spacing-xs) var(--spacing-sm);
  border-bottom: 1px solid var(--color-border-primary);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--color-fg-muted);
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
}

table:not(.source) tr:hover > td {
  background: var(--color-bg-secondary);
}

/* ---------------------------------------------------------------------
   Back to Top Button
   --------------------------------------------------------------------- */

.back-to-top {
  position: fixed;
  bottom: var(--spacing-xl);
  right: var(--spacing-xl);
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--border-radius-full);
  color: var(--color-fg-primary);
  font-size: 1.25rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  opacity: 0;
  visibility: hidden;
  z-index: 1000;
}

.back-to-top:hover {
  background: var(--color-bg-hover);
}

.back-to-top.visible {
  opacity: 1;
  visibility: visible;
}

/* ---------------------------------------------------------------------
   Responsive Utilities
   --------------------------------------------------------------------- */

@media (max-width: 64rem) {
  .main-container {
    padding: 0 var(--spacing-sm) var(--spacing-xl);
  }
}

@media (max-width: 40rem) {
  .hide-on-mobile {
    display: none !important;
  }
}
