/* ===== 代码演播台 · 手绘风格 ===== */
:root {
  --paper: #fbf7ec;
  --paper-line: #ece3cd;
  --ink: #3a3a3a;
  --blue: #2b6cb0;
  --red: #d64541;
  --hl: rgba(246, 195, 67, 0.45);
  --sticky-y: #fff3b0;
  --sticky-p: #ffd6e8;
  --sticky-b: #d0e6ff;
  --card-shadow: 3px 4px 0 rgba(58, 58, 58, 0.15);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe Print", "Comic Sans MS", "Segoe UI", cursive;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    repeating-linear-gradient(0deg, transparent 0, transparent 27px, var(--paper-line) 27px, var(--paper-line) 28px);
  background-position: 0 0;
  overflow-x: hidden;
}
.hidden { display: none !important; }

/* 手写面板 */
.panel {
  background: rgba(255, 255, 255, 0.62);
  border: none;
  border-radius: 8px 255px 12px 225px / 255px 8px 225px 12px;
  box-shadow: var(--card-shadow);
  padding: 10px 14px;
}

/* 隐私提示 */
.privacy-note {
  position: fixed; left: 8px; bottom: 6px; z-index: 20;
  font-size: 12px; color: rgba(58, 58, 58, 0.65);
  background: rgba(255, 255, 255, 0.7);
  padding: 2px 8px; border-radius: 6px;
}

/* 顶部 */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  margin: 10px 12px 6px;
  transform: rotate(-0.4deg);
}
.app-title { font-size: 26px; margin: 0; letter-spacing: 1px; }
.header-tools { display: flex; gap: 8px; flex-wrap: wrap; }

/* 按钮 */
.btn {
  font-family: inherit;
  background: var(--sticky-y);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 15px;
  box-shadow: 2px 3px 0 rgba(58,58,58,.25);
  transform: rotate(-0.5deg);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:hover { transform: rotate(0.8deg) translateY(-1px); box-shadow: 3px 5px 0 rgba(58,58,58,.25); }
.btn:active { transform: rotate(0) translateY(1px); box-shadow: 1px 1px 0 rgba(58,58,58,.25); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--sticky-b); }

/* 布局 */
.layout {
  display: grid;
  grid-template-columns: minmax(340px, 44%) 1fr;
  gap: 10px;
  margin: 6px 12px;
  align-items: stretch;
}
.code-panel, .trace-panel { min-height: 380px; max-height: 62vh; overflow: hidden; display: flex; flex-direction: column; }

/* 代码面板 */
#code-input {
  width: 100%; height: 100%; min-height: 360px;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13.5px; line-height: 1.65;
  background: transparent; border: none; outline: none;
  color: var(--ink); resize: none; padding: 4px 2px;
}
#code-view { flex: 1; overflow: auto; padding: 4px 2px; }
.code-line { display: flex; white-space: pre; font-family: Consolas, "Courier New", monospace; font-size: 13.5px; line-height: 1.65; cursor: pointer; border-radius: 3px; }
.code-line:hover { background: rgba(246,195,67,.18); }
.code-line.current { background: var(--hl); box-shadow: inset 0 0 0 1px rgba(246,195,67,.8); }
.line-no {
  display: inline-block; min-width: 38px; text-align: right; margin-right: 12px;
  color: rgba(58,58,58,.45); user-select: none;
  font-family: "Segoe Print", cursive; font-size: 12px;
}
.line-text { flex: 1; }
.py-keyword { color: #7c3aed; font-weight: 600; }
.py-comment { color: #8a8a8a; font-style: italic; }
.py-str { color: #b02e4c; }
.py-number { color: #1a7f37; }
.py-func { color: #2b6cb0; }

/* 轨迹面板 */
#mode-switch { display: flex; gap: 6px; margin-bottom: 8px; }
.mode-btn {
  font-family: inherit; font-size: 14px;
  border: 2px solid var(--ink); background: #fff; cursor: pointer;
  padding: 3px 10px;
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
}
.mode-btn.active { background: var(--hl); font-weight: 600; }
.steps-container { flex: 1; overflow-y: auto; padding: 6px 4px 30px; }

/* 便利贴步骤卡 */
.step-card {
  position: relative;
  background: var(--sticky-y);
  border: 2px solid var(--ink);
  padding: 12px 12px 10px;
  margin: 12px 6px 14px;
  border-radius: 2px 18px 3px 20px / 3px 20px 2px 18px;
  box-shadow: 3px 4px 0 rgba(58,58,58,.18);
  transform: rotate(-1deg);
  cursor: pointer;
  transition: transform .1s ease, box-shadow .1s ease;
}
.step-card:nth-child(even) { transform: rotate(1.2deg); background: var(--sticky-p); }
.step-card:nth-child(3n) { transform: rotate(-0.8deg); background: var(--sticky-b); }
.step-card:hover { transform: rotate(0) translateY(-2px); box-shadow: 4px 6px 0 rgba(58,58,58,.2); }
.step-card.active { box-shadow: 0 0 0 3px var(--red), 3px 4px 0 rgba(58,58,58,.18); transform: rotate(0); }
.step-card.low-conf { border-style: dashed; }
.step-tape {
  position: absolute; top: -10px; left: 50%; transform: translateX(-50%) rotate(-3deg);
  width: 90px; height: 20px;
  background: rgba(255,255,255,.55);
  border-left: 2px dashed rgba(58,58,58,.25); border-right: 2px dashed rgba(58,58,58,.25);
}
.step-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.step-kbadge { font-size: 17px; }
.step-title { font-weight: 600; font-size: 15px; flex: 1; }
.step-lines { font-size: 12px; color: rgba(58,58,58,.6); white-space: nowrap; }
.step-desc { font-size: 13px; line-height: 1.5; }
.step-loop { margin-top: 6px; font-size: 12px; color: var(--blue); border-top: 1px dashed rgba(58,58,58,.3); padding-top: 5px; }

/* 逐行事件 */
.line-event {
  display: flex; gap: 8px; align-items: baseline;
  font-family: Consolas, monospace; font-size: 13px;
  padding: 4px 8px; margin: 3px 0;
  border: 1px dashed transparent; cursor: pointer; border-radius: 4px;
}
.line-event:hover { background: rgba(246,195,67,.2); }
.line-event.active { background: var(--hl); border-color: rgba(58,58,58,.5); }
.le-no { min-width: 30px; text-align: right; color: rgba(58,58,58,.5); }
.le-type { min-width: 70px; color: var(--blue); font-size: 12px; }
.le-vars { color: var(--ink); }

/* 播放控制 */
.player-controls {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  border-top: 2px dashed var(--paper-line); padding-top: 8px; margin-top: 4px;
}
#step-indicator { font-size: 14px; white-space: nowrap; }
#speed-slider { width: 90px; accent-color: var(--blue); }
#speed-label { font-size: 13px; min-width: 26px; }

/* 详情 */
.detail-panel { margin: 6px 12px 40px; min-height: 150px; }
#detail-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.tab-btn {
  font-family: inherit; font-size: 14px;
  border: 2px solid var(--ink); background: #fff; cursor: pointer;
  padding: 3px 10px; border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
}
.tab-btn.active { background: var(--hl); font-weight: 600; }
.var-row { display: flex; align-items: baseline; gap: 8px; padding: 3px 0; font-family: Consolas, monospace; font-size: 13.5px; }
.var-name { color: var(--blue); font-weight: 600; }
.var-eq { color: rgba(58,58,58,.5); }
.var-value { color: var(--ink); word-break: break-all; }
.var-type { font-size: 11px; color: rgba(58,58,58,.55); background: #eee; border-radius: 4px; padding: 0 5px; }
.var-row.low .var-value { text-decoration: underline dotted var(--red); }
.var-warn { font-size: 11px; color: var(--red); }
.stack-row { padding: 3px 0; font-family: Consolas, monospace; font-size: 13px; }
.output-box {
  background: rgba(255,255,255,.6); border: 1px dashed rgba(58,58,58,.4);
  padding: 8px; border-radius: 6px;
  font-family: Consolas, monospace; font-size: 13px; white-space: pre-wrap; margin: 0;
}
.exp-desc { font-size: 14px; line-height: 1.6; }
.exp-detail { margin-top: 6px; color: var(--blue); line-height: 1.6; }
.exp-notes { margin-top: 6px; color: var(--red); line-height: 1.6; }
.empty { color: rgba(58,58,58,.5); font-size: 14px; padding: 14px 6px; text-align: center; }

/* 设置弹层 */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(58,58,58,.35);
  display: flex; align-items: center; justify-content: center;
}
.modal-card { width: min(480px, 92vw); padding: 20px 22px; background: var(--paper); transform: rotate(-0.4deg); }
.modal-card h2 { margin-top: 0; }
.modal-card label { display: block; margin: 12px 0 4px; font-size: 14px; }
.modal-card input[type="text"], .modal-card input[type="password"] {
  width: 100%; font-family: Consolas, monospace; font-size: 14px;
  border: 2px solid var(--ink); background: #fff;
  padding: 7px 9px; border-radius: 6px;
  border-radius: 255px 15px 225px 15px / 15px 225px 15px 255px;
}
.key-row { display: flex; gap: 8px; align-items: center; }
.key-row input { flex: 1; }
.modal-actions { display: flex; gap: 8px; margin-top: 18px; justify-content: flex-end; }

/* 便利贴提示 */
.sticky {
  position: fixed; z-index: 60; right: 16px; top: 60px;
  padding: 12px 18px; font-size: 15px;
  box-shadow: 3px 4px 0 rgba(58,58,58,.2);
  border: 2px solid var(--ink); border-radius: 2px 14px 2px 14px;
  transform: rotate(1deg); max-width: 60vw;
}
.sticky.error { background: #ffd0cc; color: #8a1f1a; }
.sticky.toast { background: #e7f4d0; }
.sticky.loading { background: #fff3b0; }

/* 历史菜单 */
.history-menu {
  position: fixed; z-index: 40; top: 66px; right: 110px;
  width: min(380px, 86vw);
  background: var(--paper); border: 2px solid var(--ink);
  box-shadow: 4px 5px 0 rgba(58,58,58,.2);
  padding: 10px 12px; border-radius: 4px 18px 4px 18px;
}
.history-title { font-weight: 600; margin-bottom: 6px; }
.history-item { padding: 7px 6px; border-bottom: 1px dashed var(--paper-line); cursor: pointer; }
.history-item:hover { background: rgba(246,195,67,.2); }
.hi-preview { font-family: Consolas, monospace; font-size: 12.5px; }
.hi-len { font-size: 11px; color: rgba(58,58,58,.5); }

/* 滚动条 */
::-webkit-scrollbar { width: 12px; }
::-webkit-scrollbar-thumb { background: rgba(58,58,58,.35); border-radius: 6px; border: 3px solid var(--paper); }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .code-panel, .trace-panel { max-height: 46vh; }
}
