/* ===== 托卡马克交互式 3D 模型 ===== */
:root {
  --ink: #141b2d;
  --deep: #1c2440;
  --teal: #2c3a6b;
  --accent: #2f6fb8;
  --accent2: #ffc94d;
  --panel: rgba(10, 28, 34, 0.86);
  --panel-border: rgba(120, 190, 210, 0.18);
  --text: #eaf4f7;
  --muted: #9db8c0;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: radial-gradient(1200px 800px at 50% 30%, #232c46 0%, #161c30 55%, #0e1220 100%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#leader-lines { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* ===== 加载画面 ===== */
#loader {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1000px 700px at 50% 40%, #232c46 0%, #161c30 60%, #0e1220 100%);
  transition: opacity 0.6s ease, visibility 0.6s;
}
#loader.done { opacity: 0; visibility: hidden; pointer-events: none; }
.loader-inner { text-align: center; padding: 24px; max-width: 520px; }
.loader-logo { display: flex; justify-content: center; margin-bottom: 18px; animation: spin 6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#loader h1 { font-size: 30px; letter-spacing: 2px; font-weight: 700; }
.loader-sub { color: var(--accent2); letter-spacing: 3px; font-size: 12px; margin: 10px 0 26px; }
.loader-bar { height: 4px; background: rgba(255,255,255,0.12); border-radius: 3px; overflow: hidden; }
#loader-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--teal), var(--accent2)); border-radius: 3px; transition: width 0.25s ease; }
#loader-text { margin-top: 12px; font-size: 13px; color: var(--muted); }

/* ===== 顶部栏 ===== */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; pointer-events: none;
}
.title-block h1 { font-size: 20px; font-weight: 700; letter-spacing: 1px; text-shadow: 0 2px 10px rgba(0,0,0,0.5); }
.title-block .subtitle { font-size: 12px; color: var(--accent2); letter-spacing: 1px; }
.top-actions { display: flex; gap: 8px; pointer-events: auto; }
.tb-btn {
  background: var(--panel); color: var(--text); border: 1px solid var(--panel-border);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; cursor: pointer; backdrop-filter: blur(8px);
  transition: background 0.2s, border-color 0.2s;
}
.tb-btn:hover { background: var(--teal); border-color: var(--accent2); }
.tb-btn.active { background: var(--accent); border-color: var(--accent2); }

/* ===== 部件面板 ===== */
#parts-panel {
  position: fixed; top: 84px; left: 16px; z-index: 20; width: 252px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px;
  backdrop-filter: blur(10px); display: flex; flex-direction: column; max-height: calc(100% - 210px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}
.panel-header { position: relative; padding: 13px 16px 10px; border-bottom: 1px solid var(--panel-border); }
.panel-header h2 { font-size: 15px; font-weight: 600; }
.panel-header .panel-hint { font-size: 11px; color: var(--muted); }
.collapse-btn {
  position: absolute; top: 10px; right: 10px; width: 24px; height: 24px;
  background: rgba(255,255,255,0.07); color: var(--muted); border: 1px solid var(--panel-border);
  border-radius: 6px; font-size: 12px; line-height: 1; cursor: pointer; transition: background 0.2s;
}
.collapse-btn:hover { background: var(--teal); color: var(--text); }
#parts-panel.collapsed #parts-list,
#parts-panel.collapsed .panel-footer { display: none; }
#parts-panel.collapsed .panel-header { border-bottom: 0; }
#parts-list { list-style: none; overflow-y: auto; padding: 6px; flex: 1; }
#parts-list::-webkit-scrollbar { width: 6px; }
#parts-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 3px; }
.part-item {
  display: flex; align-items: center; gap: 9px; padding: 8px 9px; border-radius: 8px;
  cursor: pointer; transition: background 0.15s; border: 1px solid transparent;
}
.part-item:hover { background: rgba(255,255,255,0.06); }
.part-item.active { background: rgba(77, 159, 230, 0.25); border-color: var(--accent); }
.part-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; box-shadow: 0 0 6px currentColor; }
.part-name { flex: 1; font-size: 13px; }
.part-eye { flex: none; width: 26px; height: 22px; display: flex; align-items: center; justify-content: center;
  border-radius: 5px; font-size: 14px; opacity: 0.75; }
.part-eye:hover { background: rgba(255,255,255,0.12); opacity: 1; }
.part-item.off .part-name { color: var(--muted); text-decoration: line-through; }
.part-item.off .part-eye { opacity: 0.3; }
.panel-footer { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--panel-border); }
.mini-btn {
  flex: 1; background: rgba(255,255,255,0.07); color: var(--text); border: 1px solid var(--panel-border);
  padding: 7px 6px; border-radius: 7px; font-size: 12px; cursor: pointer; transition: background 0.2s;
}
.mini-btn:hover { background: var(--teal); }

/* ===== 底部控制条 ===== */
#controls-bar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 22px; padding: 11px 20px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px; backdrop-filter: blur(10px);
}
.explode-group { display: flex; align-items: center; gap: 11px; }
.explode-group label { font-size: 13px; color: var(--text); white-space: nowrap; }
#explode { width: 190px; accent-color: var(--accent2); cursor: pointer; }
#explode-val { font-size: 12px; color: var(--accent2); width: 36px; }
.hint-text { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ===== 3D 标签 ===== */
.label3d {
  position: relative; pointer-events: auto; cursor: pointer;
  background: rgba(28, 36, 64, 0.92); color: #fff; font-size: 12.5px; padding: 5px 10px;
  border-radius: 6px; border: 1px solid rgba(255, 122, 26, 0.45); white-space: nowrap;
  transform: translate(-50%, -50%); transition: background 0.2s, transform 0.15s; user-select: none;
  box-shadow: 0 3px 12px rgba(0,0,0,0.4);
}
.label3d:hover { background: var(--accent); transform: translate(-50%, -50%) scale(1.07); }
.label3d.active { background: var(--accent); border-color: #fff; }
.label3d .lab-dot {
  position: absolute; left: 50%; bottom: -5px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent2); transform: translateX(-50%); box-shadow: 0 0 7px var(--accent2);
}

/* ===== 详情面板 ===== */
#detail-panel {
  position: fixed; top: 84px; right: 16px; z-index: 30; width: 340px; max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--accent); border-radius: 14px; padding: 20px;
  backdrop-filter: blur(12px); box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  animation: slideIn 0.28s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
#detail-panel.hidden { display: none; }
#detail-close { position: absolute; top: 10px; right: 12px; background: none; border: none; color: var(--muted);
  font-size: 24px; cursor: pointer; line-height: 1; }
#detail-close:hover { color: #fff; }
#detail-tag { display: inline-block; background: var(--accent); color: #fff; font-size: 11px; padding: 3px 9px;
  border-radius: 5px; letter-spacing: 1px; margin-bottom: 9px; }
#detail-title { font-size: 21px; font-weight: 700; margin-bottom: 2px; }
#detail-en { font-size: 12px; color: var(--accent2); letter-spacing: 1px; margin-bottom: 12px; }
#detail-desc { font-size: 13.5px; line-height: 1.75; color: #d7e6ea; }
#detail-facts { margin-top: 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fact { background: rgba(255,255,255,0.05); border: 1px solid var(--panel-border); border-radius: 8px; padding: 8px 10px; }
.fact .fk { font-size: 10.5px; color: var(--muted); letter-spacing: 0.5px; }
.fact .fv { font-size: 14px; font-weight: 600; color: #fff; margin-top: 2px; }

/* ===== 帮助弹窗 ===== */
#help-modal { position: fixed; inset: 0; z-index: 60; background: rgba(4, 12, 16, 0.7);
  display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); }
#help-modal.hidden { display: none; }
.help-card { position: relative; width: 480px; max-width: calc(100vw - 40px); background: var(--panel);
  border: 1px solid var(--panel-border); border-radius: 14px; padding: 26px 28px; }
.help-card h2 { margin-bottom: 14px; font-size: 19px; }
.help-card ul { list-style: none; }
.help-card li { font-size: 13.5px; padding: 6px 0; color: #d7e6ea; line-height: 1.6; }
.help-card b { color: var(--accent2); }
.help-card .credit { margin-top: 16px; font-size: 11.5px; color: var(--muted); line-height: 1.6;
  border-top: 1px solid var(--panel-border); padding-top: 12px; }
#help-close { position: absolute; top: 10px; right: 14px; background: none; border: none; color: var(--muted);
  font-size: 26px; cursor: pointer; }
#help-close:hover { color: #fff; }

/* ===== 响应式 ===== */
/* 平板：略缩窄面板，隐藏次要文字 */
@media (max-width: 1024px) {
  #parts-panel { width: 226px; }
  #detail-panel { width: 312px; }
  .hint-text { display: none; }
}

/* 手机（竖屏/横屏）或矮窗口：侧栏部件面板变为底部横条，控制条全宽，详情变底部抽屉 */
@media (max-width: 768px), (max-height: 540px) {
  /* 顶栏紧凑 */
  #topbar { padding: 10px 12px; }
  .title-block h1 { font-size: 16px; }
  .title-block .subtitle { font-size: 10px; }
  .tb-btn { padding: 7px 9px; font-size: 12px; }

  /* 部件面板 → 底部横向滚动条（含批量按钮） */
  #parts-panel {
    top: auto; left: 10px; right: 10px; bottom: 74px;
    width: auto; max-height: none; flex-direction: row; align-items: center;
    padding: 6px 8px;
  }
  .panel-header { display: none; }
  #parts-list {
    display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center;
    overflow-x: auto; overflow-y: hidden; gap: 5px; padding: 0; flex: 1 1 auto;
    -webkit-overflow-scrolling: touch; scrollbar-width: thin;
  }
  #parts-list::-webkit-scrollbar { height: 4px; }
  .part-item { flex: 0 0 auto; padding: 6px 8px; gap: 6px; }
  .part-name { font-size: 11px; white-space: nowrap; }
  .part-eye { width: 22px; height: 18px; }
  .panel-footer { display: flex; flex-direction: row; gap: 4px; padding: 0 0 0 6px; border-top: 0; flex: 0 0 auto; }
  .mini-btn { padding: 6px 8px; font-size: 10px; white-space: nowrap; }

  /* 控制条 → 全宽底栏 */
  #controls-bar { left: 10px; right: 10px; bottom: 10px; transform: none; padding: 8px 12px; gap: 10px; }
  .explode-group { flex: 1 1 auto; }
  #explode { flex: 1 1 auto; width: auto; }

  /* 详情面板 → 底部抽屉，可滚动 */
  #detail-panel {
    left: 10px; right: 10px; width: auto; top: auto; bottom: 138px;
    max-height: 44vh; overflow-y: auto; padding: 16px;
  }

  /* 标签更小，避免遮挡 */
  .label3d { font-size: 11px; padding: 4px 7px; }
}

/* 小屏手机：进一步压缩，按钮仅图标 */
@media (max-width: 480px) {
  .title-block .subtitle { display: none; }
  #topbar { padding: 8px 10px; }
  .title-block h1 { font-size: 15px; }
  .tb-btn { padding: 7px 8px; }
  .tb-txt { display: none; }            /* 顶栏按钮仅保留图标 */
  #detail-panel { bottom: 132px; }
  #detail-title { font-size: 18px; }
  #detail-facts { grid-template-columns: 1fr; }
  .label3d { font-size: 10px; padding: 3px 6px; }
}
