/* ============================================================
 * style.css — 数字电路实验室
 * ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0f1620;
  --panel: #16202d;
  --panel2: #1c2735;
  --border: #2a3a4d;
  --text: #c8d6e5;
  --text-dim: #6b7f93;
  --accent: #5db0ff;
  --accent2: #ffe066;
  --danger: #ff6b6b;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  display: flex;
  flex-direction: column;   /* 纵向：Tab 栏在上，内容在下 */
  height: 100vh;
}

/* ---------- Tab 栏（2026-08-20 慕慕打磨：index.html 原来漏了此样式，显示成蓝色链接）---------- */
#tabbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.tab {
  padding: 7px 16px;
  border-radius: 8px;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
}
.tab:hover { border-color: var(--accent); }
.tab.active { background: #1e5aa8; border-color: #2f7bd6; color: #fff; }
.tab-title { margin-left: auto; font-size: 12px; color: var(--text-dim); }

#app-body {
  flex: 1;
  display: flex;
  min-height: 0;            /* 允许内容区收缩 */
}

/* ---------- 侧栏 ---------- */
#sidebar {
  width: 230px;
  min-width: 230px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.logo {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #1a2c42, #16202d);
}
.logo-ic { font-size: 26px; }
.logo-title { font-weight: 700; font-size: 15px; color: #fff; }
.logo-sub { font-size: 11px; color: var(--text-dim); }

.lib { padding: 10px; flex: 1; }
.cat {
  font-size: 12px; color: var(--accent);
  margin: 12px 0 6px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.lib-item {
  display: flex; flex-direction: column; align-items: flex-start;
  width: 100%; padding: 7px 10px; margin-bottom: 5px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: all .15s;
}
.lib-item:hover { border-color: var(--accent); background: #21324a; transform: translateX(2px); }
.lib-name { font-family: monospace; font-weight: 700; font-size: 13px; }
.lib-desc { font-size: 11px; color: var(--text-dim); }

.hint {
  padding: 10px 14px 16px;
  font-size: 11px; color: var(--text-dim);
  border-top: 1px solid var(--border);
}
.hint p { color: var(--text); font-weight: 600; margin-bottom: 6px; }
.hint ul { padding-left: 16px; }
.hint li { margin: 3px 0; }

/* ---------- 主区 ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#toolbar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.tb-btn {
  padding: 6px 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.tb-btn:hover { border-color: var(--accent); }
.tb-btn.primary { background: #1e5aa8; border-color: #2f7bd6; font-weight: 700; }
.tb-btn.primary.active { background: #b3541e; border-color: #e67e22; }
.tb-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }

#btnExample { display: none; }  /* 桌面用原生下拉 */
.sel {
  padding: 6px 8px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.speed-label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }
.speed-label input[type=range] { width: 90px; accent-color: var(--accent); }

.sim-time { font-family: monospace; font-size: 12px; color: var(--accent2); }

.status { font-size: 12px; color: var(--text-dim); margin-left: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 380px; }
.status.warn { color: var(--danger); font-weight: 600; }

/* ---------- 画布 ---------- */
#canvasWrap { flex: 1; position: relative; min-height: 0; }
#canvas { width: 100%; height: 100%; display: block; cursor: crosshair; background: #101823; }

/* ---------- 波形面板（可拖拽调高） ---------- */
#wavePanel {
  height: 220px;
  min-height: 100px;
  max-height: 70vh;
  background: var(--panel);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
}
#waveDrag {
  position: absolute;
  top: -5px;
  left: 0;
  right: 0;
  height: 10px;
  cursor: ns-resize;
  z-index: 10;
}
#waveDrag:hover { background: rgba(93, 176, 255, 0.25); }
.wave-head {
  padding: 5px 12px;
  font-size: 12px; font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.wave-tip { font-weight: 400; font-size: 11px; color: var(--text-dim); }
#wave { flex: 1; width: 100%; display: block; background: #121b28; }

/* ---------- 时钟频率设置弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(8, 12, 18, 0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
.modal-box {
  background: #1a2432;
  border: 1px solid #3f5b7a;
  border-radius: 10px;
  padding: 18px 22px;
  width: 320px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
.modal-title {
  font-size: 14px; font-weight: 700; color: #e8eef5;
  margin-bottom: 14px;
}
.modal-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px;
}
.modal-row label { color: #9db1c7; font-size: 12px; flex: 1; }
.modal-row input {
  width: 90px;
  background: #0f1824;
  border: 1px solid #3f5b7a;
  border-radius: 6px;
  color: #e8eef5;
  padding: 6px 8px;
  font-size: 13px;
  text-align: center;
}
.modal-row input:focus { outline: none; border-color: #5db0ff; }
.modal-unit { color: #6b7f93; font-size: 12px; }
.modal-hint {
  font-size: 11px; color: #7d93a9;
  background: #101a27;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 8px 0 14px;
  line-height: 1.7;
}
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ---------- 示例教学说明条 ---------- */
.explain-bar {
  position: absolute;
  left: 12px; right: 12px; bottom: 12px;
  background: rgba(15, 24, 38, 0.95);
  border: 1px solid #5db0ff;
  border-left: 4px solid #5db0ff;
  border-radius: 8px;
  color: #dbe7f3;
  font-size: 12px;
  line-height: 1.7;
  padding: 10px 38px 10px 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  white-space: pre-line;
  z-index: 20;
}
.explain-close {
  position: absolute;
  top: 6px; right: 8px;
  background: none;
  border: none;
  color: #8aa0b5;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
}
.explain-close:hover { color: #fff; }

/* ═══════════ 手机版（演示用）═══════════ */
@media (max-width: 900px) {
  /* 整页可滚动：波形面板必须能滑到（html/body 都要放开） */
  html, body { height: auto; overflow: visible; }
  #app { height: auto; min-height: 100vh; }
  #app-body { flex-direction: column; height: auto; }
  #main { display: block; height: auto; }
  body { overflow-y: visible; -webkit-overflow-scrolling: touch; }
  /* 侧栏 → 顶部横条，元件库横滑 */
  #sidebar {
    width: 100%; min-width: 0; max-height: 150px;
    display: flex; flex-direction: column;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  /* 手机端隐藏 logo 区（Tab 栏已有标题，省出画布空间——2026-08-20 慕慕精简） */
  #sidebar .logo { display: none !important; }
  #sidebar .logo-sub { display: none; }
  #sidebar .hint { display: none; }
  #lib { display: flex; flex-direction: column; gap: 0; padding: 0; overflow-x: visible; flex: 1; }  /* 手机平铺：面板占满全宽 */
  #lib::-webkit-scrollbar { height: 3px; }
  #lib::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }
  .cat { flex-shrink: 0; margin: 4px 2px 0 0; font-size: 11px; }
  .lib-item {
    flex-shrink: 0; width: auto; min-width: 78px;
    padding: 8px 10px; margin-bottom: 0;
    align-items: center; text-align: center;
  }
  .lib-name { font-size: 12px; }
  .lib-desc { display: none; }
  /* 工具栏换行 + 紧凑 */
  #toolbar { flex-wrap: wrap; padding: 5px 6px; gap: 4px; }
  .tb-btn { padding: 7px 9px; font-size: 11px; }
  .tb-btn .lbl { display: none; }
  .sel { display: none; }  /* 手机端隐藏原生下拉（浏览器兼容差），用示例面板 */
  #btnExample { display: inline-flex !important; }
  /* 手机端隐藏低频按钮：保存/加载（省空间给画布——2026-08-20 慕慕精简） */
  #btnSave, #btnLoad { display: none !important; }
  .sim-time { font-size: 12px; }
  .status { font-size: 12px; max-width: 160px; }
  /* 示例面板：说明文字加大 + 关闭按钮更醒目（2026-08-20 慕慕打磨） */
  #examplePanel .ex-item-desc { font-size: 12px !important; color: #94A3B8 !important; }
  #examplePanel .ex-close { font-size: 14px !important; }
  /* 画布占主体（块级，height 直接生效，不被 flex 压缩）——2026-08-20 加大到 68vh */
  #canvasWrap { height: 68vh; min-height: 380px; }
  /* 波形：正常高度，整页滚动可达 */
  #wavePanel { height: 240px; min-height: 140px; }
  #waveDrag { padding: 2px 0; }
  /* 速度滑块 */
  #speedWrap { display: flex; align-items: center; gap: 4px; }
  #speed { width: 60px; }
  /* 手机端速度行最小化：隐藏"速度"文字，只留滑块+数值（2026-08-20 慕慕精简） */
  .speed-label { font-size: 0; }
  .speed-label #speedVal { font-size: 10px; color: var(--text-dim); margin-left: 2px; }
  /* Tab 栏压缩 */
  #tabbar { padding: 4px 8px; gap: 4px; }
  #tabbar .tab { padding: 5px 10px; font-size: 12px; }
  #tabbar .tab-title { font-size: 10px; }

  /* ── 手机版元件库：分类 Tab + 面板（2026-08-20 慕慕打磨）── */
  .lib-tabs { display: flex; gap: 4px; padding: 2px 12px 0; flex-shrink: 0; }
  .lib-tab {
    flex: 1; padding: 7px 2px; font-size: 11px; font-weight: 700;
    color: var(--text-dim); background: #16213a; border: 1px solid var(--border);
    border-bottom: none; border-radius: 8px 8px 0 0; cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .lib-tab.active { color: #ffd9a0; background: #1d2a47; border-color: var(--accent); }
  .lib-panel {
    flex-wrap: nowrap;  /* 单行横滑（2026-08-20 慕慕按主人意见：所有元件横着排，左右滑动找） */
    gap: 6px; padding: 6px 10px 8px;
    overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    align-items: stretch;
  }
  .lib-panel::-webkit-scrollbar { height: 3px; }
  .lib-panel::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }
  .lib-panel .lib-item {
    min-width: 0; flex: 0 0 62px; max-width: none;
    padding: 6px 2px; margin: 0; border-radius: 10px;
    flex-direction: column; gap: 2px; justify-content: center;
    border: 1px solid var(--border); background: #16213a;
  }
  .lib-panel .lib-item:active { transform: scale(.96); }
  .lib-panel .lib-item.picked {
    border-color: var(--accent); background: #26355a;
    box-shadow: 0 0 0 1px var(--accent), 0 4px 14px rgba(245,197,66,.15);
  }
  .lib-panel .lib-item .lib-ic { flex: 0 0 22px; }
  .lib-panel .lib-item .lib-ic svg { width: 26px; height: 17px; }
  .lib-panel .lib-item .lib-name { font-size: 10px; min-width: 0; }
  .lib-panel .lib-item .lib-desc { display: none; }  /* 手机紧凑模式：隐藏描述 */
  /* 手机版引导浮层：紧凑条状，不挡画布中心 */
  #firstGuide {
    max-width: 88% !important; padding: 12px 16px !important;
    font-size: 12px !important; line-height: 1.7 !important;
    top: 30% !important;
  }
  /* 手机版主操作按钮：运行更突出（演示主角） */
  #btnRun.tb-btn.primary {
    flex: 1.4; font-size: 13px; padding: 10px 6px;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    border: none; color: #06210f;
    box-shadow: 0 3px 14px rgba(34,197,94,.35);
    border-radius: 10px; font-weight: 800;
  }
  #btnRun.tb-btn.primary:active { transform: scale(.95); }
  /* 手机端隐藏低频按钮（导入/导出/图片——演示不常用，减少拥挤） */
  #btnImport, #btnExport, #btnPng { display: none !important; }
}

/* ---- 元件库实物图标（Coder 版） ---- */
.lib-item { display: flex; align-items: center; gap: 8px; }
.lib-ic { flex: 0 0 34px; display: flex; align-items: center; justify-content: center; }
.lib-ic svg { width: 34px; height: 22px; display: block; }
.lib-item .lib-name { flex: 0 0 auto; min-width: 52px; }
.lib-item .lib-desc { flex: 1; }
