/* ==========================================================================
   小小背書本 — 溫暖電子作業本樣式
   ========================================================================== */

:root {
  --bg: #FAF6EE;
  --surface: #FFFDF8;
  --surface-soft: #F4EDE0;
  --border: #E6DEC8;
  --border-strong: #D6C9AA;
  --text: #2F2A24;
  --text-muted: #756B5E;

  --primary: #3E8E63;
  --primary-hover: #337752;
  --primary-soft: #E8F5ED;

  --stuck: #D97724;
  --stuck-hover: #BD6318;
  --stuck-soft: #FFF1E0;
  --stuck-border: #F2BA83;

  --mask-bg: #E5DEC9;
  --mask-hover: #DBD1B6;
  --focus-bg: #FFF9E6;
  --focus-border: #E5B95C;

  --danger: #C94A4A;
  --danger-soft: #FDECEC;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 2px 8px rgba(72, 56, 32, 0.06);
  --shadow-md: 0 8px 24px rgba(72, 56, 32, 0.09);

  --reading-size: 25px;
  --reading-line-height: 2.05;
}

/* 字級切換 */
body[data-font="sm"] {
  --reading-size: 20px;
  --reading-line-height: 1.95;
}
body[data-font="md"] {
  --reading-size: 25px;
  --reading-line-height: 2.05;
}
body[data-font="lg"] {
  --reading-size: 31px;
  --reading-line-height: 2.15;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", "Heiti TC", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button,
input,
textarea {
  font-family: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   頂部導覽列
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(250, 246, 238, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.brand-btn:hover {
  background: var(--surface-soft);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.font-switcher {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.font-btn {
  min-width: 38px;
  height: 36px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: background-color 0.15s, color 0.15s;
}

.font-btn.is-active {
  background: var(--primary);
  color: #fff;
}

/* ==========================================================================
   主要容器與通用元件
   ========================================================================== */

.app-root {
  max-width: 820px;
  margin: 0 auto;
  padding: 20px 16px 88px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  transition: transform 0.08s ease, background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  text-decoration: none;
  user-select: none;
}

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

.btn:focus-visible,
.pill-btn:focus-visible,
.stage-tab:focus-visible,
.pencil-toggle-btn:focus-visible {
  outline: 3px solid rgba(62, 142, 99, 0.45);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 3px 10px rgba(62, 142, 99, 0.22);
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-stuck {
  background: var(--stuck);
  color: #fff;
  box-shadow: 0 3px 10px rgba(217, 119, 36, 0.22);
}

.btn-stuck:hover {
  background: var(--stuck-hover);
}

.btn-soft {
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border-strong);
}

.btn-soft:hover {
  background: var(--surface-soft);
}

.btn-stuck-soft {
  background: var(--stuck-soft);
  color: #9E4E0D;
  border: 1.5px solid var(--stuck-border);
}

.btn-stuck-soft:hover {
  background: #FFE5C7;
}

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

.btn-sm {
  min-height: 40px;
  padding: 6px 14px;
  font-size: 0.92rem;
}

.btn-lg {
  min-height: 54px;
  padding: 12px 24px;
  font-size: 1.08rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 700;
}

.badge-neutral {
  background: var(--surface-soft);
  color: var(--text-muted);
}

.badge-stuck {
  background: var(--stuck-soft);
  color: #9E4E0D;
  border: 1px solid var(--stuck-border);
}

.badge-ok {
  background: var(--primary-soft);
  color: #276342;
}

/* ==========================================================================
   視圖 1：課本架（首頁）
   ========================================================================== */

.home-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  margin-bottom: 20px;
  background: linear-gradient(135deg, #FFFDF8 0%, #F7EFE0 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.home-hero h1 {
  margin: 0 0 4px;
  font-size: 1.45rem;
}

.home-hero p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.lesson-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.lesson-card {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.lesson-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.lesson-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.lesson-title {
  margin: 0 0 6px;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.35;
}

.lesson-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.lesson-preview {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.lesson-card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.lesson-card-main-btns,
.lesson-card-tool-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.empty-state {
  text-align: center;
  padding: 44px 24px;
}

.empty-state-icon {
  font-size: 2.8rem;
  margin-bottom: 10px;
}

/* ==========================================================================
   視圖 2：課文練習頁（上方控制區）
   ========================================================================== */

.lesson-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.lesson-header-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
}

.scope-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.pill-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.pill-btn.is-active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.pill-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--stuck);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
}

.stage-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
  background: var(--surface-soft);
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.stage-tab {
  min-height: 46px;
  padding: 8px 10px;
  border-radius: 11px;
  font-size: 0.98rem;
  font-weight: 800;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.stage-tab:hover {
  color: var(--text);
}

.stage-tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   階段 1：出聲熟讀
   ========================================================================== */

.notebook-paper {
  padding: 24px 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.para-block + .para-block {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px dashed var(--border);
}

.para-tag {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-muted);
  background: var(--surface-soft);
  padding: 2px 10px;
  border-radius: 999px;
}

.reading-paragraph {
  margin: 0;
  font-size: var(--reading-size);
  line-height: var(--reading-line-height);
  letter-spacing: 0.06em;
  word-break: break-word;
}

.read-sentence {
  border-radius: 6px;
  padding: 2px 0;
}

.read-sentence.is-stuck {
  text-decoration: underline wavy var(--stuck);
  text-underline-offset: 6px;
  background: rgba(255, 241, 224, 0.55);
}

.read-dock {
  margin-top: 16px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.read-dots {
  display: flex;
  align-items: center;
  gap: 12px;
}

.read-dot {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.read-dot.is-done {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  transform: scale(1.06);
}

.read-encouragement {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--primary);
}

.read-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
}

/* ==========================================================================
   核心遮字方塊（版面零跳動設計）
   ========================================================================== */

.char-box {
  display: inline-block;
  min-width: 1.06em;
  text-align: center;
  border-radius: 6px;
  margin: 0 1px;
  transition: background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.char-box.is-punct {
  min-width: auto;
  margin: 0;
}

.char-box.is-masked {
  color: transparent;
  user-select: none;
  background-color: var(--mask-bg);
  box-shadow: inset 0 -2px 0 rgba(120, 102, 70, 0.22);
}

.char-box.is-masked-dim {
  color: transparent;
  user-select: none;
  background-color: #EFE9DA;
}

.char-box.is-revealed {
  color: var(--text);
  background-color: rgba(232, 245, 237, 0.45);
}

/* ==========================================================================
   階段 2：遮字背誦（雙模式）
   ========================================================================== */

.practice-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.toolbar-label {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-muted);
  margin-right: 4px;
}

.seg-group {
  display: inline-flex;
  flex-wrap: wrap;
  background: var(--surface-soft);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
  gap: 4px;
}

.seg-btn {
  min-height: 36px;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.seg-btn.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* 逐句過關模式 */
.step-progress-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
}

.progress-track {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.step-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step-para-heading {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--text-muted);
  margin: 8px 0 2px;
}

.step-item {
  padding: 14px 18px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: var(--reading-size);
  line-height: var(--reading-line-height);
  letter-spacing: 0.06em;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  transition: all 0.18s ease;
}

.step-item-text {
  flex: 1;
  min-width: 0;
}

.step-item-tag {
  flex-shrink: 0;
  font-size: 0.88rem;
  font-weight: 800;
  padding-top: 6px;
}

.step-item.is-current {
  background: var(--focus-bg);
  border-color: var(--focus-border);
  border-width: 2px;
  box-shadow: var(--shadow-md);
  cursor: pointer;
}

.step-item.is-current:hover .char-box.is-masked {
  background-color: var(--mask-hover);
}

.step-item.is-passed {
  border-left: 5px solid var(--primary);
  background: #F6FBF8;
  opacity: 0.92;
}

.step-item.is-stuck {
  border: 2px dashed var(--stuck);
  background: var(--stuck-soft);
}

.step-item.is-upcoming {
  opacity: 0.65;
  background: #FBF8F1;
}

/* 整段自由偷看模式 */
.free-hint-banner {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: var(--surface-soft);
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.free-sentence-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.free-sentence-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--surface);
  transition: border-color 0.15s, background-color 0.15s;
}

.free-sentence-row.is-stuck {
  border-color: var(--stuck-border);
  border-left: 5px solid var(--stuck);
  background: #FFF8EE;
}

.free-sentence-touch {
  flex: 1;
  min-width: 0;
  text-align: left;
  font-size: var(--reading-size);
  line-height: var(--reading-line-height);
  letter-spacing: 0.06em;
  padding: 2px 4px;
  border-radius: 8px;
}

.free-sentence-touch:hover .char-box.is-masked {
  background-color: var(--mask-hover);
}

.pencil-toggle-btn {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  font-size: 1rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.pencil-toggle-btn:hover {
  border-color: var(--stuck);
  color: var(--stuck);
}

.pencil-toggle-btn.is-stuck {
  background: var(--stuck);
  border-color: var(--stuck);
  color: #fff;
}

/* 底部操作列 */
.practice-dock {
  position: sticky;
  bottom: 12px;
  z-index: 20;
  margin-top: 18px;
  padding: 14px 16px;
  background: rgba(255, 253, 248, 0.96);
  backdrop-filter: blur(8px);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dock-main-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  flex: 1;
  justify-content: flex-end;
}

.dock-side-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ==========================================================================
   階段 3：卡點特訓（消滅鉛筆記號）
   ========================================================================== */

.drill-card {
  padding: 24px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-md);
}

.drill-context-box {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  border-left: 4px solid var(--border-strong);
  margin-bottom: 20px;
}

.drill-context-label {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.drill-context-text {
  font-size: 1.08rem;
  color: var(--text-muted);
  line-height: 1.75;
}

.drill-stage-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 800;
  margin-bottom: 14px;
}

.drill-stage-badge.is-study {
  background: var(--stuck-soft);
  color: #9E4E0D;
}

.drill-stage-badge.is-recall {
  background: #EEF2FF;
  color: #374785;
}

.drill-stage-badge.is-verify {
  background: var(--primary-soft);
  color: #276342;
}

.drill-target-box {
  padding: 24px 20px;
  border-radius: var(--radius-md);
  background: var(--focus-bg);
  border: 2px solid var(--focus-border);
  font-size: var(--reading-size);
  line-height: var(--reading-line-height);
  letter-spacing: 0.06em;
  text-align: center;
  margin-bottom: 18px;
}

.drill-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

/* ==========================================================================
   結算與慶祝卡片
   ========================================================================== */

.celebration-card {
  padding: 32px 24px;
  text-align: center;
  background: linear-gradient(180deg, #FFFDF8 0%, #F2FAF5 100%);
  border: 2px solid #BCE0CA;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.celebration-card.has-stuck {
  background: linear-gradient(180deg, #FFFDF8 0%, #FFF5E8 100%);
  border-color: var(--stuck-border);
}

.celebration-stars {
  font-size: 2.6rem;
  margin-bottom: 8px;
  animation: starPop 0.55s ease;
}

@keyframes starPop {
  0% {
    transform: scale(0.6);
    opacity: 0;
  }
  70% {
    transform: scale(1.15);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.erase-pop {
  animation: erasePop 0.36s ease;
}

@keyframes erasePop {
  0% {
    transform: scale(0.97);
  }
  50% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1);
  }
}

.celebration-card h2 {
  margin: 0 0 8px;
  font-size: 1.45rem;
}

.celebration-card p {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 1rem;
}

.celebration-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* ==========================================================================
   Modal 對話框與 Toast 提示
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(47, 42, 36, 0.48);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-dialog {
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-md);
}

.modal-dialog.modal-sm {
  max-width: 420px;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.modal-close {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1.2rem;
  color: var(--text-muted);
}

.modal-close:hover {
  background: var(--surface-soft);
}

.form-field {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 800;
  font-size: 0.95rem;
}

.form-input,
.form-textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font-size: 1rem;
  line-height: 1.65;
}

.form-input:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(62, 142, 99, 0.16);
}

.form-textarea {
  min-height: 190px;
  resize: vertical;
}

.form-stats {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.form-error {
  margin-top: 6px;
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 700;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  pointer-events: none;
  max-width: calc(100vw - 32px);
  text-align: center;
}

/* ==========================================================================
   手機與窄螢幕 RWD
   ========================================================================== */

@media (max-width: 640px) {
  .topbar-inner {
    padding: 8px 10px;
    gap: 6px;
  }

  .brand-btn {
    font-size: 1rem;
    padding: 4px 6px;
    gap: 5px;
  }

  .font-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 7px;
    font-size: 0.84rem;
  }

  #topbar-add-btn,
  #topbar-back-btn {
    padding: 6px 10px;
    font-size: 0.85rem;
    min-height: 36px;
  }

  .app-root {
    padding: 14px 12px 96px;
  }

  .home-hero {
    flex-direction: column;
    align-items: stretch;
    padding: 16px;
  }

  .notebook-paper {
    padding: 18px 16px;
  }

  .stage-tabs {
    gap: 4px;
  }

  .stage-tab {
    font-size: 0.88rem;
    padding: 8px 6px;
  }

  .practice-dock {
    bottom: 8px;
    padding: 12px;
  }

  .dock-side-actions,
  .dock-main-actions {
    width: 100%;
    justify-content: stretch;
  }

  .dock-main-actions .btn,
  .dock-side-actions .btn {
    flex: 1;
  }

  .step-item {
    padding: 12px 14px;
  }

  .drill-card {
    padding: 18px 14px;
  }
}

@media (max-width: 420px) {
  .topbar-inner {
    flex-wrap: wrap;
  }

  .brand-text {
    font-size: 0.92rem;
  }
}
