:root {
  --bg-cream: #FFFBF2;
  --bg-warm: #FFF4DF;
  --card-bg: #FFFFFF;
  --ink: #3D2C2E;
  --ink-soft: #756063;
  --sun: #FFB703;
  --sun-deep: #F49D00;
  --coral: #FF6B4A;
  --coral-deep: #E55333;
  --mint: #2EC4B6;
  --mint-deep: #1FA89B;
  --sky: #4EA8DE;
  --sky-deep: #328BC2;
  --purple: #9B5DE5;
  --grid-red: #E05A47;
  --grid-line: #EFA397;
  --grid-diag: #F4C3BB;
  --fourline-outer: #7AC7B8;
  --fourline-inner: #E07A68;
  --shadow-soft: 0 10px 28px rgba(108, 72, 42, 0.09);
  --shadow-btn: 0 5px 0 rgba(0, 0, 0, 0.12);
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --font-ui: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Rounded Mplus 1c", system-ui, -apple-system, sans-serif;
  --font-pinyin: "Century Gothic", "Chalkboard SE", "Arial Rounded MT Bold", "Quicksand", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-kaiti: "KaiTi", "STKaiti", "BiauKai", "Kaiti SC", "DFKai-SB", "FangSong", serif;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 183, 3, 0.16), transparent 34%),
    radial-gradient(circle at 88% 12%, rgba(46, 196, 182, 0.15), transparent 32%),
    radial-gradient(circle at 84% 88%, rgba(255, 107, 74, 0.13), transparent 36%),
    var(--bg-cream);
  color: var(--ink);
  font-family: var(--font-ui);
  line-height: 1.5;
}

button, input, select {
  font-family: inherit;
  touch-action: manipulation;
}

.is-hidden {
  display: none !important;
}

.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 1200;
}

.app-shell {
  max-width: 1060px;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
}

/* ==================== Topbar ==================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 50px;
  height: 50px;
  border-radius: 16px;
  background: linear-gradient(135deg, #FFD166, #FFB703);
  display: grid;
  place-items: center;
  font-size: 28px;
  box-shadow: 0 6px 16px rgba(255, 183, 3, 0.35);
}

.brand-title {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--ink);
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 46px;
  padding: 8px 16px;
  border: 2px solid transparent;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.pill-btn:active {
  transform: translateY(2px);
}

.pill-sky {
  background: #E8F5FD;
  color: #1F6F9F;
  border-color: #BEE3F8;
}

.pill-mint {
  background: #E7FAF7;
  color: #12746B;
  border-color: #AEEBE2;
}

.pill-tag-mint {
  background: rgba(46, 196, 182, 0.2);
}

.pill-gold {
  background: #FFF3D1;
  color: #A65E00;
  border-color: #FFD97D;
}

.pill-soft {
  background: #FFFFFF;
  color: var(--ink);
  border-color: #EDE0CE;
}

.pill-tag {
  background: rgba(78, 168, 222, 0.18);
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
}

.pill-count {
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--coral);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

/* ==================== Mascot Coach Bar ==================== */
.coach-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card-bg);
  border: 2px solid #F3E5D0;
  border-radius: var(--radius-lg);
  padding: 8px 14px;
  box-shadow: var(--shadow-soft);
  margin-bottom: 10px;
}

.mascot-wrap {
  width: 60px;
  height: 60px;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}

.mascot-wrap.is-cheering {
  animation: mascotBounce 0.55s ease 2;
}

@keyframes mascotBounce {
  0%, 100% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-9px) scale(1.08); }
}

.mascot-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.coach-bubble {
  flex: 1;
  min-width: 0;
}

.coach-bubble-top {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}

.coach-name {
  font-size: 13px;
  font-weight: 800;
  color: var(--mint-deep);
}

.today-chip {
  font-size: 12px;
  font-weight: 700;
  background: #E8FAF7;
  color: #157F75;
  padding: 2px 10px;
  border-radius: 999px;
}

.coach-text {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.char-nav-mini {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-nav-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 2px solid #EFE1CE;
  background: #FFF9EE;
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-nav-btn:hover {
  background: #FFEEC7;
}

.char-index-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-soft);
  min-width: 48px;
  text-align: center;
}

/* ==================== 3-Step Stepper ==================== */
.step-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.step-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 18px;
  border-radius: 999px;
  border: 2px solid #EBDCC8;
  background: #FFFFFF;
  color: var(--ink-soft);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: all 0.16s ease;
}

.step-tab .step-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #F4EAE0;
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  font-size: 14px;
}

.step-tab.is-active {
  background: linear-gradient(135deg, #FF7B54, #FF5D3A);
  border-color: #E84E2D;
  color: #FFFFFF;
  box-shadow: 0 6px 16px rgba(255, 107, 74, 0.3);
}

.step-tab.is-active .step-num {
  background: #FFFFFF;
  color: #FF5D3A;
}

.step-tab.is-done {
  background: #E8FAF7;
  border-color: #8DE0D5;
  color: #167E74;
}

.step-tab.is-done .step-num {
  background: var(--mint);
  color: #FFFFFF;
}

.step-line {
  width: 30px;
  height: 4px;
  border-radius: 999px;
  background: #ECDCC8;
}

/* ==================== Main Stage Card ==================== */
.stage-card {
  background: var(--card-bg);
  border: 2px solid #F2E3CE;
  border-radius: var(--radius-xl);
  padding: 16px 20px;
  box-shadow: var(--shadow-soft);
}

.step-panel {
  display: none;
}

.step-panel.is-active {
  display: block;
  animation: fadeSlideIn 0.22s ease;
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==================== 四线三格 Pinyin Box ==================== */
.pinyin-fourline-box {
  position: relative;
  width: 100%;
  border: 2px solid #EBDAC5;
  border-radius: 16px;
  background: #FFFEFA;
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  display: block;
  transition: border-color 0.15s ease, transform 0.12s ease;
}

.pinyin-fourline-box:hover {
  border-color: var(--mint);
}

.pinyin-fourline-box:active {
  transform: scale(0.99);
}

.pinyin-fourline-lg {
  max-width: 310px;
  height: 92px;
  margin: 0 auto 14px;
}

.pinyin-fourline-md {
  max-width: 320px;
  height: 72px;
  margin: 0 auto 10px;
}

.pinyin-fourline-opt {
  height: 68px;
  width: 100%;
  pointer-events: none;
  border: none;
  background: transparent;
}

.fourline-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.fl-outer {
  stroke: var(--fourline-outer);
  stroke-width: 1.4;
}

.fl-inner {
  stroke: var(--fourline-inner);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}

.fl-base {
  stroke-dasharray: none;
  stroke-width: 1.7;
}

.fourline-text {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  font-family: var(--font-pinyin);
  font-weight: 700;
  color: #2B2D42;
  line-height: 1;
  letter-spacing: 1px;
  user-select: none;
}

.pinyin-fourline-lg .fourline-text {
  font-size: 46px;
  top: 26px;
}

.pinyin-fourline-md .fourline-text {
  font-size: 36px;
  top: 20px;
}

.pinyin-fourline-opt .fourline-text {
  font-size: 32px;
  top: 19px;
}

.audio-hint-badge {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 11px;
  font-weight: 700;
  color: #1E7E74;
  background: rgba(232, 250, 247, 0.92);
  padding: 2px 7px;
  border-radius: 999px;
}

/* ==================== 米字格 / 田字格 Hanzi Cell ==================== */
.hanzi-cell {
  position: relative;
  background: #FFFEFA;
  border-radius: 16px;
  padding: 0;
  border: none;
  display: grid;
  place-items: center;
  margin: 0 auto;
  overflow: hidden;
}

.hanzi-cell-lg {
  width: min(280px, 76vw);
  height: min(280px, 76vw);
  cursor: pointer;
  transition: transform 0.14s ease;
}

.hanzi-cell-lg:active {
  transform: scale(0.98);
}

.hanzi-grid-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.grid-border {
  fill: none;
  stroke: var(--grid-red);
  stroke-width: 3.6;
}

.grid-mid {
  stroke: var(--grid-line);
  stroke-width: 1.8;
  stroke-dasharray: 7 6;
}

.grid-diag {
  stroke: var(--grid-diag);
  stroke-width: 1.5;
  stroke-dasharray: 6 6;
  transition: opacity 0.2s ease;
}

.hanzi-cell.grid-tianzi .grid-diag {
  opacity: 0;
}

.hanzi-kaiti-display {
  position: relative;
  z-index: 2;
  font-family: var(--font-kaiti);
  font-size: min(192px, 50vw);
  line-height: 1;
  color: #2B2D42;
  user-select: none;
}

/* Grid Toggle Pill */
.grid-toggle {
  display: inline-flex;
  padding: 4px;
  border-radius: 999px;
  background: #F4EAE0;
  gap: 4px;
}

.grid-toggle-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 800;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.grid-toggle-btn.is-active {
  background: #FFFFFF;
  color: var(--coral-deep);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.grid-toggle-lg .grid-toggle-btn {
  min-height: 42px;
  padding: 8px 20px;
  font-size: 15px;
  flex: 1;
}

.grid-toggle-lg {
  width: 100%;
}

/* ==================== Step 1 Layout ==================== */
.learn-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

@media (min-width: 768px) {
  .learn-grid {
    grid-template-columns: 350px 1fr;
    gap: 26px;
  }
}

.notebook-card {
  background: #FFF9EE;
  border: 2px solid #F3E2C6;
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
}

.notebook-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.learned-ribbon {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #FFE8E1;
  color: #C94228;
  font-size: 13px;
  font-weight: 800;
  padding: 5px 12px;
  border-radius: 999px;
}

.char-meta-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.meta-chip {
  background: #FFFFFF;
  border: 1.5px solid #EFE0CB;
  border-radius: 10px;
  padding: 5px 10px;
  font-size: 13px;
  color: var(--ink-soft);
}

.meta-chip strong {
  color: var(--ink);
}

.learn-info-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.info-box {
  background: #FFFDF8;
  border: 2px solid #F2E6D6;
  border-radius: 16px;
  padding: 10px 14px;
}

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

.info-tag {
  font-size: 13px;
  font-weight: 800;
  padding: 3px 11px;
  border-radius: 999px;
}

.tag-orange { background: #FFF0D9; color: #C26700; }
.tag-teal { background: #E3F8F5; color: #147E73; }
.tag-blue { background: #E6F4FD; color: #1E6EA1; }
.tag-purple { background: #F2E8FD; color: #6F34B8; }

.mini-speak-btn {
  border: 1.5px solid #D9EFEA;
  background: #EDFBF8;
  color: #167B71;
  font-size: 13px;
  font-weight: 800;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.mini-speak-btn:active {
  transform: scale(0.96);
}

.pinyin-parts-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.pinyin-part-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 12px;
  font-family: var(--font-pinyin);
  font-size: 20px;
  font-weight: 800;
  background: #FFF3D6;
  color: #9C5300;
}

.pinyin-part-chip small {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 700;
  opacity: 0.78;
}

.pinyin-part-chip.is-whole {
  background: #E8F5FD;
  color: #1D6E9E;
}

.pinyin-plus {
  font-size: 18px;
  font-weight: 800;
  color: var(--ink-soft);
}

.tone-desc {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
}

.word-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.word-chip-btn {
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 14px;
  border: 2px solid #CDEEE9;
  background: #FFFFFF;
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.14s ease;
}

.word-chip-btn:hover {
  background: #E8FAF7;
  border-color: var(--mint);
}

.sentence-text {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
}

.sentence-highlight {
  display: inline-block;
  padding: 0 4px;
  border-radius: 6px;
  background: #FFE599;
  color: #C73E1D;
  font-weight: 800;
}

.tip-text {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #4E3769;
}

.step-cta-row {
  margin-top: 4px;
}

/* ==================== Buttons ==================== */
.primary-big-btn {
  width: 100%;
  min-height: 56px;
  padding: 12px 24px;
  border: none;
  border-radius: 18px;
  background: linear-gradient(135deg, #FF7A52, #FF5733);
  color: #FFFFFF;
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 6px 0 #CC3E1E, 0 10px 22px rgba(255, 87, 51, 0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.primary-big-btn:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #CC3E1E, 0 5px 12px rgba(255, 87, 51, 0.24);
}

.primary-big-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.primary-btn {
  min-height: 44px;
  padding: 8px 20px;
  border: none;
  border-radius: 12px;
  background: var(--coral);
  color: #FFFFFF;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.secondary-btn {
  min-height: 48px;
  padding: 10px 18px;
  border: 2px solid #EBDAC5;
  border-radius: 14px;
  background: #FFF9EE;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.secondary-btn:hover {
  background: #FFEEC7;
}

.ghost-btn {
  min-height: 48px;
  padding: 10px 18px;
  border: 2px dashed #DFC9AF;
  border-radius: 14px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.full-width {
  width: 100%;
}

/* ==================== Step 2: Quiz Stage ==================== */
.quiz-stage {
  max-width: 680px;
  margin: 0 auto;
  text-align: center;
}

.quiz-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.quiz-round-pill {
  background: #FFF3D1;
  color: #9A5500;
  font-size: 15px;
  font-weight: 800;
  padding: 7px 16px;
  border-radius: 999px;
}

.quiz-prompt-card {
  background: #FFF9EE;
  border: 2px solid #F2DFC2;
  border-radius: var(--radius-lg);
  padding: 20px 16px;
  margin-bottom: 18px;
}

.quiz-question-title {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
}

.quiz-big-char {
  display: inline-grid;
  place-items: center;
  width: 136px;
  height: 136px;
  margin: 0 auto;
  font-family: var(--font-kaiti);
  font-size: 98px;
  line-height: 1;
  background: #FFFEFA;
  border: 3px solid var(--grid-red);
  border-radius: 16px;
  color: #2B2D42;
}

.quiz-clue-words {
  margin: 10px 0 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink-soft);
}

.quiz-options-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.quiz-option-btn {
  min-height: 82px;
  padding: 10px 12px;
  border: 3px solid #ECDCC8;
  border-radius: 18px;
  background: #FFFFFF;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.quiz-option-btn:hover {
  border-color: var(--sky);
  background: #F4FAFF;
}

.quiz-option-btn:active {
  transform: scale(0.97);
}

.quiz-option-char {
  font-family: var(--font-kaiti);
  font-size: 56px;
  line-height: 1.1;
}

.quiz-option-btn.is-correct {
  border-color: var(--mint);
  background: #E6FAF7;
  animation: popSuccess 0.36s ease;
}

.quiz-option-btn.is-wrong {
  border-color: #FFB4A2;
  background: #FFF2EF;
  animation: gentleShake 0.35s ease;
}

@keyframes popSuccess {
  0% { transform: scale(1); }
  45% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes gentleShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.quiz-feedback {
  min-height: 28px;
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 800;
  color: var(--mint-deep);
}

.quiz-feedback.is-hint {
  color: #C96A00;
}

.quiz-footer-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* ==================== Step 3: Writing Stage (Tablet Optimized) ==================== */
.write-grid-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  align-items: start;
}

@media (min-width: 768px) {
  .write-grid-layout {
    grid-template-columns: minmax(320px, 380px) 1fr;
    gap: 26px;
    align-items: stretch;
  }
}

.write-board-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.write-notebook-frame {
  width: 100%;
  max-width: 360px;
  background: #FFF9EE;
  border: 2px solid #F2DFC2;
  border-radius: 22px;
  padding: 14px;
}

.write-cell {
  width: min(320px, 78vw);
  height: min(320px, 78vw);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  box-shadow: inset 0 0 0 1px rgba(224, 90, 71, 0.12);
}

.write-ghost-char {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  font-family: var(--font-kaiti);
  font-size: min(230px, 56vw);
  line-height: 1;
  color: rgba(186, 168, 152, 0.34);
  pointer-events: none;
  user-select: none;
}

.hanzi-writer-host {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hanzi-writer-host svg {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
}

.stroke-guide-svg {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.guide-start-pulse {
  fill: rgba(255, 87, 51, 0.28);
  transform-box: fill-box;
  transform-origin: center;
  animation: guidePulse 1.3s ease-out infinite;
}

@keyframes guidePulse {
  0% { transform: scale(0.82); opacity: 0.9; }
  75% { transform: scale(1.42); opacity: 0.12; }
  100% { transform: scale(1.48); opacity: 0; }
}

.guide-arrow-path {
  animation: dashFlow 1.1s linear infinite;
}

@keyframes dashFlow {
  from { stroke-dashoffset: 24; }
  to { stroke-dashoffset: 0; }
}

.write-cell.is-stroke-error {
  box-shadow: 0 0 0 4px rgba(255, 87, 51, 0.55);
  animation: gentleShake 0.4s ease;
}

.freehand-canvas {
  position: absolute;
  inset: 0;
  z-index: 5;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.write-status-bar {
  width: 100%;
  max-width: 360px;
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
}

.stroke-badge {
  display: inline-block;
  align-self: center;
  background: #E8F5FD;
  color: #1D6E9E;
  font-size: 14px;
  font-weight: 800;
  padding: 4px 14px;
  border-radius: 999px;
}

.write-feedback {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
  padding: 5px 10px;
  border-radius: 12px;
  transition: background 0.18s ease, color 0.18s ease;
}

.write-feedback.is-error {
  background: #FFEBE6;
  color: #C93518;
  border: 1.5px solid #FFB3A0;
}

.write-feedback.is-good {
  background: #E8FAF7;
  color: #13786E;
}

.write-controls-col {
  display: flex;
  flex-direction: column;
  gap: 14px;
  justify-content: space-between;
}

.control-group {
  background: #FFFDF8;
  border: 2px solid #F2E6D6;
  border-radius: 18px;
  padding: 13px 15px;
}

.control-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-soft);
  margin-bottom: 9px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-toggle-btn {
  min-height: 48px;
  border-radius: 14px;
  border: 2px solid #ECDCC8;
  background: #FFFFFF;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
}

.mode-toggle-btn.is-active {
  background: #E8FAF7;
  border-color: var(--mint);
  color: #13786E;
}

.action-btn-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.tool-btn {
  min-height: 50px;
  padding: 8px 12px;
  border-radius: 14px;
  border: 2px solid transparent;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease;
}

.tool-btn:active {
  transform: scale(0.97);
}

.tool-sky { background: #E8F5FD; color: #1C6EA0; border-color: #C3E4F9; }
.tool-mint { background: #E5FAF6; color: #147E73; border-color: #B4ECE2; }
.tool-gold { background: #FFF3D1; color: #9E5900; border-color: #FFDC85; }
.tool-coral { background: #FFF0EB; color: #C63F21; border-color: #FFC6B6; }
.tool-soft { background: #F7F1E8; color: var(--ink); border-color: #E7D8C5; }

.action-span-2 {
  grid-column: span 2;
}

.ink-palette {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.ink-dot {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid #FFFFFF;
  box-shadow: 0 0 0 2px #E3D3BE;
  cursor: pointer;
  transition: transform 0.14s ease;
}

.ink-dot.is-active {
  transform: scale(1.14);
  box-shadow: 0 0 0 3px var(--coral);
}

.write-cta-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ==================== Modals ==================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(45, 31, 33, 0.48);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 16px;
  overflow-y: auto;
}

.modal-card {
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  background: #FFFDF8;
  border: 3px solid #FFE2A8;
  border-radius: 28px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(45, 31, 33, 0.25);
  animation: modalPop 0.28s cubic-bezier(0.22, 1.28, 0.36, 1);
}

.modal-wide {
  max-width: 760px;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.88); }
  to { opacity: 1; transform: scale(1); }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-head h2 {
  margin: 0;
  font-size: 22px;
}

.modal-close-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 2px solid #ECDCC8;
  background: #FFFFFF;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}

/* ==================== Praise Modal ==================== */
.praise-card {
  text-align: center;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 209, 102, 0.35), transparent 55%),
    #FFFDF8;
}

.praise-sticker {
  font-size: 76px;
  line-height: 1;
  margin-bottom: 8px;
  animation: stickerJump 0.7s ease infinite alternate;
}

@keyframes stickerJump {
  from { transform: translateY(0) rotate(-4deg); }
  to { transform: translateY(-8px) rotate(4deg); }
}

.praise-char-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  background: #FFF3D1;
  border: 2px solid #FFD269;
  border-radius: 20px;
  padding: 6px 20px;
  margin-bottom: 12px;
}

.praise-char-big {
  font-family: var(--font-kaiti);
  font-size: 46px;
  line-height: 1.1;
  color: var(--coral-deep);
}

.praise-pinyin-tag {
  font-family: var(--font-pinyin);
  font-size: 24px;
  font-weight: 800;
  color: var(--ink);
}

.praise-headline {
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 900;
  color: #D94826;
}

.praise-detail {
  margin: 0 0 14px;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}

.milestone-banner {
  background: linear-gradient(135deg, #FFE699, #FFD166);
  border: 2px solid #F4A261;
  border-radius: 16px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 15px;
  font-weight: 800;
  color: #7F3D00;
}

.praise-flower-summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #FFF0EB;
  color: #C43D22;
  border-radius: 999px;
  padding: 7px 18px;
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 18px;
}

.praise-actions {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
}

/* ==================== Book Modal ==================== */
.unit-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.unit-tab-btn {
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 2px solid #ECDCC8;
  background: #FFFFFF;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.unit-tab-btn.is-active {
  background: var(--sun);
  border-color: var(--sun-deep);
  color: #532D00;
}

.book-char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.book-char-item {
  position: relative;
  min-height: 86px;
  border-radius: 16px;
  border: 2px solid #EFE0CC;
  background: #FFFFFF;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  padding: 8px 4px;
}

.book-char-item.is-current {
  border-color: var(--coral);
  background: #FFF3EF;
}

.book-char-item.is-learned {
  border-color: #9EE2D8;
  background: #F1FCF9;
}

.book-char-pinyin {
  font-family: var(--font-pinyin);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}

.book-char-glyph {
  font-family: var(--font-kaiti);
  font-size: 34px;
  line-height: 1.1;
  color: var(--ink);
}

.book-char-flower {
  position: absolute;
  top: 4px;
  right: 5px;
  font-size: 13px;
}

.custom-char-panel {
  border: 2px dashed #DFC9AF;
  border-radius: 16px;
  padding: 12px 14px;
  background: #FFF9EE;
}

.custom-char-panel summary {
  font-size: 15px;
  font-weight: 800;
  color: #9B5400;
  cursor: pointer;
}

.custom-char-form {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.custom-char-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}

.custom-char-form input,
.custom-char-form select {
  min-height: 42px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 2px solid #E8D7C0;
  background: #FFFFFF;
  font-size: 15px;
  color: var(--ink);
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.form-msg {
  font-size: 13px;
  font-weight: 700;
  color: #C94228;
}

/* ==================== Rewards Modal ==================== */
.rewards-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  background: linear-gradient(135deg, #FFF3D1, #FFE8B3);
  border: 2px solid #FFD36E;
  border-radius: 20px;
  padding: 16px;
  margin-bottom: 18px;
}

.rewards-title-icon {
  font-size: 52px;
  line-height: 1;
}

.rewards-current-label {
  font-size: 12px;
  font-weight: 800;
  color: #9C5A00;
}

.rewards-current-title {
  margin: 2px 0 4px;
  font-size: 24px;
  font-weight: 900;
  color: var(--ink);
}

.rewards-summary-text {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-soft);
}

.sub-heading {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 800;
}

.milestone-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.milestone-card {
  border-radius: 16px;
  border: 2px solid #EFE0CC;
  background: #FBF6EE;
  padding: 12px;
  text-align: center;
  opacity: 0.58;
}

.milestone-card.is-unlocked {
  opacity: 1;
  background: #FFFFFF;
  border-color: #FFD269;
  box-shadow: 0 4px 12px rgba(255, 183, 3, 0.16);
}

.milestone-icon {
  font-size: 30px;
}

.milestone-name {
  font-size: 15px;
  font-weight: 800;
  margin-top: 4px;
}

.milestone-req {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 2px;
}

.learned-garden-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.garden-flower-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 12px;
  background: #FFF3EF;
  border: 1.5px solid #FFD0C2;
  font-weight: 800;
  cursor: pointer;
}

.garden-flower-chip span {
  font-family: var(--font-kaiti);
  font-size: 22px;
}

/* ==================== Profile Login Modal ==================== */
.profile-section {
  margin-bottom: 18px;
}

.profile-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 10px;
}

.profile-card-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 18px;
  border: 2px solid #EFE0CC;
  background: #FFFFFF;
  text-align: left;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}

.profile-card-btn:hover {
  border-color: var(--mint);
  background: #F2FCF9;
}

.profile-card-btn.is-active {
  border-color: var(--coral);
  background: #FFF4F0;
}

.profile-card-avatar {
  font-size: 36px;
  line-height: 1;
  flex-shrink: 0;
}

.profile-card-name {
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
}

.profile-card-meta {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-top: 2px;
}

.profile-login-form {
  background: #FFF9EE;
  border: 2px solid #F2DFC2;
  border-radius: 18px;
  padding: 14px;
}

.avatar-picker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.avatar-pick-btn {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 2px solid #EBDAC5;
  background: #FFFFFF;
  font-size: 26px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.avatar-pick-btn.is-active {
  border-color: var(--coral);
  background: #FFF1EC;
  transform: scale(1.08);
}

.profile-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.profile-input-row input {
  min-height: 54px;
  padding: 10px 14px;
  border-radius: 16px;
  border: 2px solid #E6D3BA;
  background: #FFFFFF;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
}

.profile-submit-btn {
  width: auto;
  min-height: 54px;
  padding: 10px 22px;
  font-size: 17px;
}

.profile-footer-note {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}

@media (max-width: 600px) {
  .profile-input-row {
    grid-template-columns: 1fr;
  }
  .profile-submit-btn {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .hide-xs {
    display: none;
  }
  .coach-bar {
    flex-wrap: wrap;
  }
  .char-nav-mini {
    width: 100%;
    justify-content: flex-end;
  }
  .step-tab {
    padding: 6px 12px;
    font-size: 14px;
  }
  .step-line {
    width: 14px;
  }
  .stage-card {
    padding: 14px;
  }
  .praise-actions {
    grid-template-columns: 1fr;
  }
}
