/* ==========================================================================
   概率与损失函数手算课 · 基础样式（设计变量 / 排版 / 通用组件）
   设计变量与 transformer-lab、nn-lab 保持一致（同一套品牌色、明暗主题），方便学生在不同课程间切换时不违和。
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #f4f5fb;
  --bg-grad-1: rgb(91 94 224 / 0.10);
  --bg-grad-2: rgb(14 165 164 / 0.08);
  --surface: #ffffff;
  --surface-2: #f0f2fa;
  --surface-3: #e7eaf6;
  --border: #e1e4f0;
  --border-strong: #c9cfe4;
  --text: #1a1e33;
  --text-2: #444b6b;
  --muted: #747c9c;
  --brand: #5457e0;
  --brand-2: #8b5cf6;
  --brand-soft: #ecedff;
  --brand-ink: #3a3db5;
  --accent: #0d9f9e;
  --accent-soft: #e0f6f5;
  --good: #15803d;
  --good-soft: #e6f6ec;
  --warn: #b45309;
  --warn-soft: #fff3df;
  --bad: #dc2626;
  --bad-soft: #fdeaea;

  /* 颜色约定（与神经网络课一致）：模型 / 前向 = 蓝，损失 = 琥珀，梯度 = 玫红，真相 / 更新 = 绿；
     本课里交叉熵用品牌靛色，平方损失用琥珀色，所以两条曲线一眼就能分开 */
  --fwd: #3b82f6;
  --loss: #f59e0b;
  --upd: #10b981;
  --fwd-soft: rgb(59 130 246 / 0.12);
  --loss-soft: rgb(245 158 11 / 0.14);
  --upd-soft: rgb(16 185 129 / 0.13);

  /* 反向传播（梯度）统一用玫红 */
  --grad: #e11d48;
  --grad-soft: rgb(225 29 72 / 0.10);

  /* 抛硬币：反面蓝、正面橙（只写三个通道，用的时候套 rgb()） */
  --c-pos: 59 130 246;
  --c-neg: 249 115 22;

  --shadow-1: 0 1px 2px rgb(24 28 60 / 0.05), 0 2px 10px rgb(24 28 60 / 0.06);
  --shadow-2: 0 10px 40px rgb(24 28 60 / 0.14);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --font-math: 'STIX Two Math', 'Latin Modern Math', 'Cambria Math', 'STIXGeneral', 'Times New Roman', serif;

  --nav-h: 58px;
}

[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0e1020;
  --bg-grad-1: rgb(110 113 255 / 0.16);
  --bg-grad-2: rgb(20 184 166 / 0.10);
  --surface: #171a30;
  --surface-2: #1e2240;
  --surface-3: #272c52;
  --border: #2a2f55;
  --border-strong: #3a4072;
  --text: #e8eaf8;
  --text-2: #b4b9d8;
  --muted: #858cb0;
  --brand: #8183ff;
  --brand-2: #a78bfa;
  --brand-soft: #25285a;
  --brand-ink: #b3b5ff;
  --accent: #2dd4bf;
  --accent-soft: #123a3d;
  --good: #4ade80;
  --good-soft: #12372a;
  --warn: #fbbf24;
  --warn-soft: #3b2e12;
  --bad: #f87171;
  --bad-soft: #3d1b24;
  --fwd: #60a5fa;
  --loss: #fbbf24;
  --upd: #34d399;
  --grad: #fb7185;
  --grad-soft: rgb(251 113 133 / 0.14);
  --c-pos: 96 165 250;
  --c-neg: 251 146 60;
  --shadow-1: 0 1px 2px rgb(0 0 0 / 0.3), 0 2px 12px rgb(0 0 0 / 0.25);
  --shadow-2: 0 12px 44px rgb(0 0 0 / 0.5);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-h) + 12px);
  -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  background-image: radial-gradient(900px 500px at 8% -5%, var(--bg-grad-1), transparent 60%),
    radial-gradient(800px 480px at 100% 4%, var(--bg-grad-2), transparent 60%);
  background-repeat: no-repeat;
  background-attachment: scroll;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

::selection {
  background: rgb(91 94 224 / 0.25);
}

h1,
h2,
h3,
h4 {
  line-height: 1.3;
  margin: 0;
  letter-spacing: -0.01em;
}

p {
  margin: 0 0 0.9em;
}

a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

code,
kbd,
.mono {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.05em 0.35em;
}

kbd {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 0.05em 0.4em;
  font-size: 0.82em;
}

button {
  font: inherit;
  color: inherit;
}

/* 内联线条图标的默认尺寸（各处可以用更具体的选择器覆盖） */
svg.icon {
  width: 1.15em;
  height: 1.15em;
  flex: none;
  vertical-align: -0.17em;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 6px;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------- 公式 ---------- */
math {
  font-family: var(--font-math);
  font-size: 1.12em;
}
.tex {
  display: inline-block;
  vertical-align: middle;
}
.tex-block {
  display: block;
  text-align: center;
  padding: 6px 0;
  overflow-x: auto;
  overflow-y: hidden;
}
.tex-block math {
  font-size: 1.28em;
}
@media (max-width: 520px) {
  .tex-block math {
    font-size: 1.12em;
  }
}
.formula {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 12px 0;
}
.formula .formula-cap {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 2px;
  letter-spacing: 0.02em;
}
.formula.is-grad {
  border-left-color: var(--grad);
}

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) {
  border-color: var(--brand);
  box-shadow: 0 2px 10px rgb(84 87 224 / 0.18);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 16px rgb(84 87 224 / 0.35);
}
.btn-primary:hover:not(:disabled) {
  border-color: transparent;
  box-shadow: 0 6px 22px rgb(84 87 224 / 0.5);
  filter: brightness(1.05);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  box-shadow: none;
  border-color: transparent;
}
.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}
.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}
.icon-btn {
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover {
  color: var(--brand);
  border-color: var(--brand);
}
.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ---------- 分段选择器 ---------- */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  max-width: 100%;
  overflow-x: auto;
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.seg button:hover {
  color: var(--text);
}
.seg button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.seg button:disabled:hover {
  color: var(--text-2);
}
.seg button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--brand-ink);
  box-shadow: 0 1px 4px rgb(24 28 60 / 0.15);
}
@media (max-width: 520px) {
  .seg button {
    padding: 6px 10px;
    font-size: 13px;
  }
  /* 选项文字长、一行放不下时折到下一行，而不是在里面横着滚：
     一出现滚动条，最后一个选项就被藏在屏幕外面了 */
  .seg {
    flex-wrap: wrap;
    border-radius: 18px;
    overflow: visible;
  }
  .seg button {
    flex: 1 1 auto;
  }
}

/* ---------- 提示框 ---------- */
.callout {
  display: grid;
  /* minmax(0, 1fr)：让正文列可以比内容窄，里面的宽公式才会出现自己的横向滚动条，而不是把整页撑宽 */
  grid-template-columns: auto minmax(0, 1fr);
  gap: 4px 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin: 14px 0;
  font-size: 15px;
  line-height: 1.65;
}
.callout > .callout-ico {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  color: var(--brand);
}
.callout > .callout-ico svg {
  width: 22px;
  height: 22px;
}
.callout .callout-t {
  font-weight: 700;
  margin-bottom: 2px;
}
.callout .callout-b > :last-child {
  margin-bottom: 0;
}
.callout.tip {
  background: var(--brand-soft);
  border-color: transparent;
}
.callout.hand {
  background: var(--accent-soft);
  border-color: transparent;
}
.callout.hand .callout-ico {
  color: var(--accent);
}
.callout.warn {
  background: var(--warn-soft);
  border-color: transparent;
}
.callout.warn .callout-ico {
  color: var(--warn);
}
.callout.grad {
  background: var(--grad-soft);
  border-color: transparent;
}
.callout.grad .callout-ico {
  color: var(--grad);
}

/* ---------- 小徽标 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.badge.brand {
  background: var(--brand-soft);
  color: var(--brand-ink);
  border-color: transparent;
}
.badge.good {
  background: var(--good-soft);
  color: var(--good);
  border-color: transparent;
}
.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: transparent;
}
.badge.bad {
  background: var(--bad-soft);
  color: var(--bad);
  border-color: transparent;
}
.badge.grad {
  background: var(--grad-soft);
  color: var(--grad);
  border-color: transparent;
}

/* ---------- 滑块 ---------- */
.field {
  display: grid;
  gap: 4px;
  min-width: 150px;
}
.field > label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-2);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.field .val {
  font-family: var(--font-mono);
  color: var(--brand-ink);
}
input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 99px;
  background: var(--surface-3);
  outline-offset: 6px;
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border: 2px solid var(--surface);
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.3);
  cursor: pointer;
}
input[type='range']::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand);
  border: 2px solid var(--surface);
  cursor: pointer;
}
input[type='number'],
input[type='text'],
select {
  font: inherit;
  font-family: var(--font-mono);
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  min-width: 0;
}
input[type='number']:focus,
input[type='text']:focus,
select:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

/* ---------- 通用小件 ---------- */
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
}
.muted {
  color: var(--muted);
}
.warn-text {
  color: var(--warn);
}
.small {
  font-size: 13.5px;
}

@media (max-width: 640px) {
  body {
    font-size: 15.5px;
  }
  .container {
    padding: 0 14px;
  }
}

/* 截图/录屏/测试时可给 <html> 加 class="no-anim" 关闭所有动画 */
.no-anim *,
.no-anim *::before,
.no-anim *::after {
  animation: none !important;
  transition: none !important;
}
