/* ============================================================
   MathLingua · Duolingo Design System
   色板 / 字体 / 3D Chunky 按钮 / 状态胶囊 / 弹窗 / Toast
   ============================================================ */

:root {
  /* 主色系 */
  --green: #58cc02;
  --green-dark: #46a302;
  --green-deep: #3f7d07;
  --green-soft: #e8ffd4;
  --yellow: #ffc800;
  --yellow-dark: #e5a500;
  --yellow-deep: #a06b00;
  --yellow-soft: #fff6d4;
  --blue: #1cb0f6;
  --blue-dark: #1899d6;
  --blue-deep: #0b6f9e;
  --blue-soft: #ddf4ff;
  --red: #ff4b4b;
  --red-dark: #ea2b2b;
  --red-deep: #c22323;
  --red-soft: #ffdfe0;
  --purple: #ce82ff;
  --purple-dark: #a559d9;
  --purple-deep: #7b3aae;
  --purple-soft: #f3e5ff;
  --orange: #ff9600;
  --orange-dark: #e08500;
  --orange-deep: #9c5c00;
  --orange-soft: #ffe9cc;

  /* 中性色 */
  --white: #ffffff;
  --canvas: #f7f7f7;
  --line: #e5e5e5;
  --line-strong: #d6d6d6;
  --text: #3c3c3c;
  --text-soft: #6f6f6f;
  --text-muted: #a3a3a3;

  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --radius-pill: 999px;

  --shadow-card: 0 4px 0 var(--line);
  --shadow-pop: 0 18px 44px rgba(0, 0, 0, 0.16);

  --sidebar-w: 268px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font: "Nunito", "Baloo 2", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body {
  background: var(--canvas);
  font-family: var(--font);
  color: var(--text);
  font-weight: 700;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p { margin: 0; }
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }

::selection { background: var(--green-soft); color: var(--green-deep); }

/* 细滚动条，桌面端更清爽 */
* { scrollbar-width: thin; scrollbar-color: #dcdcdc transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: #dcdcdc; border-radius: 99px;
  border: 3px solid transparent; background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: #c6c6c6; background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ============================ 3D 实体按钮 ============================ */
.btn-3d {
  --fill: var(--green);
  --edge: var(--green-dark);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius-md);
  background: var(--fill); color: #fff;
  box-shadow: 0 4px 0 var(--edge);
  font: inherit; font-size: 16px; font-weight: 800; letter-spacing: 0.3px;
  padding: 12px 20px;
  cursor: pointer; user-select: none;
  white-space: nowrap;
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.15s ease,
    background 0.15s ease;
}
.btn-3d:hover:not(:disabled) { filter: brightness(1.04); }
.btn-3d:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--edge);
}
.btn-3d:focus-visible {
  outline: 3px solid rgba(28, 176, 246, 0.55);
  outline-offset: 3px;
}
.btn-3d:disabled {
  filter: grayscale(0.45) opacity(0.55);
  cursor: not-allowed;
}
.btn-3d.lg { padding: 15px 26px; font-size: 17px; border-radius: 18px; }
.btn-3d.sm { padding: 8px 14px; font-size: 14px; border-radius: 13px; }
.btn-3d.green { --fill: var(--green); --edge: var(--green-dark); }
.btn-3d.yellow { --fill: var(--yellow); --edge: var(--yellow-dark); color: #6b4a00; }
.btn-3d.blue { --fill: var(--blue); --edge: var(--blue-dark); }
.btn-3d.red { --fill: var(--red); --edge: var(--red-dark); }
.btn-3d.purple { --fill: var(--purple); --edge: var(--purple-dark); }
.btn-3d.orange { --fill: var(--orange); --edge: var(--orange-dark); }
.btn-3d.gray {
  --fill: var(--white); --edge: var(--line-strong); color: var(--text-soft);
}

.icon-btn {
  border: none; background: var(--white); color: var(--text-soft);
  width: 38px; height: 38px; border-radius: 13px;
  font-size: 17px; font-weight: 800; cursor: pointer;
  box-shadow: 0 3px 0 var(--line);
  display: grid; place-items: center;
  transition: transform 0.1s ease, box-shadow 0.1s ease, color 0.15s ease;
}
.icon-btn:hover { color: var(--text); }
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.icon-btn.muted { opacity: 0.5; }

/* ============================ 状态胶囊 ============================ */
.stat-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 8px 13px; border-radius: var(--radius-pill);
  border: 2px solid var(--line);
  background: var(--white);
  box-shadow: 0 2px 0 var(--line);
  font: inherit; font-size: 14px; font-weight: 800; color: var(--text);
  line-height: 1; cursor: default;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
button.stat-pill { cursor: pointer; }
button.stat-pill:hover { transform: translateY(-1px); }
button.stat-pill:active { transform: translateY(1px); box-shadow: 0 1px 0 var(--line); }
.stat-pill b { font-size: 14px; font-variant-numeric: tabular-nums; }
.stat-pill.fire { color: var(--orange-deep); border-color: #ffe0b0; background: #fff9f0; }
.stat-pill.gems { color: var(--blue-deep); border-color: #c9ebff; background: #f5fcff; }
.stat-pill.xp { color: var(--yellow-deep); border-color: #ffe8a3; background: #fffdf3; }
.stat-pill.hearts { gap: 2px; padding: 8px 11px; }
.stat-pill.hearts:hover { background: #fff5f5; }

.heart {
  font-size: 13px; line-height: 1; display: inline-block;
  transition: transform 0.2s ease, filter 0.25s ease, opacity 0.25s ease;
}
.heart.dead { filter: grayscale(1); opacity: 0.25; transform: scale(0.8); }
.heart.pop { animation: heartPop 0.45s ease; }
@keyframes heartPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.5) rotate(-8deg); }
  100% { transform: scale(0.8); }
}

/* ============================ 筛选 chips / 标签 ============================ */
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 2px solid var(--line);
  border-bottom-width: 4px;
  background: var(--white);
  color: var(--text-soft);
  border-radius: var(--radius-pill);
  padding: 9px 16px;
  font: inherit; font-size: 14px; font-weight: 800;
  cursor: pointer;
  transition: transform 0.08s ease, color 0.15s ease, border-color 0.15s ease,
    background 0.15s ease, box-shadow 0.1s ease;
}
.chip i {
  font-style: normal; font-size: 11.5px;
  background: #f1f1f1; color: var(--text-muted);
  border-radius: var(--radius-pill); padding: 1px 7px;
}
.chip:hover { color: var(--text); border-color: var(--line-strong); }
.chip:active { transform: translateY(2px); border-bottom-width: 2px; }
.chip.active {
  color: var(--green-deep);
  background: var(--green-soft);
  border-color: #b6eb85;
}
.chip.active i { background: rgba(255, 255, 255, 0.85); color: var(--green-deep); }

/* ============================ 开关 ============================ */
.switch {
  flex: none;
  width: 58px; height: 32px; border-radius: var(--radius-pill);
  border: none; padding: 0; cursor: pointer;
  background: #dcdcdc;
  position: relative;
  transition: background 0.2s ease;
  box-shadow: inset 0 2px 0 rgba(0, 0, 0, 0.06);
}
.switch i {
  position: absolute; top: 4px; left: 4px;
  width: 24px; height: 24px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform 0.22s cubic-bezier(0.3, 1.4, 0.5, 1);
}
.switch.on { background: var(--green); }
.switch.on i { transform: translateX(26px); }
.switch:focus-visible { outline: 3px solid rgba(28, 176, 246, 0.5); outline-offset: 2px; }

/* ============================ 弹窗 ============================ */
.modal {
  position: fixed; inset: 0;
  background: rgba(38, 46, 32, 0.55);
  display: none; align-items: center; justify-content: center;
  padding: 24px;
  z-index: 90;
  backdrop-filter: blur(3px);
}
.modal.show { display: flex; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  width: 100%; max-width: 460px;
  max-height: 92vh; overflow-y: auto;
  background: var(--white);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: var(--shadow-pop);
  animation: modalIn 0.24s cubic-bezier(0.2, 1.2, 0.4, 1);
}
.modal-card.modal-wide { max-width: 620px; }
@keyframes modalIn {
  from { transform: translateY(16px) scale(0.97); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.modal-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.modal-head > div { flex: 1; min-width: 0; }
.modal-head h3 { font-size: 19px; font-weight: 900; margin-bottom: 3px; }
.modal-sub { font-size: 12.5px; color: var(--text-muted); font-weight: 700; line-height: 1.5; }
.modal-actions { display: flex; justify-content: center; gap: 10px; margin-top: 14px; }

.settings-card .settings-row {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 0;
  border-top: 2px dashed #efefef;
}
.settings-meta { flex: 1; min-width: 0; }
.settings-meta b { display: block; font-size: 15px; margin-bottom: 2px; }
.settings-meta small { font-size: 12.5px; color: var(--text-muted); font-weight: 700; line-height: 1.5; }
.settings-note {
  margin-top: 14px; padding-top: 12px;
  border-top: 2px dashed #efefef;
  font-size: 12px; font-weight: 700; color: var(--text-muted);
}

/* 通用：hidden 属性优先 */
[hidden] { display: none !important; }

/* ============================ Toast ============================ */
.toast {
  position: fixed; left: 50%; bottom: 28px;
  transform: translate(-50%, 18px);
  background: rgba(61, 61, 61, 0.96);
  color: #fff; font-size: 13.5px; font-weight: 800;
  padding: 12px 20px; border-radius: var(--radius-pill);
  opacity: 0; pointer-events: none;
  transition: opacity 0.24s ease, transform 0.24s ease;
  z-index: 120;
  max-width: 86vw; text-align: center;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.24);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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