:root {
  --primary: #165DFF;
  --primary-light: #3C7EFF;
  --primary-dark: #0E42D2;
  --primary-bg: rgba(22, 93, 255, 0.08);
  --primary-border: rgba(22, 93, 255, 0.2);

  --bg: #ffffff;
  --bg-secondary: #f7f8fa;
  --bg-tertiary: #f0f1f5;
  --bg-hover: #e8e9ed;
  --bg-canvas: #fafbfc;
  --bg-code: #1e1e2e;
  --bg-code-header: #181825;

  --text: #1d2129;
  --text-secondary: #4e5969;
  --text-tertiary: #86909c;
  --text-code: #cdd6f4;
  --text-inverse: #ffffff;

  --border: #e5e6eb;
  --border-light: #f0f1f5;
  --border-heavy: #c9cdd4;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.16);

  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --nav-height: 52px;
  --control-height: 48px;
  --control-top-margin: 30px;
  --sidebar-width: 260px;
  --right-panel-width: 380px;
  --panel-resizer-width: 6px;
  --bottom-panel-height: 280px;
  --bottom-panel-toggle-height: 32px;

  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-base: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;
  --fs-2xl: 24px;
  --fs-3xl: 32px;

  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, 'Courier New', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;

  --transition-fast: 0.15s ease;
  --transition: 0.25s ease;
  --transition-slow: 0.35s ease;

  --font-scale: 1;
  --sidebar-collapsed: 0;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --bg-hover: #21262d;
  --bg-canvas: #111820;
  --bg-code: #0d1117;
  --bg-code-header: #161b22;

  --text: #e6edf3;
  --text-secondary: #8b949e;
  --text-tertiary: #6e7681;
  --text-code: #cdd6f4;

  --border: #30363d;
  --border-light: #21262d;
  --border-heavy: #484f58;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.6);

  --primary-bg: rgba(22, 93, 255, 0.15);
  --primary-border: rgba(22, 93, 255, 0.3);
}

[data-font-scale="small"] { --font-scale: 0.9; }
[data-font-scale="large"] { --font-scale: 1.15; }
[data-font-scale="xlarge"] { --font-scale: 1.3; }

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: calc(14px * var(--font-scale));
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  transition: background var(--transition), color var(--transition);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-heavy);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ========== TOP NAVIGATION ========== */
.top-nav {
  height: var(--nav-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  position: relative;
  flex-shrink: 0;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
}

.nav-logo svg {
  width: 28px;
  height: 28px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 24px;
}

.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: var(--fs-base);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
  font-family: inherit;
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-link.active {
  background: var(--primary-bg);
  color: var(--primary);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.nav-icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-icon-btn svg {
  width: 18px;
  height: 18px;
}

.nav-user-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text);
  cursor: pointer;
  font-size: var(--fs-sm);
  font-family: inherit;
  transition: all var(--transition-fast);
}

.nav-user-btn:hover {
  border-color: var(--primary);
  background: var(--primary-bg);
}

/* ========== MAIN LAYOUT ========== */
.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ========== LEFT SIDEBAR ========== */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: all var(--transition);
  overflow: hidden;
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-search {
  width: 100%;
  padding: 7px 10px 7px 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-sm);
  font-family: inherit;
  outline: none;
  transition: all var(--transition-fast);
  position: relative;
}

.sidebar-search-wrap {
  position: relative;
}

.sidebar-search-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.sidebar-search:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-border);
}

.sidebar-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}

.sidebar-action-btn {
  flex: 1;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition-fast);
}

.sidebar-action-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sidebar-tree {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.tree-node {
  user-select: none;
}

.tree-node-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: var(--fs-base);
  color: var(--text);
  position: relative;
}

.tree-node-header:hover {
  background: var(--bg-hover);
}

.tree-node-header.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 600;
}

.tree-node-header.completed {
  color: var(--primary);
}

.tree-arrow {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform var(--transition-fast);
  color: var(--text-tertiary);
}

.tree-arrow.expanded {
  transform: rotate(90deg);
}

.tree-arrow svg {
  width: 12px;
  height: 12px;
}

.tree-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--primary);
}

.tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}

.tree-badge {
  font-size: var(--fs-xs);
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 500;
  flex-shrink: 0;
}

.tree-children {
  overflow: hidden;
  transition: max-height var(--transition);
}

.tree-children.collapsed {
  max-height: 0 !important;
}

.tree-leaf {
  padding: 4px 8px 4px 42px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-leaf:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.tree-leaf.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 500;
}

.tree-leaf .progress-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.tree-leaf .progress-dot.done { background: var(--primary); }
.tree-leaf .progress-dot.starred { background: #f7ba1e; }
.tree-leaf .progress-dot.none { background: var(--border-heavy); }

/* ========== CENTER CANVAS AREA ========== */
.canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-canvas);
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.canvas-title {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
}

.canvas-toolbar-actions {
  display: flex;
  gap: 6px;
}

.canvas-tool-btn {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 4px;
}

.canvas-tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.canvas-tool-btn svg {
  width: 14px;
  height: 14px;
}

.canvas-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.canvas-wrapper:active {
  cursor: grabbing;
}

.canvas-wrapper.panning {
  cursor: grabbing;
}

#animationCanvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.canvas-watermark {
  position: absolute;
  bottom: 12px;
  right: 16px;
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  opacity: 0.6;
  pointer-events: none;
}

/* ========== RIGHT PANEL ========== */
.right-panel-wrapper {
  display: flex;
  height: 100%;
  position: relative;
}

.right-panel {
  width: var(--right-panel-width);
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
  overflow: hidden;
}

.right-panel-knowledge {
  width: var(--right-panel-width);
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
  overflow: hidden;
}

.right-panel-knowledge .knowledge-detail-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.right-panel-knowledge .knowledge-detail-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
}

.right-panel-knowledge .knowledge-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg);
}

.right-panel-knowledge .knowledge-section {
  font-family: var(--font-sans);
  line-height: 1.7;
  color: var(--text);
}

.right-panel-knowledge .knowledge-section h3 {
  font-size: var(--fs-xl);
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
}

.right-panel-knowledge .knowledge-section h4 {
  font-size: var(--fs-base);
  color: var(--text);
  margin: 14px 0 8px;
  padding-left: 8px;
  border-left: 3px solid var(--primary);
}

.right-panel-knowledge .knowledge-section h5 {
  font-size: var(--fs-sm);
  color: var(--text);
  margin: 12px 0 6px;
}

.right-panel-knowledge .knowledge-section p {
  margin: 8px 0;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.right-panel-knowledge .knowledge-section ul,
.right-panel-knowledge .knowledge-section ol {
  margin: 8px 0;
  padding-left: 20px;
}

.right-panel-knowledge .knowledge-section li {
  margin: 4px 0;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.right-panel-knowledge .knowledge-section pre {
  background: var(--bg-code);
  color: var(--text-code);
  padding: 12px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 10px 0;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.5;
  border: 1px solid var(--border);
}

.right-panel-knowledge .knowledge-section code {
  font-family: var(--font-mono);
  background: var(--primary-bg);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs);
}

.right-panel-knowledge .knowledge-section table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: var(--fs-xs);
}

.right-panel-knowledge .knowledge-section table th,
.right-panel-knowledge .knowledge-section table td {
  padding: 8px 10px;
  border: 1px solid var(--border);
  text-align: left;
}

.right-panel-knowledge .knowledge-section table th {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text);
}

.right-panel-knowledge .knowledge-section table tr:hover {
  background: var(--bg-secondary);
}

.panel-resizer {
  width: var(--panel-resizer-width);
  background: transparent;
  cursor: col-resize;
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  z-index: 10;
}

.panel-resizer:hover,
.panel-resizer.active {
  background: var(--primary);
  opacity: 0.3;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 8px;
}

.panel-tab {
  padding: 10px 16px;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  font-family: inherit;
  white-space: nowrap;
}

.panel-tab:hover {
  color: var(--text);
}

.panel-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.panel-content {
  flex: 1;
  overflow-y: auto;
  display: none;
}

.panel-content.active {
  display: block;
}

/* Code Panel */
.code-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.code-lang-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.lang-btn {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.lang-btn:hover {
  background: var(--bg-hover);
}

.lang-btn.active {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
}

.code-display {
  flex: 1;
  overflow: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  background: var(--bg-code);
  color: var(--text-code);
  padding: 12px;
  position: relative;
}

.code-display pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.code-display code {
  font-family: var(--font-mono);
  font-size: 12px;
}

.code-line {
  display: block;
  padding: 1px 8px;
  border-left: 3px solid transparent;
  transition: all var(--transition-fast);
}

.code-line.highlight {
  background: rgba(22, 93, 255, 0.2);
  border-left-color: var(--primary);
}

.code-line.current-step {
  background: rgba(22, 93, 255, 0.3);
  border-left-color: var(--primary-light);
  animation: pulse-line 1.5s ease infinite;
}

@keyframes pulse-line {
  0%, 100% { background: rgba(22, 93, 255, 0.3); }
  50% { background: rgba(22, 93, 255, 0.15); }
}

/* Explanation Panel */
.explanation-panel {
  padding: 16px;
}

.explanation-step-indicator {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  margin-bottom: 8px;
}

.explanation-title {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

.explanation-text {
  font-size: var(--fs-base);
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 16px;
}

.explanation-highlight {
  background: var(--primary-bg);
  border-left: 3px solid var(--primary);
  padding: 10px 14px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: 12px 0;
  font-size: var(--fs-sm);
  color: var(--text);
}

.explanation-tips {
  font-size: var(--fs-sm);
  color: var(--text-tertiary);
  padding: 10px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  margin-top: 12px;
}

/* Data Panel */
.data-panel {
  padding: 16px;
}

.data-section {
  margin-bottom: 16px;
}

.data-section-title {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.data-table th,
.data-table td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-light);
}

.data-table th {
  font-weight: 500;
  color: var(--text-tertiary);
  font-size: var(--fs-xs);
}

.data-table td {
  color: var(--text);
}

.data-table .changed {
  color: var(--primary);
  font-weight: 600;
  animation: flash-change 0.6s ease;
}

@keyframes flash-change {
  0%, 100% { color: var(--primary); }
  50% { color: var(--primary-light); }
}

.data-var-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  margin-bottom: 6px;
  transition: all var(--transition-fast);
}

.data-var-card.changed {
  background: var(--primary-bg);
  border: 1px solid var(--primary-border);
}

.data-var-name {
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--text);
  min-width: 60px;
}

.data-var-value {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--primary);
}

.data-var-type {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
}

.data-var-address {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  margin-left: auto;
}

/* ========== BOTTOM CONTROL BAR ========== */
.control-bar {
  height: var(--control-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 10;
}

.control-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.control-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.control-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.control-btn:hover {
  background: var(--bg-hover);
  border-color: var(--primary);
}

.control-btn:active {
  transform: scale(0.95);
}

.control-btn.active {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
}

.control-btn svg {
  width: 16px;
  height: 16px;
}

.control-btn.play-btn {
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
  border-radius: 50%;
}

.control-btn.play-btn:hover {
  background: var(--primary-dark);
}

.step-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.step-current {
  color: var(--primary);
  font-weight: 600;
  font-size: var(--fs-md);
}

.progress-slider-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  max-width: 400px;
  margin: 0 16px;
}

.progress-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.progress-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid var(--bg);
  box-shadow: var(--shadow-sm);
}

.speed-selector {
  display: flex;
  gap: 2px;
}

.speed-btn {
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition-fast);
}

.speed-btn:hover {
  background: var(--bg-hover);
}

.speed-btn.active {
  background: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
}

.zoom-display {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  min-width: 40px;
  text-align: center;
}

/* ========== MOBILE SIDEBAR TOGGLE ========== */
.mobile-sidebar-toggle {
  display: none;
}

/* ========== MOBILE PANEL TABS (HIDDEN ON DESKTOP) ========== */
.mobile-panel-tabs {
  display: none;
}

/* ========== OVERLAY PANELS (MOBILE) ========== */
.mobile-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
}

.mobile-overlay-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  max-height: 70vh;
  background: var(--bg);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
}

.mobile-overlay-handle {
  width: 36px;
  height: 4px;
  background: var(--border-heavy);
  border-radius: 2px;
  margin: 10px auto;
}

/* ========== RESPONSIVE - TABLET ========== */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 240px;
    --right-panel-width: 320px;
  }

  .nav-links {
    display: none;
  }

  .canvas-toolbar {
    padding: 6px 10px;
  }

  .canvas-tool-btn span {
    display: none;
  }

  .progress-slider-wrap {
    max-width: 200px;
  }
}

/* ========== RESPONSIVE - MOBILE ========== */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
    --right-panel-width: 0px;
    --nav-height: 48px;
    --control-height: 44px;
  }

  .nav-links {
    display: none;
  }

  .nav-logo span {
    font-size: var(--fs-md);
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    min-width: 280px;
    height: 100%;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--shadow-xl);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-sidebar-toggle {
    display: flex;
  }

  .right-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: 300;
    transform: translateX(100%);
    transition: transform var(--transition);
  }

  .right-panel.open {
    transform: translateX(0);
  }

  .control-bar {
    padding: 0 8px;
    gap: 4px;
  }

  .control-left,
  .control-right {
    gap: 4px;
  }

  .progress-slider-wrap {
    display: none;
  }

  .mobile-overlay {
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
  }

  .mobile-overlay.visible {
    opacity: 1;
    pointer-events: all;
  }

  .mobile-panel-tabs {
    display: flex;
    gap: 4px;
    padding: 8px;
    position: fixed;
    bottom: var(--control-height);
    left: 0;
    width: 100%;
    z-index: 50;
    justify-content: center;
  }

  .mobile-panel-btn {
    padding: 6px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow);
  }

  .mobile-panel-btn.active {
    background: var(--primary);
    color: var(--text-inverse);
    border-color: var(--primary);
  }
}

@media (max-width: 480px) {
  .canvas-title {
    font-size: var(--fs-sm);
  }

  .control-btn {
    width: 30px;
    height: 30px;
  }

  .control-btn.play-btn {
    width: 36px;
    height: 36px;
  }

  .step-indicator {
    font-size: var(--fs-xs);
  }
}

/* ========== SETTINGS PANEL ========== */
.settings-dropdown {
  position: absolute;
  top: 100%;
  right: 8px;
  width: 240px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 12px;
  z-index: 150;
  display: none;
}

.settings-dropdown.visible {
  display: block;
}

.settings-group {
  margin-bottom: 12px;
}

.settings-group:last-child {
  margin-bottom: 0;
}

.settings-group-title {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.settings-label {
  font-size: var(--fs-sm);
  color: var(--text);
}

.theme-toggle {
  display: flex;
  gap: 2px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 2px;
}

.theme-option {
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition-fast);
}

.theme-option.active {
  background: var(--primary);
  color: var(--text-inverse);
}

.font-size-options {
  display: flex;
  gap: 2px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 2px;
}

.font-size-btn {
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: var(--fs-xs);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition-fast);
}

.font-size-btn.active {
  background: var(--primary);
  color: var(--text-inverse);
}

/* ========== TODO / NOTE PANEL ========== */
.note-panel {
  position: fixed;
  right: 0;
  top: var(--nav-height);
  bottom: 0;
  width: 320px;
  background: var(--bg);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index: 120;
  transform: translateX(100%);
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
}

.note-panel.open {
  transform: translateX(0);
}

.note-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.note-panel-title {
  font-weight: 600;
  font-size: var(--fs-md);
}

.note-panel-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
}

.note-panel-close:hover {
  background: var(--bg-hover);
}

.note-panel-body {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
}

.note-textarea {
  width: 100%;
  height: 100%;
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  color: var(--text);
  background: var(--bg-secondary);
  resize: none;
  outline: none;
  line-height: 1.6;
}

.note-textarea:focus {
  border-color: var(--primary);
}

.note-panel-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.note-save-btn {
  padding: 6px 16px;
  border-radius: var(--radius);
  border: none;
  background: var(--primary);
  color: var(--text-inverse);
  font-size: var(--fs-sm);
  cursor: pointer;
  font-family: inherit;
}

.note-save-btn:hover {
  background: var(--primary-dark);
}

/* ========== BOTTOM KNOWLEDGE PANEL ========== */
.bottom-knowledge-panel {
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: height var(--transition);
  overflow: hidden;
}

.bottom-knowledge-panel.expanded {
  height: var(--bottom-panel-height);
}

.bottom-knowledge-panel.collapsed {
  height: var(--bottom-panel-toggle-height);
}

.bottom-panel-toggle {
  height: var(--bottom-panel-toggle-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  user-select: none;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}

.bottom-panel-toggle:hover {
  background: var(--bg-hover);
}

.bottom-panel-toggle-icon {
  font-size: 10px;
  color: var(--text-tertiary);
  transition: transform var(--transition);
}

.bottom-knowledge-panel.expanded .bottom-panel-toggle-icon {
  transform: rotate(180deg);
}

.bottom-panel-toggle-text {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
}

.bottom-panel-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.bottom-panel-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

.bottom-panel-title {
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--text);
}

.bottom-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  background: var(--bg);
}

#bottomKnowledgeContent {
  font-family: var(--font-sans);
  line-height: 1.8;
  color: var(--text);
  max-width: 1200px;
  margin: 0 auto;
}

#bottomKnowledgeContent h3 {
  font-size: var(--fs-xl);
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
}

#bottomKnowledgeContent h4 {
  font-size: var(--fs-md);
  color: var(--text);
  margin: 16px 0 8px;
  padding-left: 10px;
  border-left: 3px solid var(--primary);
}

#bottomKnowledgeContent h5 {
  font-size: var(--fs-base);
  color: var(--text);
  margin: 12px 0 6px;
}

#bottomKnowledgeContent p {
  margin: 8px 0;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  line-height: 1.8;
}

#bottomKnowledgeContent ul,
#bottomKnowledgeContent ol {
  margin: 8px 0;
  padding-left: 24px;
}

#bottomKnowledgeContent li {
  margin: 5px 0;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  line-height: 1.7;
}

#bottomKnowledgeContent pre {
  background: var(--bg-code);
  color: var(--text-code);
  padding: 14px 18px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 12px 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  border: 1px solid var(--border);
}

#bottomKnowledgeContent code {
  font-family: var(--font-mono);
  background: var(--primary-bg);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--primary);
}

#bottomKnowledgeContent table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: var(--fs-sm);
}

#bottomKnowledgeContent table th,
#bottomKnowledgeContent table td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}

#bottomKnowledgeContent table th {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text);
}

#bottomKnowledgeContent table tr:hover {
  background: var(--bg-secondary);
}

#bottomKnowledgeContent strong {
  color: var(--text);
  font-weight: 600;
}

/* ========== RESPONSIVE - BOTTOM PANEL ========== */
@media (max-width: 768px) {
  :root {
    --bottom-panel-height: 250px;
    --bottom-panel-toggle-height: 30px;
  }

  .bottom-panel-content {
    padding: 12px 14px;
  }
}

/* Knowledge Detail Panel inside right panel */
#panelKnowledge {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
}

#panelKnowledge .knowledge-detail-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

#panelKnowledge .knowledge-detail-title {
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text);
}

#panelKnowledge .knowledge-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  background: var(--bg);
}

#panelKnowledge .knowledge-section {
  font-family: var(--font-sans);
  line-height: 1.7;
  color: var(--text);
}

#panelKnowledge .knowledge-section h3 {
  font-size: var(--fs-lg);
  color: var(--primary);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--primary);
}

#panelKnowledge .knowledge-section h4 {
  font-size: var(--fs-sm);
  color: var(--text);
  margin: 12px 0 6px;
  padding-left: 6px;
  border-left: 3px solid var(--primary);
}

#panelKnowledge .knowledge-section h5 {
  font-size: var(--fs-xs);
  color: var(--text);
  margin: 10px 0 4px;
}

#panelKnowledge .knowledge-section p {
  margin: 6px 0;
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

#panelKnowledge .knowledge-section ul,
#panelKnowledge .knowledge-section ol {
  margin: 6px 0;
  padding-left: 16px;
}

#panelKnowledge .knowledge-section li {
  margin: 3px 0;
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}

#panelKnowledge .knowledge-section pre {
  background: var(--bg-code);
  color: var(--text-code);
  padding: 10px;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 8px 0;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  border: 1px solid var(--border);
}

#panelKnowledge .knowledge-section code {
  font-family: var(--font-mono);
  background: var(--primary-bg);
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  font-size: 11px;
}

#panelKnowledge .knowledge-section table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 11px;
}

#panelKnowledge .knowledge-section table th,
#panelKnowledge .knowledge-section table td {
  padding: 6px 8px;
  border: 1px solid var(--border);
  text-align: left;
}

#panelKnowledge .knowledge-section table th {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text);
}

#panelKnowledge .knowledge-section table tr:hover {
  background: var(--bg-secondary);
}