/* ============================================================
   SeouLink 한국어교실 — Web Textbook CSS Framework v2
   Design: Warm, Illustration-forward, Premium Korean Textbook
   Palette aligned with illustration style:
     Primary #2D5A7B / Accent #E86B6B / BG #FAFAF8
   ============================================================ */

/* --- Google Fonts Import --- */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;700;900&family=Noto+Sans+JP:wght@300;400;500;700&family=Inter:wght@300;400;500;600;700&display=swap');

/* --- CSS Custom Properties --- */
:root {
  /* Illustration-aligned palette */
  --sl-primary: #2D5A7B;
  --sl-primary-dark: #1e3f57;
  --sl-primary-light: #e9f0f5;
  --sl-primary-lighter: #f4f8fa;
  --sl-accent: #E86B6B;
  --sl-accent-light: #fdf0f0;
  --sl-accent-warm: #F4A89A;
  --sl-success: #5BA88C;
  --sl-success-light: #edf7f3;
  --sl-warning: #D4A95A;
  --sl-warning-light: #fdf8ef;
  --sl-info: #5B9EAD;
  --sl-info-light: #edf6f8;

  /* Warm neutrals (off-white base) */
  --cream: #FAFAF8;
  --cream-warm: #F7F5F0;
  --gray-50: #FAF9F7;
  --gray-100: #F3F1ED;
  --gray-200: #E8E5DF;
  --gray-300: #D4D0C8;
  --gray-400: #A9A49B;
  --gray-500: #7D786F;
  --gray-600: #5A564E;
  --gray-700: #3D3A34;
  --gray-800: #2A2723;
  --gray-900: #1A1815;

  /* Typography */
  --font-ko: 'Noto Sans KR', 'Apple SD Gothic Neo', sans-serif;
  --font-jp: 'Noto Sans JP', 'Hiragino Sans', sans-serif;
  --font-en: 'Inter', -apple-system, sans-serif;
  --font-hangul: 'Noto Sans KR', sans-serif;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Layout */
  --content-max-width: 860px;
  --sidebar-width: 260px;

  /* Shadows — softer, warmer */
  --shadow-sm: 0 1px 3px rgba(45,90,123,0.06);
  --shadow-md: 0 4px 12px rgba(45,90,123,0.08);
  --shadow-lg: 0 8px 24px rgba(45,90,123,0.1);
  --shadow-xl: 0 16px 40px rgba(45,90,123,0.12);
  --shadow-illustration: 0 8px 32px rgba(45,90,123,0.15), 0 2px 8px rgba(0,0,0,0.05);

  /* Borders */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-2xl: 32px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-ko);
  color: var(--gray-800);
  background: var(--cream);
  line-height: 1.8;
  min-height: 100vh;
}

/* --- Layout: Sidebar + Content --- */
.textbook-layout {
  display: flex;
  min-height: 100vh;
}

/* ============ SIDEBAR — Light & Warm ============ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: linear-gradient(180deg, #F8F6F2 0%, #F0EDE6 100%);
  border-right: 1px solid var(--gray-200);
  overflow-y: auto;
  z-index: 100;
  transition: transform var(--transition-normal);
  color: var(--gray-700);
}

/* 사이드바 배경 일러스트 — 커버가 은은하게 비치도록 */
.sidebar::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg, none) center/cover no-repeat;
  opacity: 0.35;
  z-index: -1;
  pointer-events: none;
}

.sidebar-header {
  padding: var(--space-xl) var(--space-lg) var(--space-lg);
  border-bottom: 1px solid var(--gray-200);
  background: linear-gradient(180deg, rgba(45,90,123,0.04) 0%, transparent 100%);
  position: relative;
}

/* 사이드바 미니 커버 이미지 */
.sidebar-header .sidebar-cover {
  width: 80px;
  height: auto;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  margin-bottom: var(--space-md);
  border: 2px solid white;
}

.sidebar-header .brand {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--sl-primary);
  opacity: 0.6;
  margin-bottom: var(--space-sm);
}

.sidebar-header .book-title {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--gray-800);
  letter-spacing: -0.01em;
}

.sidebar-header .book-subtitle {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: var(--space-xs);
  font-family: var(--font-jp);
  font-weight: 300;
}

.sidebar-nav {
  padding: var(--space-md) 0;
}

.sidebar-nav .nav-group {
  margin-bottom: var(--space-xs);
}

.sidebar-nav .nav-group-title {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gray-400);
  padding: var(--space-sm) var(--space-lg) var(--space-xs);
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0.45rem var(--space-lg);
  color: var(--gray-600);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 400;
  transition: all var(--transition-fast);
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  background: rgba(45,90,123,0.06);
  color: var(--sl-primary);
}

.sidebar-nav a.active {
  background: var(--sl-primary-light);
  color: var(--sl-primary);
  font-weight: 600;
  border-left-color: var(--sl-accent);
}

.sidebar-nav a .nav-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gray-200);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--gray-500);
  flex-shrink: 0;
}

.sidebar-nav a.active .nav-number {
  background: var(--sl-accent);
  color: white;
}

/* Mobile sidebar toggle */
.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--sl-primary);
  color: white;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  transition: transform var(--transition-fast);
}

.sidebar-toggle:active { transform: scale(0.9); }

/* ============ MAIN CONTENT ============ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
  max-width: calc(100vw - var(--sidebar-width));
  overflow-x: hidden;
}

/* ============ HERO — Illustration-forward, bright ============ */
.textbook-hero {
  position: relative;
  background: linear-gradient(160deg, var(--cream) 0%, var(--sl-primary-lighter) 40%, var(--cream-warm) 100%);
  color: var(--gray-800);
  padding: var(--space-3xl) var(--space-xl) var(--space-2xl);
  text-align: center;
  overflow: hidden;
  min-height: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* 히어로 — 커버 일러스트 배경 + 부드러운 장식 */
.textbook-hero::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--hero-bg, none) center/cover no-repeat;
  opacity: 0.30;
  z-index: 0;
  pointer-events: none;
}

.textbook-hero::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 40%;
  background: linear-gradient(to top, var(--cream) 0%, transparent 100%);
  z-index: 0;
  pointer-events: none;
}

.textbook-hero .hero-content { position: relative; z-index: 1; }

.textbook-hero .series-badge {
  display: inline-block;
  background: var(--sl-primary);
  color: white;
  padding: 0.3rem 1.2rem;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-lg);
}

.textbook-hero .hero-flag {
  font-size: 3rem;
  margin-bottom: var(--space-md);
}

.textbook-hero h1 {
  font-size: 2.5rem;
  font-weight: 900;
  line-height: 1.3;
  margin-bottom: var(--space-sm);
  color: var(--gray-900);
}

.textbook-hero .hero-subtitle {
  font-size: 1.1rem;
  font-family: var(--font-jp);
  color: var(--gray-500);
  font-weight: 300;
}

.textbook-hero .hero-desc {
  margin-top: var(--space-lg);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--sl-accent);
}

.textbook-hero .hero-desc-jp {
  font-size: 0.95rem;
  font-family: var(--font-jp);
  color: var(--gray-500);
  margin-top: var(--space-xs);
}

/* Cover image — hero의 주인공 */
.textbook-hero .cover-image {
  margin-top: var(--space-xl);
  max-width: 220px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-illustration);
  border: 4px solid white;
  transition: transform var(--transition-normal);
}

.textbook-hero .cover-image:hover {
  transform: scale(1.03) rotate(-1deg);
}

/* CEFR 레벨 태그 */
.textbook-hero .cefr-tag {
  display: inline-block;
  margin-top: var(--space-md);
  padding: 0.2rem 0.8rem;
  background: rgba(45,90,123,0.08);
  border: 1px solid rgba(45,90,123,0.15);
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--sl-primary);
  letter-spacing: 0.05em;
}

/* ============ CONTENT SECTIONS ============ */
.content-wrapper {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-2xl) var(--space-xl);
}

/* ============ LESSON STAGE — 일러스트 분위기 배경 ============ */
.lesson-stage {
  margin-bottom: var(--space-3xl);
  scroll-margin-top: var(--space-xl);
  position: relative;
  overflow: visible;
}

/* 전폭 워터마크 — content-wrapper 밖까지 확장 + 좌우 페이드 */
.lesson-stage::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100vw - var(--sidebar-width));
  height: 100%;
  background: var(--lesson-bg, none) center top / cover no-repeat;
  opacity: 0.30;
  filter: blur(1px) saturate(1.3);
  z-index: 0;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(to right, rgba(0,0,0,0.4) 0%, rgba(0,0,0,1) 3%, rgba(0,0,0,1) 97%, rgba(0,0,0,0.4) 100%);
  mask-image: linear-gradient(to right, rgba(0,0,0,0.4) 0%, rgba(0,0,0,1) 3%, rgba(0,0,0,1) 97%, rgba(0,0,0,0.4) 100%);
}

/* 워터마크 하단 페이드아웃 */
.lesson-stage::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100vw - var(--sidebar-width));
  height: 120px;
  background: linear-gradient(to top, var(--cream), transparent);
  z-index: 0;
  pointer-events: none;
}

.lesson-stage > * {
  position: relative;
  z-index: 1;
}

/* C 방식: 레슨 시작 풀블리드 배너 — 일러스트 임팩트 */
.lesson-banner {
  position: relative;
  width: 100%;
  height: 240px;
  margin-bottom: var(--space-xl);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-illustration);
}

.lesson-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform var(--transition-slow);
}

.lesson-banner:hover img {
  transform: scale(1.03);
}

/* 배너 위 그라데이션 오버레이 — 제목 가독성 */
.lesson-banner .banner-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: var(--space-2xl) var(--space-xl) var(--space-lg);
  background: linear-gradient(to top, rgba(26, 24, 21, 0.65), transparent);
  color: white;
  z-index: 2;
}

.lesson-banner .banner-overlay .stage-number {
  color: rgba(255,255,255,0.8);
}

.lesson-banner .banner-overlay .stage-number .badge {
  background: var(--sl-accent);
}

.lesson-banner .banner-overlay h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: white;
  text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.lesson-banner .banner-overlay .stage-subtitle {
  color: rgba(255,255,255,0.85);
  font-size: 0.9rem;
  font-family: var(--font-jp);
}

/* 스테이지 헤더 — 일러스트 없는 경우 기본 스타일 */
.stage-header {
  position: relative;
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 2px solid var(--gray-200);
}

/* 스테이지 배너 — 일러스트 있는 경우 풀폭 배너 */
.stage-header:has(.stage-illustration) {
  height: clamp(140px, 22vw, 220px);
  border-radius: var(--radius-xl);
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  padding: var(--space-lg) var(--space-xl);
  border-bottom: none;
  cursor: pointer;
}

/* 배너 하단 그래디언트 오버레이 */
.stage-header:has(.stage-illustration)::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0;
  width: 100%; height: 70%;
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
  z-index: 1;
  pointer-events: none;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* 배너 위 제목 텍스트 — 흰색으로 */
.stage-header:has(.stage-illustration) .stage-number {
  color: rgba(255,255,255,0.9);
}
.stage-header:has(.stage-illustration) .stage-number .badge {
  background: rgba(255,255,255,0.25);
  backdrop-filter: blur(4px);
}
.stage-header:has(.stage-illustration) h2 {
  color: white;
  text-shadow: 0 1px 6px rgba(0,0,0,0.5), 0 0 20px rgba(0,0,0,0.2);
}
.stage-header:has(.stage-illustration) .stage-subtitle {
  color: rgba(255,255,255,0.8);
}

.stage-header-text {
  position: relative;
  z-index: 2;
  flex: 1;
  min-width: 0;
}

.stage-number {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--sl-primary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-sm);
}

.stage-number .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--sl-primary);
  color: white;
  font-size: 0.85rem;
  font-weight: 700;
}

.stage-header h2 {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--gray-900);
  line-height: 1.4;
}

.stage-header .stage-subtitle {
  font-size: 0.95rem;
  color: var(--gray-500);
  font-family: var(--font-jp);
  margin-top: var(--space-xs);
}

/* ============ ILLUSTRATION — 스테이지 배너 배경 ============ */
.stage-illustration {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border-radius: var(--radius-xl);
  overflow: hidden;
  z-index: 0;
}

.stage-illustration img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.6s ease;
}

.stage-header:has(.stage-illustration):hover .stage-illustration img {
  transform: scale(1.05);
}

/* 배너 확대 아이콘 */
.stage-illustration::after {
  content: '🔍 크게 보기';
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  font-size: 0.7rem;
  background: rgba(255,255,255,0.85);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  opacity: 0;
  transition: opacity var(--transition-normal);
  pointer-events: none;
  z-index: 3;
}

.stage-header:has(.stage-illustration):hover .stage-illustration::after {
  opacity: 1;
}

/* Lightbox — 썸네일 클릭시 확대 보기 */
.ill-lightbox {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.75);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  backdrop-filter: blur(4px);
}

.ill-lightbox.active {
  display: flex;
}

.ill-lightbox img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.ill-lightbox .ill-close {
  position: absolute;
  top: 20px;
  right: 24px;
  font-size: 2rem;
  color: white;
  cursor: pointer;
  background: none;
  border: none;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

/* 구버전 캡션 — 더이상 사용하지 않으나 폴백 유지 */
.stage-illustration .ill-caption {
  display: none;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font-jp);
}

/* Scene illustration */
.scene-illustration {
  width: 100%;
  max-width: 560px;
  margin: 0 auto var(--space-lg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: block;
  border: 1px solid var(--gray-200);
  transition: all var(--transition-normal);
}

.scene-illustration:hover {
  box-shadow: var(--shadow-lg);
}

/* Illustration placeholder */
.illustration-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  width: 100%;
  max-width: 640px;
  height: 240px;
  margin: 0 auto var(--space-2xl);
  background: linear-gradient(135deg, var(--sl-primary-lighter) 0%, var(--cream-warm) 100%);
  border-radius: var(--radius-xl);
  color: var(--gray-400);
  font-size: 0.85rem;
  font-weight: 500;
  border: 2px dashed var(--gray-300);
}

.illustration-placeholder::before {
  content: '🎨';
  font-size: 2rem;
}

/* ============ INFO BOX ============ */
.info-box {
  background: rgba(255,255,255,0.75);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--sl-primary);
  backdrop-filter: blur(3px);
}

.info-box.tip {
  border-left-color: var(--sl-info);
  background: rgba(237,246,248,0.75);
}

.info-box.warning {
  border-left-color: var(--sl-warning);
  background: rgba(253,248,239,0.75);
}

.info-box.important {
  border-left-color: var(--sl-accent);
  background: rgba(253,240,240,0.75);
}

.info-box.success {
  border-left-color: var(--sl-success);
  background: rgba(237,247,243,0.75);
}

.info-box .box-icon {
  font-size: 1.2rem;
  margin-bottom: var(--space-sm);
}

.info-box .box-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: var(--space-sm);
}

.info-box p, .info-box .box-content {
  font-size: 0.9rem;
  color: var(--gray-600);
  line-height: 1.7;
}

/* ============ TABLES ============ */
.data-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: var(--space-lg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  max-width: 100%;
}

/* 테이블 overflow는 .data-table-wrapper가 처리, content-wrapper는 워터마크 확장을 위해 overflow 허용 */

table.data-table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(255,255,255,0.78);
  font-size: 0.88rem;
  table-layout: auto;
  word-break: keep-all;
  backdrop-filter: blur(3px);
}

table.data-table thead th {
  background: var(--sl-primary);
  color: white;
  font-weight: 600;
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

table.data-table tbody td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

table.data-table tbody tr:hover {
  background: rgba(233,240,245,0.85);
}

table.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Hangul display in tables */
table.data-table .hangul-cell {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--sl-primary);
  text-align: center;
  font-family: var(--font-hangul);
}

table.data-table .romanization {
  font-family: var(--font-en);
  font-size: 0.8rem;
  color: var(--gray-500);
}

table.data-table .jp-cell {
  font-family: var(--font-jp);
  color: var(--gray-600);
  font-size: 0.85rem;
}

/* Speaker cell for dialogue tables */
table.data-table .speaker-cell {
  font-weight: 700;
  color: var(--sl-primary);
  white-space: nowrap;
  min-width: 60px;
}

/* ============ CHARACTER CARDS ============ */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.char-card {
  background: rgba(255,255,255,0.72);
  border-radius: var(--radius-md);
  padding: var(--space-lg) var(--space-md);
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
  border: 1px solid var(--gray-200);
  cursor: default;
  backdrop-filter: blur(3px);
}

.char-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--sl-primary);
}

.char-card .char-hangul {
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--sl-primary);
  font-family: var(--font-hangul);
  line-height: 1.2;
}

.char-card .char-roman {
  font-size: 0.85rem;
  font-family: var(--font-en);
  color: var(--gray-500);
  font-weight: 500;
  margin-top: var(--space-xs);
}

.char-card .char-name {
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: var(--space-xs);
}

.char-card .char-jp {
  font-size: 0.75rem;
  font-family: var(--font-jp);
  color: var(--gray-400);
  margin-top: 2px;
}

/* ============ SYLLABLE TABLE ============ */
.syllable-table-wrapper {
  overflow-x: auto;
  margin-bottom: var(--space-lg);
}

table.syllable-table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(255,255,255,0.75);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(3px);
}

table.syllable-table th {
  background: var(--sl-primary);
  color: white;
  font-weight: 700;
  padding: 0.6rem;
  text-align: center;
  font-size: 1.1rem;
}

table.syllable-table th.row-header {
  background: var(--sl-primary-dark);
}

table.syllable-table td {
  padding: 0.5rem;
  text-align: center;
  font-size: 1.2rem;
  font-weight: 500;
  color: var(--gray-700);
  border: 1px solid var(--gray-100);
  font-family: var(--font-hangul);
  transition: all var(--transition-fast);
}

table.syllable-table td:hover {
  background: var(--sl-primary-light);
  color: var(--sl-primary);
  font-weight: 700;
}

/* ============ WRITING PRACTICE ============ */
.writing-section {
  background: rgba(255,255,255,0.72);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-xl);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  backdrop-filter: blur(3px);
}

.writing-section .writing-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 1rem;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: var(--space-sm);
}

.writing-section .writing-subtitle {
  font-size: 0.85rem;
  color: var(--gray-500);
  font-family: var(--font-jp);
  margin-bottom: var(--space-lg);
}

.writing-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.writing-cell {
  aspect-ratio: 1;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: rgba(255,255,255,0.70);
}

.writing-cell.guide {
  background: #fffde7;
  border-color: #fdd835;
}

.writing-cell .guide-char {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--gray-300);
  font-family: var(--font-hangul);
}

.writing-cell.guide .guide-char {
  color: var(--gray-700);
}

.writing-cell .cell-label {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 0.55rem;
  color: var(--gray-300);
  font-family: var(--font-en);
}

/* ============ PRONUNCIATION RULE ============ */
.pronunciation-rule {
  background: rgba(255,255,255,0.72);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-lg);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(3px);
}

.pronunciation-rule .rule-icon {
  font-size: 1.5rem;
  margin-bottom: var(--space-sm);
}

.pronunciation-rule .rule-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: var(--space-xs);
}

.pronunciation-rule .rule-title-jp {
  font-size: 0.85rem;
  color: var(--gray-500);
  font-family: var(--font-jp);
  margin-bottom: var(--space-md);
}

.pronunciation-rule .rule-explanation {
  font-size: 0.9rem;
  color: var(--gray-600);
  line-height: 1.8;
  margin-bottom: var(--space-md);
}

.pronunciation-rule .rule-example {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  background: rgba(250,249,247,0.80);
  padding: var(--space-md);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
}

.pronunciation-rule .rule-example .example-before {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gray-500);
}

.pronunciation-rule .rule-example .example-arrow {
  color: var(--sl-accent);
  font-weight: 700;
}

.pronunciation-rule .rule-example .example-after {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--sl-primary);
}

/* ============ VOCABULARY CARDS ============ */
.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.vocab-card {
  background: rgba(255,255,255,0.72);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  transition: all var(--transition-fast);
  backdrop-filter: blur(3px);
}

.vocab-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.vocab-card .vocab-ko {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: var(--space-xs);
}

.vocab-card .vocab-pron {
  font-size: 0.8rem;
  font-family: var(--font-en);
  color: var(--sl-primary);
  margin-bottom: var(--space-sm);
}

.vocab-card .vocab-jp {
  font-size: 0.85rem;
  font-family: var(--font-jp);
  color: var(--gray-500);
  margin-bottom: var(--space-sm);
}

.vocab-card .vocab-desc {
  font-size: 0.78rem;
  color: var(--gray-400);
  line-height: 1.5;
}

/* ============ SENTENCE PRACTICE ============ */
.sentence-practice {
  background: rgba(255,255,255,0.72);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-lg);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(3px);
}

.sentence-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-lg);
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--gray-100);
}

.sentence-item:last-child { border-bottom: none; }

.sentence-item .sentence-ko {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--gray-900);
  min-width: 0;
  flex: 1;
}

.sentence-item .sentence-pron {
  font-size: 0.8rem;
  color: var(--gray-400);
  font-family: var(--font-en);
  margin-top: 2px;
}

.sentence-item .sentence-jp {
  font-size: 0.9rem;
  font-family: var(--font-jp);
  color: var(--gray-500);
  flex-shrink: 0;
}

.sentence-item .sentence-pattern {
  font-size: 0.75rem;
  color: var(--sl-primary);
  font-weight: 500;
  margin-top: 4px;
  padding: 2px 8px;
  background: var(--sl-primary-light);
  border-radius: 100px;
  display: inline-block;
}

/* ============ APPENDIX ============ */
.appendix-section {
  background: var(--cream-warm);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-xl);
  border: 1px solid var(--gray-200);
}

.appendix-section h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: var(--space-lg);
}

/* ============ FREE WRITING ============ */
.free-writing-area {
  background: rgba(255,255,255,0.72);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
  backdrop-filter: blur(3px);
}

.free-writing-area .prompt {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: var(--space-md);
}

.free-writing-area .prompt-jp {
  font-size: 0.8rem;
  font-family: var(--font-jp);
  color: var(--gray-400);
  margin-bottom: var(--space-md);
}

.free-writing-area .writing-lines {
  width: 100%;
  min-height: 120px;
  border: none;
  outline: none;
  font-family: var(--font-hangul);
  font-size: 1.1rem;
  line-height: 2.5;
  background-image: repeating-linear-gradient(
    transparent, transparent 2.6em,
    var(--gray-200) 2.6em, var(--gray-200) calc(2.6em + 1px)
  );
  resize: vertical;
  color: var(--gray-700);
}

/* ============ FOOTER ============ */
.textbook-footer {
  background: var(--sl-primary);
  color: rgba(255,255,255,0.7);
  text-align: center;
  padding: var(--space-xl);
  font-size: 0.8rem;
  margin-top: var(--space-3xl);
}

.textbook-footer .footer-brand {
  font-weight: 700;
  color: white;
  margin-bottom: var(--space-xs);
}

/* ============ PROGRESS BAR ============ */
.progress-bar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: 3px;
  background: var(--gray-200);
  z-index: 150;
}

.progress-bar .progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--sl-primary), var(--sl-accent));
  width: 0%;
  transition: width 100ms linear;
}

/* ============ LEVEL NAV (sidebar) ============ */
.level-nav {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--gray-200);
  background: rgba(0,0,0,0.02);
}

.level-nav .level-title {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gray-400);
  margin-bottom: var(--space-sm);
}

.level-nav .level-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.level-nav .level-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: var(--radius-sm);
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--gray-500);
  text-decoration: none;
  transition: all var(--transition-fast);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
}

.level-nav .level-item:hover {
  background: var(--sl-primary-light);
  color: var(--sl-primary);
  border-color: var(--sl-primary);
}

.level-nav .level-item.current {
  background: var(--sl-accent);
  color: white;
  border-color: var(--sl-accent);
  font-weight: 700;
}

/* ============ DIFFICULTY TAGS ============ */
.diff-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
}

.diff-tag.hangul { background: #e0f2fe; color: #0369a1; }
.diff-tag.beginner { background: #dcfce7; color: #15803d; }
.diff-tag.intermediate { background: #fef3c7; color: #92400e; }
.diff-tag.advanced { background: #fce7f3; color: #9d174d; }
.diff-tag.spinoff { background: #f3e8ff; color: #7c3aed; }

/* ============ KEYBOARD GUIDE ============ */

/* --- OS Tab System (CSS-only) --- */
.os-tabs { margin: var(--space-lg) 0; }
.os-tabs input[type="radio"] { display: none; }

.os-tab-labels {
  display: flex; gap: var(--space-sm); flex-wrap: wrap;
  margin-bottom: var(--space-md);
  padding: var(--space-xs);
  background: rgba(255,255,255,0.4);
  border-radius: var(--radius-lg);
}

.os-tab-label {
  flex: 1; min-width: 120px;
  padding: var(--space-sm) var(--space-md);
  text-align: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
  background: rgba(255,255,255,0.7);
  color: var(--gray-600);
  font-weight: 600; font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.25s ease;
}
.os-tab-label:hover { background: rgba(255,255,255,0.95); color: var(--sl-primary); border-color: var(--sl-primary); }

.os-tabs input:checked + .os-tab-label {
  background: var(--sl-primary); color: #fff;
  border-color: var(--sl-primary);
  box-shadow: 0 2px 8px rgba(45,90,123,0.25);
}

.os-tab-panel { display: none; }
.os-tabs:has(#tab-windows:checked) .panel-windows,
.os-tabs:has(#tab-macos:checked) .panel-macos,
.os-tabs:has(#tab-android:checked) .panel-android,
.os-tabs:has(#tab-ios:checked) .panel-ios { display: block; }

.os-tab-panel {
  background: rgba(255,255,255,0.75);
  backdrop-filter: blur(3px);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  border: 1px solid var(--gray-100);
}

.os-tab-panel h4 {
  margin: 0 0 var(--space-md) 0;
  font-size: 1.1rem; color: var(--sl-primary);
  display: flex; align-items: center; gap: var(--space-sm);
}

/* --- Setup Steps --- */
.setup-steps { display: flex; flex-direction: column; gap: var(--space-md); }

.setup-step {
  display: flex; gap: var(--space-md); align-items: flex-start;
  padding: var(--space-sm) 0;
  border-bottom: 1px dashed var(--gray-100);
}
.setup-step:last-child { border-bottom: none; }

.step-number {
  flex-shrink: 0;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--sl-primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem;
}

.step-content { flex: 1; }
.step-title { font-weight: 700; color: var(--gray-800); font-size: 0.95rem; margin-bottom: 2px; }
.step-desc { color: var(--gray-500); font-size: 0.85rem; font-family: var(--font-jp); }
.step-path {
  display: inline-block;
  margin-top: 4px; padding: 2px 8px;
  background: var(--gray-50); border: 1px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-family: var(--font-en); font-size: 0.8rem; color: var(--gray-600);
}

.shortcut-box {
  margin-top: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  background: rgba(91,166,140,0.12);
  border-left: 3px solid var(--sl-success);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.shortcut-box .shortcut-label { font-weight: 700; color: var(--sl-success); font-size: 0.9rem; }
.shortcut-box kbd {
  display: inline-block;
  padding: 2px 8px; margin: 0 2px;
  background: #fff; border: 1px solid var(--gray-300);
  border-radius: 4px;
  font-family: var(--font-en); font-size: 0.85rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* --- Visual Keyboard Layout --- */
.keyboard-section-title {
  text-align: center; margin: var(--space-xl) 0 var(--space-md);
  font-size: 1.15rem; font-weight: 700; color: var(--sl-primary);
}
.keyboard-section-subtitle {
  text-align: center; margin: -0.5em 0 var(--space-lg);
  font-size: 0.85rem; color: var(--gray-500); font-family: var(--font-jp);
}

.keyboard-legend {
  display: flex; justify-content: center; gap: var(--space-lg);
  margin-bottom: var(--space-md);
}
.legend-item {
  display: flex; align-items: center; gap: var(--space-xs);
  font-size: 0.85rem; font-weight: 600;
}
.legend-swatch {
  width: 16px; height: 16px; border-radius: 4px;
}
.legend-swatch.consonant-swatch { background: rgba(45,90,123,0.18); border: 1px solid rgba(45,90,123,0.35); }
.legend-swatch.vowel-swatch { background: rgba(232,107,107,0.18); border: 1px solid rgba(232,107,107,0.35); }

.keyboard-layout {
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(3px);
  border-radius: var(--radius-lg);
  padding: var(--space-lg) var(--space-md);
  border: 1px solid var(--gray-100);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}

.keyboard-row {
  display: flex; justify-content: center; gap: 5px;
}

.key {
  min-width: 52px; height: 52px;
  border-radius: 6px;
  border: 1px solid var(--gray-200);
  background: rgba(255,255,255,0.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  transition: transform 0.15s, box-shadow 0.15s;
  cursor: default;
}
.key:hover { transform: translateY(-2px); box-shadow: 0 3px 8px rgba(0,0,0,0.1); }

.key-ko { font-size: 1.1rem; font-weight: 700; line-height: 1.2; }
.key-en { font-size: 0.6rem; color: var(--gray-400); line-height: 1; }

.key.consonant { background: rgba(45,90,123,0.1); }
.key.consonant .key-ko { color: var(--sl-primary); }

.key.vowel { background: rgba(232,107,107,0.1); }
.key.vowel .key-ko { color: var(--sl-accent); }

.key.special {
  min-width: 72px; background: var(--gray-50);
  font-size: 0.75rem; color: var(--gray-500); font-weight: 600;
}

.shift-layer {
  margin-top: var(--space-md);
  display: flex; justify-content: center; gap: var(--space-sm); flex-wrap: wrap;
}
.shift-key {
  display: flex; align-items: center; gap: var(--space-xs);
  padding: 4px 10px;
  background: rgba(255,255,255,0.8);
  border: 1px dashed var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.shift-key .key-ko { font-size: 1rem; }
.shift-key .key-en { font-size: 0.7rem; color: var(--gray-400); }
.shift-key .arrow { color: var(--gray-400); margin: 0 2px; }

/* ============ WRITING MODE TOGGLE ============ */
.writing-mode-toggle {
  display: flex; align-items: center; gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.writing-mode-toggle .mode-label {
  font-size: 0.8rem; color: var(--gray-500); font-weight: 600;
}

.mode-btn-group {
  display: flex; gap: 0; border-radius: var(--radius-md); overflow: hidden;
  border: 1px solid var(--gray-200);
}

.mode-btn {
  padding: 6px 14px;
  font-size: 0.8rem; font-weight: 600;
  background: rgba(255,255,255,0.7);
  color: var(--gray-500);
  border: none; cursor: pointer;
  transition: all 0.2s ease;
  border-right: 1px solid var(--gray-200);
}
.mode-btn:last-child { border-right: none; }
.mode-btn:hover { background: rgba(255,255,255,0.95); color: var(--sl-primary); }
.mode-btn.active { background: var(--sl-primary); color: #fff; }

/* Keyboard mode: writing cells become input cells */
.writing-cell .cell-input {
  width: 100%; height: 100%;
  border: none; background: transparent;
  text-align: center;
  font-size: 1.8rem; font-weight: 700;
  font-family: var(--font-ko);
  color: var(--gray-800);
  outline: none;
  position: absolute; top: 0; left: 0;
}
.writing-cell .cell-input:focus {
  background: rgba(45,90,123,0.06);
  border-radius: var(--radius-sm);
}

/* Touch/Draw mode: writing cells become canvas */
.writing-cell canvas.cell-canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  border-radius: var(--radius-sm);
  touch-action: none;
  cursor: crosshair;
}

.writing-cell .clear-btn {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--gray-200);
  color: var(--gray-500);
  border: none; cursor: pointer;
  font-size: 0.6rem; line-height: 18px; text-align: center;
  opacity: 0; transition: opacity 0.2s;
  z-index: 2;
}
.writing-cell:hover .clear-btn { opacity: 1; }

/* ============ RESPONSIVE ============ */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  .main-content { margin-left: 0; max-width: 100vw; }
  .progress-bar { left: 0; }
  /* 사이드바 숨김 시 워터마크를 전폭으로 */
  .lesson-stage::before,
  .lesson-stage::after {
    width: 100vw;
  }
}

@media (max-width: 768px) {
  .content-wrapper { padding: var(--space-lg) var(--space-md); }
  .textbook-hero h1 { font-size: 1.8rem; }
  .textbook-hero { min-height: 380px; padding: var(--space-2xl) var(--space-md); }
  .stage-header h2 { font-size: 1.3rem; }
  .stage-header:has(.stage-illustration) { height: clamp(100px, 30vw, 160px); }
  .char-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
  .writing-grid { grid-template-columns: repeat(4, 1fr); }
  .vocab-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .sentence-item { flex-direction: column; gap: var(--space-sm); }
  /* Keyboard Guide */
  .os-tab-labels { gap: var(--space-xs); }
  .os-tab-label { min-width: calc(50% - var(--space-xs)); font-size: 0.85rem; padding: var(--space-xs) var(--space-sm); }
  .key { min-width: 38px; height: 38px; }
  .key-ko { font-size: 0.9rem; }
  .key.special { min-width: 52px; font-size: 0.65rem; }
}

@media (max-width: 480px) {
  .textbook-hero { padding: var(--space-xl) var(--space-md); min-height: 300px; }
  .textbook-hero h1 { font-size: 1.5rem; }
  .writing-grid { grid-template-columns: repeat(3, 1fr); }
  .char-grid { grid-template-columns: repeat(3, 1fr); }
  .stage-header:has(.stage-illustration) {
    height: clamp(90px, 35vw, 130px);
    padding: var(--space-md);
  }
  .stage-header:has(.stage-illustration) h2 { font-size: 1.1rem; }
  /* Keyboard Guide */
  .os-tab-labels { flex-direction: column; }
  .os-tab-label { min-width: 100%; }
  .key { min-width: 28px; height: 34px; }
  .key-ko { font-size: 0.8rem; }
  .key-en { display: none; }
  .key.special { min-width: 40px; }
  .keyboard-layout { padding: var(--space-sm); }
}

/* ============ PRINT ============ */
@media print {
  .sidebar, .sidebar-toggle, .progress-bar { display: none !important; }
  .main-content { margin-left: 0; max-width: 100%; }
  .textbook-hero { min-height: auto; padding: var(--space-xl); }
  .lesson-stage { page-break-inside: avoid; }
  .writing-cell { border-color: var(--gray-400); }
  body { font-size: 11pt; }
  .stage-illustration { box-shadow: none; }
  .stage-header:has(.stage-illustration) { height: 150px; border: 1px solid #ccc; }
  /* Keyboard Guide: show all OS tabs when printing */
  .os-tabs input, .os-tab-labels { display: none !important; }
  .os-tab-panel { display: block !important; margin-bottom: var(--space-md); }
}
