:root {
  --primary-color: #f74c00; /* Rust Orange */
  --primary-dark: #c03500;
  --primary-light: rgba(247, 76, 0, 0.12);
  --accent-color: #ff6a2b;
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --sidebar-bg: #ffffff;
  --code-bg: #0f172a;
  --code-header-bg: #1e293b;
  --code-text: #f8fafc;
  --console-bg: #030712;
  --console-text: #4ade80;
  --tip-bg: #fff7ed;
  --tip-border: #f97316;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --header-height: 64px;
  --sidebar-width: 320px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

[data-theme="dark"] {
  --bg-color: #0d1117;
  --card-bg: #161b22;
  --text-main: #f0f6fc;
  --text-muted: #8b949e;
  --border-color: #30363d;
  --sidebar-bg: #13171f;
  --tip-bg: #27170c;
  --tip-border: #f74c00;
  --primary-light: rgba(247, 76, 0, 0.2);
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}

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

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.65;
  overflow-x: hidden;
  transition: background-color 0.25s, color 0.25s;
}

/* Header */
.top-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 50;
  backdrop-filter: blur(10px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-main);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-main);
  font-weight: 800;
  font-size: 1.25rem;
}

.brand-badge {
  background: linear-gradient(135deg, #f74c00, #ff7033);
  color: #fff;
  padding: 3px 9px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 900;
  box-shadow: 0 2px 6px rgba(247, 76, 0, 0.4);
}

.brand-text span {
  color: var(--primary-color);
}

.header-center {
  flex: 1;
  max-width: 440px;
  margin: 0 20px;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  font-size: 14px;
  color: var(--text-muted);
}

.search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background: var(--bg-color);
  color: var(--text-main);
  font-size: 0.9rem;
  outline: none;
  transition: all 0.2s;
}

.search-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.progress-container {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.progress-bar-track {
  width: 110px;
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary-color), #ff8c42);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
}

.header-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.header-btn-primary {
  background: var(--primary-color);
  color: #fff !important;
  border-color: var(--primary-color);
}

.header-btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.theme-toggle-btn {
  font-size: 16px;
  padding: 7px 12px;
}

/* App Layout */
.app-container {
  display: flex;
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

/* Left Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  position: fixed;
  top: var(--header-height);
  bottom: 0;
  left: 0;
  overflow-y: auto;
  padding: 16px 12px 30px;
  z-index: 30;
}

.sidebar-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 10px 6px;
  margin-top: 8px;
}

.sidebar-nav-list {
  list-style: none;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  margin-bottom: 2px;
  transition: all 0.15s;
  text-decoration: none;
}

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

.sidebar-nav-item.active {
  background: var(--primary-light);
  color: var(--primary-color);
  font-weight: 700;
  border-left: 3px solid var(--primary-color);
}

.sidebar-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1.5px solid var(--text-muted);
  flex-shrink: 0;
}

.sidebar-nav-item.completed .status-dot {
  background-color: var(--success-color);
  border-color: var(--success-color);
}

.nav-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--border-color);
  color: var(--text-muted);
  flex-shrink: 0;
}

.sidebar-nav-item.active .nav-badge {
  background: var(--primary-color);
  color: #fff;
}

/* Main Content Area */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 32px 48px 80px;
  max-width: 1040px;
}

.content-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.topic-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.category-tag {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-color);
}

.topic-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.3;
  margin-bottom: 14px;
}

.topic-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.btn-complete-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-complete-toggle:hover {
  border-color: var(--success-color);
  color: var(--success-color);
}

.btn-complete-toggle.is-completed {
  background: #ecfdf5;
  border-color: var(--success-color);
  color: var(--success-color);
}

[data-theme="dark"] .btn-complete-toggle.is-completed {
  background: rgba(16, 185, 129, 0.15);
}

/* Content Body */
.content-body {
  font-size: 1.05rem;
  line-height: 1.75;
  color: var(--text-main);
  margin-bottom: 28px;
}

.content-body h3 {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 24px 0 10px;
  color: var(--text-main);
}

.content-body h4 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 18px 0 8px;
  color: var(--text-main);
}

.content-body p {
  margin-bottom: 14px;
}

.content-body ul, .content-body ol {
  margin: 10px 0 18px 24px;
}

.content-body li {
  margin-bottom: 6px;
}

.content-body code {
  font-family: 'Fira Code', Consolas, monospace;
  font-size: 0.9em;
  background: var(--primary-light);
  color: var(--primary-color);
  padding: 2px 6px;
  border-radius: 4px;
}

.content-body pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 14px 0;
  font-family: 'Fira Code', monospace;
  font-size: 0.92rem;
}

.content-body pre code {
  background: none;
  color: inherit;
  padding: 0;
}

/* Concept Table */
.concept-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 24px;
  font-size: 0.95rem;
}

.concept-table th, .concept-table td {
  padding: 12px 14px;
  border: 1px solid var(--border-color);
  text-align: left;
}

.concept-table th {
  background: var(--card-bg);
  font-weight: 700;
}

/* Terminal & Tip Cards */
.code-terminal {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 14px 18px;
  border-radius: 8px;
  font-family: 'Fira Code', monospace;
  font-size: 0.9rem;
}

.tip-card {
  background: var(--tip-bg);
  border-left: 4px solid var(--tip-border);
  padding: 14px 18px;
  border-radius: 0 8px 8px 0;
  margin: 18px 0;
}

/* Key Points Box */
.keypoints-box {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 30px;
  box-shadow: var(--shadow-sm);
}

.keypoints-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 12px;
  color: var(--primary-color);
}

.keypoints-list {
  list-style: none;
}

.keypoints-list li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.96rem;
}

.keypoints-list li::before {
  content: "✔";
  color: var(--primary-color);
  font-weight: bold;
}

/* Tab Container (Code / Quiz / Visualizer) */
.tab-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.tab-btn {
  padding: 8px 18px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab-btn:hover {
  color: var(--text-main);
  background: var(--primary-light);
}

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

/* Code Editor and Runner Card */
.code-runner-card {
  background: var(--code-bg);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  margin-bottom: 24px;
}

.code-header {
  background: var(--code-header-bg);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.code-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Fira Code', monospace;
  font-size: 0.85rem;
  color: #94a3b8;
}

.code-dots {
  display: flex;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.dot-red { background-color: #ef4444; }
.dot-yellow { background-color: #eab308; }
.dot-green { background-color: #22c55e; }

.code-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-code-action {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #f8fafc;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
}

.btn-code-action:hover {
  background: rgba(255, 255, 255, 0.18);
}

.btn-run-code {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: #fff;
}

.btn-run-code:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.code-editor-area {
  position: relative;
  max-height: 520px;
  overflow-y: auto;
}

.code-editor-area pre {
  margin: 0;
  padding: 18px;
  font-family: 'Fira Code', Consolas, monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  background: transparent !important;
}

/* Console Output Section */
.console-card {
  background: var(--console-bg);
  border-radius: 12px;
  border: 1px solid var(--border-color);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}

.console-header {
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.82rem;
  color: #94a3b8;
}

.console-header-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
}

.status-indicator.running {
  background: #f59e0b;
  animation: pulse 1s infinite;
}

.status-indicator.error {
  background: #ef4444;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.9); }
}

.console-output {
  padding: 16px;
  font-family: 'Fira Code', Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--console-text);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 320px;
  overflow-y: auto;
}

/* Quiz Card */
.quiz-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.quiz-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary-color);
}

.quiz-question {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 18px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quiz-option-btn {
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  background: var(--bg-color);
  color: var(--text-main);
  border-radius: 8px;
  text-align: left;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 10px;
}

.quiz-option-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary-color);
}

.quiz-option-btn.correct {
  background: #d1fae5;
  border-color: #10b981;
  color: #065f46;
  font-weight: 700;
}

.quiz-option-btn.wrong {
  background: #fee2e2;
  border-color: #ef4444;
  color: #991b1b;
}

[data-theme="dark"] .quiz-option-btn.correct {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

[data-theme="dark"] .quiz-option-btn.wrong {
  background: rgba(239, 68, 68, 0.2);
  color: #f87171;
}

.quiz-feedback {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.92rem;
  display: none;
}

.quiz-feedback.show {
  display: block;
}

/* Memory Visualizer Card */
.visualizer-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.memory-diagram {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 16px;
}

.memory-box {
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 16px;
}

.memory-box-title {
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
}

.memory-cell {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  font-family: 'Fira Code', monospace;
  font-size: 0.88rem;
}

.memory-cell.highlight {
  border-color: var(--primary-color);
  background: var(--primary-light);
}

/* Bottom Navigation */
.bottom-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border-color);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  padding: 12px 20px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  color: var(--text-main);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 180px;
}

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

.nav-btn-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.nav-btn-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-top: 2px;
}

.nav-btn-next {
  text-align: right;
}

/* Modal Playground */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--card-bg);
  border-radius: 14px;
  width: 100%;
  max-width: 960px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}

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

.modal-title {
  font-weight: 700;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
}

.modal-editor-col, .modal-output-col {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

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

.modal-col-header {
  padding: 8px 16px;
  background: var(--bg-color);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.code-textarea {
  flex: 1;
  width: 100%;
  border: none;
  background: var(--code-bg);
  color: var(--code-text);
  font-family: 'Fira Code', monospace;
  font-size: 0.92rem;
  padding: 16px;
  resize: none;
  outline: none;
  line-height: 1.6;
}

.modal-output-box {
  flex: 1;
  background: var(--console-bg);
  color: var(--console-text);
  font-family: 'Fira Code', monospace;
  font-size: 0.92rem;
  padding: 16px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-color);
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 120;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Responsive Media Queries */
@media (max-width: 992px) {
  .menu-toggle {
    display: block;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    padding: 24px 20px 60px;
  }

  .modal-body {
    grid-template-columns: 1fr;
  }

  .modal-editor-col {
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    height: 50%;
  }

  .modal-output-col {
    height: 50%;
  }
}

@media (max-width: 640px) {
  .header-center {
    display: none;
  }

  .progress-container {
    display: none;
  }

  .topic-title {
    font-size: 1.5rem;
  }

  .bottom-nav {
    flex-direction: column;
    gap: 12px;
  }

  .nav-btn {
    width: 100%;
  }

  .nav-btn-next {
    text-align: left;
  }

  .memory-diagram {
    grid-template-columns: 1fr;
  }
}
