@layer reset, base, layout, components, utilities;

@layer reset {
  *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }
  
  html {
    scroll-behavior: smooth;
    color-scheme: light dark;
  }
  
  body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-family: 'Pretendard', system-ui, -apple-system, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    transition: background-color 0.3s, color 0.3s;
  }
}

@layer base {
  :root {
    --bg: oklch(0.98 0.01 240);
    --text: oklch(0.15 0.02 240);
    --text-muted: oklch(0.45 0.02 240);
    --primary: oklch(0.6 0.2 20);
    --surface: oklch(1 0 0);
    --border: oklch(0.9 0.01 240);
    --shadow: 0 4px 12px oklch(0 0 0 / 0.05);
    --shadow-hover: 0 12px 24px oklch(0 0 0 / 0.1);
    --radius-lg: 24px;
    --radius-md: 16px;
  }

  [data-theme="dark"] {
    --bg: oklch(0.12 0.02 240);
    --text: oklch(0.95 0.01 240);
    --text-muted: oklch(0.7 0.02 240);
    --surface: oklch(0.18 0.03 240);
    --border: oklch(0.25 0.03 240);
    --shadow: 0 4px 20px oklch(0 0 0 / 0.3);
    --shadow-hover: 0 12px 40px oklch(0 0 0 / 0.5);
  }

  h1, h2, h3 { font-weight: 800; letter-spacing: -0.02em; }
}

@layer layout {
  .container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1rem;
  }

  header {
    height: 70px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(15px);
    position: sticky;
    top: 0;
    z-index: 2000;
    background: var(--surface-glass);
  }

  header .container {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .logo { display: flex; align-items: center; gap: 0.4rem; z-index: 2100; }
  .logo h1 { font-size: 1.1rem; color: var(--primary); }

  .nav-wrapper {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    justify-content: flex-end;
  }

  .nav-group {
    display: flex;
    align-items: center;
    position: relative;
  }

  .nav-label {
    font-size: 0.65rem;
    font-weight: 900;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-right: 0.4rem;
  }

  /* Dropdown UI Refinement */
  .pill-nav {
    display: flex;
    flex-direction: column;
    background: var(--border);
    padding: 2px;
    border-radius: 100px;
    position: relative;
    cursor: pointer;
    min-width: 42px;
    transition: all 0.2s ease;
  }

  .pill-nav.expanded {
    position: absolute;
    top: -4px;
    left: -4px;
    background: var(--surface);
    border-radius: 24px;
    box-shadow: var(--shadow-hover);
    border: 1px solid var(--border);
    padding: 6px;
    width: 52px;
    z-index: 3000;
  }

  .country-btn {
    border: none;
    background: transparent;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
  }

  .country-btn.active {
    display: flex;
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  .pill-nav.expanded .country-btn {
    display: flex;
    margin-bottom: 6px;
  }
  
  .pill-nav.expanded .country-btn:last-child {
    margin-bottom: 0;
  }

  .pill-nav.expanded .country-btn:hover {
    background: var(--border);
    transform: scale(1.05);
  }

  .header-actions { display: flex; align-items: center; padding-left: 0.5rem; }

  @media (max-width: 600px) {
    header { height: 60px; }
    .logo h1 { font-size: 0.95rem; }
    .nav-wrapper { gap: 0.5rem; }
    .country-btn { width: 34px; height: 34px; font-size: 1.3rem; }
    .pill-nav.expanded { width: 46px; }
  }

  main { padding: 1.5rem 0 5rem; }

  #hero { margin-bottom: 2rem; }
  #hero h2 { font-size: 1.5rem; margin-bottom: 0.25rem; }
  #last-updated { color: var(--text-muted); font-size: 0.8rem; }

  #content-grid { display: grid; grid-template-columns: 1fr 300px; gap: 1.5rem; }

  @media (max-width: 900px) {
    #content-grid { grid-template-columns: 1fr; }
    #sidebar { display: none; }
  }

  #bg-canvas {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    z-index: -1; opacity: 0.2; pointer-events: none;
  }

  footer { padding: 2rem 0; border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--text-muted); }
  .footer-content { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
  .footer-links { list-style: none; display: flex; gap: 1rem; }
  .footer-links a { color: inherit; text-decoration: none; }
}

@layer components {
  /* Trend List Refinement */
  trend-list { width: 100%; }
  
  .theme-toggle {
    background: var(--border);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
  }

  .info-card {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
  }
}
