/* ===================================
   TopGrammar Core Styles
   Reset + Variables + Typography + Layout
   =================================== */

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

/* Screen-reader only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; line-height: 1.6; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
img, picture, video, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; }
a { text-decoration: none; color: inherit; }
ul, ol { list-style: none; }
table { border-collapse: collapse; border-spacing: 0; }

/* --- CSS Variables --- */
:root {
  --color-primary: #1B3A5C;
  --color-primary-light: #2A5A8C;
  --color-primary-dark: #0F2640;
  --color-accent: #E87A3A;
  --color-accent-light: #F59E5E;
  --color-accent-dark: #C96228;
  --color-bg: #FAFBFC;
  --color-bg-alt: #F0F2F5;
  --color-card-bg: #FFFFFF;
  --color-text: #1A1A2E;
  --color-text-sub: #6B7280;
  --color-text-light: #9CA3AF;
  --color-white: #FFFFFF;
  --color-border: #E5E7EB;
  --color-border-light: #F3F4F6;
  --color-success: #10B981;
  --color-error: #EF4444;
  --color-warning: #F59E0B;
  --color-info: #3B82F6;

  --font-primary: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-en: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3rem;

  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --weight-black: 900;

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem;
  --space-4: 1rem; --space-5: 1.25rem; --space-6: 1.5rem;
  --space-8: 2rem; --space-10: 2.5rem; --space-12: 3rem;
  --space-16: 4rem; --space-20: 5rem; --space-24: 6rem;

  --header-height: 68px;
  --max-width: 1200px;
  --container-max: 1200px;
  --radius-sm: 4px; --radius-md: 8px; --radius-lg: 12px;
  --radius-xl: 16px; --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 2px 4px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 8px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.1);
  --shadow-xl: 0 8px 16px rgba(0,0,0,0.06), 0 16px 48px rgba(0,0,0,0.12);
  --shadow-premium: 0 1px 1px rgba(0,0,0,0.02), 0 2px 4px rgba(0,0,0,0.03), 0 4px 8px rgba(0,0,0,0.04), 0 8px 16px rgba(0,0,0,0.05), 0 16px 32px rgba(0,0,0,0.06);

  --transition-fast: 150ms ease;
  --transition-base: 300ms cubic-bezier(0.4,0,0.2,1);
  --transition-slow: 500ms cubic-bezier(0.4,0,0.2,1);

  --z-banner: 99;
  --z-header: 1000;
  --z-modal: 9000;
  --z-lightbox: 9500;
  --z-toast: 10000;
  --z-loading: 10001;
}

/* --- Typography --- */
body {
  font-family: var(--font-primary);
  background-color: var(--color-bg);
  color: var(--color-text);
  font-size: var(--text-base);
  line-height: 1.6;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--weight-bold);
  line-height: 1.2;
  color: var(--color-text);
  letter-spacing: -0.025em;
  word-break: keep-all;
}
h1 { font-size: var(--text-5xl); letter-spacing: -0.03em; }
h2 { font-size: var(--text-4xl); margin-bottom: var(--space-4); }
h3 { font-size: var(--text-3xl); letter-spacing: -0.02em; }
h4 { font-size: var(--text-2xl); letter-spacing: -0.015em; }
h5 { font-size: var(--text-xl); }
p { color: var(--color-text-sub); line-height: 1.75; }
strong { font-weight: var(--weight-semibold); }
::selection { background: rgba(232,122,58,0.2); color: var(--color-text); }

/* Premium Section Header Decorator */
.section-header { text-align: center; margin-bottom: var(--space-12); }
.section-header__label {
  display: inline-block; font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase; letter-spacing: 0.12em; color: var(--color-accent);
  margin-bottom: var(--space-3);
}
.section-header__title { margin-bottom: var(--space-3); }
.section-header__desc { max-width: 600px; margin: 0 auto; font-size: var(--text-base); color: var(--color-text-sub); }
.section-header__line {
  width: 48px; height: 3px; border-radius: 2px;
  background: linear-gradient(90deg, var(--color-accent), var(--color-accent-light));
  margin: var(--space-4) auto 0;
}

/* --- Layout --- */
.container { width: 100%; max-width: var(--max-width); margin: 0 auto; padding: 0 var(--space-6); }
.section { padding: 80px 0; position: relative; }
.section--tight { padding: 48px 0; }
.section--spacious { padding: 100px 0; }
.section--alt { background: var(--color-bg-alt); }
.section--primary { background: var(--color-primary); color: var(--color-white); }
.section--primary h2, .section--primary h3 { color: var(--color-white); }
.section--primary p { color: rgba(255,255,255,0.8); }

/* --- Grid --- */
.grid { display: grid; gap: var(--space-6); }
.grid--2 { grid-template-columns: repeat(2,1fr); }
.grid--3 { grid-template-columns: repeat(3,1fr); }
.grid--4 { grid-template-columns: repeat(4,1fr); }

/* --- Flex --- */
.flex { display: flex; }
.flex--between { display: flex; justify-content: space-between; align-items: center; }
.flex--center { display: flex; justify-content: center; align-items: center; }
.flex--gap { gap: var(--space-4); }

/* --- Utilities --- */
.text-center { text-align: center; }
.text-muted { color: var(--color-text-light); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.mb-12 { margin-bottom: var(--space-12); }
.mt-8 { margin-top: var(--space-8); }
.mt-12 { margin-top: var(--space-12); }

/* ========================
   Header
   ======================== */
.site-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--header-height);
  background: rgba(255,255,255,0.97);
  border-bottom: 1px solid var(--color-border);
  transition: box-shadow var(--transition-base);
}
.site-header--scrolled { box-shadow: var(--shadow-md); }
.site-header__inner {
  max-width: var(--max-width); margin: 0 auto;
  padding: 0 var(--space-6); height: 100%;
  display: flex; align-items: center; justify-content: space-between;
}
.site-header__logo { display: flex; align-items: center; gap: var(--space-3); }
.site-header__logo-mark {
  width: 40px; height: 40px; border-radius: var(--radius-md);
  flex-shrink: 0; object-fit: contain;
}
.site-header__logo-text { display: flex; flex-direction: column; }
.site-header__logo-title {
  font-size: var(--text-lg); font-weight: var(--weight-bold);
  color: var(--color-primary); line-height: 1.2;
}
.site-header__logo-sub {
  font-size: var(--text-xs); color: var(--color-text-sub); line-height: 1.2;
}

/* --- Nav --- */
.site-nav { display: flex; align-items: center; gap: var(--space-1); }
.site-nav__link {
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  color: var(--color-text-sub); transition: all var(--transition-fast);
}
.site-nav__link:hover { color: var(--color-primary); background: var(--color-bg-alt); }
.site-nav__link--active { color: var(--color-accent); font-weight: var(--weight-semibold); }
.site-nav__cta {
  margin-left: var(--space-2); padding: var(--space-2) var(--space-5);
  background: var(--color-accent); color: #fff; border-radius: var(--radius-full);
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  transition: background var(--transition-fast);
}
.site-nav__cta:hover { background: var(--color-accent-dark); }

/* Hamburger */
.site-header__hamburger {
  display: none; background: none; border: none; cursor: pointer;
  width: 36px; height: 36px; flex-direction: column; align-items: center;
  justify-content: center; gap: 5px; padding: 0;
}
.site-header__hamburger span {
  display: block; width: 22px; height: 2px; background: var(--color-text);
  border-radius: 2px; transition: all var(--transition-fast);
}
.site-header__hamburger.is-active span:nth-child(1) { transform: rotate(45deg) translate(5px,5px); }
.site-header__hamburger.is-active span:nth-child(2) { opacity: 0; }
.site-header__hamburger.is-active span:nth-child(3) { transform: rotate(-45deg) translate(5px,-5px); }

/* ========================
   Footer
   ======================== */
.site-footer {
  background: var(--color-primary-dark); color: rgba(255,255,255,0.7);
  padding: var(--space-16) 0 var(--space-8);
}
.site-footer__grid {
  display: grid; grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: var(--space-8); margin-bottom: var(--space-12);
}
.site-footer__brand-desc { font-size: var(--text-sm); line-height: 1.7; margin-top: var(--space-3); }
.site-footer__title {
  font-size: var(--text-sm); font-weight: var(--weight-semibold);
  color: var(--color-white); margin-bottom: var(--space-4);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.site-footer__link {
  display: block; font-size: var(--text-sm); padding: var(--space-1) 0;
  color: rgba(255,255,255,0.6); transition: color var(--transition-fast);
}
.site-footer__link:hover { color: var(--color-accent-light); }
.site-footer__bottom {
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: var(--space-6); display: flex;
  justify-content: space-between; align-items: center;
  font-size: var(--text-xs); color: rgba(255,255,255,0.7);
}
.site-footer__bottom a { color: rgba(255,255,255,0.75); }
.site-footer__bottom a:hover { color: var(--color-accent-light); }
.site-footer__info {
  margin-bottom: var(--space-4); font-size: var(--text-xs);
  color: rgba(255,255,255,0.7); line-height: 1.8;
}
.site-footer__info span + span::before { content: ' | '; }

/* ========================
   Toast
   ======================== */
.toast-container {
  position: fixed; top: calc(var(--header-height) + var(--space-4));
  right: var(--space-4); z-index: 10000;
  display: flex; flex-direction: column; gap: var(--space-2);
}
.toast {
  background: var(--color-card-bg); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm); box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s ease;
}
.toast__icon { font-weight: bold; margin-right: 4px; }
.toast--success { border-left: 3px solid var(--color-success); }
.toast--success .toast__icon { color: var(--color-success); }
.toast--error { border-left: 3px solid var(--color-error); }
.toast--error .toast__icon { color: var(--color-error); }
.toast--warning { border-left: 3px solid var(--color-warning); }
.toast--warning .toast__icon { color: var(--color-warning); }
.toast--info { border-left: 3px solid var(--color-info); }
.toast--info .toast__icon { color: var(--color-info); }
@keyframes toast-in { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }

/* Loading Overlay */
.tg-loading-overlay {
  position: fixed; inset: 0; z-index: 10001;
  background: rgba(0,0,0,0.35); display: flex; align-items: center; justify-content: center;
}
.tg-loading-overlay__inner { text-align: center; }
.tg-loading-overlay__msg { margin-top: var(--space-3); color: #fff; font-size: var(--text-sm); }
.tg-spinner {
  width: 40px; height: 40px; border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff; border-radius: 50%; animation: tg-spin 0.7s linear infinite; margin: 0 auto;
}
@keyframes tg-spin { to { transform: rotate(360deg); } }

/* ========================
   Animations
   ======================== */
.slide-up { opacity: 0; transform: translateY(30px); transition: opacity 0.6s ease, transform 0.6s ease; animation: slideUpFallback 0.01s 0.8s forwards; }
.slide-up.is-visible { opacity: 1; transform: translateY(0); animation: none; }
@keyframes slideUpFallback { to { opacity: 1; transform: translateY(0); } }
.no-js .slide-up, .slide-up[data-no-animate] { opacity: 1; transform: none; animation: none; transition: none; }
.hover-lift { transition: transform 0.3s ease, box-shadow 0.3s ease; }
.hover-lift:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }

/* ========================
   Skip Link
   ======================== */
.skip-link {
  position: absolute; top: -100%; left: var(--space-4);
  background: var(--color-accent); color: #fff;
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm);
  font-size: var(--text-sm); font-weight: var(--weight-semibold); z-index: 100000;
}
.skip-link:focus { top: var(--space-2); }

/* ========================
   Responsive
   ======================== */
@media (max-width: 1024px) {
  .grid--4 { grid-template-columns: repeat(2,1fr); }
  .grid--3 { grid-template-columns: repeat(2,1fr); }
  h1 { font-size: var(--text-4xl); }
  h2 { font-size: var(--text-3xl); }
  .section { padding: 60px 0; }
}

@media (max-width: 768px) {
  .container { padding: 0 var(--space-4); }
  .section { padding: 48px 0; }
  .grid--4, .grid--3, .grid--2 { grid-template-columns: 1fr; }
  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }

  .site-header__hamburger { display: flex; }
  .site-nav {
    position: fixed; top: var(--header-height); left: 0; right: 0; bottom: 0;
    background: var(--color-white); flex-direction: column;
    padding: var(--space-6); gap: var(--space-2);
    transform: translateX(100%); transition: transform var(--transition-base);
    overflow-y: auto;
  }
  .site-nav--open { transform: translateX(0); }
  .site-nav__link { font-size: var(--text-lg); padding: var(--space-3) var(--space-4); width: 100%; }
  .site-nav__cta { width: 100%; text-align: center; margin-left: 0; margin-top: var(--space-4); padding: var(--space-3); }

  .site-footer__grid { grid-template-columns: 1fr; gap: var(--space-6); }
  .site-footer__bottom { flex-direction: column; gap: var(--space-2); text-align: center; }
}

@media (max-width: 480px) {
  :root {
    --text-5xl: 2rem; --text-4xl: 1.75rem;
    --text-3xl: 1.5rem; --text-2xl: 1.25rem;
  }
  .section { padding: 36px 0; }
  .container { padding: 0 var(--space-3); }

  /* Reduce heading margins */
  h2 { margin-bottom: var(--space-3); }

  /* Footer → tighter padding */
  .site-footer { padding: var(--space-8) 0 var(--space-6); }
  .site-footer__grid { gap: var(--space-4); margin-bottom: var(--space-8); }

  /* Header logo text → hide subtitle on very small */
  .site-header__logo-sub { display: none; }
}

/* ========================
   Dark Mode
   ======================== */
.dark {
  --color-bg: #1a1a2e;
  --color-bg-alt: #16213e;
  --color-card-bg: #1e1e3a;
  --color-text: #e0e0e0;
  --color-text-sub: #a0a0a0;
  --color-text-light: #787878;
  --color-white: #e0e0e0;
  --color-border: #2a2a4a;
  --color-border-light: #232346;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.35);
  --shadow-xl: 0 16px 48px rgba(0,0,0,0.45);
}
.dark .site-header {
  background: rgba(26,26,46,0.97);
}
.dark .site-nav__link:hover {
  background: var(--color-bg-alt);
}
.dark ::selection {
  background: rgba(232,122,58,0.3);
}

/* Theme toggle button */
.theme-toggle {
  position: fixed; bottom: var(--space-6); left: var(--space-6);
  z-index: 9999; width: 42px; height: 42px;
  border: 1px solid var(--color-border); border-radius: var(--radius-full);
  background: var(--color-card-bg); color: var(--color-text);
  font-size: 1.15rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
}
.theme-toggle:hover {
  box-shadow: var(--shadow-lg);
}

@media (max-width: 768px) {
  .dark .site-nav {
    background: var(--color-bg);
  }
}

/* Auto dark-mode for OS-level preference (when no .dark/.light class is set manually) */
@media (prefers-color-scheme: dark) {
  html:not(.light) {
    --color-bg: #1a1a2e;
    --color-bg-alt: #16213e;
    --color-card-bg: #1e1e3a;
    --color-text: #e0e0e0;
    --color-text-sub: #a0a0a0;
    --color-text-light: #787878;
    --color-white: #e0e0e0;
    --color-border: #2a2a4a;
    --color-border-light: #232346;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.35);
    --shadow-xl: 0 16px 48px rgba(0,0,0,0.45);
  }
  html:not(.light) .site-header {
    background: rgba(26,26,46,0.78);
  }
  html:not(.light) ::selection {
    background: rgba(232,122,58,0.3);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ========================
   Enhanced UX — v4
   ======================== */

/* 1. Animated Hero Gradient */
@keyframes heroGradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
.hero {
  background-size: 200% 200%;
  animation: heroGradientShift 12s ease infinite;
}

/* 2. Frosted Glass Header */
@supports (backdrop-filter: blur(12px)) {
  .site-header {
    background: rgba(255,255,255,0.72);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
  }
  .dark .site-header {
    background: rgba(26,26,46,0.78);
  }
}

/* 3. Button Active State */
.btn:active, .hero__btn:active {
  transform: scale(0.97);
  transition-duration: 80ms;
}

/* 4. Stagger Classes */
.stagger-1 { transition-delay: 0.1s; }
.stagger-2 { transition-delay: 0.2s; }
.stagger-3 { transition-delay: 0.3s; }
.stagger-4 { transition-delay: 0.4s; }
.stagger-5 { transition-delay: 0.5s; }
.stagger-6 { transition-delay: 0.6s; }

/* 5. Custom Scrollbar */
html { scrollbar-width: thin; scrollbar-color: var(--color-primary-light) var(--color-bg-alt); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--color-bg-alt); }
::-webkit-scrollbar-thumb {
  background: var(--color-primary-light);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: var(--color-primary); }

/* 6. Better Focus Ring — deferred to components.css :focus-visible (outline-based) */

/* 7. Page Load Fade-in */
body:not(.is-loaded) {
  opacity: 0;
  animation: bodyFadeIn 0.01s 1.5s forwards;
}
body.is-loaded {
  opacity: 1;
}
@keyframes bodyFadeIn { to { opacity: 1; } }

/* 8. Text Gradient */
.text-gradient {
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* 9. Hover Underline Animation */
.hover-underline { position: relative; display: inline-block; }
.hover-underline::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 50%;
  width: 0;
  height: 2px;
  background: var(--color-accent);
  transition: width 0.3s ease, left 0.3s ease;
}
.hover-underline:hover::after {
  width: 100%;
  left: 0;
}

/* 10. Section Wave Divider */
.section--wave { position: relative; }
.section--wave::before {
  content: '';
  position: absolute;
  top: -47px;
  left: 0;
  right: 0;
  height: 48px;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 1200 48' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 48h1200V24C1050 0 900 48 750 24S450 0 300 24 0 0 0 24z' fill='%23FAFBFC'/%3E%3C/svg%3E") no-repeat bottom center;
  background-size: 100% 48px;
  pointer-events: none;
}
.section--alt.section--wave::before {
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 1200 48' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 48h1200V24C1050 0 900 48 750 24S450 0 300 24 0 0 0 24z' fill='%23F0F2F5'/%3E%3C/svg%3E");
}
.dark .section--wave::before {
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 1200 48' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 48h1200V24C1050 0 900 48 750 24S450 0 300 24 0 0 0 24z' fill='%231a1a2e'/%3E%3C/svg%3E");
}
