:root {
  /* 和風清爽配色系統 */
  --bg-page: #f7f5f0;
  --bg-card: #ffffff;
  --bg-soft: #f0ece3;
  --bg-accent-soft: #e8eff8;
  --bg-sakura-soft: #fdf0f2;
  --bg-matcha-soft: #edf6ef;

  --primary: #2b4c7e;       /* 靛藍 Ai-iro */
  --primary-hover: #1f3961;
  --accent: #d95d67;        /* 櫻紅 / 朱紅 */
  --matcha: #3b8256;        /* 抹茶綠（熟練/正確） */
  --amber: #d9822b;         /* 琥珀橘（學習中/提示） */

  --text-main: #1f2937;
  --text-secondary: #52606d;
  --text-muted: #7b8794;
  --border: #e4dfd5;
  --shadow-sm: 0 2px 8px rgba(31, 41, 55, 0.05);
  --shadow-md: 0 8px 24px rgba(31, 41, 55, 0.08);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;

  --sidebar-width: 248px;
  --bottom-nav-height: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-page);
  color: var(--text-main);
  font-family: "Noto Sans TC", "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
  overflow-x: hidden;
}

.jp {
  font-family: "Noto Sans JP", "Noto Sans TC", sans-serif;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
}

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

/* ===== App Layout Shell (Mobile-First RWD) ===== */
.app-shell {
  display: flex;
  min-height: 100dvh;
  width: 100%;
}

/* Sidebar: hidden on mobile, visible on tablet landscape / desktop */
.sidebar {
  display: none;
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  flex-direction: column;
  justify-content: space-between;
  position: sticky;
  top: 0;
  height: 100dvh;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--border);
}

.brand-logo, .topbar-logo {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #436eb0);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 700;
  font-family: "Noto Sans JP", sans-serif;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(43, 76, 126, 0.25);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--primary);
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  text-align: left;
  transition: background 0.18s, color 0.18s;
}

.nav-item:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.nav-item.active {
  background: var(--bg-accent-soft);
  color: var(--primary);
  font-weight: 700;
}

.nav-icon {
  font-size: 1.2rem;
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.voice-speed-box label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

/* Main Wrapper */
.main-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 12px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(247, 245, 240, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.topbar-logo {
  width: 36px;
  height: 36px;
  font-size: 1.15rem;
}

.topbar-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.25;
}

.topbar-subtitle {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.icon-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  min-width: 40px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

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

.main-content {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Mobile Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + var(--safe-bottom));
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
  border-radius: 10px;
}

.bottom-nav-item.active {
  color: var(--primary);
  font-weight: 700;
}

.bottom-nav-icon {
  font-size: 1.25rem;
  line-height: 1.1;
}

/* ===== Reusable Components ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

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

.card-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text-main);
}

.hero-card {
  background: linear-gradient(135deg, #2b4c7e 0%, #3d68a8 100%);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  box-shadow: var(--shadow-md);
}

.hero-card h2 {
  margin: 0 0 6px;
  font-size: 1.35rem;
}

.hero-card p {
  margin: 0 0 16px;
  opacity: 0.92;
  font-size: 0.94rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.94rem;
  transition: transform 0.12s, background 0.18s, border-color 0.18s;
  white-space: nowrap;
}

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

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

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

.btn-hero {
  background: #ffffff;
  color: var(--primary);
}

.btn-hero:hover {
  background: #f0f4fa;
}

.btn-secondary {
  background: var(--bg-accent-soft);
  color: var(--primary);
}

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

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

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

.btn-outline {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-main);
}

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

.btn-danger-outline {
  background: #fff;
  border: 1px solid #f0b8bd;
  color: #c53030;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-full {
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* Inputs */
.select-input, .text-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
}

.select-input:focus, .text-input:focus {
  outline: 2px solid rgba(43, 76, 126, 0.25);
  border-color: var(--primary);
}

/* Badges & Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-blue {
  background: var(--bg-accent-soft);
  color: var(--primary);
}

.badge-green {
  background: var(--bg-matcha-soft);
  color: var(--matcha);
}

.badge-sakura {
  background: var(--bg-sakura-soft);
  color: var(--accent);
}

.badge-amber {
  background: #fef3e2;
  color: var(--amber);
}

/* JLPT Level Badges */
.jlpt-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  vertical-align: middle;
}

.jlpt-n5 {
  background: #e6f4ea;
  color: #1e7e34;
  border: 1px solid #b7dfc1;
}

.jlpt-n4 {
  background: #fef3e2;
  color: #b45309;
  border: 1px solid #f7d6a3;
}

.jlpt-starter {
  background: #e8eff8;
  color: #2b4c7e;
  border: 1px solid #c3d6ef;
}

.jlpt-n3 {
  background: #ede9fe;
  color: #5b21b6;
  border: 1px solid #c4b5fd;
}

.jlpt-n2 {
  background: #fce7f3;
  color: #9d174d;
  border: 1px solid #f9a8d4;
}

.jlpt-n1 {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  color: #78350f;
  border: 1px solid #f59e0b;
}

/* Locked Level Card & Promotion Exam */
.level-locked-card {
  text-align: center;
  padding: 36px 20px;
  background: linear-gradient(145deg, #ffffff, #f3f0e8);
  border: 2px dashed #cfc7b8;
}

.level-pill-locked {
  opacity: 0.62;
}

.exam-banner {
  background: linear-gradient(135deg, #2b4c7e, #4a3f8f);
  color: #fff;
  border: none;
}

.exam-option-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
  text-align: left;
}

.exam-option-btn {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  transition: all 0.15s;
}

.exam-option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--bg-accent-soft);
}

.exam-option-btn.correct {
  background: var(--bg-matcha-soft);
  border-color: var(--matcha);
  color: var(--matcha);
}

.exam-option-btn.wrong {
  background: var(--bg-sakura-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* Segmented Tabs */
.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  flex-shrink: 0;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.88rem;
}

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

/* Grids */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-sub {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

/* Progress Bar */
.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #4f86d4);
  border-radius: 999px;
  transition: width 0.35s ease;
}

/* ===== Kana Grid & Detail ===== */
.kana-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.kana-row-selector {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.kana-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.kana-cell {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
  min-height: 74px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all 0.15s;
  position: relative;
}

.kana-cell:active {
  transform: scale(0.95);
}

.kana-cell.selected {
  border-color: var(--primary);
  background: var(--bg-accent-soft);
}

.kana-cell.mastered {
  border-color: #9ed2b1;
  background: var(--bg-matcha-soft);
}

.kana-cell.empty {
  visibility: hidden;
  pointer-events: none;
}

.kana-char {
  font-size: 1.55rem;
  font-weight: 700;
  font-family: "Noto Sans JP", sans-serif;
  line-height: 1.1;
  color: var(--text-main);
}

.kana-romaji {
  font-size: 0.76rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.kana-sub-char {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Kana Detail Card */
.kana-detail-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  background: var(--bg-soft);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
}

.kana-big-display {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.kana-big-main {
  font-size: 3.4rem;
  font-weight: 700;
  line-height: 1;
  color: var(--primary);
  font-family: "Noto Sans JP", sans-serif;
}

.kana-big-pair {
  font-size: 1.5rem;
  color: var(--text-secondary);
  font-family: "Noto Sans JP", sans-serif;
}

.kana-big-romaji {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.tip-box {
  background: #fffaf0;
  border-left: 4px solid var(--amber);
  padding: 10px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

/* ===== Handwriting Canvas (Touch Optimized) ===== */
.canvas-wrapper {
  position: relative;
  width: 100%;
  max-width: 340px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: var(--radius-md);
  border: 2px dashed #c8c1b4;
  background: #ffffff;
  overflow: hidden;
  touch-action: none; /* 防止平板與手機書寫時頁面跟著捲動 */
}

.canvas-guide-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, transparent calc(50% - 0.5px), #e8e4dc calc(50% - 0.5px), #e8e4dc calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), #e8e4dc calc(50% - 0.5px), #e8e4dc calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

.canvas-watermark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11rem;
  font-family: "Noto Sans JP", sans-serif;
  color: rgba(43, 76, 126, 0.13);
  pointer-events: none;
  user-select: none;
  line-height: 1;
}

.drawing-canvas {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* ===== Lessons (Vocab / Grammar / Dialogue) ===== */
.vocab-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.vocab-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.vocab-jp {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}

.vocab-kana {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.vocab-romaji {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
}

.vocab-zh {
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 2px;
}

.grammar-card {
  border-left: 4px solid var(--primary);
}

.grammar-pattern {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--bg-accent-soft);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin: 8px 0;
}

.example-line {
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Dialogue */
.dialogue-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialogue-bubble {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-card);
  max-width: 92%;
}

.dialogue-bubble.speaker-b {
  align-self: flex-end;
  background: var(--bg-accent-soft);
  border-color: #cbdcf2;
}

.dialogue-speaker {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* ===== Quiz & Speaking ===== */
.quiz-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.quiz-option-btn {
  min-height: 64px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 2px solid var(--border);
  background: var(--bg-card);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  transition: all 0.15s;
}

.quiz-option-btn:hover {
  border-color: var(--primary);
}

.quiz-option-btn.correct {
  background: var(--bg-matcha-soft);
  border-color: var(--matcha);
  color: var(--matcha);
}

.quiz-option-btn.wrong {
  background: var(--bg-sakura-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.mic-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 1.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(217, 93, 103, 0.35);
}

.mic-btn.recording {
  animation: pulse-mic 1.2s infinite;
  background: #c53030;
}

@keyframes pulse-mic {
  0% { box-shadow: 0 0 0 0 rgba(217, 93, 103, 0.6); }
  70% { box-shadow: 0 0 0 18px rgba(217, 93, 103, 0); }
  100% { box-shadow: 0 0 0 0 rgba(217, 93, 103, 0); }
}

/* Flashcard */
.flashcard {
  min-height: 210px;
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, #ffffff, #f7f4ee);
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-sm);
}

/* ===== AI Tutor Chat ===== */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 210px);
  min-height: 420px;
  max-height: 680px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 4px;
}

.chat-msg {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.94rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.ai {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
}

.chat-input-bar {
  display: flex;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.quick-prompts {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 6px 0;
}

.quick-chip {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text-main);
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid var(--border);
}

/* ===== Roadmap ===== */
.roadmap-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.roadmap-stage {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.stage-num {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

/* ===== Modal & Toast ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  background: var(--bg-card);
  border-radius: 22px 22px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

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

.close-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-soft);
  font-size: 1rem;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-footer {
  padding: 14px 20px calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.settings-section h3 {
  margin: 0 0 10px;
  font-size: 0.96rem;
  color: var(--primary);
}

.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.form-hint {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.toast {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
  z-index: 120;
  box-shadow: var(--shadow-md);
  max-width: 90vw;
  text-align: center;
}

/* Global Romaji Hide Mode（脫離拐杖訓練） */
body.hide-romaji .kana-romaji,
body.hide-romaji .kana-big-romaji,
body.hide-romaji .vocab-romaji,
body.hide-romaji .romaji-text {
  display: none !important;
}

/* Pitch Accent Visual Indicator（高低音重音標示） */
.pitch-word {
  display: inline-flex;
  align-items: baseline;
  font-family: "Noto Sans JP", sans-serif;
  font-size: 0.92rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.pitch-mora {
  display: inline-block;
  padding: 1px 1px 0;
  border-top: 2px solid transparent;
  border-right: 2px solid transparent;
  line-height: 1.25;
}

.pitch-mora.high {
  border-top-color: var(--accent);
  color: var(--text-main);
  font-weight: 600;
}

.pitch-mora.drop {
  border-right-color: var(--accent);
  padding-right: 2px;
  margin-right: 1px;
}

.pitch-tag {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-left: 6px;
}

/* Confusing Kana Pair Cards */
.confusing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.confusing-tile {
  background: var(--bg-soft);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.15s, border-color 0.15s;
}

.confusing-tile:hover {
  border-color: var(--primary);
}

.confusing-tile:active {
  transform: scale(0.95);
}

.confusing-big {
  font-size: 2.8rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--primary);
  font-family: "Noto Sans JP", sans-serif;
}

/* Hands-Free Ear Training Player */
.ear-player-card {
  background: linear-gradient(145deg, #1f3961, #2b4c7e);
  color: #fff;
  border: none;
  text-align: center;
  padding: 26px 18px;
}

.ear-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 0.84rem;
  font-weight: 600;
  margin-bottom: 14px;
}

.hidden {
  display: none !important;
}

/* ===== Interactive Animations & Micro-Interactions ===== */

/* 1. Soft Sakura Petals Background */
.sakura-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
}

.sakura-petal {
  position: absolute;
  top: -24px;
  border-radius: 75% 15% 75% 15%;
  background: linear-gradient(135deg, rgba(246, 189, 200, 0.55), rgba(217, 93, 103, 0.25));
  animation-name: sakura-fall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
  will-change: transform;
}

@keyframes sakura-fall {
  0% {
    transform: translate3d(0, -10px, 0) rotate(0deg);
    opacity: 0;
  }
  12% {
    opacity: 0.75;
  }
  50% {
    transform: translate3d(28px, 50vh, 0) rotate(180deg);
  }
  88% {
    opacity: 0.65;
  }
  100% {
    transform: translate3d(-18px, 104vh, 0) rotate(360deg);
    opacity: 0;
  }
}

/* 2. View & Card Stagger Entrance */
.view-enter > * {
  animation: fade-slide-up 0.36s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.view-enter > *:nth-child(2) { animation-delay: 0.05s; }
.view-enter > *:nth-child(3) { animation-delay: 0.1s; }
.view-enter > *:nth-child(4) { animation-delay: 0.15s; }
.view-enter > *:nth-child(5) { animation-delay: 0.2s; }

@keyframes fade-slide-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Card hover lift on desktop/tablet */
.card, .stat-card, .vocab-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

@media (hover: hover) {
  .stat-card:hover, .vocab-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }
}

/* 3. Progress Bar Shimmer */
.progress-fill {
  position: relative;
  overflow: hidden;
}

.progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.35) 50%,
    transparent 100%
  );
  transform: translateX(-100%);
  animation: progress-shimmer 2.4s infinite;
}

@keyframes progress-shimmer {
  100% { transform: translateX(100%); }
}

/* 4. Kana Pop & Audio Speaking Wave */
.pop-bounce {
  animation: pop-bounce 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop-bounce {
  0% { transform: scale(0.86); }
  55% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.shake-error {
  animation: shake-error 0.42s ease;
}

@keyframes shake-error {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.speaking-active {
  position: relative;
  animation: speaking-glow 0.9s ease-in-out infinite;
}

@keyframes speaking-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(43, 76, 126, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(43, 76, 126, 0); }
}

/* 5. True 3D Flip Flashcard */
.flashcard-scene {
  perspective: 1100px;
  width: 100%;
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  min-height: 230px;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.flashcard-scene.is-flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, #ffffff, #f7f4ee);
  border: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 22px;
  box-shadow: var(--shadow-sm);
  user-select: none;
}

.flashcard-back {
  transform: rotateY(180deg);
  background: linear-gradient(145deg, #ffffff, #edf4fc);
  border-color: #bfd4ee;
}

/* 6. Celebration Confetti Particles */
.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}

.confetti-piece {
  position: fixed;
  line-height: 1;
  animation: confetti-burst 0.88s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  will-change: transform, opacity;
}

@keyframes confetti-burst {
  0% {
    transform: translate(0, 0) scale(0.5) rotate(0deg);
    opacity: 1;
  }
  75% {
    opacity: 1;
  }
  100% {
    transform: translate(var(--tx), var(--ty)) scale(1.15) rotate(var(--rot));
    opacity: 0;
  }
}

/* 7. AI Typing Dots & Chat Message Pop */
.chat-msg {
  animation: chat-pop 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes chat-pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 4px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.4;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* 8. Modal Entrance */
.modal-backdrop:not(.hidden) .modal-card {
  animation: modal-up 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes modal-up {
  from { transform: translateY(28px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Combo Pill */
.combo-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, #f59e0b, #d95d67);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  animation: pop-bounce 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Reduced Motion Accessibility */
@media (prefers-reduced-motion: reduce) {
  .sakura-layer, .confetti-container { display: none !important; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== Tablet Breakpoint (>= 640px) ===== */
@media (min-width: 640px) {
  .main-content {
    padding: 22px 24px;
    gap: 20px;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .vocab-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }

  .modal-card {
    border-radius: var(--radius-lg);
  }
}

/* ===== Tablet Landscape & Desktop Breakpoint (>= 960px) ===== */
@media (min-width: 960px) {
  .sidebar {
    display: flex;
  }

  .bottom-nav {
    display: none;
  }

  .main-wrapper {
    padding-bottom: 24px;
  }

  .topbar-logo {
    display: none;
  }

  .kana-layout {
    grid-template-columns: 1.15fr 1fr;
    align-items: start;
  }

  .toast {
    bottom: 28px;
  }
}
