/* =========================================================
   Korean for TOPIK — stylesheet
   Palette: primary red #C8102E, dark navy secondary, white cards
   ========================================================= */
:root {
  --red: #C8102E;
  --red-dark: #9e0c24;
  --red-soft: #fbe7ea;
  --navy: #16213e;
  --navy-2: #1f2a4d;
  --ink: #1a1f2c;
  --muted: #6b7280;
  --line: #e7e9ef;
  --bg: #f5f6fa;
  --card: #ffffff;
  --good: #1f9d55;
  --shadow-sm: 0 1px 3px rgba(22, 33, 62, 0.08);
  --shadow-md: 0 8px 28px rgba(22, 33, 62, 0.10);
  --shadow-lg: 0 18px 50px rgba(22, 33, 62, 0.16);
  --radius: 16px;
  --radius-sm: 10px;
  --maxw: 1080px;
  --kr: "Noto Sans KR", "Inter", system-ui, sans-serif;
  --sans: "Inter", "Noto Sans KR", system-ui, sans-serif;
}

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

html { scroll-behavior: smooth; scroll-padding-top: 80px; }

body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.01em; }

/* ---------------- Navbar ---------------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(22, 33, 62, 0.96);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
}
.nav-inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 22px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
  font-weight: 800;
  font-size: 1.15rem;
}
.brand-mark {
  font-family: var(--kr);
  background: var(--red);
  color: #fff;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  font-weight: 900;
  font-size: 1.1rem;
}
.brand-accent { color: var(--red); font-family: var(--kr); }

.nav-links { display: flex; gap: 6px; align-items: center; }
.nav-links a {
  color: #cdd3e4;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  padding: 8px 14px;
  border-radius: 8px;
  transition: color .15s, background .15s;
}
.nav-links a:hover { color: #fff; background: rgba(255,255,255,0.07); }
.nav-links a.active { color: #fff; background: var(--red); }

.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: 0;
  cursor: pointer;
  padding: 6px;
}
.nav-toggle span {
  width: 24px; height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: transform .25s, opacity .2s;
}
.nav-toggle.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.open span:nth-child(2) { opacity: 0; }
.nav-toggle.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ---------------- Sections ---------------- */
.section {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 78px 22px;
}
.section-alt { background: #fff; max-width: none; }
.section-alt > * { max-width: var(--maxw); margin-left: auto; margin-right: auto; }

.section-head { text-align: center; margin-bottom: 38px; }
.section-head h2 { font-size: 2rem; margin-bottom: 10px; }
.section-head p { color: var(--muted); max-width: 620px; margin: 0 auto; }
.section-kr {
  display: block;
  font-family: var(--kr);
  color: var(--red);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: .04em;
  margin-bottom: 4px;
}

/* ---------------- Hero ---------------- */
.hero {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 48px;
  align-items: center;
  padding-top: 90px;
  padding-bottom: 90px;
}
.hero-eyebrow {
  font-family: var(--kr);
  color: var(--red);
  font-weight: 700;
  letter-spacing: .04em;
  margin-bottom: 14px;
  font-size: .95rem;
}
.hero h1 { font-size: 3rem; color: var(--navy); margin-bottom: 18px; }
.hero-sub { color: var(--muted); font-size: 1.08rem; max-width: 520px; margin-bottom: 28px; }
.hero-actions { display: flex; gap: 14px; flex-wrap: wrap; }
.hero-stats { display: grid; gap: 16px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--red);
  border-radius: var(--radius-sm);
  padding: 18px 22px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}
.stat-num { font-size: 2rem; font-weight: 800; color: var(--navy); line-height: 1; }
.stat-label { color: var(--muted); font-size: .9rem; margin-top: 6px; }

/* ---------------- Buttons ---------------- */
.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: .98rem;
  border: 0;
  border-radius: 10px;
  padding: 12px 22px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform .12s, box-shadow .15s, background .15s, color .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--red); color: #fff; box-shadow: 0 6px 16px rgba(200,16,46,.28); }
.btn-primary:hover { background: var(--red-dark); }
.btn-ghost { background: transparent; color: var(--navy); border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: var(--red); color: var(--red); }
.btn-small { padding: 8px 14px; font-size: .85rem; }

/* ---------------- Tabs ---------------- */
.level-tabs { display: inline-flex; gap: 6px; background: #eef0f6; padding: 5px; border-radius: 12px; }
.section-alt .level-tabs { background: #f1f3f8; }
.tab {
  font-family: inherit;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: .9rem;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--navy); }
.tab.active { background: var(--red); color: #fff; box-shadow: var(--shadow-sm); }

/* ---------------- Progress bar ---------------- */
.progress-wrap { display: flex; align-items: center; gap: 14px; max-width: 560px; margin: 0 auto 26px; }
.progress-bar { flex: 1; height: 10px; background: #e7e9ef; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--red), #e8556d); border-radius: 999px; transition: width .4s ease; }
.progress-text { font-size: .85rem; color: var(--muted); white-space: nowrap; font-weight: 600; }

/* ---------------- Flashcards ---------------- */
.fc-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 560px;
  margin: 0 auto 22px;
  gap: 12px;
  flex-wrap: wrap;
}
.flashcard-stage { display: flex; justify-content: center; perspective: 1400px; }
.flashcard {
  width: 100%;
  max-width: 460px;
  height: 280px;
  cursor: pointer;
  outline: none;
}
.flashcard-inner {
  position: relative;
  width: 100%; height: 100%;
  transition: transform .55s cubic-bezier(.4,.2,.2,1);
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard:focus-visible .flashcard-inner { box-shadow: 0 0 0 3px rgba(200,16,46,.4); border-radius: var(--radius); }
.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
}
.flashcard-front { border-top: 5px solid var(--red); }
.flashcard-back { transform: rotateY(180deg); border-top: 5px solid var(--navy); }
.fc-pos {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--red);
  font-weight: 700;
  background: var(--red-soft);
  padding: 3px 10px;
  border-radius: 999px;
}
.fc-word { font-family: var(--kr); font-size: 3rem; font-weight: 700; color: var(--navy); }
.fc-hint { font-size: .8rem; color: #aab0bd; }
.fc-rom { font-style: italic; color: var(--muted); font-size: 1.05rem; }
.fc-meaning { font-size: 1.6rem; font-weight: 700; color: var(--navy); }
.fc-example { font-family: var(--kr); color: var(--ink); font-size: .98rem; margin-top: 6px; }
.fc-example small { display: block; font-family: var(--sans); color: var(--muted); margin-top: 4px; }

.fc-rate {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 26px;
  flex-wrap: wrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.fc-rate.show { opacity: 1; pointer-events: auto; }
.fc-rate .btn { color: #fff; min-width: 84px; }
.rate-again { background: #c0392b; }
.rate-hard  { background: #e67e22; }
.rate-good  { background: #2980b9; }
.rate-easy  { background: var(--good); }
.fc-rate .btn:hover { filter: brightness(1.07); }
.fc-counter { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 16px; }

/* ---------------- Grammar ---------------- */
.grammar-filters {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 26px;
}
.search-input {
  font-family: inherit;
  font-size: .95rem;
  padding: 10px 16px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  min-width: 240px;
  flex: 1;
  max-width: 320px;
  background: #fff;
}
.search-input:focus { outline: none; border-color: var(--red); }
.grammar-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 18px; }
.grammar-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s;
}
.grammar-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.gr-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.gr-pattern { font-family: var(--kr); font-size: 1.35rem; font-weight: 700; color: var(--navy); }
.gr-badge {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.gr-badge.l1 { background: var(--red-soft); color: var(--red); }
.gr-badge.l2 { background: #e6ebf7; color: var(--navy-2); }
.gr-rom { color: var(--muted); font-style: italic; font-size: .85rem; }
.gr-meaning { font-weight: 700; color: var(--red); margin: 8px 0 8px; }
.gr-explain { font-size: .92rem; color: var(--ink); margin-bottom: 12px; }
.gr-examples { border-top: 1px dashed var(--line); padding-top: 12px; display: grid; gap: 10px; }
.gr-ex-ko { font-family: var(--kr); color: var(--navy); font-weight: 500; }
.gr-ex-en { color: var(--muted); font-size: .88rem; }
.empty-state { grid-column: 1/-1; text-align: center; color: var(--muted); padding: 40px; }

/* ---------------- Reading ---------------- */
#reading .level-tabs { display: flex; justify-content: center; margin: 0 auto 24px; }
.reading-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 5px solid var(--red);
  border-radius: var(--radius);
  padding: 34px;
  max-width: 760px;
  margin: 0 auto;
  box-shadow: var(--shadow-md);
}
.reading-title { font-family: var(--kr); color: var(--navy); font-size: 1.5rem; margin-bottom: 18px; }
.reading-body { font-family: var(--kr); font-size: 1.25rem; line-height: 2.1; color: var(--ink); }
.rd-word {
  cursor: pointer;
  border-bottom: 2px dotted var(--red);
  transition: background .15s, color .15s;
  border-radius: 3px;
  padding: 0 1px;
}
.rd-word:hover, .rd-word.active { background: var(--red); color: #fff; border-bottom-color: transparent; }
.reading-tip { text-align: center; color: var(--muted); margin-top: 20px; font-size: .9rem; }

.word-pop {
  position: absolute;
  z-index: 60;
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 150px;
  max-width: 260px;
  transform: translate(-50%, -100%);
  pointer-events: none;
}
.word-pop::after {
  content: "";
  position: absolute;
  bottom: -7px; left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: var(--navy);
  border-bottom: 0;
}
.word-pop-ko { font-family: var(--kr); font-weight: 700; font-size: 1.1rem; }
.word-pop-rom { font-style: italic; color: #b9c1da; font-size: .82rem; }
.word-pop-en { color: #fff; font-size: .95rem; }

/* ---------------- Quiz ---------------- */
.quiz-shell {
  max-width: 600px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 36px;
  box-shadow: var(--shadow-md);
}
.quiz-start { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 22px; }
.quiz-intro { color: var(--muted); }
.quiz-topbar { display: flex; justify-content: space-between; font-weight: 700; color: var(--navy); margin-bottom: 12px; }
.quiz-score { color: var(--red); }
.quiz-game .progress-bar { margin-bottom: 26px; }
.quiz-question { font-family: var(--kr); font-size: 2rem; text-align: center; color: var(--navy); margin-bottom: 26px; }
.quiz-options { display: grid; gap: 12px; }
.quiz-opt {
  font-family: inherit;
  text-align: left;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 15px 18px;
  font-size: 1rem;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  color: var(--ink);
}
.quiz-opt:hover:not(:disabled) { border-color: var(--red); background: #fffafb; }
.quiz-opt:disabled { cursor: default; }
.quiz-opt.correct { border-color: var(--good); background: #eafaf0; color: #15793f; font-weight: 600; }
.quiz-opt.wrong { border-color: var(--red); background: var(--red-soft); color: var(--red-dark); font-weight: 600; }

.quiz-result { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.result-ring {
  width: 140px; height: 140px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: conic-gradient(var(--red) var(--pct, 0%), #eef0f6 0);
  position: relative;
  margin-bottom: 6px;
}
.result-ring::before {
  content: "";
  position: absolute;
  inset: 12px;
  background: #fff;
  border-radius: 50%;
}
.result-ring span { position: relative; font-size: 2.6rem; font-weight: 800; color: var(--navy); }
.result-ring small { position: relative; font-size: 1rem; color: var(--muted); }
.quiz-result h3 { font-size: 1.5rem; color: var(--navy); }
.quiz-result p { color: var(--muted); }

.hidden { display: none !important; }

/* ---------------- Footer ---------------- */
.footer {
  background: var(--navy);
  color: #cdd3e4;
  text-align: center;
  padding: 34px 22px;
}
.footer-fine { color: #7d869f; font-size: .85rem; margin-top: 6px; }

/* ---------------- Responsive ---------------- */
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: 36px; padding-top: 56px; }
  .hero h1 { font-size: 2.3rem; }
  .hero-stats { grid-template-columns: repeat(3, 1fr); }
  .stat-card { border-left: 0; border-top: 4px solid var(--red); }
}
@media (max-width: 680px) {
  .nav-toggle { display: flex; }
  .nav-links {
    position: absolute;
    top: 64px; left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    background: var(--navy);
    padding: 10px 16px 18px;
    box-shadow: var(--shadow-md);
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: max-height .28s ease, opacity .2s;
  }
  .nav-links.open { max-height: 320px; opacity: 1; pointer-events: auto; }
  .nav-links a { padding: 12px 14px; }
  .section { padding: 56px 18px; }
  .section-head h2 { font-size: 1.6rem; }
  .hero-stats { grid-template-columns: 1fr; }
  .fc-word { font-size: 2.4rem; }
  .reading-body { font-size: 1.12rem; line-height: 2; }
  .quiz-shell { padding: 24px 18px; }
  .quiz-question { font-size: 1.6rem; }
  .grammar-list { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .fc-rate .btn { min-width: 70px; padding: 10px 12px; }
}
