:root {
  --bg-0: #07080b;
  --bg-1: #121620;
  --panel: rgba(20, 23, 31, 0.74);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #eceef3;
  --text-2: #a3a9b6;
  --text-3: #6d7482;
  --accent: #ff4fd8; /* 和 3D 箭头同色 */
  --danger: #ff5a6a;
  --radius: 16px;
  --mono: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(1100px 760px at 50% 42%, #1c2230 0%, var(--bg-1) 35%, var(--bg-0) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

button { font: inherit; color: inherit; cursor: pointer; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; touch-action: none; cursor: grab; }
#stage canvas:active { cursor: grabbing; }
body.hovering-sticker #stage canvas { cursor: pointer; }

/* ---------- 面板 ---------- */
.panel {
  position: fixed;
  top: 24px;
  background: var(--panel);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.panel-left { left: 24px; width: 232px; }
.panel-right { right: 24px; width: 316px; max-height: calc(100vh - 48px); overflow: auto; }

.input-ui { transition: opacity 0.8s ease, transform 0.8s ease; }
body.teaching .input-ui { opacity: 0; pointer-events: none; }
body.teaching .panel-left { transform: translateX(-24px); }
body.teaching .panel-right { transform: translateX(24px); }
body.teaching .hint { transform: translate(-50%, 16px); }

.brand { margin-bottom: 22px; }
.brand-title { font-size: 20px; font-weight: 700; letter-spacing: 0.5px; }
.brand-sub { margin-top: 6px; font-size: 13px; color: var(--text-2); line-height: 1.5; }

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 1px;
  margin-bottom: 12px;
}

/* 阶数选择 */
.order-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.order-item {
  position: relative;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 12px 10px 10px;
  text-align: left;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.order-item:hover { background: rgba(255, 255, 255, 0.06); }
.order-item:active { transform: scale(0.97); }
.order-item .oi-grid {
  width: 28px;
  height: 28px;
  display: grid;
  gap: 2px;
  margin-bottom: 8px;
}
.order-item .oi-grid i { background: #59606d; border-radius: 2px; }
.order-item .oi-name { font-size: 14px; font-weight: 600; }
.order-item .oi-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.order-item.active { border-color: rgba(255, 255, 255, 0.85); background: rgba(255, 255, 255, 0.08); }
.order-item.active .oi-grid i:nth-child(3n + 1) { background: #ffd21f; }
.order-item.active .oi-grid i:nth-child(3n + 2) { background: #12a150; }
.order-item.active .oi-grid i:nth-child(3n) { background: #ff6d12; }
.order-item.locked { opacity: 0.5; }
.order-item .oi-lock { position: absolute; top: 10px; right: 10px; width: 14px; height: 14px; color: var(--text-2); }

/* 填色说明 */
.guide { margin: 0 0 18px; padding-left: 18px; font-size: 13px; line-height: 1.65; color: var(--text-2); }
.guide li { margin-bottom: 4px; }
.guide b { color: var(--text); font-weight: 600; }

.progress-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-2); }
.progress-row b { color: var(--text); font-size: 15px; }
.progress { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.08); margin: 8px 0 16px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, #9aa3b5, #fff); border-radius: 3px; transition: width 0.3s ease; }

.color-counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 16px; }
.cc {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
  color: var(--text-2);
}
.cc i { width: 14px; height: 14px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }
.cc b { color: var(--text); font-weight: 600; margin-left: auto; font-variant-numeric: tabular-nums; }
.cc.full b { color: #7be0a0; }
.cc.over { background: rgba(255, 90, 106, 0.14); }
.cc.over b { color: var(--danger); }

.error-box {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 90, 106, 0.12);
  border: 1px solid rgba(255, 90, 106, 0.35);
  color: #ffc2c8;
  font-size: 13px;
  line-height: 1.6;
}
.error-box p { margin: 0; }
.error-box p + p { margin-top: 6px; }

.tool-row { display: flex; justify-content: space-between; margin-bottom: 12px; }
.btn-text {
  background: none;
  border: none;
  padding: 4px 0;
  font-size: 13px;
  color: var(--text-2);
}
.btn-text:hover { color: var(--text); }

.btn-done {
  width: 100%;
  height: 48px;
  border-radius: 12px;
  border: none;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  background: #fff;
  color: #0b0d12;
  transition: background 0.35s, color 0.35s, box-shadow 0.35s, transform 0.15s;
  box-shadow: 0 8px 28px rgba(255, 255, 255, 0.18);
}
.btn-done:not(:disabled):hover { transform: translateY(-1px); }
.btn-done:not(:disabled):active { transform: scale(0.98); }
.btn-done:disabled {
  background: #3a3f49;
  color: #7d8494;
  box-shadow: none;
  cursor: not-allowed;
}

.hint {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  font-size: 13px;
  color: var(--text-3);
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- 颜色选择弹窗 ---------- */
.picker {
  position: fixed;
  z-index: 20;
  width: 232px;
  padding: 14px;
  background: rgba(24, 27, 36, 0.94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  animation: pop 0.16s ease-out;
}
.picker[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: scale(0.94); } to { opacity: 1; transform: scale(1); } }
.picker-title { font-size: 12px; color: var(--text-3); margin-bottom: 10px; }
.picker-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px 7px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.swatch:hover:not(:disabled) { background: rgba(255, 255, 255, 0.09); }
.swatch:active:not(:disabled) { transform: scale(0.95); }
.swatch.current { border-color: rgba(255, 255, 255, 0.7); }
.swatch:disabled { opacity: 0.3; cursor: not-allowed; }
.swatch i { width: 34px; height: 34px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }
.swatch span { font-size: 12px; color: var(--text-2); }
.swatch span em { font-style: normal; color: var(--text-3); margin-left: 3px; font-variant-numeric: tabular-nums; }
.picker-clear {
  margin-top: 10px;
  width: 100%;
  padding: 7px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: none;
  font-size: 12px;
  color: var(--text-2);
}
.picker-clear:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }

/* ---------- 教学界面 ---------- */
.teach-ui { opacity: 0; pointer-events: none; transition: opacity 0.7s ease; }
body.teach-ready .teach-ui { opacity: 1; }
body.teach-ready .teach-ui > * { pointer-events: auto; }
body.teach-ready .teach-ui > .teach-hint { pointer-events: none; }

.teach-top {
  position: fixed;
  top: 20px;
  left: 24px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.stage-track { flex: 1; display: flex; gap: 6px; max-width: 720px; margin: 0 auto; }
.stage-seg {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  padding: 0;
  text-align: left;
}
.stage-seg .bar { height: 4px; border-radius: 2px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.stage-seg .bar i { display: block; height: 100%; width: 0; background: #fff; transition: width 0.3s ease; }
.stage-seg .lbl {
  margin-top: 7px;
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s;
}
.stage-seg:hover .lbl { color: var(--text-2); }
.stage-seg.current .lbl { color: var(--text); font-weight: 600; }

.btn-ghost {
  flex: none;
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(20, 23, 31, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 14px;
  color: var(--text-2);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.btn-ghost:hover:not(:disabled) { color: var(--text); background: rgba(40, 44, 56, 0.8); border-color: rgba(255, 255, 255, 0.22); }
.btn-ghost:disabled { opacity: 0.35; cursor: default; }

.step-card {
  position: fixed;
  left: 24px;
  bottom: 24px;
  width: min(440px, calc(100vw - 48px));
  background: var(--panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
.step-tag { font-size: 12px; color: var(--text-3); letter-spacing: 0.5px; }
.step-title { margin-top: 6px; font-size: 18px; font-weight: 700; line-height: 1.45; }
.step-body { margin-top: 8px; font-size: 14px; color: var(--text-2); line-height: 1.7; }
.step-body:empty, .step-note:empty, .formula:empty { display: none; }
.step-body b { color: var(--text); }

.formula { margin-top: 14px; display: flex; flex-wrap: wrap; gap: 6px; }
.formula .tk {
  min-width: 34px;
  padding: 5px 8px;
  border-radius: 7px;
  text-align: center;
  font-family: var(--mono);
  font-size: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-2);
  transition: background 0.2s, color 0.2s;
}
.formula .tk.done { color: var(--text-3); background: rgba(255, 255, 255, 0.03); }
.formula .tk.now { background: var(--accent); color: #1a0716; font-weight: 700; }

.move-row { margin-top: 16px; display: flex; align-items: center; gap: 16px; }
.move-row[hidden] { display: none; }
.move-big {
  min-width: 72px;
  height: 64px;
  padding: 0 12px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 32px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(255, 79, 216, 0.1);
  border: 1px solid rgba(255, 79, 216, 0.35);
}
.move-desc { font-size: 16px; font-weight: 600; line-height: 1.5; }
.move-desc small { display: block; font-size: 12px; font-weight: 400; color: var(--text-3); margin-top: 2px; }
.step-note { margin-top: 12px; font-size: 12px; color: var(--text-3); line-height: 1.6; }

.step-nav {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.step-counter { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.step-counter b { color: var(--text); font-size: 16px; }
.nav-buttons { display: flex; gap: 10px; }
.btn-next {
  height: 52px;
  padding: 0 28px;
  border-radius: 14px;
  border: none;
  background: #fff;
  color: #0b0d12;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 1px;
  box-shadow: 0 10px 30px rgba(255, 255, 255, 0.18);
  transition: transform 0.15s, box-shadow 0.2s;
}
.btn-next:hover { transform: translateY(-1px); box-shadow: 0 12px 36px rgba(255, 255, 255, 0.26); }
.btn-next:active { transform: scale(0.97); }
.nav-buttons .btn-ghost { height: 52px; }

.teach-hint {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: 24px;
  z-index: 30;
  transform: translate(-50%, -12px);
  padding: 10px 18px;
  border-radius: 12px;
  background: rgba(30, 34, 44, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 窄屏 ---------- */
@media (max-width: 900px) {
  .panel-left { top: 12px; left: 12px; right: 12px; width: auto; padding: 12px 14px; }
  .brand { display: none; }
  .panel-left .section-title { display: none; }
  .order-list { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .order-item { padding: 8px 4px; text-align: center; }
  .order-item .oi-grid { display: none; }
  .order-item .oi-sub { display: none; }
  .order-item .oi-lock { top: 4px; right: 4px; width: 10px; height: 10px; }
  .panel-right { top: auto; bottom: 12px; left: 12px; right: 12px; width: auto; max-height: 46vh; padding: 14px; }
  .panel-right .guide { display: none; }
  .color-counts { grid-template-columns: repeat(6, 1fr); gap: 4px; }
  .cc { flex-direction: column; gap: 3px; padding: 6px 2px; }
  .cc span { display: none; }
  .cc b { margin: 0; }
  .hint { display: none; }

  .teach-top { top: 12px; left: 12px; right: 12px; gap: 8px; flex-wrap: wrap; }
  .stage-track { order: 3; flex-basis: 100%; }
  .stage-seg .lbl { display: none; }
  #backBtn { margin-right: auto; }
  .step-card { left: 12px; right: 12px; width: auto; bottom: 88px; padding: 14px 16px; }
  .step-title { font-size: 16px; }
  .step-body { font-size: 13px; }
  .move-big { height: 52px; min-width: 60px; font-size: 26px; }
  .step-nav { left: 12px; right: 12px; bottom: 16px; flex-direction: row; align-items: center; justify-content: space-between; }
  .btn-next { height: 48px; padding: 0 20px; }
  .nav-buttons .btn-ghost { height: 48px; padding: 0 12px; }
  .teach-hint { display: none; }
}
