/* ==========================================================================
   魔方复原系统 — 样式
   浅色主题，桌面优先；窄屏自动改为上下堆叠。
   ========================================================================== */

:root {
  --bg:        #eef1f6;
  --panel:     #ffffff;
  --panel-2:   #f7f9fc;
  --line:      #e2e7ef;
  --line-2:    #eef2f7;
  --text:      #1b1f27;
  --text-2:    #4a5361;
  --muted:     #77808f;
  --accent:    #2563eb;
  --accent-2:  #1d4ed8;
  --accent-bg: #e9f0fe;
  --ok:        #0f9d58;
  --warn:      #d97706;
  --err:       #dc2626;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px -12px rgba(16, 24, 40, .18);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

/* 魔方六面标准配色 */
:root {
  --f-u: #f4f6f8;
  --f-d: #f3c400;
  --f-f: #0d9d4f;
  --f-b: #1656b8;
  --f-r: #c4262e;
  --f-l: #f2760f;
}

* { box-sizing: border-box; }

/* 必须显式声明：任何设了 display 的类都会盖掉 hidden 属性的浏览器默认样式，
   导致「已隐藏」的遮罩仍然占据布局并拦截指针事件。 */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: .01em; }
p { margin: 0; }
code {
  font-family: var(--mono);
  font-size: .92em;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}

/* ============================ 顶栏 ============================ */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  height: 62px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  width: 34px; height: 34px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  background: #16191f;
  border-radius: 9px;
  flex: 0 0 auto;
}
.logo i { border-radius: 3px; display: block; }
.logo .lg-u { background: var(--f-u); }
.logo .lg-r { background: var(--f-r); }
.logo .lg-f { background: var(--f-f); }
.logo .lg-d { background: var(--f-d); }

.brand-text h1 { font-size: 16px; line-height: 1.25; }
.brand-text p { font-size: 12px; color: var(--muted); line-height: 1.3; }

.statusbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
}
.pill b { font-weight: 650; color: var(--text); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.pill.is-dirty .dot { background: var(--warn); }
.pill-dim { color: var(--muted); }

/* ============================ 主区 ============================ */

.stage {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.viewport {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, #ffffff 0%, #e9edf4 55%, #dfe5ee 100%);
  overflow: hidden;
}

#cube-host { position: absolute; inset: 0; }

/* 必须显式给出 CSS 尺寸：CubeView 用 setSize(w, h, false)（不写 style），
   否则 canvas 会按 width/height 属性以 devicePixelRatio 倍的尺寸显示，
   被 overflow:hidden 裁掉大半，鼠标坐标也随之全部错位。 */
#cube-host canvas { display: block; width: 100%; height: 100%; touch-action: none; }

.viewport-tools {
  position: absolute;
  top: 14px; right: 14px;
  display: flex; gap: 8px;
  z-index: 3;
}

.icon-btn {
  height: 30px; padding: 0 12px;
  font: inherit; font-size: 12.5px;
  color: var(--text-2);
  background: rgba(255, 255, 255, .86);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: #fff; color: var(--text); border-color: #cfd6e2; }

.playbar {
  position: absolute;
  left: 50%; bottom: 22px;
  transform: translateX(-50%);
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
  padding: 9px;
  background: rgba(255, 255, 255, .82);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  z-index: 3;
  max-width: calc(100% - 28px);
}

.nowplaying {
  position: absolute;
  left: 50%; bottom: 86px;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
  padding: 7px 14px;
  background: rgba(27, 31, 39, .88);
  color: #fff;
  border-radius: 999px;
  font-size: 13px;
  z-index: 4;
  pointer-events: none;
  box-shadow: 0 10px 26px -10px rgba(0, 0, 0, .5);
}
.np-label { color: rgba(255, 255, 255, .62); font-size: 12px; }
.np-move { font-family: var(--mono); font-weight: 700; font-size: 15px; min-width: 30px; text-align: center; }
.np-count { color: rgba(255, 255, 255, .62); font-size: 12px; font-variant-numeric: tabular-nums; }

.busy {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  /* ⚠️ 这里**不能**用 backdrop-filter：全屏背景模糊会让浏览器每帧对整块视口
     重新做一次模糊光栅化。实测把 23 步转动动画从 188ms/步拖到 524ms/步（2.8 倍），
     而且遮罩隐藏后光栅化积压仍会持续拖慢后续动画。改用纯半透明底色。 */
  background: rgba(240, 243, 248, .82);
  font-size: 14px; color: var(--text-2);
  z-index: 6;
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(37, 99, 235, .25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================ 侧栏 ============================ */

.sidebar {
  flex: 0 0 396px;
  width: 396px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  min-height: 0;
}

.tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--line);
}
.tab {
  flex: 1 1 0;
  height: 36px;
  font: inherit; font-size: 13.5px; font-weight: 550;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 7px 7px 0 0;
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s;
}
.tab:hover { color: var(--text-2); background: var(--panel-2); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.panels { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; }
.panel { display: none; padding: 14px; }
.panel.is-active { display: block; }

/* ---------- 卡片 ---------- */

.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card:last-child { margin-bottom: 0; }
.card-flat { background: transparent; border: 0; padding: 2px 2px 10px; }
.card h2 { font-size: 13.5px; margin-bottom: 6px; }
.card .muted { font-size: 12.5px; color: var(--muted); }

.muted { color: var(--muted); }

.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.row-wrap { flex-wrap: wrap; }

/* ---------- 按钮 ---------- */

.btn {
  height: 34px; padding: 0 14px;
  font: inherit; font-size: 13px; font-weight: 550;
  color: var(--text-2);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover:not(:disabled) { background: #fff; border-color: #cfd6e2; color: var(--text); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary {
  color: #fff; background: var(--accent); border-color: var(--accent);
  box-shadow: 0 1px 2px rgba(37, 99, 235, .3);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }

.btn-ghost { background: transparent; }
.btn-sm { height: 29px; padding: 0 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ---------- 输入 ---------- */

input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  height: 34px;
  padding: 0 11px;
  font: inherit;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
input[type="text"].is-bad { border-color: var(--err); box-shadow: 0 0 0 3px rgba(220, 38, 38, .1); }

.err { margin-top: 8px; font-size: 12.5px; color: var(--err); }

/* ---------- 转动按钮网格 ---------- */

.movegrid { margin-top: 10px; display: flex; flex-direction: column; gap: 7px; }

.moverow { display: flex; align-items: center; gap: 7px; }
.moverow .rowlabel {
  flex: 0 0 22px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 13px;
  color: var(--text-2);
  text-align: center;
}
.moverow .facechip {
  flex: 0 0 6px; height: 22px; border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, .12);
}

.mv {
  flex: 1 1 0;
  height: 32px;
  font: inherit;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.mv:hover:not(:disabled) { background: var(--accent-bg); border-color: #c7d9fb; color: var(--accent-2); }
.mv:active:not(:disabled) { transform: translateY(1px); }
.mv:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 预设公式 chips ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  height: 26px; padding: 0 10px;
  font: inherit; font-family: var(--mono); font-size: 12px;
  color: var(--text-2);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s;
}
.chip:hover:not(:disabled) { background: var(--accent-bg); border-color: #c7d9fb; color: var(--accent-2); }
.chip:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 图例 ---------- */

.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.legend i {
  width: 12px; height: 12px; border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, .14);
  display: block;
}

/* ---------- 教程手风琴 ---------- */

.accordion { display: flex; flex-direction: column; gap: 8px; padding: 0 14px 14px; }

.acc {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.acc.is-open { border-color: #c7d9fb; box-shadow: 0 6px 18px -12px rgba(37, 99, 235, .5); }

.acc-head {
  width: 100%;
  display: flex; align-items: center; gap: 10px;
  padding: 11px 13px;
  font: inherit; text-align: left;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.acc-head:hover { background: var(--panel-2); }

.acc-num {
  flex: 0 0 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: 12.5px; font-weight: 700;
}
.acc.is-open .acc-num { background: var(--accent); color: #fff; }

.acc-title { flex: 1 1 auto; min-width: 0; }
.acc-title b { display: block; font-size: 13.5px; font-weight: 600; }
.acc-title span { display: block; font-size: 12px; color: var(--muted); }

.acc-caret {
  flex: 0 0 auto;
  width: 18px; height: 18px;
  color: var(--muted);
  transition: transform .2s;
}
.acc.is-open .acc-caret { transform: rotate(180deg); }

.acc-body { display: none; padding: 0 13px 13px; }
.acc.is-open .acc-body { display: block; }

.acc-body .goal {
  font-size: 13px;
  color: var(--text-2);
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: 0 7px 7px 0;
  padding: 9px 11px;
  margin-bottom: 11px;
}
.acc-body .goal b { color: var(--text); }

.acc-body h4 {
  font-size: 12px; font-weight: 650;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin: 0 0 6px;
}

.acc-body ul { margin: 0 0 12px; padding-left: 18px; }
.acc-body li { font-size: 13px; color: var(--text-2); margin-bottom: 5px; }
.acc-body li:last-child { margin-bottom: 0; }

.algrow {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 0;
  border-top: 1px solid var(--line-2);
}
.algrow:first-of-type { border-top: 0; }
.algrow .algtext { flex: 1 1 auto; min-width: 0; }
.algrow .algseq {
  font-family: var(--mono);
  font-size: 13.5px; font-weight: 600;
  color: var(--text);
  display: block;
  word-break: break-word;
}
.algrow .algname { font-size: 12px; color: var(--muted); display: block; margin-top: 2px; }

/* ---------- 分步求解结果 ---------- */

.summary {
  margin-top: 11px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.summary div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.summary span { display: block; font-size: 11.5px; color: var(--muted); }
.summary b { display: block; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

.stagelist { display: flex; flex-direction: column; gap: 8px; padding: 0 14px 14px; }

.sg {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}
.sg.is-current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.sg.is-done { border-color: #bfe6cd; }

.sg-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
}
.sg-num {
  flex: 0 0 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12.5px; font-weight: 700;
  color: var(--text-2);
}
.sg.is-current .sg-num { background: var(--accent); border-color: var(--accent); color: #fff; }
.sg.is-done .sg-num { background: #e8f7ee; border-color: #bfe6cd; color: var(--ok); }

.sg-title { flex: 1 1 auto; min-width: 0; }
.sg-title b { display: block; font-size: 13.5px; font-weight: 600; }
.sg-title span { display: block; font-size: 12px; color: var(--muted); }

.sg-seq {
  padding: 0 12px 10px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-2);
  word-break: break-word;
  line-height: 1.75;
}
.sg-seq .tok {
  display: inline-block;
  padding: 1px 5px;
  margin: 0 2px 2px 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
}
.sg-seq .tok.is-now { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.sg-seq .tok.is-past { opacity: .4; }
.sg-seq .none { color: var(--muted); font-family: inherit; }

.sg-actions { display: flex; gap: 7px; padding: 0 12px 11px; }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 26px 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
}

/* ============================ 轻提示 ============================ */

.toast {
  /* 定位在顶栏下方，避免与底部播放条 / "正在执行"条重叠 */
  position: fixed;
  left: 50%;
  top: 74px;
  transform: translate(-50%, -14px);
  max-width: min(560px, calc(100vw - 40px));
  padding: 10px 18px;
  background: rgba(27, 31, 39, .93);
  color: #fff;
  font-size: 13.5px;
  line-height: 1.5;
  border-radius: 10px;
  box-shadow: 0 14px 34px -14px rgba(0, 0, 0, .6);
  opacity: 0;
  pointer-events: none;
  z-index: 50;
  transition: opacity .22s ease, transform .22s ease;
}
.toast.is-show { opacity: 1; transform: translate(-50%, 0); }
.toast.is-ok  { background: rgba(15, 90, 54, .95); }
.toast.is-err { background: rgba(150, 30, 30, .95); }

/* ============================ 窄屏 ============================ */

@media (max-width: 940px) {
  body { overflow: auto; }
  .stage { flex-direction: column; }
  .viewport { flex: 0 0 auto; height: 58vh; min-height: 340px; }
  .sidebar {
    flex: 1 1 auto;
    width: 100%;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
  .panels { overflow: visible; }
  .topbar { height: auto; padding: 10px 14px; flex-wrap: wrap; }
  .pill-dim { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
