/* ============================================================
   光镜实验室 · 凸透镜成像规律探究
   视觉系统：深夜实验室 / 玻璃拟态 / 光束发光
   ============================================================ */

:root {
  --bg: #060a18;
  --bg-2: #0a1024;
  --panel: rgba(255, 255, 255, 0.045);
  --panel-strong: rgba(255, 255, 255, 0.07);
  --line: rgba(255, 255, 255, 0.09);
  --line-soft: rgba(255, 255, 255, 0.05);
  --text: #e6edf7;
  --text-dim: #93a1bd;
  --text-faint: #64748b;
  --cyan: #5eead4;
  --indigo: #818cf8;
  --violet: #c084fc;
  --amber: #fbbf24;
  --green: #34d399;
  --rose: #fb7185;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px -20px rgba(0, 0, 0, 0.9);
  --font: "PingFang SC", "Microsoft YaHei", -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Consolas, "Courier New", monospace;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* 背景：实验室环境光 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(900px 600px at 12% -5%, rgba(94, 234, 212, 0.10), transparent 60%),
    radial-gradient(1000px 700px at 88% 0%, rgba(129, 140, 248, 0.12), transparent 62%),
    radial-gradient(800px 800px at 50% 110%, rgba(192, 132, 252, 0.07), transparent 60%),
    linear-gradient(180deg, #060a18 0%, #080d1e 100%);
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(255,255,255,0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.022) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(ellipse 90% 65% at 50% 25%, #000 30%, transparent 100%);
}

::selection { background: rgba(94, 234, 212, 0.28); }

/* ---------- 布局骨架 ---------- */

.wrap { max-width: 1560px; margin: 0 auto; padding: 0 26px; }

/* ---------- 顶部导航 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  background: rgba(6, 10, 24, 0.72);
  border-bottom: 1px solid var(--line-soft);
}

.topbar-inner {
  max-width: 1560px;
  margin: 0 auto;
  padding: 14px 26px;
  display: flex;
  align-items: center;
  gap: 26px;
}

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

.brand-mark {
  width: 38px; height: 38px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(94,234,212,0.2), rgba(129,140,248,0.22));
  border: 1px solid rgba(94, 234, 212, 0.28);
  box-shadow: 0 0 24px rgba(94, 234, 212, 0.14) inset;
}

.brand-mark svg { width: 22px; height: 22px; }

.brand-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(100deg, #fff 10%, var(--cyan) 55%, var(--indigo) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-sub { font-size: 11px; color: var(--text-faint); letter-spacing: 1.6px; margin-top: -3px; }

.nav { display: flex; gap: 4px; margin-left: auto; }

.nav a {
  padding: 8px 15px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--text-dim);
  text-decoration: none;
  transition: all 0.22s;
  border: 1px solid transparent;
  white-space: nowrap;
}

.nav a:hover { color: var(--text); background: var(--panel); }

.nav a.active {
  color: var(--cyan);
  background: rgba(94, 234, 212, 0.09);
  border-color: rgba(94, 234, 212, 0.22);
}

/* ---------- 首屏标题 ---------- */

.hero { padding: 46px 0 26px; text-align: center; }

.hero-tag {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 6px 16px;
  border-radius: 100px;
  border: 1px solid rgba(129, 140, 248, 0.26);
  background: rgba(129, 140, 248, 0.07);
  font-size: 12px;
  color: #b6c2f5;
  letter-spacing: 1px;
  margin-bottom: 20px;
}

.hero-tag .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.45;transform:scale(.8)} }

.hero h1 {
  font-size: clamp(30px, 4.4vw, 50px);
  font-weight: 800;
  letter-spacing: 1px;
  line-height: 1.25;
  background: linear-gradient(105deg, #ffffff 5%, #c7f9ef 40%, #b3bcff 75%, #e0c3fc 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero p {
  margin: 16px auto 0;
  max-width: 660px;
  color: var(--text-dim);
  font-size: 15px;
}

/* ---------- 主工作区 ---------- */

.lab {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  gap: 22px;
  align-items: start;
  padding-bottom: 30px;
}

@media (max-width: 1180px) {
  .lab { grid-template-columns: minmax(0, 1fr); }
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

/* ---------- 实验台 ---------- */

.stage-card { overflow: hidden; }

.stage-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.018);
}

.stage-title { font-size: 14px; font-weight: 600; letter-spacing: 0.4px; }

.stage-state {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  padding: 5px 13px;
  border-radius: 100px;
  border: 1px solid var(--line);
  color: var(--text-dim);
  transition: all 0.3s;
}

.stage-state.real { color: var(--green); border-color: rgba(52, 211, 153, 0.35); background: rgba(52, 211, 153, 0.08); }
.stage-state.virtual { color: var(--violet); border-color: rgba(192, 132, 252, 0.35); background: rgba(192, 132, 252, 0.08); }
.stage-state.none { color: var(--amber); border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.08); }

.canvas-wrap { position: relative; background: #050913; }

/* 显示尺寸完全由 CSS 决定，JS 只调整像素分辨率，避免尺寸反馈环 */
#optics {
  display: block;
  width: 100%;
  height: 520px;
  cursor: grab;
  touch-action: none;
}

#optics.dragging { cursor: grabbing; }

@media (max-width: 1100px) { #optics { height: 440px; } }
@media (max-width: 760px)  { #optics { height: 360px; } }
@media (max-width: 520px)  { #optics { height: 300px; } }

/* 拟合图同样由 CSS 定显示高度 */
#fit {
  display: block;
  width: 100%;
  height: 290px;
}

@media (max-width: 760px) { #fit { height: 250px; } }

.canvas-hint {
  position: absolute;
  left: 18px;
  bottom: 14px;
  font-size: 12px;
  color: var(--text-faint);
  pointer-events: none;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.canvas-hint span { display: inline-flex; align-items: center; gap: 6px; }

.canvas-hint i {
  width: 7px; height: 7px; border-radius: 2px; display: inline-block;
}

/* 悬浮读数气泡 */
.readout {
  position: absolute;
  pointer-events: none;
  font-family: var(--mono);
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 7px;
  background: rgba(6, 12, 28, 0.9);
  border: 1px solid var(--line);
  color: var(--cyan);
  opacity: 0;
  transition: opacity 0.18s;
  white-space: nowrap;
  z-index: 5;
}
.readout.show { opacity: 1; }

/* ---------- 预设情形条 ---------- */

.presets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1px;
  background: var(--line-soft);
  border-top: 1px solid var(--line-soft);
}

.preset {
  background: rgba(8, 13, 30, 0.85);
  border: none;
  padding: 14px 10px;
  cursor: pointer;
  color: var(--text-dim);
  font-family: var(--font);
  transition: all 0.24s;
  text-align: center;
}

.preset:hover { background: rgba(94, 234, 212, 0.07); color: var(--text); }
.preset.on { background: rgba(94, 234, 212, 0.12); color: var(--cyan); }

.preset .p-range { display: block; font-family: var(--mono); font-size: 13px; font-weight: 600; }
.preset .p-use { display: block; font-size: 11px; margin-top: 4px; opacity: 0.8; }

@media (max-width: 640px) {
  .presets { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- 控制面板 ---------- */

.side { display: flex; flex-direction: column; gap: 18px; }

.panel { padding: 18px 20px; }

.panel-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.8px;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-title::before {
  content: "";
  width: 3px; height: 12px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--cyan), var(--indigo));
}

/* 滑块 */
.ctrl { margin-bottom: 18px; }
.ctrl:last-child { margin-bottom: 0; }

.ctrl-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 9px; }

.ctrl-label { font-size: 13px; color: var(--text-dim); display: flex; align-items: center; gap: 7px; }

.ctrl-label .sym {
  font-family: var(--mono);
  font-style: italic;
  color: var(--cyan);
  font-size: 14px;
  width: 16px;
  text-align: center;
}

.ctrl-val {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 9px;
  border-radius: 6px;
  min-width: 62px;
  text-align: right;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 100px;
  background: linear-gradient(90deg, var(--cyan) var(--pct, 50%), rgba(255,255,255,0.1) var(--pct, 50%));
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--cyan);
  box-shadow: 0 0 14px rgba(94, 234, 212, 0.55);
  cursor: grab;
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.18); }
input[type="range"]::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.05); }

input[type="range"]::-moz-range-thumb {
  width: 15px; height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--cyan);
  box-shadow: 0 0 14px rgba(94, 234, 212, 0.55);
  cursor: grab;
}

input[type="range"]::-moz-range-track {
  height: 5px; border-radius: 100px; background: rgba(255,255,255,0.1);
}

/* 开关 */
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-dim);
  transition: all 0.2s;
  user-select: none;
}

.toggle:hover { border-color: var(--line); color: var(--text); }

.toggle input { display: none; }

.toggle .box {
  width: 15px; height: 15px;
  border-radius: 4px;
  border: 1.5px solid rgba(255,255,255,0.25);
  display: grid; place-items: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

.toggle .box::after {
  content: "";
  width: 7px; height: 7px;
  border-radius: 2px;
  background: var(--cyan);
  transform: scale(0);
  transition: transform 0.18s;
}

.toggle input:checked + .box { border-color: var(--cyan); background: rgba(94,234,212,0.14); }
.toggle input:checked + .box::after { transform: scale(1); }
.toggle:has(input:checked) { color: var(--text); border-color: rgba(94,234,212,0.3); }

/* ---------- 数据读数 ---------- */

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.metric {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.028);
  border: 1px solid var(--line-soft);
}

.metric-label { font-size: 11.5px; color: var(--text-faint); margin-bottom: 5px; }

.metric-value {
  font-family: var(--mono);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.4px;
  color: var(--text);
}

.metric-value small { font-size: 11px; color: var(--text-dim); font-weight: 400; margin-left: 3px; }

.metric.accent .metric-value { color: var(--cyan); }

/* 公式验证 */
.formula {
  margin-top: 14px;
  padding: 15px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(94,234,212,0.06), rgba(129,140,248,0.06));
  border: 1px solid rgba(94, 234, 212, 0.18);
}

.formula-eq {
  font-family: var(--mono);
  font-size: 17px;
  text-align: center;
  color: var(--text);
  letter-spacing: 0.5px;
}

.formula-eq .frac { display: inline-flex; flex-direction: column; vertical-align: middle; margin: 0 5px; text-align: center; }
.formula-eq .frac .num { border-bottom: 1.5px solid var(--text-dim); padding: 0 7px 2px; }
.formula-eq .frac .den { padding: 2px 7px 0; }

.formula-sub {
  margin-top: 11px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  word-break: break-all;
  line-height: 1.9;
}

.formula-sub .ok { color: var(--green); }
.formula-sub .bad { color: var(--amber); }

/* 像的性质 */
.nature {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 13px;
}

.chip {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 100px;
  border: 1px solid var(--line);
  color: var(--text-dim);
  background: rgba(255,255,255,0.03);
}

.chip.on-green { color: var(--green); border-color: rgba(52,211,153,0.35); background: rgba(52,211,153,0.09); }
.chip.on-violet { color: var(--violet); border-color: rgba(192,132,252,0.35); background: rgba(192,132,252,0.09); }
.chip.on-amber { color: var(--amber); border-color: rgba(251,191,36,0.35); background: rgba(251,191,36,0.09); }
.chip.on-cyan { color: var(--cyan); border-color: rgba(94,234,212,0.35); background: rgba(94,234,212,0.09); }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn:hover { background: rgba(255,255,255,0.11); border-color: rgba(255,255,255,0.2); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(120deg, rgba(94,234,212,0.9), rgba(129,140,248,0.9));
  color: #04121a;
  border: none;
  font-weight: 700;
  box-shadow: 0 8px 26px -10px rgba(94, 234, 212, 0.7);
}

.btn-primary:hover { filter: brightness(1.12); background: linear-gradient(120deg, rgba(94,234,212,0.9), rgba(129,140,248,0.9)); }

.btn-block { width: 100%; }

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ---------- 通用分区 ---------- */

.section { padding: 34px 0; }

.section-head { margin-bottom: 24px; }

.section-title { font-size: 24px; font-weight: 700; letter-spacing: 0.5px; }

.section-desc { color: var(--text-dim); font-size: 14px; margin-top: 7px; max-width: 720px; }

/* ---------- 数据表格 ---------- */

.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  background: rgba(255,255,255,0.045);
  padding: 12px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 0.6px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line-soft); font-family: var(--mono); }

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(94, 234, 212, 0.035); }

.empty { padding: 34px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* ---------- 挑战模式 ---------- */

.challenge-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

.challenge {
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  transition: all 0.25s;
}

.challenge:hover { border-color: rgba(94,234,212,0.28); transform: translateY(-3px); }

.challenge.done { border-color: rgba(52, 211, 153, 0.45); background: rgba(52,211,153,0.05); }

.challenge-tag {
  display: inline-block;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 100px;
  background: rgba(129,140,248,0.12);
  color: #b6c2f5;
  border: 1px solid rgba(129,140,248,0.24);
  margin-bottom: 11px;
}

.challenge h4 { font-size: 15px; margin-bottom: 8px; }
.challenge p { font-size: 13px; color: var(--text-dim); min-height: 42px; }

.challenge-status { margin-top: 14px; font-size: 12.5px; font-weight: 600; color: var(--text-faint); }
.challenge-status.ok { color: var(--green); }

/* ---------- 知识卡片 ---------- */

.knowledge { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; }

.kcard { padding: 22px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); }

.kcard .k-icon {
  width: 40px; height: 40px;
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 19px;
  margin-bottom: 14px;
  background: rgba(94,234,212,0.1);
  border: 1px solid rgba(94,234,212,0.2);
}

.kcard h4 { font-size: 15px; margin-bottom: 9px; }
.kcard p { font-size: 13px; color: var(--text-dim); }
.kcard .k-formula { font-family: var(--mono); color: var(--cyan); font-size: 14px; margin-top: 9px; }

/* ---------- 提示条 ---------- */

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 24px;
  border-radius: 100px;
  background: rgba(10, 18, 38, 0.95);
  border: 1px solid rgba(94,234,212,0.35);
  color: var(--text);
  font-size: 13.5px;
  box-shadow: 0 16px 44px -12px rgba(0,0,0,0.85);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 100;
  backdrop-filter: blur(14px);
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 页脚 ---------- */

.footer {
  border-top: 1px solid var(--line-soft);
  padding: 26px 0 34px;
  margin-top: 20px;
  color: var(--text-faint);
  font-size: 12.5px;
  text-align: center;
}

.footer strong { color: var(--text-dim); font-weight: 600; }

/* ---------- 滚动条 ---------- */

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 100px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ---------- 动画 ---------- */

@keyframes fadeUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.fade-up { animation: fadeUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) both; }
.d1 { animation-delay: 0.06s; }
.d2 { animation-delay: 0.12s; }
.d3 { animation-delay: 0.18s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
