/* ============================================================
   LOVE · 函数拼字 —— 简洁风格样式
   纯手写 CSS，无依赖，可直接放到 GitHub Pages
   ============================================================ */

:root {
  --bg: #fbfafc;
  --card: #ffffff;
  --ink: #111621;
  --muted: #6c7789;
  --muted-2: #9aa5b5;
  --line: #edf0f5;
  --line-2: #dfe4ec;
  --accent: #e11d48;
  --accent-soft: #fdeef3;
  --ok: #0f9d78;
  --radius: 20px;
  --shadow: 0 1px 2px rgba(17, 22, 33, .04), 0 18px 40px -24px rgba(17, 22, 33, .22);
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --serif: Georgia, "Times New Roman", "Songti SC", serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.modal-open { overflow: hidden; }

a { color: inherit; text-decoration: none; }

button { font-family: inherit; }

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 20px 26px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */

.bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 2px 18px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.brand-mark {
  font-family: var(--serif);
  font-style: italic;
  font-size: 21px;
  letter-spacing: .02em;
  color: var(--accent);
}

.brand-sub {
  font-size: 12px;
  letter-spacing: .18em;
  color: var(--muted-2);
}

.steps {
  margin-left: auto;
  display: flex;
  gap: 7px;
}

.step {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: border-color .18s ease, color .18s ease, background .18s ease, transform .18s ease, box-shadow .18s ease;
}

.step:hover { transform: translateY(-1px); border-color: var(--accent); color: var(--accent); }
.step.current { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.step.done { background: var(--accent); border-color: var(--accent); color: #fff; }
.step.done:hover { color: #fff; }
.step.locked { opacity: .45; cursor: default; transform: none; }
.step.locked:hover { border-color: var(--line-2); color: var(--muted); }

.bar-actions { display: flex; gap: 8px; }

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

.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .16s ease, color .16s ease, border-color .16s ease, transform .16s ease;
  background: none;
}

.btn:active { transform: scale(.98); }

.btn.ghost {
  color: var(--muted);
  border-color: var(--line-2);
  background: #fff;
}

.btn.ghost:hover { color: var(--accent); border-color: var(--accent); }

.btn.primary {
  color: #fff;
  background: var(--accent);
}

.btn.primary:hover { background: #c9163f; }

.btn.wide { width: 100%; padding: 11px 16px; margin-top: 6px; }

/* ---------- 主布局 ---------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 348px;
  gap: 20px;
  align-items: start;
}

.stage {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: box-shadow .3s ease;
}

.stage.passed { box-shadow: 0 1px 2px rgba(17,22,33,.04), 0 0 0 1px rgba(225, 29, 72, .12), 0 22px 46px -26px rgba(225, 29, 72, .35); }

.stage-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.level-info {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}

.level-no {
  font-family: var(--serif);
  font-size: 13px;
  color: var(--muted-2);
  letter-spacing: .1em;
  padding-top: 8px;
}

.level-title {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 21px;
  font-weight: 600;
  line-height: 1.2;
}

.level-title #levelLetter {
  font-family: var(--serif);
  font-style: italic;
  font-size: 30px;
  color: var(--accent);
  line-height: 1;
}

.level-title small {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: .08em;
}

.level-desc {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  max-width: 34em;
}

.score {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  padding-top: 2px;
}

.score-num {
  display: flex;
  align-items: baseline;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}

.score-num b {
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -.02em;
  line-height: 1;
  transition: color .2s ease;
}

.score-num span { font-size: 13px; color: var(--muted-2); }

.score.passed .score-num b { color: var(--accent); }

.score-meta { display: flex; flex-direction: column; gap: 2px; }

.stars { display: flex; gap: 2px; font-size: 13px; color: #dfe4ec; line-height: 1; }
.stars span { transition: color .2s ease, transform .2s ease; }
.stars span.on { color: var(--accent); }
.stars span.on:nth-child(2) { transform: translateY(-1px); }

.score-meta small { font-size: 10.5px; color: var(--muted-2); letter-spacing: .1em; }

/* ---------- 画板 ---------- */

.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 680px;
  margin: 0 auto;
}

canvas#board {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  background: #fff;
  touch-action: manipulation;
}

.tip {
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted-2);
  min-height: 18px;
}

/* ---------- 右侧面板 ---------- */

.panel { display: flex; flex-direction: column; gap: 12px; }

.panel-block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px 14px;
  box-shadow: 0 1px 2px rgba(17, 22, 33, .03);
}

.panel-title {
  margin: 0 0 10px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .14em;
  color: var(--muted);
}

.panel-title .count {
  font-weight: 500;
  letter-spacing: .04em;
  font-size: 11px;
  color: var(--muted-2);
}

/* 已添加的函数 */

.fn-list { display: flex; flex-direction: column; gap: 7px; }

.fn-empty {
  margin: 0;
  padding: 10px 2px 6px;
  font-size: 12.5px;
  color: var(--muted-2);
}

.fn-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: border-color .16s ease, background .16s ease;
}

.fn-chip:hover { border-color: var(--line-2); }

.fn-chip.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.fn-chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
  opacity: .35;
}

.fn-chip.selected .dot { opacity: 1; }

.fn-chip .eq {
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fn-chip .del {
  margin-left: auto;
  border: 0;
  background: none;
  color: var(--muted-2);
  font-size: 15px;
  line-height: 1;
  padding: 3px 2px 3px 8px;
  cursor: pointer;
  border-radius: 6px;
  flex: none;
}

.fn-chip .del:hover { color: var(--accent); }

/* 函数库 */

.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }

.pal-btn {
  text-align: left;
  padding: 8px 10px 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: border-color .16s ease, transform .16s ease, background .16s ease;
  min-width: 0;
}

.pal-btn:hover { border-color: var(--accent); background: #fffafc; transform: translateY(-1px); }
.pal-btn:active { transform: translateY(0); }
.pal-btn b { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink); }
.pal-btn .f {
  display: block;
  font-family: var(--serif);
  font-style: italic;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

/* 参数 */

.params { display: flex; flex-direction: column; gap: 9px; }

.param {
  display: grid;
  grid-template-columns: 74px 1fr 54px;
  align-items: center;
  gap: 9px;
  font-size: 12px;
}

.param label { color: var(--muted); white-space: nowrap; }

.param input[type="range"] {
  width: 100%;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  background: transparent;
}

.param output {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink);
  font-family: var(--serif);
}

/* 提示 */

details.hint summary {
  cursor: pointer;
  font-size: 12.5px;
  color: var(--muted);
  list-style: none;
  user-select: none;
}

details.hint summary::-webkit-details-marker { display: none; }
details.hint summary::after { content: "+"; float: right; color: var(--muted-2); font-size: 14px; }
details.hint[open] summary { color: var(--accent); }
details.hint[open] summary::after { content: "−"; }
details.hint p { margin: 10px 0 0; font-size: 12.5px; line-height: 1.75; color: var(--ink); }

/* 行动区 */

.cta { display: flex; flex-direction: column; gap: 8px; }

.cta-hint {
  margin: 0;
  padding: 2px 4px;
  font-size: 12px;
  color: var(--muted-2);
  text-align: center;
}

.cta-best {
  margin: 0;
  font-size: 11.5px;
  color: var(--muted-2);
  text-align: center;
}

.cta .btn.primary { width: 100%; padding: 11px 16px; }

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

.foot {
  padding: 22px 0 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted-2);
  letter-spacing: .06em;
}

.foot-love {
  font-family: var(--serif);
  font-style: italic;
  font-size: 12px;
  letter-spacing: .02em;
  color: #b9aeb5;
}

/* ---------- 提示气泡 ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 10px);
  background: rgba(17, 22, 33, .92);
  color: #fff;
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
  max-width: 86vw;
  text-align: center;
}

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

/* ---------- 弹层 ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 22, 33, .38);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in .18s ease both;
}

.modal[hidden] { display: none; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  background: #fff;
  border-radius: 22px;
  padding: 26px 26px 22px;
  box-shadow: 0 30px 80px -30px rgba(17, 22, 33, .45);
  animation: pop-in .22s cubic-bezier(.2, .8, .2, 1) both;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.modal-card h2 { margin: 0 0 14px; font-size: 20px; font-weight: 650; letter-spacing: .02em; }

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted-2);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover { background: var(--line); color: var(--ink); }

.help-list {
  margin: 0 0 12px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--ink);
}

.help-list b { color: var(--accent); font-family: var(--serif); font-style: italic; font-size: 15px; }

.help-note {
  margin: 0 0 14px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 12px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
}

/* 通关 */

.finale-card { width: min(860px, 100%); }
.finale-eyebrow {
  margin: 0 0 2px;
  font-size: 11.5px;
  letter-spacing: .22em;
  color: var(--muted-2);
  text-align: center;
}

#finaleTitle {
  display: flex;
  justify-content: center;
  gap: .16em;
  margin: 0 0 10px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 40px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: .01em;
}

#finaleTitle span { display: inline-block; animation: letter-in .5s cubic-bezier(.2,.8,.2,1) both; }
#finaleTitle span:nth-child(1) { animation-delay: .05s; }
#finaleTitle span:nth-child(2) { animation-delay: .17s; }
#finaleTitle span:nth-child(3) { animation-delay: .29s; }
#finaleTitle span:nth-child(4) { animation-delay: .41s; }

@keyframes letter-in {
  from { opacity: 0; transform: translateY(10px) scale(.92); }
  to { opacity: 1; transform: none; }
}

.finale-board { background: var(--bg); border-radius: 14px; overflow: hidden; }
.finale-board canvas { display: block; width: 100%; }

.finale-note {
  margin: 12px 0 16px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--serif);
  font-style: italic;
}

.finale-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.finale-actions .btn { padding: 10px 18px; }

/* ---------- 响应式 ---------- */

@media (max-width: 980px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .panel { order: 2; }
  .stage { order: 1; }
  .palette { grid-template-columns: repeat(3, 1fr); }
  .board-wrap { max-width: none; }
}

@media (max-width: 620px) {
  .page { padding: 12px 12px 20px; }
  .bar { gap: 10px; padding-bottom: 14px; }
  .brand-sub { display: none; }
  .stage { padding: 14px 14px 12px; border-radius: 16px; }
  .stage-head { align-items: center; }
  .level-title { font-size: 18px; }
  .level-title #levelLetter { font-size: 25px; }
  .level-desc { display: none; }
  .score-num b { font-size: 24px; }
  .stars { font-size: 12px; }
  .palette { grid-template-columns: 1fr 1fr; }
  .param { grid-template-columns: 66px 1fr 46px; }
  .modal { padding: 12px; }
  .modal-card { padding: 20px 18px 18px; border-radius: 18px; }
  #finaleTitle { font-size: 32px; }
  .step { width: 30px; height: 30px; font-size: 14px; }
  .bar-actions .btn { padding: 7px 10px; font-size: 12px; }
}

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