/* ==========================================================================
   MARKDOWN CRAFT - DESIGN SYSTEM & STYLESHEET
   Modern Developer Aesthetic, Dual Theme, Glassmorphism & Micro-animations
   ========================================================================== */

:root {
  /* Dark Theme (Default) */
  --bg-primary: #0b0f17;
  --bg-secondary: #131a26;
  --bg-tertiary: #1b2434;
  --bg-card: rgba(22, 31, 46, 0.85);
  --bg-glass: rgba(19, 26, 38, 0.7);
  --bg-input: #0e1522;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #6366f1;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.25);
  
  --accent-success: #10b981;
  --accent-success-bg: rgba(16, 185, 129, 0.12);
  --accent-warning: #f59e0b;
  --accent-warning-bg: rgba(245, 158, 11, 0.12);
  --accent-danger: #ef4444;
  --accent-danger-bg: rgba(239, 68, 68, 0.15);
  --accent-info: #0ea5e9;
  --accent-info-bg: rgba(14, 165, 233, 0.12);

  --font-sans: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Light Theme */
[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-glass: rgba(255, 255, 255, 0.8);
  --bg-input: #ffffff;
  --border-color: rgba(0, 0, 0, 0.08);
  --border-focus: #4f46e5;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent-primary: #4f46e5;
  --accent-primary-hover: #4338ca;
  --accent-glow: rgba(79, 70, 229, 0.15);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 0 15px rgba(79, 70, 229, 0.15);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==========================================================================
   HEADER & NAVIGATION
   ========================================================================== */
.app-header {
  height: 64px;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  user-select: none;
}

.brand-logo-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-family: var(--font-mono);
  font-size: 1.1rem;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.4);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.brand-tag {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  background: var(--accent-success-bg);
  color: var(--accent-success);
  font-weight: 600;
}

/* Nav Tabs */
.nav-tabs {
  display: flex;
  gap: 0.35rem;
  background: var(--bg-input);
  padding: 4px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.nav-tab-btn {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.nav-tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.nav-tab-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
}

/* Header Action Controls */
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.progress-pill {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-warning);
}

/* ==========================================================================
   MAIN CONTENT CONTAINER & TAB PANELS
   ========================================================================== */
.app-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.tab-panel {
  display: none;
  flex: 1;
  animation: fadeIn 0.25s ease;
}

.tab-panel.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   MODE 1: 퀘스트 학습 모드 (Quest Mode)
   ========================================================================== */
.quest-layout {
  display: flex;
  width: 100%;
  height: calc(100vh - 64px);
  overflow: hidden;
}

/* Left Sidebar - Curriculum */
.quest-sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.quest-sidebar-header {
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sidebar-progress-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--accent-success-bg);
  color: var(--accent-success);
  font-weight: 600;
}

.curriculum-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.chapter-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.chapter-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  padding: 0.25rem 0.5rem;
}

.lesson-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: left;
}

.lesson-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.lesson-item.active {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.4);
  color: #ffffff;
  font-weight: 600;
}

.lesson-item.completed .lesson-check {
  color: var(--accent-success);
}

.lesson-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  overflow: hidden;
}

.lesson-check {
  font-size: 1rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.lesson-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lesson-badge {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  background: var(--bg-input);
  padding: 0.15rem 0.4rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

/* Quest Main Workspace */
.quest-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--bg-primary);
}

/* Quest Topbar */
.quest-topbar {
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.quest-headline {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.quest-difficulty-tag {
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(99, 102, 241, 0.15);
  color: var(--accent-primary);
}

.quest-title-text {
  font-size: 1.15rem;
  font-weight: 700;
}

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

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.825rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-input);
  border-color: var(--text-muted);
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent-primary);
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
  transition: all var(--transition-fast);
}

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

/* Quest Guide & Mission Box */
.quest-guide-section {
  padding: 1.25rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.guide-desc {
  font-size: 0.95rem;
  color: var(--text-primary);
  line-height: 1.6;
}

.guide-desc strong {
  color: var(--accent-warning);
}

.guide-syntax-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.guide-code-chip {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #38bdf8;
}

/* Mission Checklist Box */
.mission-criteria-card {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.1rem;
}

.criteria-header {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.criteria-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  list-style: none;
}

.criteria-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: color var(--transition-fast);
}

.criteria-item.checked {
  color: var(--accent-success);
  font-weight: 600;
}

.criteria-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  color: transparent;
  transition: all var(--transition-fast);
}

.criteria-item.checked .criteria-icon {
  background: var(--accent-success);
  border-color: var(--accent-success);
  color: #ffffff;
}

/* Split Coding & Preview Area */
.quest-split-editor {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 380px;
  border-top: 1px solid var(--border-color);
}

.editor-pane, .preview-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.editor-pane {
  border-right: 1px solid var(--border-color);
}

.pane-header {
  height: 42px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
}

.pane-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.text-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.775rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0.2rem 0.45rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.text-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.code-textarea {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  line-height: 1.6;
  padding: 1.1rem;
  tab-size: 2;
}

.code-textarea:focus {
  background: var(--bg-primary);
}

/* Preview Tabs */
.preview-tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-input);
  padding: 2px;
  border-radius: var(--radius-sm);
}

.prev-tab-btn {
  padding: 0.2rem 0.55rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
}

.prev-tab-btn.active {
  background: var(--accent-primary);
  color: #fff;
}

.rendered-markdown-view {
  flex: 1;
  padding: 1.25rem;
  overflow-y: auto;
  background: var(--bg-primary);
}

/* Quest Hint & Answer Drawers */
.hint-drawer {
  background: var(--accent-warning-bg);
  border-left: 4px solid var(--accent-warning);
  padding: 0.85rem 1.25rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  display: none;
}
.hint-drawer.open {
  display: block;
}

/* Success Celebration Banner */
.celebration-toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  padding: 1rem 1.5rem;
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 25px rgba(16, 185, 129, 0.4);
  display: flex;
  align-items: center;
  gap: 1rem;
  z-index: 1000;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.celebration-toast.show {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   MODE 2: 마크다운 타자/스피드 연습 (Typing Practice)
   ========================================================================== */
.typing-container {
  max-width: 1050px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.typing-level-selector {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.level-btn {
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 0.825rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.level-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.level-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.typing-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--accent-primary);
  margin-top: 0.2rem;
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Typing Stage Display */
.typing-stage-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  position: relative;
  box-shadow: var(--shadow-md);
}

.typing-source-text {
  font-family: var(--font-mono);
  font-size: 1.2rem;
  line-height: 2;
  white-space: pre-wrap;
  word-break: break-all;
  user-select: none;
  min-height: 120px;
  letter-spacing: 0.02em;
}

.char {
  position: relative;
}

.char.correct {
  color: var(--accent-success);
}

.char.incorrect {
  color: var(--accent-danger);
  background: var(--accent-danger-bg);
  border-radius: 2px;
}

.char.current {
  border-bottom: 3px solid var(--accent-primary);
  animation: cursorBlink 0.8s infinite;
}

@keyframes cursorBlink {
  0%, 100% { border-color: var(--accent-primary); }
  50% { border-color: transparent; }
}

.typing-input-hidden {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: default;
}

.typing-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

/* Live Preview Box for Typing */
.typing-live-preview-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.75rem;
}

/* ==========================================================================
   MODE 3: 마크다운 문법 퀴즈 (Quiz Mode)
   ========================================================================== */
.quiz-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.quiz-progress-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent-primary);
}

.quiz-score-badge {
  font-size: 0.85rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--accent-warning);
  font-weight: 700;
}

.quiz-bar-track {
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.quiz-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #10b981);
  width: 10%;
  transition: width 0.3s ease;
}

.quiz-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.quiz-question {
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.5;
}

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

.quiz-option-btn {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-fast);
}

.quiz-option-btn:hover:not(:disabled) {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.08);
}

.option-letter {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.quiz-option-btn.correct {
  border-color: var(--accent-success);
  background: var(--accent-success-bg);
  color: var(--accent-success);
}
.quiz-option-btn.correct .option-letter {
  background: var(--accent-success);
  color: #fff;
}

.quiz-option-btn.wrong {
  border-color: var(--accent-danger);
  background: var(--accent-danger-bg);
  color: var(--accent-danger);
}
.quiz-option-btn.wrong .option-letter {
  background: var(--accent-danger);
  color: #fff;
}

.quiz-explanation-box {
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  border-left: 4px solid var(--accent-info);
  font-size: 0.9rem;
  line-height: 1.6;
  display: none;
}
.quiz-explanation-box.show {
  display: block;
}

/* ==========================================================================
   MODE 4: 자유 연습장 & 에디터 (Playground / Live Editor)
   ========================================================================== */
.playground-layout {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: calc(100vh - 64px);
  overflow: hidden;
}

.toolbar-bar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.tool-btn {
  height: 32px;
  padding: 0 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.tool-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border-color);
  margin: 0 0.25rem;
}

.template-select {
  height: 32px;
  padding: 0 0.6rem;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
}

.playground-editor-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}

.playground-footer {
  height: 36px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.footer-stats {
  display: flex;
  align-items: center;
  gap: 1.2rem;
}

/* ==========================================================================
   INTERACTIVE CHEAT SHEET DRAWER
   ========================================================================== */
.cheatsheet-drawer {
  position: fixed;
  top: 64px;
  right: -420px;
  width: 420px;
  height: calc(100vh - 64px);
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  z-index: 90;
  display: flex;
  flex-direction: column;
  transition: right 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.cheatsheet-drawer.open {
  right: 0;
}

.cheatsheet-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cheatsheet-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.cheat-group {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
}

.cheat-group-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-primary);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.cheat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.cheat-table td {
  padding: 0.4rem 0.3rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.cheat-code {
  font-family: var(--font-mono);
  color: #38bdf8;
  cursor: pointer;
  background: rgba(56, 189, 248, 0.08);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}
.cheat-code:hover {
  background: rgba(56, 189, 248, 0.2);
}

/* ==========================================================================
   MARKDOWN RENDERED STYLES (GITHUB-FLAVORED MARKDOWN)
   ========================================================================== */
.markdown-body {
  font-family: var(--font-sans);
  color: var(--text-primary);
  line-height: 1.7;
  word-break: break-word;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-weight: 700;
  line-height: 1.3;
  margin-top: 1.4em;
  margin-bottom: 0.6em;
  color: var(--text-primary);
}

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child {
  margin-top: 0;
}

.markdown-body h1 {
  font-size: 1.85rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.35rem;
}

.markdown-body h2 {
  font-size: 1.45rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.25rem;
}

.markdown-body h3 {
  font-size: 1.2rem;
}

.markdown-body p {
  margin-bottom: 1em;
}

.markdown-body strong {
  font-weight: 700;
  color: #fbbf24;
}

.markdown-body em {
  font-style: italic;
  color: #a78bfa;
}

.markdown-body del {
  text-decoration: line-through;
  color: var(--text-muted);
}

.markdown-body blockquote {
  border-left: 4px solid var(--accent-primary);
  padding: 0.5rem 1rem;
  margin: 1em 0;
  background: rgba(99, 102, 241, 0.06);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.markdown-body blockquote blockquote {
  margin-left: 0.5rem;
  border-left-color: var(--accent-warning);
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.8em 0 1em 1.5em;
  padding: 0;
}

.markdown-body li {
  margin-bottom: 0.35em;
}

/* Task List */
.markdown-body .task-list-item {
  list-style-type: none;
  margin-left: -1.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.markdown-body .task-list-item input[type="checkbox"] {
  accent-color: var(--accent-primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* Links & Images */
.markdown-body a {
  color: #38bdf8;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color var(--transition-fast);
}

.markdown-body a:hover {
  color: #7dd3fc;
}

.markdown-body img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: 0.8em 0;
  border: 1px solid var(--border-color);
}

/* Code */
.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.2em 0.45em;
  border-radius: 4px;
  color: #f43f5e;
}

.markdown-body pre {
  background: #090d16;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin: 1em 0;
  overflow-x: auto;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  color: #e2e8f0;
  font-size: 0.9em;
  border-radius: 0;
}

/* Tables */
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.markdown-body th,
.markdown-body td {
  padding: 0.65rem 1rem;
  border: 1px solid var(--border-color);
  text-align: left;
}

.markdown-body th {
  background: var(--bg-tertiary);
  font-weight: 700;
}

.markdown-body tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

/* Details & Summary */
.markdown-body details {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  margin: 1em 0;
}

.markdown-body summary {
  font-weight: 600;
  cursor: pointer;
  color: var(--accent-info);
  outline: none;
}

.markdown-body details[open] summary {
  margin-bottom: 0.75rem;
}

/* GFM Callouts / Alerts */
.markdown-body .callout-box {
  border-left: 4px solid var(--accent-primary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: 0.85rem 1.15rem;
  margin: 1em 0;
  background: rgba(99, 102, 241, 0.08);
}

.markdown-body .callout-title {
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.markdown-body .callout-tip {
  border-left-color: var(--accent-success);
  background: var(--accent-success-bg);
}
.markdown-body .callout-tip .callout-title { color: var(--accent-success); }

.markdown-body .callout-warning {
  border-left-color: var(--accent-warning);
  background: var(--accent-warning-bg);
}
.markdown-body .callout-warning .callout-title { color: var(--accent-warning); }

.markdown-body .callout-caution {
  border-left-color: var(--accent-danger);
  background: var(--accent-danger-bg);
}
.markdown-body .callout-caution .callout-title { color: var(--accent-danger); }

/* Horizontal Rule */
.markdown-body hr {
  border: none;
  height: 1px;
  background: var(--border-color);
  margin: 1.5em 0;
}

/* ==========================================================================
   MODALS & POPUPS
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-window {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.open .modal-window {
  transform: scale(1);
}

.modal-header {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-body {
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.modal-footer {
  padding: 0.9rem 1.4rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Canvas Confetti */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 999;
}

/* Responsive */
@media (max-width: 900px) {
  .quest-layout {
    flex-direction: column;
    height: auto;
  }
  .quest-sidebar {
    width: 100%;
    height: 220px;
  }
  .quest-split-editor,
  .playground-editor-grid {
    grid-template-columns: 1fr;
  }
  .editor-pane {
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    height: 300px;
  }
}
