/* 100Hz 防晕动 — UI */

:root {
  --bg: #f4f1ec;
  --bg-glow: #e9f3f0;
  --surface: #ffffff;
  --surface-2: #f7f5f1;
  --ink: #171a18;
  --ink-2: #4a4f4b;
  --muted: #7b817c;
  --line: #e5e0d7;
  --accent: #0d8a7c;
  --accent-ink: #ffffff;
  --accent-soft: rgba(13, 138, 124, 0.12);
  --band: rgba(13, 138, 124, 0.18);
  --track: #ece8e1;
  --shadow: 0 1px 2px rgba(23, 26, 24, 0.04), 0 10px 30px rgba(23, 26, 24, 0.06);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1211;
    --bg-glow: #10201d;
    --surface: #171c1b;
    --surface-2: #131817;
    --ink: #ecf1ef;
    --ink-2: #c6cecb;
    --muted: #8d9793;
    --line: #252c2a;
    --accent: #33c8b3;
    --accent-ink: #06201c;
    --accent-soft: rgba(51, 200, 179, 0.14);
    --band: rgba(51, 200, 179, 0.2);
    --track: #232a28;
    --shadow: none;
  }
}

html[data-theme="dark"] {
  --bg: #0e1211;
  --bg-glow: #10201d;
  --surface: #171c1b;
  --surface-2: #131817;
  --ink: #ecf1ef;
  --ink-2: #c6cecb;
  --muted: #8d9793;
  --line: #252c2a;
  --accent: #33c8b3;
  --accent-ink: #06201c;
  --accent-soft: rgba(51, 200, 179, 0.14);
  --band: rgba(51, 200, 179, 0.2);
  --track: #232a28;
  --shadow: none;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: -20% -20% auto -20%;
  height: 62vh;
  background: radial-gradient(60% 60% at 50% 0%, var(--bg-glow), transparent 72%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 10px) 16px calc(var(--safe-bottom) + 8px);
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 14px;
  flex: 0 0 auto;
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-ink);
  flex: 0 0 auto;
}

.brand-text {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions { display: flex; gap: 8px; flex: 0 0 auto; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}

.icon-btn:active { transform: scale(0.94); }

html[data-theme="dark"] .ico-sun { display: none; }
html[data-theme="light"] .ico-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ico-sun { display: none; }
  :root:not([data-theme="light"]) .ico-moon { display: block; }
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .ico-moon { display: none; }
}

/* ---------- content ---------- */

.content {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 6px;
  scrollbar-width: none;
}
.content::-webkit-scrollbar { display: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: 0.02em;
}

.tag {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}

.hint {
  margin: 10px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

/* ---------- 论文原理卡片 ---------- */

.note-card {
  background: var(--surface);
  color: var(--muted);
}

.note-p {
  margin: 2px 0 14px;
  font-size: 13px;
  line-height: 1.62;
  color: var(--muted);
}

.note-p em { font-style: italic; color: var(--ink-2); }

.note-p.tight { margin-bottom: 10px; }

.k {
  display: inline-block;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
  border-bottom: 1px solid var(--line);
  margin-right: 6px;
}

.fig {
  margin: 0 0 14px;
  padding: 10px 10px 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-2);
}

.fig-svg { display: block; width: 100%; height: auto; color: var(--muted); }

.fig .ax  { stroke: currentColor; stroke-width: 0.8; opacity: 0.55; }
.fig .tick { stroke: currentColor; stroke-width: 0.8; opacity: 0.55; }
.fig .amp { stroke: currentColor; stroke-width: 0.8; opacity: 0.45; stroke-dasharray: 2 2; }
.fig .wave { fill: none; stroke: var(--ink-2); stroke-width: 1.5; stroke-linejoin: round; opacity: 0.75; }
.fig .arw { stroke: currentColor; stroke-width: 1; fill: none; opacity: 0.6; }
.fig .arwh { fill: currentColor; opacity: 0.6; }

.fig .box rect {
  fill: var(--surface);
  stroke: var(--line);
  stroke-width: 1;
}

.fig .box text { text-anchor: middle; }
.fig .fig-b { font-size: 10.5px; font-weight: 600; fill: var(--ink-2); }
.fig .fig-s { font-size: 9px; fill: var(--muted); }
.fig .fig-t { font-size: 8.5px; fill: var(--muted); }

.figcap {
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.5;
  color: var(--muted);
}

.eqi {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  font-size: 0.95em;
  color: var(--ink-2);
  white-space: nowrap;
}

.eqs {
  margin: 0 0 14px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.eqrow {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 9px 0;
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
}

.eqrow:last-child { border-bottom: none; }

.eqlab {
  flex: 0 0 80px;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.eqnote { color: var(--muted); font-size: 11.5px; }

.cite {
  margin: 8px 0 0;
  font-size: 10.5px;
  line-height: 1.55;
  color: var(--muted);
  opacity: 0.85;
  border-left: 2px solid var(--line);
  padding-left: 8px;
}

/* ---------- timer ---------- */

.play-card { display: flex; flex-direction: column; gap: 14px; }

.timer {
  position: relative;
  border-radius: 18px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 18px 16px 16px;
  text-align: center;
  overflow: hidden;
  transition: background 0.3s ease;
}

body.is-playing .timer { background: var(--accent-soft); }

.timer-main {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 3px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  font-size: 62px;
  font-weight: 620;
  line-height: 1;
  transition: color 0.3s ease;
}

body.is-playing .timer-main { color: var(--accent); }

.timer-main .timer-unit {
  font-size: 24px;
  font-weight: 560;
  color: var(--muted);
  letter-spacing: 0;
}

.timer-label {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.timer-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 4px;
  background: transparent;
}

.timer-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s linear;
}

/* ---------- play button ---------- */

.play-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 62px;
  padding: 0 18px;
  border: none;
  border-radius: 20px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 19px;
  font-weight: 640;
  letter-spacing: 0.02em;
  font-family: inherit;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(13, 138, 124, 0.24);
  transition: transform 0.14s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.play-btn:active { transform: scale(0.985); }

.play-btn .ico-pause { display: none; }
body.is-playing .play-btn .ico-play { display: none; }
body.is-playing .play-btn .ico-pause { display: block; }

.play-btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
  min-height: 52px;
  font-size: 16px;
  margin-top: 6px;
}

/* ---------- presets ---------- */

.presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 4px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.chip {
  border: none;
  background: transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 15px;
  font-weight: 560;
  padding: 10px 4px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.chip.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow);
}

/* ---------- misc ---------- */

.safety {
  margin: 2px 4px 4px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}

.a2hs {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 11px 12px;
  border-radius: 16px;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-2);
  flex: 0 0 auto;
}

.a2hs button {
  border: none; background: transparent; color: var(--muted);
  font-size: 15px; padding: 4px 6px; cursor: pointer;
}

.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; }

.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(10, 14, 13, 0.42);
  backdrop-filter: blur(3px);
}

.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  padding: 22px 22px calc(var(--safe-bottom) + 20px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
  max-height: 84dvh;
  overflow-y: auto;
  animation: sheet-up 0.28s cubic-bezier(0.22, 0.61, 0.36, 1);
}

@keyframes sheet-up {
  from { transform: translateY(14%); }
  to { transform: translateY(0); }
}

.sheet-panel h2 { margin: 0 0 10px; font-size: 20px; }
.sheet-panel h3 { margin: 18px 0 6px; font-size: 15px; color: var(--ink-2); }
.sheet-panel p, .sheet-panel li { font-size: 14px; color: var(--ink-2); line-height: 1.65; }
.sheet-panel ol { margin: 0; padding-left: 20px; }
.sheet-meta { color: var(--muted) !important; font-size: 12.5px !important; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 84px);
  transform: translateX(-50%);
  background: rgba(20, 24, 23, 0.92);
  color: #fff;
  font-size: 13.5px;
  padding: 10px 16px;
  border-radius: 999px;
  z-index: 30;
  max-width: 84vw;
  text-align: center;
  animation: toast-in 0.22s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.no-audio { color: #c0522f; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

@media (min-width: 480px) {
  .level-value { font-size: 52px; }
  .timer-main { font-size: 68px; }
}
