/* ============================================================
   小小魔方（魔方 AI 教学助手）— 样式
   主题与主站 my-docs-site 设计变量保持一致：
   暗色默认；[data-theme="light"] 亮色；与主站共用 localStorage 键 'theme'
   （令牌取值与 static/style.css 的 :root / [data-theme="light"] 一致）
   ============================================================ */
:root {
  /* —— 站点令牌（暗色，默认）—— */
  --bg: #0b1020; --bg-soft: #0f1730; --bg-elev: #121c38;
  --border: #24304f; --text: #dbe3f4; --text-dim: #93a0bd; --text-faint: #6b7899;
  --accent: #5eead4; --accent-soft: rgba(94, 234, 212, .12); --link: #7dd3fc;
  --code-bg: #0a1122;
  --radius: .75rem;
  --gold: #fbbf24; --gold-soft: rgba(251, 191, 36, .14);
  --danger: #f87171; --warn: #f59e0b;
  --topbar-h: 3.75rem;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Microsoft YaHei",
          "PingFang SC", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Consolas,
          "Cascadia Mono", Menlo, monospace;
  --shadow: 0 1rem 3rem rgb(0 0 0 / 45%);
  color-scheme: dark;

  /* —— 页面语义别名（沿用页面原有变量名，全部映射到站点令牌）—— */
  --panel: var(--bg-soft);
  --panel-2: var(--bg-elev);
  --muted: var(--text-dim);
  --primary: var(--accent);   /* 主操作按钮：实心 accent */
  --primary-ink: #04201c;     /* 主操作按钮上的文字 */
}

[data-theme="light"] {
  --bg: #f7f9fc; --bg-soft: #eef2f9; --bg-elev: #ffffff;
  --border: #dde4f0; --text: #1a2233; --text-dim: #5a6780; --text-faint: #8894ab;
  --accent: #0d9488; --accent-soft: rgba(13, 148, 136, .1); --link: #0369a1;
  --code-bg: #f1f5fb;
  --gold: #b45309; --gold-soft: rgba(180, 83, 9, .1);
  --danger: #dc2626; --warn: #b45309;
  --shadow: 0 1rem 3rem rgb(15 23 42 / 12%);
  color-scheme: light;

  --primary: var(--accent);
  --primary-ink: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  display: flex; flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  overflow: hidden;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 顶栏（与主站一致的站点头栏） ---------- */
.topbar {
  flex: 0 0 auto; z-index: 40;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brandrow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; row-gap: 8px; }
.back {
  display: inline-grid; place-items: center; width: 2.25rem; height: 2.25rem; flex: none;
  color: var(--accent); background: var(--accent-soft); border: 1px solid var(--border);
  border-radius: .55rem; text-decoration: none; font-size: 1.05rem; transition: .15s;
}
.back:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.seal {
  width: 40px; height: 40px; border-radius: 10px; flex: 0 0 auto;
  background: linear-gradient(160deg, var(--accent), var(--link)); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; letter-spacing: 1px;
  box-shadow: 0 4px 14px var(--accent-soft);
}
.brand-titles h1 { font-size: 19px; font-weight: 700; letter-spacing: .5px; white-space: nowrap; color: var(--text); }
.brand-titles .sub { font-size: 12.5px; color: var(--text-dim); }
.hright { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.theme-btn {
  width: 2.25rem; height: 2.25rem; flex: none; display: inline-grid; place-items: center;
  background: transparent; color: var(--text-dim); border: 1px solid var(--border);
  border-radius: .55rem; font-size: 1.05rem; cursor: pointer; transition: .15s; font-family: var(--font);
}
.theme-btn:hover { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.api-status { font-size: 12px; color: var(--muted); }
.api-status.up { color: var(--accent); }
.api-status.busy { color: var(--warn); }

/* 模块标签（窄屏单列时显示） */
.mod-tabs { display: none; gap: 6px; flex: 1; justify-content: center; min-width: 0; }
html[data-mode="phone"] .mod-tabs { display: flex; flex-wrap: wrap; }
.mod-tab {
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text-dim);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer;
  font-family: inherit; white-space: nowrap; transition: .15s;
}
.mod-tab:hover { border-color: var(--accent); color: var(--accent); }
.mod-tab.on { color: var(--primary-ink); background: var(--accent); border-color: var(--accent); font-weight: 600; }

/* ---------- 布局 ---------- */
.layout {
  flex: 1 1 auto; min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 2.05fr) minmax(0, 1fr);
  gap: 14px;
  padding: 14px 16px;
}
.left-col, .right-col { display: flex; flex-direction: column; gap: 14px; min-height: 0; min-width: 0; }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
.cube-panel { flex: 1 1 56%; }
.follow-panel { flex: 1 1 44%; }
.sol-a { flex: 0 0 40%; }
.sol-b { flex: 1 1 60%; }
.panel-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; row-gap: 6px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); flex: 0 0 auto;
}
.panel-head h2 {
  font-size: 14px; font-weight: 600; cursor: pointer; user-select: none;
  border-radius: 6px; padding: 2px 8px; margin: -2px -8px;
}
.panel-head h2:hover { color: var(--accent); background: var(--accent-soft); }
.cube-title-sub { font-size: 12px; color: var(--muted); }
.cube-title-sub:empty { display: none; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }

/* ---------- 按钮 ---------- */
.btn-sm, .btn {
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text);
  border-radius: .55rem; padding: 5px 11px; font-size: 12.5px; cursor: pointer;
  white-space: nowrap; transition: background .15s, border-color .15s, color .15s, opacity .15s;
  font-family: inherit;
}
.btn-sm:hover, .btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm:disabled, .btn:disabled { opacity: .45; cursor: not-allowed; color: var(--text-dim); border-color: var(--border); }
.btn-accent { background: var(--accent-soft); border-color: var(--border); color: var(--accent); }
.btn-accent:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn-primary:hover { color: var(--primary-ink); filter: brightness(1.08); }
.btn-primary:disabled { background: var(--bg-elev); border-color: var(--border); color: var(--text-faint); }
.btn-sm.on { outline: 2px solid var(--link); }

/* ---------- 视频学习 ---------- */
.demo-row { flex: 1 1 auto; display: flex; min-height: 0; }
.cube-view { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; position: relative; }
.cube-stages { flex: 1 1 auto; display: flex; min-height: 0; }
.cube-diag {
  flex: 0 0 25%; display: flex; align-items: center; justify-content: center;
  border-right: 1px solid var(--border); padding: 6px;
}
.cube-diag-stage {
  position: relative; width: 100%; height: 0; padding-bottom: 100%;
  max-height: 100%; max-width: 100%;
}
.cube-diag-label {
  position: absolute; left: 0; right: 0; top: -18px; text-align: center;
  font-size: 11px; color: var(--muted); white-space: nowrap;
}
.cube-stage { flex: 1 1 auto; position: relative; min-width: 0; }
.cube-canvas { position: absolute; left: 0; top: 0; display: block; }
.demo-voice-info {
  flex: 0 0 auto; min-height: 22px; padding: 3px 12px 6px;
  font-size: 12.5px; color: var(--text); line-height: 1.5;
}
.demo-voice-info.done { color: var(--accent); }
.demo-voice-info .step-label { color: var(--accent); font-weight: 600; }

/* 右侧公式循环演示小魔方 */
.formula-demo {
  flex: 0 0 22%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-left: 1px solid var(--border); padding: 6px 4px; gap: 2px;
}
.formula-cube { position: relative; width: 100%; height: 0; padding-bottom: 82%; }
.formula-view { font-size: 11px; color: var(--muted); }
.formula-side { text-align: center; }
.formula-count { font-size: 11px; color: var(--accent); }
.formula-move { font-size: 12px; color: var(--text); font-weight: 600; }

.control-bar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 14px; border-top: 1px solid var(--border); background: var(--bg);
}
.demo-progress { font-size: 12px; color: var(--muted); margin-left: auto; }

/* 倍速下拉 */
.speed-pick { position: relative; display: inline-block; }
.speed-trigger { display: inline-flex; align-items: center; gap: 5px; }
.speed-caret {
  width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid currentColor; opacity: .8;
}
.speed-menu {
  display: none; position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 30;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px; width: 165px; box-shadow: var(--shadow);
}
.speed-pick:hover .speed-menu, .speed-pick:focus-within .speed-menu { display: block; }
.speed-menu .speed-opt { display: block; width: 100%; text-align: left; margin-bottom: 5px; }
.speed-menu .speed-opt.on { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.speed-note { display: block; font-size: 11px; color: var(--muted); line-height: 1.45; margin-top: 4px; }

/* ---------- 跟随练习 ---------- */
.follow-main { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.cube-follows { flex: 0 0 58%; display: flex; min-height: 0; position: relative; }
.cube-follow-demo { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.cube-follow-stage { flex: 1 1 auto; position: relative; min-height: 0; }
.cube-follow { position: absolute; inset: 0; }
.follow-status { flex: 0 0 auto; padding: 4px 12px 8px; font-size: 12.5px; line-height: 1.55; color: var(--text); }
.follow-status.ok { color: var(--accent); }
.follow-status.warn { color: var(--warn); }
.cube-faces {
  flex: 0 0 32%; display: grid; grid-template-columns: repeat(2, 1fr); grid-auto-rows: 1fr;
  gap: 4px; padding: 6px; border-left: 1px solid var(--border); overflow: auto;
}
.cube-face-wrap { position: relative; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.cube-face { position: absolute; inset: 0; }
.cube-face-tag {
  position: absolute; left: 3px; top: 2px; font-size: 9.5px; color: var(--muted);
  background: color-mix(in srgb, var(--bg) 78%, transparent); border-radius: 4px; padding: 0 4px; pointer-events: none;
}
.follow-body {
  flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0;
  border-top: 1px solid var(--border); padding: 8px 12px; gap: 6px;
}
.follow-summary { font-size: 12.5px; color: var(--accent); flex: 0 0 auto; }
.follow-guide {
  flex: 1 1 auto; overflow: auto; font-size: 13px; line-height: 1.6; min-height: 0;
}
.follow-guide h4 { font-size: 13px; color: var(--accent); margin: 6px 0 3px; }
.follow-guide .cur-move {
  display: inline-block; font-size: 17px; font-weight: 700; letter-spacing: 1px;
  color: var(--gold); background: var(--gold-soft); border-radius: 6px; padding: 1px 8px;
}
.follow-guide .mv { display: inline-block; font-family: var(--mono); padding: 0 3px; color: var(--muted); }
.follow-guide .mv.done { color: var(--text-faint); }
.follow-guide .mv.cur { color: var(--gold); font-weight: 700; }
.follow-steps { flex: 0 0 auto; font-size: 12px; color: var(--muted); max-height: 76px; overflow: auto; line-height: 1.7; }
.follow-steps .st { display: inline-block; margin-right: 8px; }
.follow-steps .st.on { color: var(--accent); font-weight: 600; }
.follow-steps .st.done { color: var(--text-dim); }
.follow-controls { flex: 0 0 auto; display: flex; gap: 8px; }

/* ---------- 解法文字面板 ---------- */
.method-body { flex: 1 1 auto; overflow: auto; padding: 12px 16px; font-size: 13px; line-height: 1.75; min-height: 0; }
.method-body h3 {
  font-size: 13.5px; color: var(--accent); margin: 12px 0 4px;
  border-left: 3px solid var(--accent); padding-left: 8px;
}
.method-body h3:first-child { margin-top: 0; }
.method-para { margin: 3px 0; }
.method-para .lead { color: var(--muted); }
.alg, .method-body code {
  font-family: var(--mono); background: var(--code-bg); border: 1px solid var(--border);
  color: var(--link); border-radius: .3rem; padding: 0 5px; font-size: 12.5px;
}
.m-steps { margin: 4px 0 4px 18px; }
.m-steps li { margin: 3px 0; }
.m-formula {
  font-family: var(--mono); background: var(--accent-soft); color: var(--accent);
  border-radius: 6px; padding: 3px 9px; margin: 4px 0; display: inline-block; font-size: 12.5px;
}
.m-formula .mf-label { color: var(--muted); margin-right: 4px; font-family: inherit; }
.m-formula .f-note { color: var(--muted); font-size: 11.5px; margin-left: 4px; }
.method-tip {
  margin-top: 12px; padding: 9px 11px; border-radius: 8px; font-size: 12.5px;
  background: var(--accent-soft);
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, transparent); line-height: 1.7;
}
.notation-wrap { overflow: auto; margin: 6px 0; }
table.notation { border-collapse: collapse; font-size: 12.5px; width: 100%; }
table.notation th, table.notation td { border: 1px solid var(--border); padding: 3px 8px; text-align: left; }
table.notation th { background: var(--panel-2); color: var(--muted); font-weight: 500; }
.notation-note { color: var(--muted); font-size: 12px; }

/* ---------- 弹窗 ---------- */
.diag-mask {
  position: fixed; inset: 0; z-index: 100; background: rgb(2 6 23 / 78%);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
[data-theme="light"] .diag-mask { background: rgb(15 23 42 / 45%); }
.diag-mask.hidden, .hidden { display: none !important; }
.diag-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(1080px, 96vw); max-height: 92vh; display: flex; flex-direction: column;
  padding: 14px 18px; gap: 10px; overflow: auto; box-shadow: var(--shadow);
}
.diag-box h3 { font-size: 15px; }
.fill-layout { display: flex; gap: 14px; min-height: 0; }
.fill-3d-wrap { flex: 1 1 52%; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.fill-cube { position: relative; width: 100%; height: 0; padding-bottom: 78%; border: 1px solid var(--border); border-radius: 10px; }
.fill-hint { font-size: 11.5px; color: var(--muted); }
.fill-side { flex: 1 1 48%; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.fill-side-title { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.color-chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.color-chip {
  width: 34px; height: 34px; border-radius: 8px; border: 2px solid var(--border); cursor: pointer;
}
.color-chip.on { outline: 3px solid var(--accent); }
.fill-net { display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; width: 100%; }
.fill-net .fn-cell {
  aspect-ratio: 1 / 1; border-radius: 3px; border: 1px solid rgba(0, 0, 0, .5); cursor: pointer;
}
.fill-net .fn-center { border: 2px solid var(--text); }
.fill-net .fn-gap { visibility: hidden; }
.fill-stats { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; }
.fill-stats span { font-family: var(--mono); }
.fill-err { min-height: 17px; font-size: 12px; color: var(--danger); }
.diag-actions { display: flex; justify-content: flex-end; gap: 8px; }
.fill-cam-row { display: flex; gap: 12px; align-items: flex-start; }
.pc-cam-wrap { position: relative; width: 300px; flex: 0 0 auto; aspect-ratio: 1/1; background: #000; border-radius: 10px; overflow: hidden; }
.pc-cam-wrap video, .pc-cam-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pc-cam-side { flex: 1 1 auto; }
.pc-guide { font-size: 12.5px; line-height: 1.6; color: var(--muted); }
.pc-btns { display: flex; gap: 8px; margin: 8px 0; }
.pc-status { font-size: 12px; color: var(--warn); min-height: 17px; }

/* 最大化面板 */
body.panel-max .left-col .panel:not(.is-max),
body.panel-max .right-col { display: none; }
body.panel-max .panel.is-max { flex: 1 1 100% !important; }

/* ---------- 窄屏：单列 + 标签页 ---------- */
@media (max-width: 1080px) {
  body { overflow: auto; display: block; height: auto; }
  .layout { grid-template-columns: 1fr; height: auto; flex: none; }
  .left-col, .right-col { display: block; }
  .panel { margin-bottom: 12px; height: min(78vh, 720px); }
  html[data-mode="phone"] .panel { display: none; }
  html[data-mode="phone"] .panel.active { display: flex; }
  html[data-mode="phone"] .panel { height: calc(100vh - var(--topbar-h) - 2.5rem); }
  /* 窄屏把模块标签整体压到顶栏下一行，标题行只留「返回 + 印章 + 标题 + 状态/主题/全屏」 */
  html[data-mode="phone"] .mod-tabs { order: 9; flex-basis: 100%; justify-content: flex-start; }
  .formula-demo { flex-basis: 26%; }
}