@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;
    --surface-glass: oklch(1 0 0 / 0.8);
  }

  [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);
    --surface-glass: oklch(0.18 0.03 240 / 0.8);
  }

  h1, h2, h3, h4 { font-weight: 800; letter-spacing: -0.02em; }
  ul { list-style: none; }
  a { color: var(--primary); text-decoration: none; transition: 0.2s; }
  a:hover { opacity: 0.8; }
/* Update Status */
.update-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

.hidden { display: none !important; }

/* ... existing styles ... */
}

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

  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;
  }

  .header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
  }

  .header-right {
    display: flex;
    align-items: center;
  }

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

  /* Theme Menu */
  .theme-menu {
    position: relative;
  }
  .theme-menu-btn {
    background: transparent;
    border: 1px solid var(--border);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text);
  }
  
  /* High contrast for Light Mode */
  [data-theme="light"] .theme-menu-btn,
  [data-theme="light"] .theme-opt {
    color: #000 !important;
  }
  [data-theme="light"] .theme-dropdown {
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(0, 0, 0, 0.15);
  }

  /* High contrast for Dark Mode */
  [data-theme="dark"] .theme-menu-btn,
  [data-theme="dark"] .theme-opt {
    color: #fff !important;
  }
  [data-theme="dark"] .theme-dropdown {
    background: rgba(20, 20, 20, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.15);
  }

  .theme-menu-btn:hover {
    border-color: var(--primary);
    background: var(--border);
  }
  .theme-trigger-icon {
    font-size: 1.2rem;
  }

  .theme-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    backdrop-filter: blur(25px);
    border-radius: 16px;
    padding: 0.5rem;
    min-width: 150px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    box-shadow: var(--shadow-hover);
    z-index: 3000;
    transform-origin: top right;
    transition: all 0.2s cubic-bezier(0.165, 0.84, 0.44, 1);
  }
  .theme-dropdown.hidden {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    pointer-events: none;
  }

  .theme-opt {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.8rem;
    border: none;
    background: transparent;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 700; /* Bolder for visibility */
    font-size: 0.85rem;
    transition: all 0.2s;
    text-align: left;
  }
  .theme-opt:hover {
    background: rgba(128, 128, 128, 0.1);
  }
  .theme-opt.active {
    background: var(--primary);
    color: white !important;
  }
  .opt-icon { 
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.1rem;
    height: 1.1rem;
  }
  
  .theme-trigger-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.2rem;
    height: 1.2rem;
  }
  .theme-menu-btn svg, .theme-opt svg {
    width: 100%;
    height: 100%;
    fill: none; /* Reset fill for stroke-based icons */
    stroke: currentColor;
  }
  /* Fill system icon specifically */
  .system-svg svg path:last-child {
    fill: currentColor;
  }

  /* Side Menu Toggle */
  .menu-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
  }
  .menu-toggle:hover {
    background-color: var(--border);
  }
  .menu-icon {
    font-size: 2rem;
    color: var(--text);
    line-height: 1;
  }

  /* Side Menu (Drawer) */
  .side-menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 5000;
    transition: opacity 0.3s ease;
  }
  .side-menu-overlay.hidden {
    opacity: 0;
    pointer-events: none;
  }

  .side-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 320px;
    max-width: 85%;
    height: 100%;
    background: var(--bg);
    z-index: 5100;
    box-shadow: 10px 0 30px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
  }
  .side-menu.active {
    transform: translateX(0);
  }

  .side-menu-header {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
  }
  .menu-close {
    background: var(--border);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
  }

  .side-menu-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
  }

  .menu-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }
  .menu-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    font-weight: 800;
  }

  .menu-links {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }
  .menu-links a {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    padding: 0.5rem 0;
    display: block;
    transition: color 0.2s;
  }
  .menu-links a:hover {
    color: var(--primary);
  }

  .side-menu-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
  }

  /* Nav Groups inside side menu */
  .nav-group { 
    display: flex; 
    flex-direction: column; 
    gap: 0.75rem; 
    position: relative; 
    min-height: 50px;
  }
  
  .nav-label { 
    font-size: 0.65rem; 
    font-weight: 900; 
    text-transform: uppercase; 
    color: var(--text-muted); 
    letter-spacing: 0.05em;
  }

  .pill-nav {
    display: flex;
    align-items: center;
    background: var(--border);
    padding: 3px;
    border-radius: 100px;
    position: relative;
    width: 44px; /* Fixed width for single icon */
    height: 44px;
    cursor: pointer;
    transition: width 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
    overflow: hidden;
  }

  .pill-nav.expanded {
    width: 140px; /* Expand to show all icons */
    background: var(--surface);
    box-shadow: var(--shadow-hover);
    border: 1px solid var(--border);
    overflow: visible;
    z-index: 6000;
  }

  .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, background-color 0.2s;
    flex-shrink: 0;
  }

  .country-btn.active { display: flex; background: var(--surface); box-shadow: var(--shadow); }
  .pill-nav.expanded .country-btn { display: flex; margin-right: 6px; }
  .pill-nav.expanded .country-btn:last-child { margin-right: 0; }
  .pill-nav.expanded .country-btn:hover { background: var(--border); transform: scale(1.1); }

  main { padding: 2rem 0 5rem; }
  #hero { margin-bottom: 2.5rem; text-align: center; }
  #hero h2 { font-size: 2.2rem; margin-bottom: 0.5rem; }
  #last-updated { color: var(--text-muted); font-size: 0.9rem; font-weight: 600; }

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

  @media (max-width: 900px) {
    #content-grid { grid-template-columns: 1fr; }
    #sidebar { display: flex; flex-direction: column; gap: 1.5rem; }
    #hero h2 { font-size: 1.8rem; }
  }

  footer { padding: 4rem 0; border-top: 1px solid var(--border); font-size: 0.85rem; color: var(--text-muted); background: var(--surface); }
  .footer-content { display: flex; flex-direction: column; align-items: center; gap: 1.5rem; text-align: center; }
  .footer-links { list-style: none; display: flex; gap: 1.5rem; flex-wrap: wrap; justify-content: center; }
  .footer-links a { color: var(--text); font-weight: 600; }
}

@layer components {
  /* Ad Slots */
  .ad-slot {
    background: var(--border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    border: 1px dashed var(--text-muted);
    margin-bottom: 1.5rem;
    min-height: 100px;
  }
  .sidebar-ad { min-height: 250px; }
  .banner-ad { min-height: 120px; margin-top: 2rem; }

  /* Cookie Banner */
  .cookie-banner {
    position: fixed; bottom: 2rem; left: 2rem;
    width: calc(100% - 4rem); max-width: 350px; background: var(--surface);
    border: 1px solid var(--border); padding: 1.5rem; border-radius: var(--radius-lg);
    box-shadow: var(--shadow-hover); z-index: 9999;
    display: flex; flex-direction: column; gap: 1.25rem;
  }
  .cookie-banner p { font-size: 0.85rem; font-weight: 500; line-height: 1.5; color: var(--text); }
  .btn-sm { 
    padding: 0.7rem 1.2rem; background: var(--primary); color: white; border: none; 
    border-radius: 100px; font-weight: 700; cursor: pointer; font-size: 0.8rem;
    align-self: flex-end; transition: transform 0.2s;
  }
  .btn-sm:active { transform: scale(0.95); }

  /* Info Modals */
  trend-modal, trend-list { display: block; }
  
  .info-modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(10px);
    display: flex; align-items: center; justify-content: center; z-index: 6000; padding: 1.5rem;
  }
  .info-modal-content {
    background: var(--bg); width: 100%; max-width: 700px; max-height: 80vh;
    border-radius: var(--radius-lg); padding: 2.5rem; position: relative;
    overflow-y: auto; border: 1px solid var(--border); box-shadow: var(--shadow-hover);
  }
  .info-modal-close { position: absolute; top: 1.5rem; right: 1.5rem; background: var(--border); border: none; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; }
  
  #info-modal-body h2 { margin-bottom: 1.5rem; color: var(--primary); }
  #info-modal-body h3 { margin: 1.5rem 0 0.75rem; font-size: 1.1rem; }
  #info-modal-body p { margin-bottom: 1rem; line-height: 1.7; font-size: 0.95rem; color: var(--text); }
  #info-modal-body ul { margin-bottom: 1.5rem; padding-left: 1.2rem; list-style: disc; }
  #info-modal-body li { margin-bottom: 0.5rem; font-size: 0.95rem; }
}
