/* ============ 线性代数 · 交互式入门 ============
   夜空黑板风：深墨蓝底、粉笔网格、3B1B 式高饱和向量色 */

:root {
  --bg: #0b0f1a;
  --panel: #121a2c;
  --panel-2: #0e1524;
  --ink: #e8ecf5;
  --muted: #8b96ad;
  --line: rgba(255, 255, 255, 0.07);
  --gold: #ffc94d;
  --teal: #3fd0c9;
  --coral: #ff7a76;
  --violet: #a78bfa;
  --green: #5fd68a;
  --red: #ff6b81;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --math: Georgia, "Times New Roman", serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--sans);
  background:
    radial-gradient(1200px 800px at 75% -10%, rgba(63, 208, 201, 0.06), transparent 60%),
    radial-gradient(1000px 700px at -10% 100%, rgba(255, 201, 77, 0.05), transparent 55%),
    var(--bg);
  color: var(--ink);
  line-height: 1.75;
  min-height: 100vh;
}

#app {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------- 侧边栏 ---------- */
#sidebar {
  background: linear-gradient(180deg, var(--panel-2), #0a101e);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

#sidebar header { padding: 26px 22px 16px; border-bottom: 1px solid var(--line); }

#sidebar h1 {
  font-family: var(--serif);
  font-size: 27px;
  letter-spacing: 2px;
  color: var(--gold);
  font-weight: 700;
}

#sidebar .sub { font-size: 12px; color: var(--muted); margin-top: 2px; letter-spacing: 1px; }

#progress { margin-top: 16px; }
#progress .bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 99px;
  overflow: hidden;
}
#progress .bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  border-radius: 99px;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
#progress .label { font-size: 12px; color: var(--muted); display: block; margin-top: 7px; }

#lesson-list { flex: 1; overflow-y: auto; padding: 10px 12px 16px; }
#lesson-list::-webkit-scrollbar { width: 8px; }
#lesson-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 8px; }

.unit-label {
  font-size: 11px;
  letter-spacing: 4px;
  color: var(--muted);
  margin: 18px 10px 6px;
  text-transform: uppercase;
}
.unit-label::before { content: "— "; color: rgba(255, 255, 255, 0.18); }

.lesson-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--ink);
  font-size: 14px;
  font-family: var(--sans);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.lesson-item:hover:not(:disabled) { background: rgba(255, 255, 255, 0.045); }
.lesson-item.active {
  background: rgba(255, 201, 77, 0.08);
  border-color: rgba(255, 201, 77, 0.35);
}
.lesson-item.locked { color: rgba(139, 150, 173, 0.45); cursor: not-allowed; }
.lesson-item .no { font-family: var(--math); font-size: 12px; color: var(--muted); width: 20px; }
.lesson-item.active .no { color: var(--gold); }
.lesson-item .t { flex: 1; }

.lesson-item .dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1.5px solid rgba(139, 150, 173, 0.45);
  font-size: 11px;
  line-height: 15px;
  text-align: center;
  color: #08243a;
  flex: none;
}
.lesson-item.done .dot { background: var(--gold); border-color: var(--gold); font-weight: 700; }
.lesson-item.locked .dot { border-style: dashed; }

#sidebar footer { padding: 14px 22px; border-top: 1px solid var(--line); }
#reset-btn {
  background: none;
  border: none;
  color: rgba(139, 150, 173, 0.7);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--sans);
}
#reset-btn:hover { color: var(--red); text-decoration: underline; }

/* ---------- 主区 ---------- */
#main { padding: 44px 56px 90px; max-width: 980px; }

.lesson-head { display: flex; align-items: center; gap: 22px; margin-bottom: 26px; }
.lesson-no {
  font-family: var(--math);
  font-size: 76px;
  font-weight: 700;
  line-height: 1;
  color: transparent;
  -webkit-text-stroke: 1.5px rgba(255, 201, 77, 0.55);
}
.unit-tag { font-size: 12px; letter-spacing: 5px; color: var(--teal); }
.lesson-head h2 {
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 1px;
}

.card {
  background: linear-gradient(180deg, var(--panel), rgba(18, 26, 44, 0.6));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px 30px;
  margin-bottom: 22px;
  animation: rise 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.card:nth-of-type(2) { animation-delay: 0.07s; }
.card:nth-of-type(3) { animation-delay: 0.14s; }
.card:nth-of-type(4) { animation-delay: 0.21s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.card h3 {
  font-family: var(--serif);
  font-size: 16px;
  letter-spacing: 4px;
  color: var(--teal);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.card h3::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.theory p { margin-bottom: 12px; font-size: 15.5px; }
.theory p:last-child { margin-bottom: 0; }
.kw { color: var(--gold); font-weight: 600; }

/* ---------- 画布 ---------- */
.plane-wrap {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background:
    radial-gradient(600px 320px at 50% 0%, rgba(63, 208, 201, 0.05), transparent 70%),
    var(--panel-2);
  margin: 6px 0 12px;
}
canvas.plane {
  display: block;
  /* 允许纵向滚动穿透；命中拖拽点时由 JS 的 touchstart preventDefault 接管 */
  touch-action: pan-y pinch-zoom;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- 控件 ---------- */
.ctrl-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin: 10px 0; }
.ctrl-label { font-size: 14px; color: var(--muted); }

.ctrl { display: inline-flex; align-items: center; gap: 9px; font-size: 13.5px; color: var(--muted); }
.ctrl input[type="range"] { width: 150px; accent-color: var(--gold); }
.ctrl-val {
  font-family: var(--math);
  color: var(--gold);
  min-width: 34px;
  text-align: right;
  font-size: 15px;
}

.btn {
  font-family: var(--sans);
  font-size: 14px;
  border-radius: 99px;
  padding: 8px 18px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform 0.12s, background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn, .key, .lesson-item, #nav-toggle {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--gold); color: #221a05; font-weight: 600; }
.btn.primary:hover { background: #ffd97a; }
.btn.ghost { background: none; border-color: rgba(255, 255, 255, 0.18); color: var(--ink); }
.btn.ghost:hover { border-color: var(--teal); color: var(--teal); }
.btn.small { font-size: 13px; padding: 5px 13px; }
.btn.picked { border-color: var(--gold); color: var(--gold); background: rgba(255, 201, 77, 0.08); }

.readout {
  font-size: 14.5px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.035);
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 9px 14px;
  margin-top: 10px;
}
.readout.dim { color: var(--muted); }
.dim { color: var(--muted); }

/* ---------- 数学排版 ---------- */
.mvar { font-family: var(--math); font-style: italic; font-size: 1.06em; }
.meq { font-family: var(--math); font-size: 1.08em; white-space: nowrap; }
.tuple { font-family: var(--math); white-space: nowrap; }
.tuple.gold, .gold { color: var(--gold); }
.tuple.teal, .teal { color: var(--teal); }
.tuple.coral, .coral { color: var(--coral); }

.mtx { display: inline-flex; align-items: stretch; vertical-align: middle; margin: 0 4px; }
.mtx::before, .mtx::after { content: ""; width: 7px; border: 1.6px solid currentColor; opacity: 0.75; }
.mtx::before { border-right: 0; border-radius: 6px 0 0 6px; }
.mtx::after { border-left: 0; border-radius: 0 6px 6px 0; }
.mtx .mb {
  display: grid;
  gap: 2px 16px;
  padding: 5px 8px;
  align-content: center;
  justify-items: center;
  font-family: var(--math);
  font-size: 15.5px;
}
.mtx .mb.mb1 { grid-template-columns: auto; }
.mtx .mb.mb2 { grid-template-columns: auto auto; }
.mtx.coral { color: var(--coral); }
.mtx.teal { color: var(--teal); }
.mtx.gold { color: var(--gold); }

input.cell {
  width: 58px;
  padding: 6px 4px;
  text-align: center;
  font-family: var(--math);
  font-size: 16px; /* ≥16px：避免 iOS 聚焦时自动放大页面 */
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input.cell:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(63, 208, 201, 0.15); }
input.cell:disabled { opacity: 0.5; }
.mtx-input .mb { gap: 6px 8px; }

/* ---------- 练习区 ---------- */
.practice .rule { font-size: 12px; letter-spacing: 1px; color: var(--muted); font-family: var(--sans); }

#streak { display: inline-flex; gap: 6px; margin-left: 4px; }
.sdot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 201, 77, 0.5);
  transition: background 0.25s, transform 0.25s;
}
.sdot.on { background: var(--gold); transform: scale(1.15); box-shadow: 0 0 10px rgba(255, 201, 77, 0.6); }

#q-text { font-size: 15.5px; margin-bottom: 8px; }

.badge {
  display: inline-block;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--violet);
  border: 1px solid rgba(167, 139, 250, 0.45);
  border-radius: 99px;
  padding: 1px 11px;
  margin-right: 10px;
  vertical-align: 2px;
}

.answer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 22px;
  margin: 14px 0 4px;
}
.ans-label { display: inline-flex; align-items: center; gap: 9px; font-family: var(--math); font-size: 15.5px; }
.ans-prefix { font-family: var(--math); font-size: 15.5px; }

.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 14px 0 4px; }
.btn.choice {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14.5px;
  text-align: center;
}
.btn.choice:hover { border-color: var(--teal); }
.btn.choice.off { opacity: 0.35; pointer-events: none; }
.btn.choice.picked { border-color: var(--gold); background: rgba(255, 201, 77, 0.1); pointer-events: none; }

#q-actions { display: flex; gap: 12px; margin-top: 16px; }

/* ---------- 触屏小键盘（练习区，pointer:coarse 设备） ---------- */
.keypad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 16px;
  max-width: 340px;
}
.key {
  padding: 12px 0;
  font-size: 18px;
  font-family: var(--math);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  color: var(--ink);
  cursor: pointer;
}
.key:active { background: rgba(255, 201, 77, 0.22); }
.key-ok { grid-column: span 2; background: var(--gold); color: #221a05; font-weight: 700; }
input.cell.kfocus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 201, 77, 0.18); }

#nav-toggle { display: none; }

.fb { border-radius: 12px; padding: 12px 16px; margin-top: 14px; font-size: 15px; animation: pop 0.3s ease both; }
@keyframes pop { from { opacity: 0; transform: scale(0.97); } to { opacity: 1; transform: none; } }
.fb.ok { background: rgba(95, 214, 138, 0.1); border: 1px solid rgba(95, 214, 138, 0.4); color: var(--green); }
.fb.err { background: rgba(255, 107, 129, 0.08); border: 1px solid rgba(255, 107, 129, 0.35); color: var(--red); }
.fb .hint { color: var(--ink); font-size: 14px; margin-top: 6px; }
.fb .hint::before { content: "💡 "; }
.fb.mastery { font-size: 16px; box-shadow: 0 0 30px rgba(95, 214, 138, 0.12); }

/* ---------- 消元法步骤 ---------- */
.steps { margin: 8px 0; }
.step {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 7px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 15px;
}
.step.now { background: rgba(63, 208, 201, 0.08); color: var(--ink); }
.step b { color: var(--gold); font-family: var(--math); }
.step-no {
  font-family: var(--math);
  font-size: 12px;
  color: var(--teal);
  border: 1px solid rgba(63, 208, 201, 0.4);
  border-radius: 50%;
  width: 20px; height: 20px;
  line-height: 18px;
  text-align: center;
  flex: none;
}

.sys { font-size: 16px; margin: 8px 0 4px 14px; line-height: 2; }

/* ---------- 响应式 ---------- */
@media (max-width: 920px) {
  #app { grid-template-columns: 1fr; }

  /* 侧边栏变为顶部折叠目录 */
  #sidebar { position: relative; height: auto; }
  #sidebar header { position: relative; padding: 18px 20px 14px; }
  #sidebar h1 { font-size: 22px; }
  #nav-toggle {
    display: block;
    position: absolute;
    top: 18px;
    right: 16px;
    font-family: var(--sans);
    font-size: 13px;
    color: var(--gold);
    background: rgba(255, 201, 77, 0.09);
    border: 1px solid rgba(255, 201, 77, 0.4);
    border-radius: 99px;
    padding: 6px 14px;
    cursor: pointer;
  }
  #lesson-list {
    max-height: 0;
    overflow: hidden;
    padding: 0 12px;
    transition: max-height 0.35s ease;
  }
  #sidebar.open #lesson-list {
    max-height: 62vh;
    overflow-y: auto;
    padding: 8px 12px 14px;
  }
  #sidebar footer { display: none; }
  #sidebar.open footer { display: block; padding: 10px 20px; }

  #main { padding: 28px 20px 70px; max-width: none; }
  .lesson-no { font-size: 52px; }
  .lesson-head h2 { font-size: 26px; }
}

@media (max-width: 600px) {
  #main { padding: 22px 14px 60px; }
  .card { padding: 20px 16px; border-radius: 14px; }
  .lesson-head { gap: 14px; margin-bottom: 18px; }
  .lesson-no { font-size: 42px; }
  .lesson-head h2 { font-size: 22px; }
  .unit-tag { letter-spacing: 3px; }
  .theory p { font-size: 15px; }
  .ctrl input[type="range"] { width: 120px; }
  .answer-row { gap: 10px 14px; }
  #q-actions { flex-wrap: wrap; }
  .keypad { max-width: none; }
}
