/* Material Design 3 Tokens & Core Components */
:root {
  /* Primary Brand Palette (Material Indigo / Royal Coding Blue) */
  --md-sys-color-primary: #3949AB;
  --md-sys-color-on-primary: #FFFFFF;
  --md-sys-color-primary-container: #E0E7FF;
  --md-sys-color-on-primary-container: #1E1B4B;

  /* Secondary Accent (Vibrant Coding Amber / Gold) */
  --md-sys-color-secondary: #F59E0B;
  --md-sys-color-on-secondary: #1E293B;
  --md-sys-color-secondary-container: #FEF3C7;
  --md-sys-color-on-secondary-container: #78350F;

  /* Tertiary Accent (Emerald Success / Coral Energy) */
  --md-sys-color-tertiary: #0D9488;
  --md-sys-color-tertiary-container: #CCFBF1;
  --md-sys-color-error: #DC2626;
  --md-sys-color-error-container: #FEE2E2;
  --md-sys-color-success: #16A34A;
  --md-sys-color-success-container: #DCFCE7;

  /* Surface Hierarchy */
  --md-sys-color-background: #F4F6FC;
  --md-sys-color-surface: #FFFFFF;
  --md-sys-color-surface-variant: #E8ECF8;
  --md-sys-color-surface-container: #EEF2FF;
  --md-sys-color-outline: #CBD5E1;
  --md-sys-color-outline-variant: #E2E8F0;
  --md-sys-color-on-surface: #0F172A;
  --md-sys-color-on-surface-variant: #475569;

  /* Material Elevation Shadows */
  --md-elevation-1: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
  --md-elevation-2: 0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.05);
  --md-elevation-3: 0 10px 24px rgba(15, 23, 42, 0.12), 0 4px 8px rgba(15, 23, 42, 0.06);
  --md-elevation-4: 0 20px 44px rgba(15, 23, 42, 0.2), 0 8px 16px rgba(15, 23, 42, 0.1);

  /* Motion & Radii */
  --md-motion-standard: cubic-bezier(0.2, 0, 0, 1);
  --md-motion-emphasized: cubic-bezier(0.05, 0.7, 0.1, 1);
  --md-radius-sm: 10px;
  --md-radius-md: 16px;
  --md-radius-lg: 24px;
  --md-radius-xl: 32px;
  --md-radius-full: 9999px;

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  color: var(--md-sys-color-on-surface);
  background-color: var(--md-sys-color-background);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Subtle circuit pattern background inspired by book cover */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.35;
  background-image:
    radial-gradient(circle at 20px 20px, rgba(57, 73, 171, 0.1) 1.5px, transparent 1.5px),
    radial-gradient(circle at 60px 60px, rgba(245, 158, 11, 0.12) 1.5px, transparent 1.5px);
  background-size: 80px 80px;
}

.hidden {
  display: none !important;
}

/* Material Cards */
.md-card {
  background: var(--md-sys-color-surface);
  border-radius: var(--md-radius-lg);
  border: 1px solid var(--md-sys-color-outline-variant);
  transition: transform 240ms var(--md-motion-standard), box-shadow 240ms var(--md-motion-standard), border-color 240ms var(--md-motion-standard);
}

.md-elevation-1 { box-shadow: var(--md-elevation-1); }
.md-elevation-2 { box-shadow: var(--md-elevation-2); }
.md-elevation-3 { box-shadow: var(--md-elevation-3); }
.md-elevation-4 { box-shadow: var(--md-elevation-4); }

/* Material Buttons with Ripple */
.md-btn {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.9375rem;
  letter-spacing: 0.01em;
  border: none;
  border-radius: var(--md-radius-full);
  padding: 10px 20px;
  cursor: pointer;
  user-select: none;
  transition: transform 150ms var(--md-motion-standard), box-shadow 200ms var(--md-motion-standard), background-color 200ms var(--md-motion-standard);
}

.md-btn:active {
  transform: scale(0.97);
}

.md-btn-lg {
  padding: 13px 26px;
  font-size: 1rem;
}

.md-btn-filled {
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  box-shadow: var(--md-elevation-2);
}

.md-btn-filled:hover {
  background: #303F9F;
  box-shadow: var(--md-elevation-3);
}

.md-btn-tonal {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.md-btn-tonal:hover {
  background: #C7D2FE;
}

.md-btn-outlined {
  background: transparent;
  color: var(--md-sys-color-primary);
  border: 1.5px solid var(--md-sys-color-outline);
}

.md-btn-outlined:hover {
  background: var(--md-sys-color-surface-container);
}

.md-btn-text {
  background: transparent;
  color: var(--md-sys-color-primary);
  padding: 8px 14px;
}

.md-btn-text:hover {
  background: rgba(57, 73, 171, 0.08);
}

.md-btn-success {
  background: var(--md-sys-color-success);
  color: #FFFFFF;
  box-shadow: var(--md-elevation-2);
}

.md-icon-btn {
  position: relative;
  overflow: hidden;
  width: 42px;
  height: 42px;
  border-radius: var(--md-radius-full);
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 180ms var(--md-motion-standard), color 180ms var(--md-motion-standard);
}

.md-icon-btn:hover {
  background: rgba(15, 23, 42, 0.07);
  color: var(--md-sys-color-on-surface);
}

.md-icon-btn.tonal {
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-primary);
}

.md-icon-btn.tonal:hover {
  background: var(--md-sys-color-primary-container);
}

/* Material Ripple Circle */
.md-ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transform: scale(0);
  animation: md-ripple-anim 550ms ease-out forwards;
  pointer-events: none;
}

.md-btn-tonal .md-ripple,
.md-btn-text .md-ripple,
.md-btn-outlined .md-ripple,
.md-icon-btn .md-ripple,
.md-chip .md-ripple {
  background: rgba(57, 73, 171, 0.18);
}

@keyframes md-ripple-anim {
  to {
    transform: scale(3.5);
    opacity: 0;
  }
}

/* Material Chips */
.md-chip {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--md-radius-full);
  font-size: 0.85rem;
  font-weight: 700;
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  transition: all 180ms var(--md-motion-standard);
}

.md-chip-stars {
  background: #FFFBEB;
  border-color: #FDE68A;
  color: #92400E;
  cursor: default;
}

.md-chip-profile:hover {
  background: var(--md-sys-color-surface-container);
  border-color: var(--md-sys-color-primary);
}

/* Material Linear Progress */
.md-linear-progress {
  width: 100%;
  height: 10px;
  border-radius: var(--md-radius-full);
  background: var(--md-sys-color-surface-variant);
  overflow: hidden;
}

.md-linear-progress-bar {
  height: 100%;
  border-radius: var(--md-radius-full);
  background: linear-gradient(90deg, #3949AB, #0EA5E9, #10B981);
  transition: width 500ms var(--md-motion-emphasized);
}

/* Material Dialog */
.md-dialog-scrim {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 200ms ease-out;
}

.md-dialog {
  background: var(--md-sys-color-surface);
  border-radius: var(--md-radius-xl);
  max-width: 480px;
  width: 100%;
  padding: 28px;
  position: relative;
  animation: popIn 280ms var(--md-motion-emphasized);
}

/* Material Snackbar */
.md-snackbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: #1E293B;
  color: #F8FAFC;
  padding: 12px 22px;
  border-radius: var(--md-radius-md);
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: var(--md-elevation-3);
  z-index: 1200;
  opacity: 0;
  pointer-events: none;
  transition: transform 280ms var(--md-motion-emphasized), opacity 240ms ease;
  max-width: min(92vw, 480px);
  text-align: center;
}

.md-snackbar.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.md-snackbar.success {
  background: #15803D;
}

.md-snackbar.error {
  background: #B91C1C;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.9) translateY(14px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.anim-shake {
  animation: shakeX 360ms ease;
}
