/* ===== 全局 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: #f0f2f5;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== 顶栏 ===== */
#topbar {
  flex: 0 0 auto;
  background: #1890ff;
  color: #fff;
  padding: 0 20px;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(24,144,255,0.25);
  z-index: 10;
}
#topbar h1 {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}
#topbar .badge {
  font-size: 11px;
  background: rgba(255,255,255,0.22);
  color: #fff;
  padding: 1px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.35);
}
.example-select {
  margin-left: auto;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 13px;
  cursor: pointer;
}
.example-select option { background: #1890ff; color: #fff; }

/* ===== 主体布局 ===== */
#main {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  overflow: hidden;
  padding: 12px 14px;
  gap: 0;
}

/* ===== 分隔拖拽条 ===== */
#resizer {
  flex: 0 0 14px;
  background: transparent;
  cursor: col-resize;
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#resizer::before {
  content: '⋮';
  font-size: 20px;
  color: #d9d9d9;
  line-height: 1;
  transition: color 0.15s;
  user-select: none;
}
#resizer:hover::before,
#resizer.dragging::before { color: #1890ff; }

/* ===== 代码区 ===== */
#code-panel {
  flex: 1 1 0;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  background: #1e1e2e;
  overflow: hidden;
  min-height: 0;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* 代码面板头部 */
#code-panel-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: 44px;
  border-bottom: 1px solid #2d2d4e;
  background: #1a1a2e;
  border-radius: 8px 8px 0 0;
}
.win-dots { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.win-dot  { width: 10px; height: 10px; border-radius: 50%; }
.win-dot.red    { background: #ff5f57; }
.win-dot.yellow { background: #ffbd2e; }
.win-dot.green  { background: #28ca41; }
.panel-label { font-size: 12px; color: #6b7280; flex: 1; }

#run-btn {
  background: #1890ff;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(24,144,255,0.35);
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
  flex-shrink: 0;
}
#run-btn:hover  { background: #40a9ff; box-shadow: 0 4px 12px rgba(24,144,255,0.45); }
#run-btn:active { transform: scale(0.97); }

#error-box {
  display: none;
  flex: 0 0 auto;
  background: #fff2f0;
  border-bottom: 1px solid #ffccc7;
  color: #cf1322;
  font-size: 12px;
  padding: 6px 14px;
}
#error-box.show { display: block; }

#code-editor-wrap {
  flex: 1 1 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
#code-editor-wrap .CodeMirror {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  height: 100%;
  font-size: 13px;
  font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  background: #1e1e2e;
  color: #cdd6f4;
}
.cm-current-line { background: rgba(24,144,255,0.18) !important; }
.cm-line-arrow { color: #f38ba8; font-weight: bold; padding: 0 4px; }

/* ===== 输入数据区 ===== */
#input-section {
  flex: 0 0 auto;
  border-top: 1px solid #2d2d4e;
  background: #161625;
}
#input-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px 4px 14px;
}
.input-label { font-size: 11px; color: #6b7280; }
#input-toggle {
  background: none; border: none;
  color: #6b7280; cursor: pointer;
  font-size: 13px; padding: 0 2px; line-height: 1;
}
#input-toggle:hover { color: #40a9ff; }
#input-data {
  display: block; width: 100%;
  background: #12121f; color: #cdd6f4;
  border: none; border-top: 1px solid #2d2d4e;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; padding: 7px 14px;
  resize: none; height: 60px; outline: none;
  line-height: 1.7; box-sizing: border-box;
}
#input-data::placeholder { color: #3d3d5c; }
#input-data:focus { border-top-color: #1890ff; }

/* ===== 变量面板 ===== */
#memory-panel {
  flex: 1 1 0;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
  min-height: 0;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* ===== 右侧面板顶部步骤导航栏 ===== */
#step-nav {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
  border-radius: 8px 8px 0 0;
  flex-wrap: wrap;
}
.mem-title {
  font-size: 13px;
  color: #1890ff;
  font-weight: 600;
  margin-right: 2px;
  white-space: nowrap;
}
.step-nav-btns { display: flex; gap: 4px; }

#step-nav .ctrl-btn {
  padding: 3px 10px;
  font-size: 12px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid #d9d9d9;
  color: #595959;
  font-weight: 500;
}
#step-nav .ctrl-btn:hover:not(:disabled) { border-color: #1890ff; color: #1890ff; }
#step-nav .ctrl-btn.primary {
  background: #1890ff;
  border-color: #1890ff;
  color: #fff;
  padding: 3px 16px;
  font-weight: 600;
}
#step-nav .ctrl-btn.primary:hover:not(:disabled) { background: #40a9ff; border-color: #40a9ff; }

/* 步骤进度条 */
#step-progress {
  flex: 1; min-width: 30px;
  height: 4px;
  background: #f0f0f0;
  border-radius: 2px;
  overflow: hidden;
}
#step-progress-bar {
  height: 100%;
  background: #1890ff;
  border-radius: 2px;
  width: 0%;
  transition: width 0.2s ease;
}

/* 速度滑块 */
.speed-wrap {
  display: flex; align-items: center;
  gap: 5px; color: #8c8c8c; font-size: 11px;
}
#speed-slider {
  -webkit-appearance: none;
  width: 64px; height: 3px;
  border-radius: 2px;
  background: #d9d9d9;
  outline: none; cursor: pointer;
}
#speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #1890ff;
  cursor: pointer;
}
#step-info {
  margin-left: auto;
  color: #8c8c8c;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
}

/* ===== 步骤说明 ===== */
#step-explain {
  flex: 0 0 auto;
  padding: 10px 16px 10px 44px;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.6;
  color: #613400;
  background: #fffbe6;
  border-bottom: 1px solid #ffe58f;
  min-height: 46px;
  position: relative;
}
#step-explain::before {
  content: '💬';
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  line-height: 1;
}

#memory-content {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
}

/* ===== 程序输出面板 ===== */
#stdout-panel {
  flex: 0 0 auto;
  border-top: 1px solid #b7eb8f;
  background: #f6ffed;
  display: none;
  max-height: 110px;
  overflow: hidden;
}
#stdout-panel .panel-title {
  background: #52c41a;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-bottom: none;
}
#stdout-content {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: #135200;
  padding: 6px 14px;
  margin: 0;
  white-space: pre-wrap;
  overflow-y: auto;
  max-height: 72px;
  line-height: 1.5;
}

/* ===== 调用帧 ===== */
.frame-box {
  border: 1.5px solid #1890ff;
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
  opacity: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.frame-title {
  background: #1890ff;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
}
.frame-box[data-frame="__global__"] { border-color: #52c41a; }
.frame-box[data-frame="__global__"] .frame-title { background: #52c41a; }

/* ===== 变量卡片 ===== */
.var-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px 8px;
}
.var-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border-radius: 8px;
  border: none;
  overflow: hidden;
  min-width: 52px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.10);
  transition: transform 0.1s;
}
.var-card:hover { transform: translateY(-1px); }
.vc-name {
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  padding: 4px 8px;
  width: 100%;
  text-align: center;
  color: #fff;
}
.vc-val {
  font-size: 19px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  padding: 7px 10px;
  width: 100%;
  text-align: center;
  background: #fff;
  color: #262626;
}
.vc-val.uninit { color: #bfbfbf; font-size: 13px; }
/* 变量高亮：打在整个卡片上，子选择器保证覆盖 CSS background 简写 */
.var-card.vc-changed .vc-val { background: #ffe58f !important; }

/* 变量卡片配色（Ant Design 色板） */
.vc-loop   .vc-name { background: #1890ff; }
.vc-loop   { box-shadow: 0 2px 8px rgba(24,144,255,0.22); }
.vc-temp   .vc-name { background: #fa8c16; }
.vc-temp   { box-shadow: 0 2px 8px rgba(250,140,22,0.22); }
.vc-accum  .vc-name { background: #52c41a; }
.vc-accum  { box-shadow: 0 2px 8px rgba(82,196,26,0.22); }
.vc-flag   .vc-name { background: #722ed1; }
.vc-flag   { box-shadow: 0 2px 8px rgba(114,46,209,0.22); }
.vc-size   .vc-name { background: #8c8c8c; }
.vc-size   { box-shadow: 0 2px 8px rgba(0,0,0,0.10); }
.vc-default .vc-name { background: #595959; }

/* ===== 数组区域 ===== */
.array-section { padding: 12px; border-top: 1px solid #f0f0f0; margin-top: 4px; }

.array-group {
  position: relative;
  border: 1.5px solid #91d5ff;
  border-radius: 8px;
  padding: 24px 12px 12px 12px;
  margin-bottom: 12px;
  background: #e6f7ff;
}
.array-group-name {
  position: absolute;
  top: -11px;
  left: 12px;
  background: #1890ff;
  color: #fff;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  border-radius: 4px;
  line-height: 20px;
  letter-spacing: 0.03em;
}

.array-row { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 4px; }
.array-cell-wrap { display: flex; flex-direction: column; align-items: center; }
.array-cell {
  width: 52px; height: 52px;
  border: 1.5px solid #d9d9d9;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  color: #262626;
  background: #fff;
  transition: border-color 0.15s, background 0.15s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.array-index {
  font-size: 11px;
  color: #bfbfbf;
  margin-top: 3px;
  font-family: 'JetBrains Mono', monospace;
}
.array-cell.write         { border-color: #fa8c16; background: #fff7e6; }
.array-cell.compare-true  { border-color: #52c41a; background: #f6ffed; }
.array-cell.compare-false { border-color: #ff4d4f; background: #fff2f0; }
.array-cell.uninit        { color: #bfbfbf; font-size: 12px; }

/* 省略号（大数组窗口视图） */
.array-gap {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-width: 38px; height: 52px;
  font-size: 11px; color: #91d5ff;
  letter-spacing: 0.04em;
  font-family: 'JetBrains Mono', monospace;
  padding: 0 4px; flex-shrink: 0;
}
.ptr-gap { min-width: 38px; flex-shrink: 0; }

/* ===== 变量指针行 ===== */
.ptr-row {
  display: flex; gap: 5px;
  flex-wrap: nowrap; margin-bottom: 5px; min-height: 30px;
}
.ptr-slot {
  width: 52px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-end;
  gap: 1px;
}
.ptr-slot.active .ptr-label {
  background: #1890ff;
  color: #fff;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  max-width: 58px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ptr-slot.active .ptr-arrow {
  color: #1890ff;
  font-size: 10px;
  line-height: 1;
}

/* ===== 控制按钮（通用基础） ===== */
.ctrl-btn {
  background: #fff;
  color: #595959;
  border: 1px solid #d9d9d9;
  border-radius: 6px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.ctrl-btn:hover:not(:disabled) { border-color: #1890ff; color: #1890ff; }
.ctrl-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.ctrl-btn.primary { background: #1890ff; color: #fff; border-color: #1890ff; }
.ctrl-btn.primary:hover:not(:disabled) { background: #40a9ff; border-color: #40a9ff; }

/* ===== 加载遮罩 ===== */
#loading-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: #fff; font-size: 14px; gap: 12px; z-index: 999;
}
#loading-mask.hidden { display: none; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #1890ff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 飞行数字动画 ===== */
.fly-num {
  position: fixed; z-index: 2000; pointer-events: none;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px; font-weight: 700;
  color: #52c41a; background: #f6ffed;
  border: 2px solid #52c41a; border-radius: 50%;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(82,196,26,0.3);
}
