@layer reset, base, components, utilities;

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

@layer base {
  :root {
    --primary-hue: 250;
    --accent-hue: 150;
    
    /* Default (Dark) OKLCH Colors */
    --bg-color: oklch(20% 0.02 var(--primary-hue));
    --surface-color: oklch(30% 0.04 var(--primary-hue));
    --text-color: oklch(95% 0.02 var(--primary-hue));
    --text-muted: oklch(75% 0.02 var(--primary-hue));
    --accent-color: oklch(70% 0.2 var(--accent-hue));
    --error-color: oklch(65% 0.2 25);
    --info-color: oklch(70% 0.15 250);

    /* Shadows */
    --shadow-soft: 0 4px 20px -2px oklch(0% 0 0 / 0.5);
    --shadow-deep: 0 10px 40px -4px oklch(0% 0 0 / 0.8);
    --glow: 0 0 15px oklch(70% 0.2 var(--accent-hue) / 0.5);

    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-color);
    background-color: var(--bg-color);
    line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
  }

  :root[data-theme="light"] {
    --bg-color: oklch(98% 0.01 var(--primary-hue));
    --surface-color: oklch(100% 0 0);
    --text-color: oklch(25% 0.02 var(--primary-hue));
    --text-muted: oklch(50% 0.02 var(--primary-hue));
    --accent-color: oklch(60% 0.18 var(--accent-hue));
    
    --shadow-soft: 0 4px 20px -2px oklch(0% 0 0 / 0.1);
    --shadow-deep: 0 10px 40px -4px oklch(0% 0 0 / 0.15);
    --glow: 0 0 15px oklch(60% 0.18 var(--accent-hue) / 0.3);
  }

  body {
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    background-color: var(--bg-color);
    color: var(--text-color);
  }

  /* Noise texture background */
  body::before {
    content: "";
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0.04;
    pointer-events: none;
    z-index: 10;
    background: url('data:image/svg+xml,<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><filter id="n"><feTurbulence type="fractalNoise" baseFrequency="0.65" numOctaves="3" stitchTiles="stitch" /></filter><rect width="100%" height="100%" filter="url(%23n)" /></svg>');
  }
}

@layer components {
  /* GNB Style */
  .gnb {
    position: sticky;
    top: 0;
    width: 100%;
    background: oklch(20% 0.02 var(--primary-hue) / 0.8);
    backdrop-filter: blur(15px);
    border-bottom: 1px solid oklch(100% 0 0 / 0.05);
    z-index: 100;
    padding: 0.75rem 0;
    transition: background-color 0.3s ease;
  }

  :root[data-theme="light"] .gnb {
    background: oklch(98% 0.01 var(--primary-hue) / 0.8);
  }

  .nav-content {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
  }

  .logo {
    font-weight: 900;
    font-size: 1.2rem;
    letter-spacing: -1px;
    background: linear-gradient(135deg, oklch(95% 0.02 var(--primary-hue)), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  .gnb ul {
    list-style: none;
    display: flex;
    gap: 1rem;
  }

  .gnb a {
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    transition: color 0.2s;
  }

  .gnb a:hover {
    color: var(--accent-color);
  }

  .app-container {
    width: 100%;
    max-width: 600px;
    padding: 1rem 1rem 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
    z-index: 1;
    position: relative; /* 테마 버튼의 기준점 */
    margin: 0 auto;
  }

  header {
    text-align: center;
    animation: fadeInDown 0.8s ease-out;
    padding-top: 2rem;
  }

  header h1 {
    font-size: 3rem;
    font-weight: 900;
    letter-spacing: -2px;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, oklch(95% 0.02 var(--primary-hue)), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  header h1 span {
    font-weight: 200;
  }

  .tagline {
    color: var(--text-muted);
    font-size: 1.1rem;
    letter-spacing: 2px;
    text-transform: uppercase;
  }

  .card {
    background-color: var(--surface-color);
    border-radius: 24px;
    padding: 1.5rem;
    box-shadow: var(--shadow-deep);
    border: 1px solid oklch(100% 0 0 / 0.05);
    backdrop-filter: blur(10px);
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
  }

  .theme-toggle-container {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
  }

  .theme-btn {
    background: var(--surface-color);
    border: 1px solid oklch(100% 0 0 / 0.1);
    color: var(--text-color);
    padding: 0.5rem;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: var(--shadow-soft);
  }

  .theme-btn:hover {
    transform: translateY(-2px);
    border-color: var(--accent-color);
  }

  .card h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--accent-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  .desc {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
  }

  /* Draw Section */
  .draw-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
  }

  .result-display {
    min-height: 100px;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    background: oklch(0% 0 0 / 0.2);
    border-radius: 50px;
    padding: 1.5rem;
    border: 1px dashed oklch(100% 0 0 / 0.1);
  }

  .placeholder-text {
    color: var(--text-muted);
    font-style: italic;
    font-size: 1.1rem;
  }

  .glow-button {
    background: var(--accent-color);
    color: oklch(10% 0.02 var(--primary-hue));
    border: none;
    padding: 1.25rem 3rem;
    border-radius: 50px;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: var(--glow);
    position: relative;
    overflow: hidden;
  }

  .glow-button:hover {
    transform: scale(1.05) translateY(-5px);
    box-shadow: 0 0 30px oklch(70% 0.2 var(--accent-hue) / 0.8);
  }

  .glow-button:active {
    transform: scale(0.95);
  }

  /* Lotto Ball Component */
  lotto-ball {
    display: inline-flex;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    justify-content: center;
    align-items: center;
    font-weight: 800;
    font-size: 1.2rem;
    color: white;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
    box-shadow: 
      inset -4px -4px 10px rgba(0,0,0,0.4),
      inset 4px 4px 10px rgba(255,255,255,0.2),
      0 4px 10px rgba(0,0,0,0.5);
    animation: ballPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    user-select: none;
  }

  /* History Styles */
  .history-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 300px;
    overflow-y: auto;
    padding-right: 0.5rem;
  }

  .history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: oklch(100% 0 0 / 0.03);
    border-radius: 12px;
    border-left: 4px solid var(--accent-color);
    animation: slideIn 0.4s ease-out;
  }

  .history-balls {
    display: flex;
    gap: 0.4rem;
  }

  .history-balls lotto-ball {
    width: 24px;
    height: 24px;
    font-size: 0.7rem;
    box-shadow: none;
  }

  .history-time {
    font-size: 0.75rem;
    color: var(--text-muted);
  }

  /* Number Grid */
  number-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 8px;
    width: 100%;
  }

  .grid-number {
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: oklch(100% 0 0 / 0.05);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    border: 1px solid transparent;
  }

  .grid-number:hover {
    background: oklch(100% 0 0 / 0.1);
  }

  .grid-number.include {
    background: var(--info-color);
    color: black;
    font-weight: bold;
    box-shadow: 0 0 10px var(--info-color);
  }

  .grid-number.exclude {
    background: var(--error-color);
    color: white;
    font-weight: bold;
    box-shadow: 0 0 10px var(--error-color);
  }

  /* Info Section Styles */
  .info-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    text-align: left;
  }

  .info-content {
    color: var(--text-muted);
    font-size: 0.95rem;
  }

  .info-content p {
    margin-bottom: 1rem;
  }

  .info-content h3 {
    font-size: 1.1rem;
    color: var(--text-color);
    margin: 1.5rem 0 0.75rem 0;
  }

  .info-content ul {
    list-style: none;
    padding-left: 0;
  }

  .info-content li {
    margin-bottom: 0.75rem;
    position: relative;
    padding-left: 1.25rem;
  }

  .info-content li::before {
    content: "✦";
    position: absolute;
    left: 0;
    color: var(--accent-color);
  }

  footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 2rem 0;
    border-top: 1px solid oklch(100% 0 0 / 0.05);
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .footer-links {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 0.5rem;
  }

  .footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 600;
  }

  .footer-links a:hover {
    color: var(--accent-color);
    text-decoration: underline;
  }

  .footer-note {
    font-size: 0.7rem;
    opacity: 0.6;
  }
}

/* Scrollbar Styling */
.history-list::-webkit-scrollbar {
  width: 4px;
}
.history-list::-webkit-scrollbar-track {
  background: transparent;
}
.history-list::-webkit-scrollbar-thumb {
  background: oklch(100% 0 0 / 0.1);
  border-radius: 10px;
}

/* Animations */
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes ballPop {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* Responsive */
@container (max-width: 400px) {
  header h1 { font-size: 2.2rem; }
  .glow-button { padding: 1rem 2rem; font-size: 1.1rem; }
}
