:root {
  /* Colors - using oklch for vibrant, uniform colors */
  --bg-color: oklch(98% 0.01 200);
  --text-color: oklch(20% 0.02 200);
  --primary-color: oklch(65% 0.2 250);
  --accent-color: oklch(70% 0.2 30);
  --glass-bg: oklch(100% 0 0 / 70%);
  --glass-border: oklch(100% 0 0 / 30%);
  
  /* Lotto Ball Colors */
  --ball-yellow: oklch(85% 0.15 80);
  --ball-blue: oklch(65% 0.15 240);
  --ball-red: oklch(65% 0.15 30);
  --ball-gray: oklch(65% 0 0);
  --ball-green: oklch(65% 0.15 140);

  /* Spacing & Sizing */
  --space-xs: 0.5rem;
  --space-s: 1rem;
  --space-m: 2rem;
  --space-l: 4rem;
  --border-radius: 1.5rem;
  
  /* Shadows & Effects */
  --shadow-sm: 0 2px 4px oklch(0% 0 0 / 5%);
  --shadow-md: 0 8px 16px oklch(0% 0 0 / 10%);
  --shadow-lg: 0 16px 32px oklch(0% 0 0 / 15%);
  --glow: 0 0 15px var(--primary-color);
}

@layer base, layout, components, utilities;

@layer base {
  *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    background-image: 
      radial-gradient(at 0% 0%, oklch(90% 0.05 250 / 20%) 0, transparent 50%),
      radial-gradient(at 100% 100%, oklch(90% 0.05 30 / 20%) 0, transparent 50%);
    color: var(--text-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
  }

  /* Subtle noise texture */
  body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    opacity: 0.03;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    z-index: 100;
  }
}

@layer layout {
  main {
    width: 100%;
    max-width: 600px;
    padding: var(--space-m);
    display: flex;
    flex-direction: column;
    gap: var(--space-m);
  }

  .glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius);
    padding: var(--space-m);
    box-shadow: var(--shadow-lg);
  }

  .frequency-section {
    padding: var(--space-s) var(--space-m);
    margin-bottom: var(--space-s);
  }

  .frequency-section h3 {
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0.8;
    text-align: center;
    margin-bottom: var(--space-m);
  }

  #frequency-list-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(45px, 1fr));
    gap: 12px 8px;
    justify-items: center;
  }

  .freq-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }

  .freq-item lotto-ball {
    --size: 32px !important;
  }

  .freq-count {
    font-size: 0.65rem;
    font-weight: 600;
    opacity: 0.6;
  }
}

@layer components {
  h1 {
    font-size: clamp(2rem, 8vw, 3.5rem);
    font-weight: 800;
    text-align: center;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: var(--space-s);
  }

  .controls {
    display: flex;
    justify-content: center;
    gap: var(--space-s);
  }

  button {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    font-weight: 600;
    border: none;
    border-radius: 1rem;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, background 0.2s;
    box-shadow: var(--shadow-md);
  }

  button:hover {
    transform: translateY(-2px);
    box-shadow: var(--glow);
    background: oklch(70% 0.2 250);
  }

  button:active {
    transform: translateY(0);
  }

  #ball-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-m);
    min-height: 100px;
    padding: var(--space-s);
    perspective: 1000px;
  }

  .lotto-row {
    display: flex;
    justify-content: center;
    gap: var(--space-xs);
    width: 100%;
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
    padding: var(--space-xs);
    border-radius: var(--border-radius);
  }

  .lotto-row.completed {
    background: oklch(100% 0 0 / 5%);
    box-shadow: inset 0 0 20px oklch(100% 0 0 / 5%);
    animation: row-highlight 0.5s ease-out forwards;
  }

  @keyframes row-highlight {
    0% { background: transparent; }
    50% { background: oklch(65% 0.2 250 / 10%); }
    100% { background: oklch(65% 0.2 250 / 5%); }
  }

  .lotto-row.exit {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
  }

  .gravity-drop {
    animation: gravity-drop 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }

  @keyframes gravity-drop {
    0% {
      transform: translateY(-100vh) scale(0.2) rotate(-180deg);
      opacity: 0;
    }
    100% {
      transform: translateY(0) scale(1) rotate(0);
      opacity: 1;
    }
  }

  /* Responsive adjustments for mobile */
  @media (max-width: 480px) {
    .lotto-row {
      gap: 4px;
    }
    
    lotto-ball {
      --size: 45px !important;
    }
  }
}
