/* =========================================================================
 * SpeakFlow 20D — Self-Contained iOS PWA Design System (100% Offline CSS)
 * ========================================================================= */

:root {
  --bg-backdrop: #d6dfe9;
  --bg-surface: #f4f7fb;
  --bg-card: #ffffff;
  --bg-subtle: #eef3f8;

  --text-main: #0f172a;
  --text-body: #334155;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --border: #e2e8f0;
  --border-soft: rgba(226, 232, 240, 0.85);

  --primary: #1d6fa5;
  --primary-dark: #145480;
  --primary-soft: #e6f2fb;

  --accent: #f97316;
  --accent-dark: #c2410c;
  --accent-soft: #fff2e8;

  --success: #15803d;
  --success-bg: #16a34a;
  --success-soft: #e9f9ef;

  --danger: #dc2626;
  --danger-soft: #fef1f1;

  --indigo: #4f46e5;
  --indigo-dark: #3730a3;
  --indigo-soft: #eef2ff;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --radius-pill: 999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 6px 18px -6px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(15, 23, 42, 0.04);
  --shadow-modal: 0 24px 56px -12px rgba(15, 23, 42, 0.28);

  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Sukhumvit Set", "Thonburi", "Noto Sans Thai", system-ui, sans-serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Sukhumvit Set", "Thonburi", "Noto Sans Thai", system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  background: var(--bg-backdrop);
  color: var(--text-main);
  font-family: var(--font-sans);
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

button, input {
  font-family: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

button:active:not(:disabled) {
  transform: scale(0.965);
}

button:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

h1, h2, h3, p {
  margin: 0;
}

/* ==================== APP SHELL ==================== */
#app-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 501px) {
  #app-shell {
    max-width: 430px;
    height: min(94dvh, 860px);
    max-height: 860px;
    border-radius: 34px;
    box-shadow: 0 28px 65px -16px rgba(15, 23, 42, 0.28), 0 0 0 1px rgba(15, 23, 42, 0.08);
  }
}

@media (max-width: 500px) {
  html, body {
    background: #ffffff;
  }
}

.safe-top {
  padding-top: max(14px, env(safe-area-inset-top));
}

.safe-bottom {
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

/* ==================== HEADER ==================== */
.app-header {
  flex-shrink: 0;
  background: #ffffff;
  border-bottom: 1px solid var(--border-soft);
  padding-left: 12px;
  padding-right: 12px;
  padding-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  z-index: 20;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 3px 8px rgba(29, 111, 165, 0.26);
}

.brand-icon-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  letter-spacing: -0.02em;
}

.brand-icon-badge {
  position: absolute;
  top: -4px;
  right: -6px;
  background: var(--accent);
  color: #fff;
  font-size: 8px;
  font-weight: 800;
  padding: 1px 4px;
  border-radius: var(--radius-pill);
  border: 1.5px solid #fff;
  line-height: 1.1;
}

.brand-meta {
  min-width: 0;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.day-pill-mini {
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  font-family: var(--font-display);
  font-size: 9.5px;
  font-weight: 800;
  line-height: 1;
  flex-shrink: 0;
}

.autosave-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success-bg);
  flex-shrink: 0;
}

.brand-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.net-pill {
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: var(--radius-pill);
  line-height: 1.2;
}

.net-pill.online {
  background: var(--success-soft);
  color: var(--success);
}

.net-pill.offline {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

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

.audio-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 9px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 700;
}

.audio-toggle-btn.mode-auto {
  background: var(--primary-soft);
  border-color: rgba(29, 111, 165, 0.3);
  color: var(--primary);
}

.audio-toggle-btn.mode-hd {
  background: var(--indigo-soft);
  border-color: rgba(79, 70, 229, 0.3);
  color: var(--indigo);
}

.audio-toggle-btn.mode-device {
  background: var(--accent-soft);
  border-color: rgba(249, 115, 22, 0.35);
  color: var(--accent-dark);
}

.icon-circle-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-body);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==================== MAIN VIEW ==================== */
#main-view {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
}

.tab-stack {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-height: 0;
}

/* ==================== BOTTOM NAVIGATION ==================== */
.bottom-nav {
  flex-shrink: 0;
  background: #ffffff;
  border-top: 1px solid var(--border-soft);
  padding: 6px 8px 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  z-index: 20;
}

.nav-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5px 4px;
  border-radius: 12px;
  color: var(--text-muted);
  gap: 2px;
}

.nav-btn svg {
  width: 20px;
  height: 20px;
}

.nav-btn span.nav-label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.1;
}

.nav-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.nav-badge {
  position: absolute;
  top: 2px;
  right: 12px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.hidden {
  display: none !important;
}

/* ==================== CARDS & COMMON LAYOUT ==================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

.card-hero {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

.flex-1-col {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.day-switcher-card {
  flex-shrink: 0;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.day-switcher-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.step-btn {
  width: 32px;
  height: 32px;
  border-radius: 11px;
  background: var(--bg-surface);
  color: var(--text-body);
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.day-switcher-center {
  flex: 1;
  min-width: 0;
  text-align: center;
}

.day-switcher-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.day-switcher-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 800;
  color: var(--text-main);
}

.tag-primary {
  padding: 2px 7px;
  border-radius: 7px;
  background: var(--primary-soft);
  color: var(--primary);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 800;
}

.day-switcher-sub {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 1px;
}

.progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 700;
  margin-bottom: 4px;
}

.progress-track {
  width: 100%;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: var(--radius-pill);
  transition: width 0.3s ease;
}

/* ==================== STATS ROW ==================== */
.stats-grid-3 {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.stat-tile {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 13px;
  padding: 6px 8px;
  text-align: center;
}

.stat-tile.danger-active {
  background: var(--danger-soft);
  border-color: rgba(220, 38, 38, 0.32);
}

.stat-val {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 800;
  line-height: 1.15;
}

.stat-val small {
  font-size: 10px;
  color: var(--text-faint);
  font-weight: 700;
}

.stat-lbl {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ==================== TODAY MISSION CARD ==================== */
.mission-card {
  flex: 1;
  min-height: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.mission-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.mission-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 800;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mission-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}

.pill-muted { background: var(--bg-subtle); color: var(--text-muted); }
.pill-primary { background: var(--primary-soft); color: var(--primary); }
.pill-accent { background: var(--accent-soft); color: var(--accent-dark); }
.pill-success { background: var(--success-soft); color: var(--success); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-indigo { background: var(--indigo-soft); color: var(--indigo); }

.stage-list {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.stage-row {
  padding: 12px 11px;
  border-radius: 16px;
  border: 1px solid var(--border-soft);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.stage-row:active { transform: scale(0.985); }
.stage-row.is-done { background: rgba(233, 249, 239, 0.55); border-color: rgba(21, 128, 61, 0.3); }
.stage-row.has-wrong { background: rgba(255, 242, 232, 0.55); border-color: rgba(249, 115, 22, 0.4); }

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

.stage-num {
  width: 32px;
  height: 32px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.bg-primary { background: var(--primary); }
.bg-accent { background: var(--accent); }
.bg-indigo { background: var(--indigo); }
.bg-success { background: var(--success-bg); }
.bg-danger { background: var(--danger); }
.bg-dark { background: #1e293b; }

.stage-info { min-width: 0; flex: 1; }

.stage-name {
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-sub {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fix-wrong-btn {
  padding: 6px 10px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 800;
  white-space: nowrap;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(249, 115, 22, 0.25);
}

.cta-btn {
  flex-shrink: 0;
  width: 100%;
  padding: 11px 14px;
  border-radius: 16px;
  color: #fff;
  font-family: var(--font-display);
  font-size: 12.5px;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  box-shadow: 0 4px 12px -2px rgba(15, 23, 42, 0.16);
}

/* ==================== STUDY TAB (VOCAB + DIALOGUE) ==================== */
.study-topbar {
  flex-shrink: 0;
  padding: 6px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.seg-switch {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: 14px;
}

.seg-btn {
  padding: 6px 8px;
  border-radius: 11px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seg-btn.active {
  background: var(--bg-card);
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

.flashcard {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 13px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.fc-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.fc-word-block {
  text-align: center;
  padding: 2px 0;
}

.fc-word-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.fc-word {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.fc-pos {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 7px;
  border-radius: 7px;
}

.fc-pron-row {
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.fc-thai {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-body);
}

.fc-ipa {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 1px 7px;
  border-radius: 6px;
}

.fc-meaning-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12.5px;
  font-weight: 700;
}

/* Conversation Sentence Box inside Flashcard */
.sentence-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.sentence-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.sentence-label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 800;
  color: var(--primary);
}

.mini-audio-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.mini-audio-btn {
  padding: 3px 8px;
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

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

.mini-audio-btn.accent {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border: 1px solid rgba(249, 115, 22, 0.3);
}

.sentence-en {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.35;
}

.sentence-en mark {
  background: rgba(29, 111, 165, 0.13);
  color: var(--primary-dark);
  padding: 0 3px;
  border-radius: 4px;
  font-weight: 800;
}

.sentence-th {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.3;
}

.tip-box {
  background: #fffdf7;
  border: 1px solid #f5e6c4;
  border-radius: 13px;
  padding: 7px 10px;
  font-size: 11px;
  color: #6b4e16;
  line-height: 1.35;
}

.tip-box strong {
  color: #9a6700;
}

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

.btn-audio-main {
  padding: 9px 10px;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(29, 111, 165, 0.22);
}

.btn-audio-slow {
  padding: 9px 10px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  border: 1px solid rgba(249, 115, 22, 0.35);
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
}

/* Dots & Bottom Study Controls */
.dots-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 7px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot-item {
  flex: 1;
  height: 9px;
  border-radius: var(--radius-pill);
  background: var(--border);
  transition: all 0.18s ease;
}

.dot-item.seen { background: var(--success-bg); }
.dot-item.current {
  background: var(--primary);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(29, 111, 165, 0.35);
  transform: scaleY(1.15);
}
.dot-item.seen.current {
  background: var(--success-bg);
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--primary);
}

.study-nav-grid {
  display: grid;
  grid-template-columns: 1fr 1.1fr 1fr;
  gap: 7px;
}

.btn-outline {
  padding: 9px 8px;
  border-radius: 13px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-body);
  font-family: var(--font-display);
  font-size: 11.5px;
  font-weight: 800;
}

.btn-solid {
  padding: 9px 8px;
  border-radius: 13px;
  color: #fff;
  font-family: var(--font-display);
  font-size: 11.5px;
  font-weight: 800;
  box-shadow: var(--shadow-xs);
}

/* ==================== DIALOGUE CHAT SUB-VIEW ==================== */
.dialogue-card {
  flex: 1;
  min-height: 0;
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dia-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-shrink: 0;
}

.dia-tabs {
  display: flex;
  gap: 5px;
}

.dia-tab-btn {
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 700;
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

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

.dia-meta {
  flex-shrink: 0;
  background: var(--bg-surface);
  border-radius: 12px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dia-title {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 800;
  color: var(--text-main);
}

.dia-ctx {
  font-size: 10px;
  color: var(--text-muted);
}

.dia-chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-right: 2px;
}

.chat-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.chat-row.speaker-b {
  flex-direction: row-reverse;
}

.chat-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.speaker-a .chat-avatar { background: var(--primary-soft); color: var(--primary); }
.speaker-b .chat-avatar { background: var(--accent-soft); color: var(--accent-dark); }

.chat-bubble {
  max-width: 82%;
  padding: 8px 10px;
  border-radius: 15px;
  border: 1px solid var(--border-soft);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.chat-bubble:active { transform: scale(0.98); }

.speaker-a .chat-bubble {
  background: var(--bg-surface);
  border-bottom-left-radius: 4px;
}

.speaker-b .chat-bubble {
  background: #edf6fc;
  border-color: rgba(29, 111, 165, 0.22);
  border-bottom-right-radius: 4px;
}

.chat-bubble.is-playing {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(29, 111, 165, 0.22);
}

.chat-en {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.35;
}

.chat-th {
  font-size: 10.5px;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.3;
}

.dia-controls {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 7px;
}

/* ==================== QUIZ TAB ==================== */
.quiz-top-row {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.quiz-day-btn {
  padding: 7px 9px;
  border-radius: 11px;
  background: #1e293b;
  color: #fff;
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 800;
  flex-shrink: 0;
}

.quiz-sub-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}

.quiz-sub-btn {
  padding: 6px 4px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-body);
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quiz-sub-btn.active-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.quiz-sub-btn.active-indigo { background: var(--indigo); border-color: var(--indigo); color: #fff; }
.quiz-sub-btn.active-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.quiz-sub-btn.has-mistakes { background: var(--danger-soft); border-color: rgba(220, 38, 38, 0.35); color: var(--danger); }

.chip-strip-card {
  flex-shrink: 0;
  padding: 7px 8px;
}

.chip-strip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.chip-grid {
  display: grid;
  gap: 4px;
}

.chip-grid-12 { grid-template-columns: repeat(12, 1fr); }
.chip-grid-8 { grid-template-columns: repeat(8, 1fr); }

.q-chip {
  height: 24px;
  border-radius: 7px;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 800;
  background: var(--border);
  color: var(--text-body);
  display: flex;
  align-items: center;
  justify-content: center;
}

.q-chip.correct { background: var(--success-bg); color: #fff; }
.q-chip.wrong { background: var(--danger); color: #fff; }
.q-chip.current {
  box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--text-main);
  transform: scale(1.06);
  z-index: 2;
}

.quiz-card {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.q-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.q-prompt-box {
  text-align: center;
  padding: 4px 2px;
}

.q-prompt-hint {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.q-main-text {
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.25;
}

.q-main-sentence {
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.4;
  background: var(--bg-surface);
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border-soft);
}

.q-sub-meaning {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--primary);
  margin-top: 5px;
}

.q-audio-inline {
  margin-top: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.options-stack {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

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

.opt-btn {
  padding: 10px 12px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 12.5px;
  font-weight: 700;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.3;
}

.opt-btn.centered {
  justify-content: center;
  text-align: center;
  padding: 12px 10px;
}

.opt-letter {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--bg-surface);
  color: var(--text-muted);
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.opt-btn.opt-correct {
  background: var(--success-soft);
  border-color: var(--success-bg);
  color: var(--success);
}
.opt-btn.opt-correct .opt-letter { background: var(--success-bg); color: #fff; }

.opt-btn.opt-wrong {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}
.opt-btn.opt-wrong .opt-letter { background: var(--danger); color: #fff; }

.opt-btn.opt-dim { opacity: 0.45; }

.feedback-bar {
  border-radius: 14px;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.35;
}

.feedback-bar.ok {
  background: var(--success-soft);
  border: 1px solid rgba(21, 128, 61, 0.25);
  color: var(--success);
}

.feedback-bar.bad {
  background: var(--danger-soft);
  border: 1px solid rgba(220, 38, 38, 0.25);
  color: var(--danger);
}

.action-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

/* ==================== SUMMARY SCREEN ==================== */
.summary-card {
  flex: 1;
  min-height: 0;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: center;
}

.summary-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}

.summary-score {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 800;
  color: var(--text-main);
  margin: 2px 0;
}

.wrong-chips-box {
  margin-top: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: 15px;
  padding: 9px;
}

.wrong-chips-wrap {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-height: 82px;
  overflow-y: auto;
  margin-top: 6px;
}

.wrong-chip-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px 4px 9px;
  border-radius: 10px;
  background: var(--danger-soft);
  border: 1px solid rgba(220, 38, 38, 0.28);
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
}

/* ==================== 20-DAY MAP TAB ==================== */
.map-grid-card {
  flex: 1;
  min-height: 0;
  padding: 10px;
  display: flex;
  flex-direction: column;
}

.map-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 6px;
}

.map-tile {
  position: relative;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text-body);
  padding: 5px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  text-align: center;
  overflow: hidden;
}

.map-tile.is-done {
  background: var(--success-soft);
  border-color: var(--success-bg);
  color: var(--success);
}

.map-tile.is-started {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-dark);
}

.map-tile.is-current {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--primary);
}

.map-tile-top {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-display);
  font-size: 10.5px;
  font-weight: 800;
  padding: 0 2px;
}

.map-tile-icon {
  font-size: 15px;
  line-height: 1;
}

.map-tile-lbl {
  font-size: 8.8px;
  font-weight: 700;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.map-wrong-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: #fff;
  font-size: 8px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.legend-strip {
  flex-shrink: 0;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
}

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

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 3px;
}

/* ==================== TOAST & MODAL ==================== */
#toast-box {
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  bottom: 68px;
  z-index: 40;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
  white-space: nowrap;
  max-width: 92%;
  overflow: hidden;
  text-overflow: ellipsis;
}

#toast-box.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}

@media (min-width: 501px) {
  #modal-backdrop { align-items: center; }
}

#modal-card {
  width: 100%;
  max-width: 392px;
  max-height: 84%;
  background: var(--bg-card);
  border-radius: 24px;
  box-shadow: var(--shadow-modal);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-body {
  padding: 12px 14px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.guide-step {
  background: var(--bg-surface);
  border: 1px solid var(--border-soft);
  border-radius: 13px;
  padding: 9px 11px;
  font-size: 11.5px;
  color: var(--text-body);
  line-height: 1.45;
}

.guide-step strong {
  color: var(--primary-dark);
}

/* ==================== ANIMATIONS ==================== */
@keyframes speakPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.94); opacity: 0.82; }
}
.is-speaking { animation: speakPulse 0.55s ease-in-out infinite; }

@keyframes popIn {
  from { opacity: 0; transform: translateY(4px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.pop-in { animation: popIn 0.17s ease-out; }

@keyframes savePulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.6); }
  100% { transform: scale(1); }
}
.save-flash { animation: savePulse 0.4s ease-out; }
