/* ==========================================================================
   감사합니다 — Korean Expression Reference
   v2 Dynamic Balanced — Anthropic warm palette
   8pt grid · CJ ONLYONE (self-hosted, 4 weights)
   ========================================================================== */

/* --------------------------------------------------------------------------
   CJ ONLYONE @font-face (per teams/_shared/cj-font-policy.md)
   -------------------------------------------------------------------------- */
@font-face {
  font-family: 'CJ ONLYONE';
  font-weight: 300;
  font-style: normal;
  font-display: swap;
  src: url('../../public/fonts/cj-body-light.woff2') format('woff2');
}
@font-face {
  font-family: 'CJ ONLYONE';
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url('../../public/fonts/cj-body-regular.woff2') format('woff2');
}
@font-face {
  font-family: 'CJ ONLYONE';
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  src: url('../../public/fonts/cj-title-medium.woff2') format('woff2');
}
@font-face {
  font-family: 'CJ ONLYONE';
  font-weight: 800;
  font-style: normal;
  font-display: swap;
  src: url('../../public/fonts/cj-title-800.woff2') format('woff2');
}

/* --------------------------------------------------------------------------
   Design Tokens — v2 Dynamic Balanced (warm palette, Anthropic-inspired)
   -------------------------------------------------------------------------- */
:root {
  /* Color */
  --color-bg:          #FAF8F4;
  --color-bg-alt:      #F3EFE8;
  --color-surface:     #EDE8DF;
  --color-surface-hi:  #FFFFFF;
  --color-text:        #1C1915;
  --color-text-sec:    #4A4540;
  --color-muted:       #7A736A;
  --color-accent:      #8B5E3C;
  --color-accent-hi:   #C27B4A;
  --color-accent-lo:   #DEC9B2;
  --color-label:       #B05C2A;
  --color-label-bg:    #F6EDE5;
  --color-border:      #D8D0C5;
  --color-border-lo:   #EAE4DC;
  --color-white:       #FFFFFF;

  /* Typography */
  --font-main:  'CJ ONLYONE', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-title: 'CJ ONLYONE', system-ui, sans-serif;
  --font-mono:  'SF Mono', 'Fira Mono', 'Consolas', monospace;

  /* Type scale (1.333 Perfect Fourth) */
  --text-2xs: 0.625rem;   /* 10px */
  --text-xs:  0.75rem;    /* 12px */
  --text-sm:  0.875rem;   /* 14px */
  --text-base: 1rem;      /* 16px */
  --text-md:  1.125rem;   /* 18px */
  --text-lg:  1.25rem;    /* 20px */
  --text-xl:  1.5rem;     /* 24px */
  --text-2xl: 2rem;       /* 32px */
  --text-3xl: 3rem;       /* 48px */
  --text-4xl: 4rem;       /* 64px */

  /* Line-height */
  --lh-tight:   1.05;
  --lh-heading: 1.2;
  --lh-lead:    1.5;
  --lh-body:    1.75;
  --lh-loose:   1.9;

  /* Spacing (8pt grid) */
  --space-1:   8px;
  --space-2:   16px;
  --space-3:   24px;
  --space-4:   32px;
  --space-5:   40px;
  --space-6:   48px;
  --space-8:   64px;
  --space-10:  80px;
  --space-12:  96px;
  --space-16:  128px;

  /* Semantic spacing */
  --section-pad-y:   80px;
  --hero-pad-top:    128px;
  --hero-pad-bottom: 96px;

  /* Radius */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  16px;
  --radius-xl:  24px;
  --radius-pill: 999px;
  /* legacy aliases */
  --radius:     4px;
  --radius-lg-old: 8px;

  /* Shadow (warm-tone, opacity-based) */
  --shadow-xs:  0 1px 2px rgba(28, 25, 21, 0.04);
  --shadow-sm:  0 1px 4px rgba(28, 25, 21, 0.07);
  --shadow-md:  0 4px 14px rgba(28, 25, 21, 0.10);
  --shadow-lg:  0 8px 28px rgba(28, 25, 21, 0.13);

  /* Motion */
  --dur-instant: 80ms;
  --dur-fast:    160ms;
  --dur-base:    300ms;
  --dur-slow:    500ms;
  --dur-hero:    900ms;
  --dur-stagger: 120ms;
  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Parallax */
  --parallax-hero-bg:   0.3;
  --parallax-hero-text: 0.15;

  --max-width: 720px;
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

/* Layer 1: Global reduced-motion guard */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */
body {
  font-family: var(--font-main);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: var(--lh-body);
  min-height: 100vh;
}

/* --------------------------------------------------------------------------
   Skip link
   -------------------------------------------------------------------------- */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-2);
  z-index: 9999;
  padding: var(--space-1) var(--space-2);
  background: var(--color-accent);
  color: var(--color-white);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: var(--text-sm);
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: var(--space-2);
}

/* --------------------------------------------------------------------------
   Focus visible
   -------------------------------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* --------------------------------------------------------------------------
   Screen reader only
   -------------------------------------------------------------------------- */
.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;
}

/* --------------------------------------------------------------------------
   Header / Nav
   -------------------------------------------------------------------------- */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-3);
  transition: box-shadow var(--dur-fast) ease;
}
header.is-scrolled {
  box-shadow: 0 1px 8px rgba(28, 25, 21, 0.08);
}
header nav ul {
  list-style: none;
  display: flex;
  gap: var(--space-3);
  max-width: var(--max-width);
  margin: 0 auto;
  height: var(--space-6);
  align-items: center;
}
header nav a {
  color: var(--color-muted);
  text-decoration: none;
  font-size: var(--text-sm);
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: var(--space-1) 0;
  border-bottom: 2px solid transparent;
  transition: color var(--dur-fast) ease, border-color var(--dur-fast) ease;
}
header nav a:hover {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}
header nav a:focus-visible {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
  /* outline 제거 금지 — 전역 :focus-visible 규칙 (line 196) 유지 (WCAG 2.4.7 AA) */
}

/* --------------------------------------------------------------------------
   Section layout (base)
   -------------------------------------------------------------------------- */
section {
  padding: var(--section-pad-y) var(--space-3);
}
section:nth-child(even) {
  background: var(--color-bg-alt);
}
.section-inner {
  max-width: var(--max-width);
  margin: 0 auto;
}

/* --------------------------------------------------------------------------
   Hero (#hangul) — 100svh fullbleed + warm radial gradient
   -------------------------------------------------------------------------- */
#hangul {
  position: relative;
  min-height: 100svh;
  min-height: 100vh; /* fallback */
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--hero-pad-top) var(--space-3) var(--hero-pad-bottom);
  overflow: hidden;
  background: none;
}

/* Hero background layer — warm radial gradient */
.hero-bg-layer {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 30%,
      rgba(194, 123, 74, 0.12) 0%,
      rgba(222, 201, 178, 0.06) 50%,
      transparent 100%),
    linear-gradient(180deg, var(--color-bg) 0%, var(--color-bg-alt) 100%);
  z-index: 0;
  pointer-events: none;
}

.hero-inner {
  position: relative;
  z-index: 1;
  max-width: var(--max-width);
  margin: 0 auto;
}

.hero-eyebrow {
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-label);
  margin-bottom: var(--space-2);
  opacity: 0;
  transform: translateY(-8px);
  animation: hero-eyebrow-in var(--dur-fast) var(--ease-out) 100ms both;
}

.hero-word {
  font-family: var(--font-title);
  font-size: clamp(3.5rem, 13vw, 9rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: var(--lh-tight);
  color: var(--color-text);
  word-break: keep-all;
  margin-bottom: var(--space-3);
  animation: hero-word-in var(--dur-hero) var(--ease-out) 200ms both;
}

.hero-romanized {
  font-family: var(--font-main);
  font-size: var(--text-lg);
  font-weight: 300;
  color: var(--color-muted);
  letter-spacing: 0.04em;
  margin-bottom: var(--space-2);
  animation: hero-fade-in var(--dur-slow) var(--ease-out) 500ms both;
}

.hero-translation {
  font-size: var(--text-md);
  font-weight: 300;
  color: var(--color-muted);
  letter-spacing: 0.01em;
  animation: hero-fade-in var(--dur-slow) var(--ease-out) 650ms both;
}

@keyframes hero-eyebrow-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes hero-word-in {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes hero-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Hero CSS-only parallax (Layer 3: @supports guard) */
@supports (animation-timeline: scroll()) {
  @keyframes hero-parallax {
    from { transform: translateY(0); }
    to   { transform: translateY(-40px); }
  }
  .hero-inner {
    animation: hero-parallax linear;
    animation-timeline: scroll(root block);
    animation-range: 0% 40%;
    will-change: transform;
  }
  /* Layer 3: @supports + @media reduced-motion */
  @media (prefers-reduced-motion: reduce) {
    .hero-inner { animation: none; }
  }
}

/* --------------------------------------------------------------------------
   Section headings
   -------------------------------------------------------------------------- */
.section-inner h2 {
  font-family: var(--font-title);
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--color-accent);
  letter-spacing: -0.01em;
  line-height: var(--lh-heading);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--color-accent);
  display: inline-block;
}
.section-inner h3 {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-2);
}

/* --------------------------------------------------------------------------
   Scroll reveal — [data-animate]
   -------------------------------------------------------------------------- */
[data-animate] {
  opacity: 0;
  transform: translateY(24px);
  transition:
    opacity var(--dur-slow) var(--ease-out) calc(var(--stagger-i, 0) * var(--dur-stagger)),
    transform var(--dur-slow) var(--ease-out) calc(var(--stagger-i, 0) * var(--dur-stagger));
}
[data-animate].is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* --------------------------------------------------------------------------
   Pronounce (#pronounce) — desktop split layout
   -------------------------------------------------------------------------- */
#pronounce .section-inner {
  max-width: 900px;
}

@media (min-width: 768px) {
  .pronounce-split {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: var(--space-6);
    align-items: start;
  }
  .pronounce-sticky-panel {
    position: sticky;
    top: calc(var(--space-6) + 16px); /* header height offset */
  }
}
@media (max-width: 767px) {
  .pronounce-split {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }
  .pronounce-sticky-panel {
    position: static;
  }
}

.pronounce-sticky-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.pronounce-card {
  background: var(--color-surface-hi);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur-fast) ease, transform var(--dur-fast) ease;
}
.pronounce-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
@media (prefers-reduced-motion: reduce) {
  .pronounce-card:hover { transform: none; }
}

.card-label {
  font-size: var(--text-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-label);
  margin-bottom: var(--space-1);
}
.card-value {
  font-size: var(--text-xl);
  font-weight: 500;
  color: var(--color-accent);
  letter-spacing: 0.02em;
  margin-bottom: var(--space-1);
}
.card-value.ipa {
  font-family: var(--font-mono);
  font-size: 1.375rem;
}
.card-note {
  font-size: var(--text-xs);
  color: var(--color-muted);
  line-height: var(--lh-lead);
}

/* Pronounce detail panel */
.pronounce-detail {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Syllable breakdown */
.syllable-breakdown {
  background: var(--color-surface-hi);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
}
.syllable-list {
  list-style: none;
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}
.syllable-list li {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-1) var(--space-2);
  min-width: 56px;
}
.syl-hangul {
  font-size: var(--text-xl);
  font-weight: 500;
  color: var(--color-text);
  line-height: 1.3;
}
.syl-rr {
  font-size: var(--text-xs);
  color: var(--color-muted);
  font-weight: 400;
  letter-spacing: 0.02em;
}
.syllable-note {
  font-size: var(--text-xs);
  color: var(--color-muted);
  font-style: italic;
}

/* --------------------------------------------------------------------------
   Meaning (#meaning)
   -------------------------------------------------------------------------- */
.meaning-etymology {
  border-left: 4px solid var(--color-accent);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  background: var(--color-surface-hi);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
  margin-bottom: var(--space-4);
}
.meaning-etymology h3 {
  margin-bottom: var(--space-1);
}
.meaning-etymology p {
  font-size: var(--text-base);
  line-height: var(--lh-loose);
  color: var(--color-text);
}

.hanja-display {
  font-family: var(--font-title);
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--color-accent);
  letter-spacing: 0.02em;
  display: inline-block;
  margin-right: var(--space-1);
}
.hanja-reading {
  color: var(--color-muted);
  font-size: 0.9em;
}
.meaning-etymology em {
  font-style: normal;
  font-weight: 500;
  color: var(--color-label);
}

/* Formality table */
.formality-block h3 {
  margin-bottom: var(--space-2);
}
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
  background: var(--color-surface-hi);
}
th {
  background: var(--color-text);
  color: var(--color-white);
  font-weight: 500;
  font-size: var(--text-xs);
  letter-spacing: 0.04em;
  text-align: left;
  padding: var(--space-2);
  white-space: nowrap;
}
td {
  padding: var(--space-2);
  border-top: 1px solid var(--color-border-lo);
  color: var(--color-text);
  vertical-align: middle;
}
tr:hover td {
  background: var(--color-bg-alt);
}

/* Table row level accents */
tr[data-level="formal"] td:first-child {
  border-left: 3px solid var(--color-accent);
}
tr[data-level="polite"] td:first-child {
  border-left: 3px solid var(--color-accent-hi);
}
tr[data-level="informal"] td:first-child {
  border-left: 3px solid var(--color-muted);
}

.expr-highlight {
  font-weight: 500;
  font-size: 1.0625rem;
  color: var(--color-accent);
}

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge-formal {
  background: var(--color-accent-lo);
  color: var(--color-accent);
  border: 1px solid var(--color-border);
}
.badge-polite {
  background: #EDF7ED;
  color: #1E6B35;
  border: 1px solid #A8D8A8;
}
.badge-informal {
  background: var(--color-label-bg);
  color: var(--color-label);
  border: 1px solid #F2C09A;
}

/* --------------------------------------------------------------------------
   Examples (#examples) — card stack + stagger
   -------------------------------------------------------------------------- */
.example-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.example-item {
  background: var(--color-surface-hi);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  border-top: 3px solid var(--color-accent);
  /* reveal state: opacity + transform only (CLS=0) */
  opacity: 0;
  transform: translateY(16px);
  transition:
    opacity 0.35s var(--ease-out) calc(var(--stagger-i, 0) * 80ms),
    transform 0.35s var(--ease-out) calc(var(--stagger-i, 0) * 80ms),
    box-shadow var(--dur-fast) ease,
    border-color var(--dur-fast) ease;
}
.example-item.is-visible {
  opacity: 1;
  transform: translateY(0);
}
.example-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
@media (prefers-reduced-motion: reduce) {
  .example-item { opacity: 1; transform: none; }
  .example-item:hover { transform: none; }
}

/* Stagger colors per formality */
.example-item[data-level="formal"] {
  border-top-color: var(--color-accent);
}
.example-item[data-level="polite"] {
  border-top-color: var(--color-accent-hi);
}
.example-item[data-level="informal"] {
  border-top-color: var(--color-muted);
}

.example-badge-row {
  margin-bottom: var(--space-1);
}
.example-ko {
  font-size: 1.375rem;
  font-weight: 500;
  color: var(--color-text);
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.example-rr {
  font-size: 0.9375rem;
  color: var(--color-accent);
  font-weight: 400;
  letter-spacing: 0.01em;
  margin-bottom: 4px;
}
.example-en {
  font-size: var(--text-sm);
  color: var(--color-muted);
  font-weight: 300;
  font-style: italic;
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
footer {
  background: var(--color-text);
  color: rgba(250, 248, 244, 0.7);
  padding: var(--space-5) var(--space-3);
}
.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
footer p {
  font-size: var(--text-sm);
  line-height: var(--lh-lead);
}
footer nav ul {
  list-style: none;
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
}
footer nav a {
  color: rgba(250, 248, 244, 0.55);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: color var(--dur-fast) ease;
}
footer nav a:hover,
footer nav a:focus-visible {
  color: var(--color-bg);
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  section {
    padding: var(--space-8) var(--space-2);
  }
  #hangul {
    padding: var(--space-10) var(--space-2);
    min-height: 100svh;
    min-height: 100vh;
  }
  header nav ul {
    gap: var(--space-2);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 var(--space-1);
  }
  th, td {
    padding: var(--space-1);
    font-size: var(--text-xs);
  }
}

@media (min-width: 720px) {
  .footer-inner {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}
