/* 妙题家教 · 钢笔买卖题 — Socratic tutoring UI */
:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --ink: #1a202c;
  --ink-muted: #4a5568;
  --ink-faint: #718096;
  --brand: #2b6cb0;
  --brand-dark: #1a365d;
  --brand-soft: #ebf8ff;
  --accent: #dd6b20;
  --accent-soft: #fffaf0;
  --success: #38a169;
  --success-soft: #f0fff4;
  --danger: #e53e3e;
  --danger-soft: #fff5f5;
  --lock: #a0aec0;
  --cost: #3182ce;
  --qty: #805ad5;
  --profit: #dd6b20;
  --sell: #38a169;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(26, 54, 93, 0.08);
  --shadow-lg: 0 12px 40px rgba(26, 54, 93, 0.12);
  --font: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "SF Mono", "Cascadia Code", ui-monospace, monospace;
  --stage-min: 280px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(160deg, #e8f0fe 0%, var(--bg) 40%, #fef6e8 100%);
  min-height: 100dvh;
  line-height: 1.55;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); border: 0;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

/* —— Topbar —— */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff; font-weight: 700; font-size: 1.25rem;
  display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(43, 108, 176, 0.35);
}
.brand-text h1 {
  margin: 0; font-size: 1.15rem; font-weight: 700; color: var(--brand-dark);
}
.brand-sub { margin: 2px 0 0; font-size: 0.78rem; color: var(--ink-faint); }
.progress-pill {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); padding: 8px 14px; border-radius: 999px;
  box-shadow: var(--shadow); font-size: 0.85rem; font-weight: 600;
  color: var(--brand-dark);
}
.progress-track {
  width: 88px; height: 6px; background: #e2e8f0; border-radius: 999px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--brand), var(--success));
  border-radius: 999px; transition: width 0.45s ease;
}

.topbar-right {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.voice-wrap {
  display: flex; flex-direction: column; align-items: flex-end; gap: 2px;
}
.btn-voice {
  appearance: none; font-family: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 999px;
  border: 1.5px solid #bee3f8;
  background: var(--brand-soft); color: var(--brand-dark);
  font-size: 0.82rem; font-weight: 700;
  box-shadow: var(--shadow);
  transition: background 0.2s, border-color 0.2s, color 0.2s, opacity 0.2s;
}
.btn-voice:hover { border-color: var(--brand); }
.btn-voice.is-on {
  background: linear-gradient(135deg, #ebf8ff, #e6fffa);
  border-color: #63b3ed; color: var(--brand-dark);
}
.btn-voice.is-off {
  background: #edf2f7; border-color: #cbd5e0; color: var(--ink-faint);
}
.btn-voice .voice-icon { font-size: 0.95rem; line-height: 1; }
.voice-note {
  margin: 0; font-size: 0.68rem; color: var(--ink-faint);
  max-width: 11rem; text-align: right; line-height: 1.25;
}
.voice-note.is-hidden { display: none; }

/* —— Problem card —— */
.problem-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  border-left: 4px solid var(--brand);
}
.problem-label {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--brand); margin-bottom: 4px;
}
.problem-text { margin: 0; font-size: 1rem; color: var(--ink); }
.tok {
  display: inline-block;
  font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 1px 6px; border-radius: 6px;
  opacity: 0; transform: translateY(8px) scale(0.85);
}
.tok.visible {
  opacity: 1; transform: none;
  transition: opacity 0.4s ease, transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.tok-cost { background: #ebf8ff; color: var(--cost); }
.tok-qty { background: #faf5ff; color: var(--qty); }
.tok-profit { background: var(--accent-soft); color: var(--profit); }

/* —— Main grid —— */
.main-grid {
  display: grid;
  grid-template-columns: 200px 1fr 260px;
  gap: 14px;
  align-items: start;
}
@media (max-width: 960px) {
  .main-grid { grid-template-columns: 1fr; }
  .chapter-panel { order: 2; }
  .tutor-panel { order: 1; }
  .chat-panel { order: 3; }
}

.panel-title {
  margin: 0 0 10px; font-size: 0.82rem; font-weight: 700;
  color: var(--ink-muted); letter-spacing: 0.04em;
}
.lock-hint {
  margin: 10px 0 0; font-size: 0.72rem; color: var(--ink-faint); line-height: 1.4;
}

/* —— Chapter list —— */
.chapter-panel, .chat-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.chapter-list {
  list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px;
}
.chapter-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  font-size: 0.88rem; cursor: pointer; border: 1.5px solid transparent;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
  color: var(--ink);
  background: transparent;
  text-align: left; width: 100%; font-family: inherit;
}
.chapter-item:hover:not(:disabled):not(.locked) {
  background: var(--brand-soft);
}
.chapter-item.active {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-dark);
  font-weight: 600;
}
.chapter-item.done:not(.active) {
  color: var(--success);
}
.chapter-item.locked {
  color: var(--lock);
  cursor: not-allowed;
  opacity: 0.7;
}
.chapter-item .ch-icon {
  flex-shrink: 0; width: 1.4em; text-align: center; font-size: 0.9rem;
}
.chapter-item .ch-num {
  font-size: 0.7rem; font-weight: 700; color: var(--ink-faint);
  min-width: 1.2em;
}

/* —— Stage: 小黑板 —— */
.stage {
  --chalk: #f3efe0;
  --chalk-soft: #e8e0c8;
  --chalk-yellow: #ffe9a8;
  --chalk-green: #b7e4c7;
  --chalk-blue: #a8d4ff;
  --chalk-lilac: #d4bfff;
  --chalk-orange: #ffd19a;
  --board-green: #1e3d2f;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,0.06) 0%, transparent 42%),
    radial-gradient(ellipse at 70% 80%, rgba(0,0,0,0.18) 0%, transparent 50%),
    repeating-linear-gradient(
      0deg,
      rgba(255,255,255,0.015) 0px,
      rgba(255,255,255,0.015) 1px,
      transparent 1px,
      transparent 3px
    ),
    linear-gradient(165deg, #163528 0%, #1e3d2f 45%, #244a38 100%);
  border-radius: 10px;
  min-height: var(--stage-min);
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
  color: var(--chalk);
  border: 10px solid #8b5a2b;
  box-shadow:
    inset 0 0 0 2px #6d4320,
    inset 0 0 40px rgba(0,0,0,0.35),
    0 10px 28px rgba(26, 54, 93, 0.22);
  font-family: "KaiTi", "STKaiti", "TW-Kai", "Noto Serif SC", cursive, serif;
}
.stage::before {
  content: "";
  position: absolute; inset: 0;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.04 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.55;
  pointer-events: none;
  mix-blend-mode: soft-light;
}
.stage::after {
  content: "";
  position: absolute;
  right: 14px; bottom: 10px;
  width: 42px; height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, #f5f0e1, #d9d2bc);
  box-shadow: 0 1px 2px rgba(0,0,0,0.25);
  opacity: 0.55;
  pointer-events: none;
}
.stage-inner {
  position: relative;
  z-index: 1;
  min-height: var(--stage-min);
  padding: 22px 18px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.stage-caption {
  font-size: 0.85rem;
  opacity: 0.82;
  letter-spacing: 0.12em;
  text-align: center;
  color: var(--chalk-soft);
  text-shadow: 0 1px 0 rgba(0,0,0,0.25);
}
.board-write {
  width: 100%;
  max-width: 520px;
  min-height: 2.2em;
  text-align: center;
  font-size: clamp(1.15rem, 2.8vw, 1.55rem);
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--chalk);
  text-shadow: 0 1px 1px rgba(0,0,0,0.35);
  line-height: 1.55;
}
.board-write .chalk-char {
  display: inline-block;
  opacity: 0;
  transform: translateY(4px) rotate(-2deg);
  filter: blur(0.6px);
  transition: opacity 0.18s ease, transform 0.22s ease, filter 0.22s ease, color 0.2s;
}
.board-write .chalk-char.on {
  opacity: 1;
  transform: none;
  filter: none;
}
.board-write .chalk-char.hl {
  color: var(--chalk-yellow);
}
.board-write .chalk-char.dust::after {
  content: "";
  position: absolute;
  width: 3px; height: 3px;
  border-radius: 50%;
  background: rgba(243,239,224,0.55);
  animation: chalk-dust 0.55s ease-out forwards;
}
@keyframes chalk-dust {
  0% { opacity: 0.8; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(6px, 10px) scale(0.3); }
}
.board-erase {
  animation: board-wipe 0.35s ease forwards;
}
@keyframes board-wipe {
  to { opacity: 0; filter: blur(2px); transform: translateX(8px); }
}

/* Stage building blocks — chalk cards */
.token-row {
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center;
}
.big-token {
  background: transparent;
  border: 1.5px dashed rgba(243,239,224,0.35);
  border-radius: 8px;
  padding: 12px 16px;
  text-align: center;
  min-width: 88px;
  opacity: 0;
  transform: translateY(10px);
  box-shadow: none;
}
.big-token.show {
  opacity: 1; transform: none;
  transition: opacity 0.45s ease, transform 0.45s ease;
}
.big-token .bt-val {
  font-size: 1.85rem; font-weight: 700; font-variant-numeric: tabular-nums;
  line-height: 1.1; letter-spacing: 0.08em;
  text-shadow: 0 1px 0 rgba(0,0,0,0.3);
}
.big-token .bt-label { font-size: 0.78rem; opacity: 0.78; margin-top: 4px; letter-spacing: 0.1em; }
.big-token.cost .bt-val { color: var(--chalk-blue); }
.big-token.qty .bt-val { color: var(--chalk-lilac); }
.big-token.profit .bt-val { color: var(--chalk-orange); }
.big-token.sell .bt-val { color: var(--chalk-green); }
.big-token.answer .bt-val { color: var(--chalk-yellow); font-size: 2.2rem; }

/* Known cards */
.card-row {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; width: 100%;
}
.info-card {
  background: transparent;
  border: 1.5px dashed rgba(243,239,224,0.32);
  border-radius: 8px;
  padding: 12px 14px;
  min-width: 100px; flex: 1 1 100px; max-width: 140px;
  text-align: center;
  opacity: 0; transform: translateY(8px);
}
.info-card.show {
  opacity: 1; transform: none;
  transition: opacity 0.4s ease, transform 0.4s ease;
}
.info-card .ic-title { font-size: 0.78rem; opacity: 0.78; margin-bottom: 4px; letter-spacing: 0.1em; }
.info-card .ic-val { font-size: 1.45rem; font-weight: 700; letter-spacing: 0.08em; color: var(--chalk-yellow); }
.info-card .ic-tag {
  display: inline-block; margin-top: 6px; font-size: 0.7rem; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid rgba(243,239,224,0.35);
  letter-spacing: 0.08em;
}
.info-card.known .ic-tag { background: rgba(56,161,105,0.2); color: var(--chalk-green); }
.info-card.unknown .ic-tag { background: rgba(229,62,62,0.18); color: #ffc9c9; }
.info-card.highlight {
  border-color: var(--chalk-yellow);
  box-shadow: 0 0 0 1px rgba(255,233,168,0.35);
}

/* Relation bars */
.bar-scene {
  width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 10px;
}
.bar-row {
  display: grid; grid-template-columns: 64px 1fr 48px;
  align-items: center; gap: 8px; font-size: 0.78rem;
}
.bar-label { opacity: 0.85; text-align: right; }
.bar-track {
  height: 28px; background: rgba(0,0,0,0.28); border-radius: 4px; overflow: hidden;
  position: relative; border: 1px solid rgba(243,239,224,0.18);
}
.bar-fill {
  height: 100%; width: 0%; border-radius: 3px;
  transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex; align-items: center; justify-content: flex-end; padding-right: 8px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
}
.bar-fill.cost { background: linear-gradient(90deg, rgba(43,108,176,0.55), rgba(99,179,237,0.75)); }
.bar-fill.profit { background: linear-gradient(90deg, rgba(192,86,33,0.55), rgba(246,173,85,0.75)); }
.bar-fill.sell { background: linear-gradient(90deg, rgba(39,103,73,0.55), rgba(104,211,145,0.75)); }
.bar-num { font-weight: 700; font-variant-numeric: tabular-nums; opacity: 0; transition: opacity 0.3s; }
.bar-num.show { opacity: 1; }
.bar-plus {
  text-align: center; font-size: 1.2rem; font-weight: 700; opacity: 0;
  transition: opacity 0.3s;
}
.bar-plus.show { opacity: 1; }

/* Addition fly-in */
.add-scene {
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums;
}
.add-scene .op { opacity: 0.6; font-weight: 500; }
.add-scene { letter-spacing: 0.1em; color: var(--chalk); }
.add-num {
  display: inline-block;
  padding: 8px 14px; border-radius: 6px;
  background: transparent;
  border: 1px dashed rgba(243,239,224,0.35);
  opacity: 0; transform: translateY(-12px);
}
.add-num.fly {
  opacity: 1; transform: none;
  transition: opacity 0.4s, transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.add-num.result {
  background: transparent;
  border: 1.5px dashed rgba(255,233,168,0.55);
  color: var(--chalk-yellow);
  transform: scale(0.5);
}
.add-num.result.fly {
  transform: scale(1.08);
  animation: pulse-once 0.6s 0.4s ease;
}
@keyframes pulse-once {
  0%, 100% { transform: scale(1.08); }
  50% { transform: scale(1.18); }
}

/* Division / split scene */
.split-scene {
  width: 100%; max-width: 400px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.pile {
  width: 160px; height: 70px;
  background: transparent;
  border: 2px dashed rgba(183,228,199,0.55);
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 1.45rem; font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--chalk-green);
  transition: transform 0.5s, opacity 0.5s;
}
.pile.splitting {
  transform: scaleY(0.3) scaleX(1.2);
  opacity: 0.3;
}
.pen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(18px, 1fr));
  gap: 4px;
  width: 100%;
  max-width: 360px;
  justify-items: center;
}
.pen-cell {
  width: 18px; height: 28px;
  background: transparent;
  border-radius: 3px 3px 6px 6px;
  border: 1px dashed rgba(243,239,224,0.4);
  opacity: 0;
  transform: translateY(-12px);
  position: relative;
}
.pen-cell::after {
  content: "";
  position: absolute; top: 2px; left: 50%; transform: translateX(-50%);
  width: 4px; height: 6px; border-radius: 2px;
  background: rgba(251,211,141,0.7);
}
.pen-cell.show {
  opacity: 1; transform: none;
  transition: opacity 0.25s, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.pen-cell .pc-label {
  position: absolute; bottom: -16px; left: 50%; transform: translateX(-50%);
  font-size: 0.55rem; white-space: nowrap; opacity: 0;
  transition: opacity 0.3s;
}
.pen-cell.show-price .pc-label { opacity: 1; color: #faf089; font-weight: 700; }
.split-result {
  font-size: 1.5rem; font-weight: 700; color: var(--chalk-yellow);
  letter-spacing: 0.12em;
  opacity: 0; transform: scale(0.5);
}
.split-result.show {
  opacity: 1; transform: scale(1);
  transition: opacity 0.4s, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: celebrate 0.8s ease;
}
@keyframes celebrate {
  0% { transform: scale(0.5); }
  40% { transform: scale(1.25); }
  70% { transform: scale(0.95); }
  100% { transform: scale(1); }
}

/* Alt path */
.alt-scene {
  display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%;
}
.alt-eq {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  font-size: 1.2rem; font-weight: 700;
}
.alt-chip {
  padding: 8px 12px; border-radius: 10px;
  background: rgba(255,255,255,0.12);
  opacity: 0; transform: translateX(-16px);
}
.alt-chip.show {
  opacity: 1; transform: none;
  transition: opacity 0.4s, transform 0.45s ease;
}
.alt-chip.cost-u { border-bottom: 3px solid #63b3ed; }
.alt-chip.profit-u { border-bottom: 3px solid #f6ad55; }
.alt-chip.sum { border-bottom: 3px solid #faf089; color: #faf089; }

/* Check scene */
.check-scene {
  display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 380px;
}
.check-row {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,0.08);
  border-radius: 12px; padding: 12px 16px;
  opacity: 0; transform: translateX(-20px);
}
.check-row.show {
  opacity: 1; transform: none;
  transition: opacity 0.4s, transform 0.45s ease;
}
.check-eq { flex: 1; font-weight: 600; font-size: 1rem; }
.check-mark {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(56,161,105,0.3);
  display: grid; place-items: center;
  font-size: 1.1rem;
  transform: scale(0);
}
.check-row.show .check-mark {
  transform: scale(1);
  transition: transform 0.4s 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.confetti {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2;
}
.confetti i {
  position: absolute; width: 8px; height: 8px; border-radius: 2px;
  top: -10px; animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(320px) rotate(720deg); opacity: 0; }
}

/* —— Tutor card —— */
.tutor-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.tutor-meta { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; flex-wrap: wrap; }
.chapter-badge {
  font-size: 0.7rem; font-weight: 700; color: var(--brand);
  background: var(--brand-soft); padding: 3px 8px; border-radius: 999px;
}
.chapter-title { margin: 0; font-size: 1.15rem; color: var(--brand-dark); }
.chapter-subtitle {
  margin: 0 0 12px; font-size: 0.88rem; color: var(--ink-muted);
}
.tutor-bubble {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px;
}
.tutor-avatar {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff; font-weight: 700; font-size: 0.9rem;
  display: grid; place-items: center;
}
.speech-label { font-size: 0.68rem; font-weight: 700; color: var(--brand); margin-bottom: 2px; }
.speech-text { margin: 0; font-size: 0.95rem; color: var(--ink); }

/* —— Gate zone —— */
.gate-zone {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed #e2e8f0;
}
.gate-zone:empty { display: none; }
.gate-prompt {
  font-size: 0.95rem; font-weight: 600; color: var(--brand-dark); margin: 0 0 10px;
}
.gate-options {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.gate-opt {
  appearance: none; font-family: inherit; cursor: pointer;
  padding: 10px 16px; border-radius: 10px;
  border: 1.5px solid #cbd5e0; background: var(--surface);
  font-size: 0.9rem; color: var(--ink);
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.gate-opt:hover:not(:disabled) {
  border-color: var(--brand); background: var(--brand-soft);
}
.gate-opt:active:not(:disabled) { transform: scale(0.97); }
.gate-opt.correct {
  border-color: var(--success); background: var(--success-soft); color: #276749; font-weight: 600;
}
.gate-opt.wrong {
  border-color: var(--danger); background: var(--danger-soft); color: #c53030;
  animation: shake 0.4s ease;
}
.gate-opt:disabled { cursor: default; opacity: 0.85; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
.gate-feedback {
  margin-top: 10px; font-size: 0.88rem; padding: 8px 12px; border-radius: 8px;
  animation: fade-up 0.3s ease;
}
.gate-feedback.ok { background: var(--success-soft); color: #276749; }
.gate-feedback.no { background: var(--danger-soft); color: #c53030; }
.gate-feedback.hint { background: var(--accent-soft); color: #c05621; }
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.gate-input-row {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.gate-input {
  flex: 1 1 120px; min-width: 100px;
  padding: 10px 14px; border-radius: 10px;
  border: 1.5px solid #cbd5e0; font-size: 1rem; font-family: inherit;
  font-variant-numeric: tabular-nums;
}
.gate-input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.2);
}
.gate-hint-btn {
  appearance: none; font-family: inherit; cursor: pointer;
  background: none; border: none; color: var(--ink-faint);
  font-size: 0.82rem; text-decoration: underline; padding: 4px 0;
  margin-top: 8px;
}
.gate-hint-btn:hover { color: var(--brand); }

.tag-pick-row {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-start;
}
.tag-card {
  flex: 1 1 90px; max-width: 130px;
  background: var(--surface-2); border: 1.5px solid #e2e8f0;
  border-radius: 12px; padding: 10px; text-align: center;
}
.tag-card .tc-name { font-size: 0.78rem; color: var(--ink-muted); }
.tag-card .tc-val { font-size: 1.15rem; font-weight: 800; margin: 4px 0 8px; }
.tag-card .tc-btns { display: flex; gap: 4px; justify-content: center; }
.tag-card .tc-btns button {
  appearance: none; font-family: inherit; cursor: pointer;
  font-size: 0.72rem; padding: 4px 8px; border-radius: 6px;
  border: 1px solid #cbd5e0; background: #fff;
}
.tag-card .tc-btns button.sel-known {
  background: var(--success-soft); border-color: var(--success); color: #276749; font-weight: 600;
}
.tag-card .tc-btns button.sel-unknown {
  background: var(--danger-soft); border-color: var(--danger); color: #c53030; font-weight: 600;
}
.tag-card .tc-btns button:disabled { cursor: default; }

.formula-strip {
  margin-top: 12px; padding: 10px 14px;
  background: var(--brand-soft); border-radius: 10px;
  font-family: var(--mono); font-size: 0.95rem; font-weight: 600;
  color: var(--brand-dark); text-align: center;
  animation: fade-up 0.35s ease;
}

/* —— Nav —— */
.nav-bar {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px;
}
.btn {
  appearance: none; font-family: inherit; cursor: pointer;
  padding: 10px 16px; border-radius: 10px; font-size: 0.9rem; font-weight: 600;
  border: none; transition: background 0.2s, opacity 0.2s, transform 0.1s;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-secondary { background: #e2e8f0; color: var(--ink); }
.btn-secondary:hover:not(:disabled) { background: #cbd5e0; }
.btn-ghost { background: transparent; color: var(--ink-muted); border: 1.5px solid #e2e8f0; }
.btn-ghost:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; }

.answer-hint {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: linear-gradient(90deg, #f0fff4, #fffff0);
  border: 1.5px solid #9ae6b4;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  animation: fade-up 0.4s ease;
}
.answer-label {
  font-size: 0.72rem; font-weight: 700; color: var(--success);
  background: #c6f6d5; padding: 2px 8px; border-radius: 999px;
}
.answer-value { font-size: 1.25rem; color: #22543d; }
.answer-note { font-size: 0.8rem; color: var(--ink-faint); }

/* —— Chat —— */
.chat-hint { margin: 0 0 10px; font-size: 0.78rem; color: var(--ink-faint); line-height: 1.4; }
.chat-log {
  height: 220px; overflow-y: auto;
  background: var(--surface-2); border-radius: 10px;
  padding: 10px; margin-bottom: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.chat-msg {
  max-width: 95%; padding: 8px 11px; border-radius: 12px;
  font-size: 0.85rem; line-height: 1.45; animation: fade-up 0.25s ease;
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--brand); color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg.bot {
  align-self: flex-start;
  background: var(--surface); border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px; color: var(--ink);
}
.chat-form { display: flex; gap: 6px; }
.chat-input {
  flex: 1; padding: 9px 12px; border-radius: 10px;
  border: 1.5px solid #cbd5e0; font-size: 0.88rem; font-family: inherit;
}
.chat-input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(43, 108, 176, 0.15);
}
.chat-send { flex-shrink: 0; padding: 9px 14px; }

.footer {
  margin-top: 20px; text-align: center;
  font-size: 0.75rem; color: var(--ink-faint);
}

@media (max-width: 600px) {
  .app { padding: 10px 10px 24px; }
  .brand-text h1 { font-size: 1rem; }
  .stage { min-height: 240px; border-width: 8px; }
  .stage-inner { min-height: 240px; padding: 14px 12px 22px; }
  .add-scene { font-size: 1.25rem; }
  .chat-log { height: 160px; }
  .nav-bar .btn { flex: 1 1 auto; text-align: center; }
  .voice-note { max-width: 8.5rem; }
  .topbar-right { width: 100%; justify-content: space-between; }
}


/* Chalk overrides for remaining stage widgets */
.alt-chip {
  background: transparent !important;
  border: 1px dashed rgba(243,239,224,0.4) !important;
  color: var(--chalk) !important;
  letter-spacing: 0.08em;
}
.alt-chip.sum { color: var(--chalk-yellow) !important; border-color: rgba(255,233,168,0.55) !important; }
.check-row { color: var(--chalk); letter-spacing: 0.08em; }
.check-mark { color: var(--chalk-green); }
.formula-strip {
  font-family: "KaiTi", "STKaiti", cursive, var(--mono);
  letter-spacing: 0.06em;
}
