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

:root {
  --primary: #2d5daa;
  --primary-light: #4a7fd4;
  --primary-dark: #1a3d7a;
  --accent: #e63946;
  --accent-light: #ff6b6b;
  --bg: #f5f7fb;
  --bg-card: #ffffff;
  --text: #2c3e50;
  --text-light: #6b7b8d;
  --border: #e1e8f0;
  --success: #27ae60;
  --warning: #f39c12;
  --danger: #e74c3c;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.3s ease;
  --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-korean: 'Noto Sans KR', 'Malgun Gothic', sans-serif;
}

html {
  scroll-behavior: smooth;
}

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

/* ========== Navigation ========== */
#navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 64px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo {
  font-family: var(--font-korean);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
}

.brand-text {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 0.25rem;
}

.nav-link {
  text-decoration: none;
  color: var(--text-light);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 0.95rem;
  transition: var(--transition);
}

.nav-link:hover {
  color: var(--primary);
  background: rgba(45,93,170,0.08);
}

.nav-link.active {
  color: var(--primary);
  background: rgba(45,93,170,0.12);
  font-weight: 600;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text);
  padding: 0.5rem;
}

/* ========== Sections ========== */
.section {
  display: none;
  max-width: 1100px;
  margin: 0 auto;
  padding: 84px 2rem 3rem;
  min-height: 100vh;
}

.section.active {
  display: block;
}

.section h2 {
  font-size: 2rem;
  color: var(--primary-dark);
  margin-bottom: 0.5rem;
}

.korean-label {
  font-family: var(--font-korean);
  font-size: 1.2rem;
  color: var(--text-light);
  font-weight: 400;
}

.section-desc {
  color: var(--text-light);
  margin-bottom: 2rem;
  font-size: 1.05rem;
  max-width: 700px;
}

/* ========== Home / Hero ========== */
.hero {
  text-align: center;
  padding: 3rem 0 2rem;
}

.hero h1 {
  font-size: 2.8rem;
  color: var(--text);
  margin-bottom: 0.5rem;
}

.highlight {
  color: var(--primary);
  position: relative;
}

.subtitle {
  font-size: 1.2rem;
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

.hero-hangul {
  font-family: var(--font-korean);
  font-size: 4rem;
  color: var(--primary);
  margin: 1rem 0;
  letter-spacing: 0.2em;
}

.hero-desc {
  font-size: 1.1rem;
  color: var(--text-light);
  max-width: 600px;
  margin: 0 auto 2.5rem;
}

/* Feature Cards */
.feature-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow);
}

.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-light);
}

.feature-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.feature-card h3 {
  color: var(--primary-dark);
  margin-bottom: 0.5rem;
  font-size: 1.2rem;
}

.feature-card p {
  color: var(--text-light);
  font-size: 0.95rem;
}

/* Progress */
.progress-overview {
  margin-top: 3rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.progress-overview h2 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

.progress-bars {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.progress-item {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.progress-item > span:first-child {
  width: 100px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.progress-bar {
  flex: 1;
  height: 12px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 6px;
  transition: width 0.5s ease;
}

.progress-pct {
  width: 40px;
  text-align: right;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--primary);
}

/* ========== Hangul Section ========== */
.hangul-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.hangul-tab {
  padding: 0.6rem 1.2rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 500;
  transition: var(--transition);
  color: var(--text);
}

.hangul-tab:hover {
  border-color: var(--primary-light);
  color: var(--primary);
}

.hangul-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.hangul-chart {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.hangul-cell {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem 0.5rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow);
}

.hangul-cell:hover {
  border-color: var(--primary);
  transform: scale(1.05);
  box-shadow: var(--shadow-lg);
}

.hangul-cell.learned {
  border-color: var(--success);
  background: rgba(39,174,96,0.05);
}

.hangul-cell .char {
  font-family: var(--font-korean);
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-dark);
  display: block;
  margin-bottom: 0.25rem;
}

.hangul-cell .roman {
  font-size: 0.85rem;
  color: var(--text-light);
}

/* Hangul detail card */
.hangul-detail-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  min-width: 300px;
  border: 2px solid var(--primary-light);
}

.close-detail {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
}

.detail-char {
  font-family: var(--font-korean);
  font-size: 5rem;
  font-weight: 700;
  color: var(--primary);
}

.detail-roman {
  font-size: 1.5rem;
  color: var(--text);
  margin: 0.5rem 0;
  font-weight: 600;
}

.detail-name {
  font-size: 1rem;
  color: var(--text-light);
  margin-bottom: 0.5rem;
}

.detail-example {
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 1.5rem;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

/* ========== Buttons ========== */
.btn {
  padding: 0.6rem 1.4rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.btn-speak {
  background: var(--accent);
}

.btn-speak:hover {
  background: var(--accent-light);
}

.btn-know {
  background: var(--success);
}

.btn-know:hover {
  background: #219a52;
}

.btn-skip {
  background: var(--warning);
}

.btn-skip:hover {
  background: #e08e0b;
}

.btn-start-quiz {
  background: var(--accent);
  font-size: 1.1rem;
  padding: 0.8rem 2rem;
}

.btn-start-quiz:hover {
  background: #c62f3b;
}

/* ========== Vocabulary ========== */
.vocab-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.vocab-cat-btn {
  padding: 0.5rem 1.2rem;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--transition);
  color: var(--text);
}

.vocab-cat-btn:hover {
  border-color: var(--primary-light);
}

.vocab-cat-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.vocab-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.vocab-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 1rem;
}

.vocab-card:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-lg);
}

.vocab-korean {
  font-family: var(--font-korean);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-dark);
  min-width: 80px;
}

.vocab-info {
  flex: 1;
}

.vocab-roman {
  font-size: 0.85rem;
  color: var(--text-light);
}

.vocab-english {
  font-size: 1rem;
  color: var(--text);
  font-weight: 500;
}

.vocab-speak-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 50%;
  transition: var(--transition);
}

.vocab-speak-btn:hover {
  background: rgba(45,93,170,0.1);
}

/* ========== Grammar ========== */
.grammar-lessons {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.grammar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow);
}

.grammar-card h3 {
  color: var(--primary-dark);
  margin-bottom: 0.5rem;
  font-size: 1.2rem;
}

.grammar-card .grammar-pattern {
  font-family: var(--font-korean);
  font-size: 1.3rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.grammar-card .grammar-explain {
  color: var(--text);
  margin-bottom: 1rem;
  line-height: 1.7;
}

.grammar-example {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-top: 0.5rem;
}

.grammar-example .kr {
  font-family: var(--font-korean);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--primary-dark);
}

.grammar-example .ro {
  font-size: 0.9rem;
  color: var(--text-light);
  font-style: italic;
}

.grammar-example .en {
  font-size: 0.95rem;
  color: var(--text);
  margin-top: 0.25rem;
}

/* ========== Phrases ========== */
.phrase-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.phrase-cat-btn {
  padding: 0.5rem 1.2rem;
  border: 2px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: var(--transition);
  color: var(--text);
}

.phrase-cat-btn:hover {
  border-color: var(--primary-light);
}

.phrase-cat-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.phrase-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.phrase-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow);
}

.phrase-card:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-lg);
}

.phrase-korean {
  font-family: var(--font-korean);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary-dark);
  min-width: 180px;
}

.phrase-roman {
  font-size: 0.85rem;
  color: var(--text-light);
  min-width: 150px;
}

.phrase-english {
  font-size: 1rem;
  color: var(--text);
  font-weight: 500;
  flex: 1;
}

/* ========== Flashcards ========== */
.flashcard-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.flashcard-controls select {
  padding: 0.5rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
}

#card-counter {
  font-weight: 600;
  color: var(--text);
  min-width: 60px;
  text-align: center;
}

.flashcard-container {
  display: flex;
  justify-content: center;
  margin-bottom: 2rem;
  perspective: 1000px;
}

.flashcard {
  width: 360px;
  height: 260px;
  cursor: pointer;
}

.flashcard-inner {
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  position: relative;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-front, .flashcard-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  padding: 2rem;
}

.flashcard-front {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
}

.flashcard-back {
  background: var(--bg-card);
  border: 2px solid var(--primary-light);
  transform: rotateY(180deg);
}

.fc-char {
  font-family: var(--font-korean);
  font-size: 4rem;
  font-weight: 700;
}

.fc-hint {
  font-size: 0.9rem;
  opacity: 0.7;
  margin-top: 0.5rem;
}

.fc-answer {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary-dark);
  text-align: center;
}

.flashcard-score {
  display: flex;
  justify-content: center;
  gap: 1rem;
}

/* ========== Quiz ========== */
.quiz-setup {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  max-width: 500px;
  margin: 0 auto;
}

.quiz-option-group {
  margin-bottom: 1.25rem;
}

.quiz-option-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.quiz-option-group select {
  width: 100%;
  padding: 0.6rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
}

.quiz-area {
  max-width: 650px;
  margin: 0 auto;
}

.quiz-progress {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

#quiz-progress-text {
  font-weight: 600;
  min-width: 130px;
}

.quiz-score-live {
  font-weight: 600;
  color: var(--primary);
}

.quiz-question {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 2rem;
  margin-bottom: 1.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.quiz-question .q-text {
  font-size: 1.1rem;
  color: var(--text-light);
  margin-bottom: 0.75rem;
}

.quiz-question .q-main {
  font-family: var(--font-korean);
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.quiz-question .q-main.english {
  font-family: var(--font-main);
  font-size: 1.6rem;
}

.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.quiz-opt-btn {
  padding: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 500;
  transition: var(--transition);
  text-align: center;
}

.quiz-opt-btn:hover:not(.disabled) {
  border-color: var(--primary);
  background: rgba(45,93,170,0.05);
}

.quiz-opt-btn.correct {
  border-color: var(--success);
  background: rgba(39,174,96,0.1);
  color: var(--success);
}

.quiz-opt-btn.wrong {
  border-color: var(--danger);
  background: rgba(231,76,60,0.1);
  color: var(--danger);
}

.quiz-opt-btn.disabled {
  cursor: default;
  opacity: 0.7;
}

.quiz-feedback {
  text-align: center;
  font-size: 1.05rem;
  font-weight: 600;
  min-height: 2rem;
  margin-bottom: 1rem;
}

.quiz-feedback.correct-fb {
  color: var(--success);
}

.quiz-feedback.wrong-fb {
  color: var(--danger);
}

/* Quiz Results */
.quiz-results {
  text-align: center;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  margin: 0 auto;
}

.quiz-results h3 {
  font-size: 1.8rem;
  color: var(--primary-dark);
  margin-bottom: 1rem;
}

.results-score {
  font-size: 3rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1rem;
}

.results-breakdown {
  margin-bottom: 1.5rem;
  color: var(--text-light);
  font-size: 1.05rem;
}

.quiz-results .btn {
  margin: 0.5rem;
}

/* ========== Footer ========== */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-light);
  font-size: 0.9rem;
  border-top: 1px solid var(--border);
  margin-top: 3rem;
}

/* ========== Overlay ========== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  #navbar {
    padding: 0 1rem;
  }

  .nav-links {
    display: none;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    flex-direction: column;
    background: white;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 0.5rem 0;
  }

  .nav-links.open {
    display: flex;
  }

  .nav-link {
    padding: 0.75rem 1.5rem;
    border-radius: 0;
  }

  .menu-toggle {
    display: block;
  }

  .hero h1 {
    font-size: 2rem;
  }

  .hero-hangul {
    font-size: 2.5rem;
  }

  .section {
    padding: 74px 1rem 2rem;
  }

  .feature-cards {
    grid-template-columns: 1fr;
  }

  .hangul-chart {
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  }

  .flashcard {
    width: 300px;
    height: 220px;
  }

  .quiz-options {
    grid-template-columns: 1fr;
  }

  .phrase-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .phrase-korean {
    min-width: unset;
  }

  .phrase-roman {
    min-width: unset;
  }
}
