:root {
  /* === Japanese Vibe Design System (Wabi-Sabi & Zen) === */
  --washi: #F7F5F0;
  --surface: #FDFBF7;
  --surface-soft: #EFECE6;
  --sumi: #1C1B19;
  --ash: #5A5751;
  --whisper: #E6E2D8;
  --hanko: #B84A39;
  --primary: #2D3A3A;
  --koke: #5F6F52;

  --glyph: var(--primary);

  /* Pairing tokens - the text colour to place ON a given surface.
     Dark mode inverts --primary, so button labels must follow it. */
  --on-primary: #F7F5F0;
  --on-accent: #F7F5F0;
  --accent-text: #A8402F;
  --success: #5F6F52;
  --danger: #A8402F;
  --on-danger: #F7F5F0;
  --on-success: #F7F5F0;
  --primary-hover: #1C1B19;
  --accent-hover: #9E3E2F;
  --b-default: #D5CFC2;
  --b-strong: #9E988E;
  --ease: cubic-bezier(0.25, 1, 0.5, 1);

  /* Legacy aliases mapped to tokens */
  --meta-blue: var(--primary);
  --meta-blue-hover: #1C1B19;
  --meta-blue-pressed: var(--sumi);
  --meta-blue-light: var(--primary);

  --surface-white: var(--surface);
  --surface-warm: var(--washi);
  --surface-dark: var(--sumi);

  --text-primary: var(--sumi);
  --text-secondary: var(--ash);
  --text-muted: #8C8881;

  --border-default: var(--whisper);
  --border-strong: #9E988E;

  --radius-card: 4px;
  --radius-feature: 4px;
  --radius-pill: 2px;

  --shadow-l1: 0 2px 8px -2px rgba(28, 27, 25, 0.04);
  --shadow-l2: 0 8px 24px -4px rgba(28, 27, 25, 0.06);

  --space-3: 8px;
  --space-7: 16px;
  --space-9: 24px;
  --space-11: 40px;
  --space-13: 64px;
  --space-14: 80px;
}

[data-theme="dark"] {
  --washi: #1C1B19;
  --surface: #242320;
  --surface-soft: #2B2A26;
  --sumi: #F1EEE6;
  --ash: #B9B4A9;
  --whisper: #34322D;
  --hanko: #B84A39;
  --primary: #C9D1C8;
  --koke: #7A8F6C;
  --glyph: var(--primary);

  --on-primary: #1C1B19;
  --on-accent: #F7F5F0;
  --accent-text: #E5745F;
  --success: #94A886;
  --danger: #E5745F;
  --on-danger: #1C1B19;
  --on-success: #1C1B19;
  --primary-hover: #DDE3DB;
  --accent-hover: #A03F2E;
  --b-default: #45423B;
  --b-strong: #6E695F;

  --meta-blue: var(--primary);
  --meta-blue-hover: #DDE3DB;
  --meta-blue-pressed: #B4BFB5;
  --meta-blue-light: #C9D1C8;

  --surface-white: #242320;
  --surface-warm: var(--washi);
  --surface-dark: var(--sumi);

  --text-primary: var(--sumi);
  --text-secondary: var(--ash);
  --text-muted: #96928A;

  --border-default: var(--whisper);
  --border-strong: #6E695F;

  --shadow-l1: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-l2: 0 12px 28px rgba(0, 0, 0, 0.5), 0 2px 4px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

body {
  font-family: "Be Vietnam Pro", "Noto Sans JP", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--washi);
  color: var(--sumi);
  overflow-x: hidden;
  letter-spacing: -0.01em;
  transition: background-color 0.3s cubic-bezier(0.16, 1, 0.3, 1), color 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* === c4r37 Design System Overrides === */
h1, h2, h3, h4 { 
  font-family: "Space Grotesk", "Be Vietnam Pro", "Noto Sans JP", sans-serif !important;
  color: var(--sumi) !important; 
  letter-spacing: -0.02em !important; 
  font-feature-settings: "ss02", "ss03";
}

#app-container {
  background: var(--washi) !important;
}

/* Force c4r37 palette on common Tailwind classes generated by the app */
.bg-white, .bg-white\/70, .bg-white\/80, .bg-white\/90 { 
  background: var(--surface-white) !important; 
}

.bg-gray-50, .bg-slate-50, .bg-zinc-50 { 
  background: var(--washi) !important; 
}

.text-gray-900, .text-gray-800, .text-gray-700, .text-slate-900 { 
  color: var(--sumi) !important; 
}

.text-gray-600, .text-gray-500, .text-slate-600 { 
  color: var(--ash) !important; 
}

/* Buttons - match main c4r37 style */
button.bg-\[\#0064e0\],
button.bg-blue-600,
button.bg-rose-500,
button.bg-teal-500,
button.bg-purple-500,
button.bg-indigo-500,
button.bg-amber-500,
button.bg-green-500 {
  background: var(--primary) !important;
  color: var(--on-primary) !important;
  border: none !important;
  border-radius: var(--radius-sm, 2px) !important;
}

button.bg-\[\#0064e0\]:hover,
button.bg-blue-600:hover,
button.bg-rose-500:hover {
  background: #1C1B19 !important;
}

/* Ghost / outline buttons */
button.bg-white {
  background: transparent !important;
  color: var(--sumi) !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: var(--radius-sm, 2px) !important;
}

button.bg-white:hover {
  background: var(--surface-soft) !important;
  border-color: var(--sumi) !important;
}

/* Cards & containers */
.rounded-xl, .rounded-2xl, .rounded-3xl {
  border-radius: var(--radius-card, 4px) !important;
}

.shadow-lg, .shadow-xl, .shadow-2xl {
  box-shadow: var(--shadow-l2) !important;
}

/* Inputs */
input, textarea, select {
  border-color: var(--whisper) !important;
  background: var(--surface) !important;
  border-radius: var(--radius-sm, 2px) !important;
}

input:focus, textarea:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 2px rgba(45, 58, 58, 0.15) !important;
}

/* Flashcard theming */
.flashcard-face {
  background: var(--surface-white) !important;
  border-color: var(--whisper) !important;
  border-radius: var(--radius-feature, 4px) !important;
}

.flashcard-back {
  background: var(--surface-soft) !important;
}

#app-container { padding-top: calc(56px + 2.5rem) !important; }
.mistral-blocks { display: none; }

h1, h2, h3, h4 { color: var(--text-primary); letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 5vw, 4rem) !important; font-weight: 500 !important; line-height: 1.16 !important; }
p { color: var(--text-secondary); line-height: 1.44; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.animate-fade-in { animation: fadeIn 0.5s ease-out forwards; }
.animate-slide-in-up { animation: slideInUp 0.6s ease-out forwards; animation-delay: 0.15s; opacity: 0; }

.back-button-container { position: absolute; top: 4.5rem; left: 1.5rem; z-index: 20; }

button {
  border-radius: var(--radius-pill) !important;
  transition: background-color 200ms ease, transform 150ms ease, box-shadow 200ms ease !important;
  text-transform: none;
  letter-spacing: -0.14px;
}
button:active { transform: scale(0.96); }
button:disabled { background: var(--surface-soft) !important; color: var(--ash) !important; border-color: var(--whisper) !important; cursor: not-allowed !important; }

.rounded-xl { border-radius: var(--radius-feature) !important; }
.rounded-lg { border-radius: var(--radius-card) !important; }
.shadow-lg, .shadow-md, .shadow-sm { box-shadow: var(--shadow-l2) !important; }
.bg-white, .bg-white\/70, .bg-white\/80 { background: var(--surface-white) !important; }
.bg-rose-50\/50, .bg-purple-50\/50, .bg-indigo-50\/50 { background: var(--surface-soft) !important; }
.border-gray-200, .border-rose-200, .border-purple-200, .border-indigo-200, .border-amber-200, .border-amber-300 { border-color: var(--border-default) !important; }
.text-gray-900, .text-gray-800, .text-gray-700 { color: var(--text-primary) !important; }
.text-gray-600, .text-gray-500 { color: var(--text-secondary) !important; }
.text-gray-400, .text-gray-300 { color: var(--muted) !important; }
.text-\[\#B84A39\] { color: var(--accent-text) !important; }
.text-rose-700, .text-purple-700, .text-indigo-700, .text-teal-700, .text-amber-700, .text-amber-800 { color: var(--meta-blue) !important; }
/* Semantic feedback colours (correct = success, wrong = danger) */
.text-green-600, .text-green-700, .text-teal-700, .text-teal-800, .text-emerald-600 { color: var(--success) !important; }
.text-red-500, .text-red-600, .text-red-700, .text-rose-700, .text-pink-600 { color: var(--danger) !important; }
.text-amber-600, .text-amber-700, .text-amber-800, .text-purple-700, .text-purple-900, .text-indigo-700, .text-sky-500, .text-fuchsia-500 { color: var(--danger) !important; }
.bg-green-50, .bg-emerald-50 { background: color-mix(in srgb, var(--success) 12%, transparent) !important; }
.bg-red-50, .bg-rose-50, .bg-amber-50 { background: color-mix(in srgb, var(--danger) 10%, transparent) !important; }
.bg-green-500, .bg-emerald-500 { background: var(--success) !important; color: var(--on-success) !important; border: none !important; }
.bg-red-500, .bg-rose-500, .bg-amber-500 { background: var(--danger) !important; color: var(--on-danger) !important; border: none !important; }
.hover\:bg-red-600:hover, .hover\:bg-amber-600:hover, .hover\:bg-rose-600:hover { background: color-mix(in srgb, var(--danger) 82%, #000) !important; }
.hover\:bg-green-600:hover, .hover\:bg-emerald-600:hover, .hover\:bg-teal-600:hover { background: color-mix(in srgb, var(--success) 82%, #000) !important; }
.border-green-200, .border-green-400, .border-emerald-200 { border-color: color-mix(in srgb, var(--success) 40%, transparent) !important; }
.border-red-200, .border-amber-200, .border-amber-300, .border-amber-400, .border-rose-200 { border-color: color-mix(in srgb, var(--danger) 40%, transparent) !important; }
.text-yellow-400 { color: var(--hanko) !important; }
.text-gray-300 { color: var(--whisper) !important; }
.bg-rose-500, .bg-teal-500, .bg-purple-500, .bg-indigo-500, .bg-amber-500, .bg-green-500 { background: var(--meta-blue) !important; color: var(--on-primary) !important; border: none !important; }
.hover\:bg-rose-600:hover, .hover\:bg-teal-600:hover, .hover\:bg-purple-600:hover, .hover\:bg-indigo-600:hover, .hover\:bg-amber-600:hover, .hover\:bg-green-600:hover { background: var(--meta-blue-hover) !important; }
button.bg-white { background: transparent !important; color: var(--text-primary) !important; border: 1px solid var(--border-strong) !important; }
button.bg-white:hover { background: var(--surface-soft) !important; color: var(--sumi) !important; border-color: var(--sumi) !important; }

input, textarea, select { border-radius: 2px !important; border-color: var(--whisper) !important; color: var(--text-primary); }
input:focus, textarea:focus, select:focus { border-color: var(--primary) !important; box-shadow: 0 0 0 2px rgba(45, 58, 58, 0.15) !important; outline: none; }

.flashcard-scene { perspective: 1000px; }
.flashcard { width: 100%; height: 100%; position: relative; transition: transform 0.6s; transform-style: preserve-3d; cursor: pointer; }
.flashcard.is-flipped { transform: rotateY(180deg); }
.flashcard-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 2rem; border-radius: var(--radius-feature); border: 1px solid var(--border-default); box-shadow: var(--shadow-l2); background: var(--surface-white); }
.flashcard-front { background: var(--surface-white); }
.flashcard-back { background: var(--surface-soft); transform: rotateY(180deg); }

.hidden { display: none !important; }

/* Sakura effect toned down per DESIGN.md (restrained motion) */
#sakura-container { 
  position: fixed; 
  top: 0; left: 0; width: 100%; height: 100%; 
  pointer-events: none; 
  z-index: -1; 
  opacity: 0.35; 
}
.sakura { 
  position: absolute; 
  width: 6px; 
  height: 6px; 
  border-radius: 50%; 
  background: rgba(28, 25, 23, 0.06); 
  animation: fall linear infinite; 
}
@keyframes fall { 
  0% { transform: translateY(-10vh) translateX(0) rotate(0deg); opacity: 0.6; } 
  100% { transform: translateY(110vh) translateX(8vw) rotate(360deg); opacity: 0; } 
}

#music-player { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 50; cursor: pointer; }
#cd-icon { width: 56px; height: 56px; border-radius: 50% !important; background: var(--meta-blue) !important; color: var(--on-primary) !important; transition: transform 0.3s ease, background-color 0.3s ease; box-shadow: var(--shadow-l2); font-size: 24px; display: flex; align-items: center; justify-content: center; user-select: none; }
#cd-icon:hover { transform: scale(1.1); background: var(--meta-blue-hover) !important; }
#cd-icon:active { transform: scale(0.95); }
#cd-icon.spinning { animation: spin 2s linear infinite; }

/* Music Popup - Wabi-Sabi Zen Style */
#music-popup {
  position: fixed;
  bottom: 84px;
  right: 1.5rem;
  width: 250px;
  background: var(--surface);
  border-radius: 4px;
  border: 1px solid var(--whisper);
  box-shadow: 0 8px 24px -4px rgba(28, 27, 25, 0.08);
  z-index: 51;
  padding: 16px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: slideInUp 0.25s cubic-bezier(0.25, 1, 0.5, 1);
}
#music-popup.hidden { display: none !important; }
.music-popup-inner { display: flex; flex-direction: column; gap: 14px; }

.music-popup-top { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--whisper); padding-bottom: 8px; }
.music-time-display { font-size: 12px; color: var(--ash); font-variant-numeric: tabular-nums; font-family: "Geist Mono", monospace; letter-spacing: 0.02em; }
.music-close-btn { width: 22px; height: 22px; border-radius: 2px; border: 1px solid transparent; background: transparent; color: var(--ash); font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1); }
.music-close-btn:hover { background: var(--surface-soft); border-color: var(--whisper); color: var(--sumi); }

.music-progress-slider { width: 100%; height: 3px; -webkit-appearance: none; appearance: none; background: var(--whisper); border-radius: 1px; cursor: pointer; margin: 2px 0; outline: none; }
.music-progress-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 10px; height: 10px; border-radius: 2px; background: var(--primary); cursor: pointer; transition: transform 0.15s ease; }
.music-progress-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.music-progress-slider::-moz-range-thumb { width: 10px; height: 10px; border-radius: 2px; background: var(--primary); cursor: pointer; border: none; }

.music-control-btns { display: flex; align-items: center; justify-content: center; gap: 14px; }
.music-icon-btn { width: 32px; height: 32px; border-radius: 2px; border: 1px solid var(--whisper); background: var(--surface-soft); color: var(--sumi); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1); }
.music-icon-btn:hover { background: var(--surface); border-color: var(--border-strong); }
.music-icon-btn svg { width: 14px; height: 14px; }
.music-play-btn { width: 40px; height: 40px; border-radius: 2px; border: 1px solid var(--primary); background: var(--primary); color: var(--on-primary); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1); }
.music-play-btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); transform: translateY(-1px); }
.music-play-btn svg { width: 16px; height: 16px; }

.music-volume-wrap { display: flex; align-items: center; gap: 10px; padding-top: 10px; border-top: 1px solid var(--whisper); }
.music-vol-icon { width: 14px; height: 14px; color: var(--ash); flex-shrink: 0; }
.music-volume-slider { flex: 1; height: 3px; -webkit-appearance: none; appearance: none; background: var(--whisper); border-radius: 1px; cursor: pointer; outline: none; }
.music-volume-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 10px; height: 10px; border-radius: 2px; background: var(--primary); cursor: pointer; }
.music-volume-slider::-moz-range-thumb { width: 10px; height: 10px; border-radius: 2px; background: var(--primary); cursor: pointer; border: none; }

body.focus-mode #sakura-container, body.focus-mode #music-player { display: none !important; }
#bg-music { display: none; }

.lesson-progress-bar { width: 100%; height: 6px; border-radius: 2px; background: var(--surface-soft); overflow: hidden; border: 1px solid var(--whisper); }
.lesson-progress-fill { height: 100%; background: var(--primary); transition: width 200ms ease; }

.mc-eyebrow { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 2px; background: var(--surface-soft); color: var(--accent-text); font-size: 11px; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; border: 1px solid var(--whisper); }
.mc-eyebrow::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--hanko); }

.brand-hero-card { display: grid; grid-template-columns: minmax(160px, 200px) 1fr; gap: 28px; align-items: center; background: var(--surface); border: 1px solid var(--whisper); border-radius: 4px; box-shadow: var(--shadow-l1); padding: 28px; overflow: hidden; }
.brand-hero-media { display: flex; justify-content: center; }
.brand-hero-avatar { width: 180px; height: 180px; border-radius: 2px; background: var(--surface-soft); display: flex; align-items: center; justify-content: center; border: 1px solid var(--whisper); overflow: hidden; }
.brand-hero-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.brand-hero-kicker { margin: 0 0 6px 0; color: var(--accent-text); font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }
.brand-hero-title { margin: 0; color: var(--sumi); font-size: clamp(26px, 3vw, 32px); line-height: 1.25; font-weight: 500; font-family: "Shippori Mincho", "Space Grotesk", serif; }
.brand-hero-desc { margin: 10px 0 0 0; color: var(--ash); font-size: 15px; line-height: 1.75; max-width: 760px; }
.brand-hero-meta { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.brand-hero-chip { display: inline-flex; align-items: center; padding: 4px 12px; border-radius: 2px; border: 1px solid var(--whisper); background: var(--surface-soft); color: var(--ash); font-size: 12px; line-height: 1.4; }

.lesson-row-card { background: var(--surface); border: 1px solid var(--whisper); border-radius: 4px; box-shadow: var(--shadow-l1); padding: 24px; transition: border-color 240ms ease, box-shadow 240ms ease; }
.lesson-row-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-l2); }
.lesson-row-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-7); margin-bottom: 20px; border-bottom: 1px solid var(--whisper); pb: 12px; }
.lesson-row-kicker { margin: 0 0 4px 0; color: var(--ash); font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; }
.lesson-row-title { margin: 0; color: var(--sumi); font-size: 28px; line-height: 1.3; font-weight: 500; font-family: "Shippori Mincho", "Space Grotesk", serif; }
.lesson-row-cta { min-width: 120px; }

.study-module-card { background: var(--surface); border: 1px solid var(--whisper); border-radius: 2px; padding: 18px 16px; display: flex; flex-direction: column; gap: 12px; transition: all 200ms ease; }
.study-module-card:hover { border-color: var(--border-strong); }
.study-module-head { display: flex; align-items: center; gap: 10px; }
.study-module-icon { width: 34px; height: 34px; border-radius: 2px; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-soft); color: var(--primary); border: 1px solid var(--whisper); flex: 0 0 auto; }
.study-module-icon svg { width: 18px; height: 18px; }
.study-module-desc { margin: 0; min-height: 38px; color: var(--ash); font-size: 13.5px; line-height: 1.6; }

.btn-primary-pill { background: var(--primary) !important; color: var(--on-primary) !important; border: none !important; border-radius: 2px !important; padding: 8px 18px !important; font-size: 13.5px !important; font-weight: 500 !important; line-height: 1.4 !important; transition: all 200ms ease !important; }
.btn-primary-pill:hover { background: #1C1B19 !important; transform: translateY(-1px); }
.btn-primary-pill:active { transform: translateY(1px); }
.btn-secondary-pill { background: transparent !important; color: var(--sumi) !important; border: 1px solid var(--whisper) !important; border-radius: 2px !important; padding: 8px 18px !important; font-size: 13.5px !important; line-height: 1.4 !important; transition: all 200ms ease !important; }
.btn-secondary-pill:hover { background: var(--surface-soft) !important; border-color: var(--border-strong) !important; }

/* Hanko / accent action button (used by quiz flows in JS templates) */
.hanko-btn { background-color: var(--hanko); color: var(--on-accent); border-radius: var(--radius-sm, 2px) !important; transition: all 240ms var(--ease); }
.hanko-btn:hover { background-color: var(--accent-hover); transform: translateY(-1px); }
.hanko-btn:active { transform: translateY(1px) scale(0.99); }

@media (max-width: 1024px) { #app-container { padding-top: calc(56px + 2rem) !important; } }
@media (max-width: 768px) {
  #app-container { padding-top: calc(56px + 1.75rem) !important; }
  h1 { font-size: clamp(2rem, 8vw, 2.25rem) !important; }
  .lesson-row-head { flex-direction: column; align-items: flex-start; }
  .lesson-row-title { font-size: 30px; }
  .brand-hero-card { grid-template-columns: 1fr; text-align: center; gap: 16px; }
  .brand-hero-content { text-align: center !important; }
  .brand-hero-meta { justify-content: center; }
  #music-popup { right: 10px; left: 10px; width: auto; }
}

/* Grammar Document Styling - c4r37 Design System */
.study-grammar-doc h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--sumi);
    margin-top: 2rem;
    margin-bottom: 1rem;
    border-left: 4px solid var(--hanko);
    padding-left: 0.75rem;
    line-height: 1.25;
}
.study-grammar-doc h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--sumi);
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--whisper);
    padding-bottom: 0.375rem;
}
.study-grammar-doc h4 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--hanko);
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
}
.study-grammar-doc p {
    color: var(--ash);
    line-height: 1.625;
    margin-bottom: 1rem;
}
.study-grammar-doc ul {
    list-style-type: none;
    padding-left: 0;
    margin-bottom: 1.25rem;
}
.study-grammar-doc li {
    position: relative;
    padding-left: 1.25rem;
    margin-bottom: 0.5rem;
    color: var(--ash);
}
.study-grammar-doc li::before {
    content: "•";
    color: var(--hanko);
    font-weight: bold;
    position: absolute;
    left: 0.25rem;
}
.study-grammar-doc table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    font-size: 0.875rem;
    text-align: left;
}
.study-grammar-doc th {
    background-color: var(--washi);
    color: var(--sumi);
    font-weight: 600;
    padding: 0.75rem 1rem;
    border-bottom: 2px solid var(--whisper);
}
.study-grammar-doc td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--whisper);
    color: var(--ash);
}
.study-grammar-doc tr:hover td {
    background-color: rgba(249, 247, 243, 0.5);
}
.study-grammar-doc strong {
    color: var(--sumi);
    font-weight: 600;
}
.study-grammar-doc .example-box {
    background-color: var(--washi);
    border: 1px solid var(--whisper);
    border-radius: var(--radius-feature, 4px);
    padding: 1.25rem;
    margin: 1.25rem 0;
}
.study-grammar-doc .example-jp {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 1.125rem;
    color: var(--sumi);
    font-weight: 500;
    margin-bottom: 0.25rem;
}
.study-grammar-doc .example-roma {
    font-size: 0.875rem;
    color: var(--ash);
    margin-bottom: 0.5rem;
    font-style: italic;
}
.study-grammar-doc .example-vi {
    font-size: 0.95rem;
    color: var(--accent-text);
    font-weight: 500;
}
.study-grammar-doc .badge-note {
    background-color: color-mix(in srgb, var(--accent-text) 10%, transparent);
    color: var(--accent-text);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    margin-right: 0.375rem;
}

/* Override global button styling for custom study back button */
button.study-back-btn {
    border-radius: 2px !important;
    background-color: transparent !important;
    border: 1px solid var(--whisper) !important;
    color: var(--ash) !important;
    padding: 8px 16px !important;
    width: auto !important;
    height: auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 0.875rem !important;
    font-weight: 500 !important;
    box-shadow: none !important;
    white-space: nowrap !important;
}

button.study-back-btn:hover {
    background-color: var(--washi) !important;
    color: var(--sumi) !important;
    border-color: rgba(28, 25, 23, 0.25) !important;
}

button.study-back-btn:active {
    transform: scale(0.96) !important;
}

/* ============ DARK MODE OVERRIDES ============ */
[data-theme="dark"] {
  body { background-color: var(--washi) !important; color: var(--sumi) !important; }

  /* Navigation */
  nav { 
    background-color: color-mix(in srgb, var(--washi) 92%, transparent) !important; 
    border-color: var(--whisper) !important; 
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
  }

  /* Backgrounds */
  .bg-\[\#F9F7F3\], .bg-\[\#F7F5F0\] { background-color: var(--washi) !important; }
  .bg-\[\#F9F7F3\]\/95, .bg-\[\#F7F5F0\]\/95 { 
    background-color: color-mix(in srgb, var(--washi) 92%, transparent) !important; 
    backdrop-filter: blur(12px) !important;
  }
  .bg-\[\#F2F0EB\], .bg-\[\#EFECE6\] { background-color: var(--surface-soft) !important; }
  .bg-white, .bg-\[\#FDFBF7\] { background-color: var(--surface-white) !important; }
  .bg-\[\#1C1917\], .bg-\[\#1C1B19\] { 
    background-color: var(--surface-soft) !important; 
    border: 1px solid var(--whisper) !important;
  }

  /* Borders */
  .border-\[\#E7E5E4\], .border-\[\#E6E2D8\] { border-color: var(--whisper) !important; }
  .border-gray-200 { border-color: var(--whisper) !important; }
  .border-gray-300 { border-color: var(--whisper) !important; }
  .border-b { border-bottom-color: var(--whisper) !important; }

  /* Text colors - keep readable */
  .text-\[\#57534E\], .text-\[\#5A5751\] { color: var(--ash) !important; }
  .text-\[\#1C1917\], .text-\[\#1C1B19\] { color: var(--sumi) !important; }
  .text-\[\#9A3412\], .text-\[\#B84A39\] { color: var(--accent-text) !important; }
  .text-gray-900, .text-gray-800 { color: var(--sumi) !important; }
  .text-gray-700, .text-gray-600 { color: var(--ash) !important; }
  .text-gray-500, .text-gray-400 { color: var(--ash) !important; }
  .text-white { color: var(--on-accent) !important; }

  /* Links */
  a { color: var(--ash) !important; }
  a:hover { color: var(--hanko) !important; }

  /* Buttons - make readable in dark mode */
  button { color: var(--sumi) !important; }

  /* Primary pill button in dark */
  .btn-primary-pill {
    background: var(--primary) !important;
    color: var(--on-primary) !important;
    border: none !important;
    opacity: 1 !important;
  }
  .btn-primary-pill:hover {
    background: var(--primary-hover) !important;
    transform: scale(1.03);
    opacity: 1 !important;
  }
  .btn-primary-pill:active {
    background: var(--primary-hover) !important;
    transform: scale(0.97);
  }
  .btn-primary-pill:disabled {
    background: var(--surface-soft) !important;
    color: var(--text-muted) !important;
    cursor: not-allowed !important;
  }

  /* Secondary pill button in dark */
  .btn-secondary-pill {
    background: transparent !important;
    color: var(--ash) !important;
    border: 1.5px solid var(--whisper) !important;
    opacity: 1 !important;
  }
  .btn-secondary-pill:hover {
    background: var(--surface-soft) !important;
    color: var(--sumi) !important;
    border-color: var(--ash) !important;
    opacity: 1 !important;
  }
  .btn-secondary-pill:active {
    transform: scale(0.96);
  }
  .btn-secondary-pill:disabled {
    background: transparent !important;
    color: var(--muted) !important;
    border-color: var(--whisper) !important;
    cursor: not-allowed !important;
  }

  /* Inputs */
  input, textarea { background-color: var(--surface-white) !important; color: var(--sumi) !important; border-color: var(--whisper) !important; }
  input::placeholder, textarea::placeholder { color: var(--text-muted) !important; }

  /* Cards & containers */
  .study-module-card { background-color: var(--surface-white) !important; border-color: var(--whisper) !important; }
  .brand-hero-chip { background-color: var(--surface-soft) !important; border-color: var(--whisper) !important; color: var(--sumi) !important; }

  /* Progress center section */
  section { background-color: var(--surface-white) !important; border-color: var(--whisper) !important; }
  .bg-white.p-4, div.bg-white.p-4 { background-color: var(--surface-white) !important; border-color: var(--whisper) !important; }
  .bg-white.p-5, div.bg-white.p-5 { background-color: var(--surface-white) !important; border-color: var(--whisper) !important; }
  .rounded-lg { border-color: var(--whisper) !important; }

  /* Progress bar */
  .lesson-progress-bar { background: var(--whisper) !important; }
  .lesson-progress-fill { background: var(--accent-text) !important; }

  /* Solid Tailwind colour buttons -> brand tokens (label follows inverted --primary) */
  .bg-rose-500, .bg-teal-500, .bg-purple-500, .bg-indigo-500, .bg-amber-500, .bg-green-500 { background: var(--primary) !important; color: var(--on-primary) !important; }
  .hover\:bg-rose-600:hover, .hover\:bg-teal-600:hover, .hover\:bg-purple-600:hover, .hover\:bg-indigo-600:hover, .hover\:bg-amber-600:hover, .hover\:bg-green-600:hover { background: var(--primary-hover) !important; color: var(--on-primary) !important; }

  /* Hover states */
  .hover\:text-\[\#1C1917\]:hover { color: var(--accent-text) !important; }
  .hover\:text-\[\#9A3412\]:hover { color: var(--accent-text) !important; }
  .hover\:bg-\[\#E7E5E4\]\/30:hover { background-color: color-mix(in srgb, var(--accent-text) 12%, transparent) !important; }
  .hover\:bg-\[\#F2F0EB\]:hover { background-color: var(--surface-soft) !important; }
  tr:hover, .hover\:bg-gray-50:hover { background-color: rgba(255, 255, 255, 0.03) !important; }

  /* Shadows */
  .shadow-md, .shadow-sm, .shadow-lg { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important; }

  /* Specific lesson cards */
  .lesson-row-card { background-color: var(--surface-white) !important; border-color: var(--whisper) !important; }

  /* Table Headers & Elements */
  thead, .bg-gray-100 { background-color: var(--surface-soft) !important; }
  th { color: var(--sumi) !important; border-color: var(--whisper) !important; }
  tr { border-color: var(--whisper) !important; }
  td { border-color: var(--whisper) !important; }

  /* Brand hero */
  .brand-hero-card { background: var(--surface-white) !important; border-color: var(--whisper) !important; }
  .brand-hero-avatar { background: var(--surface-white) !important; border-color: var(--whisper) !important; }

  /* Grammar doc */
  .study-grammar-doc { color: var(--sumi) !important; }
  .study-grammar-doc h2 { color: var(--sumi) !important; }
  .study-grammar-doc h3 { color: var(--sumi) !important; }
  .study-grammar-doc p { color: var(--ash) !important; }
  .study-grammar-doc li { color: var(--ash) !important; }
  .study-grammar-doc td { color: var(--ash) !important; }
  .study-grammar-doc .example-jp { color: var(--sumi) !important; }
  .study-grammar-doc .example-vi { color: var(--accent-text) !important; }
  .study-grammar-doc .example-box { background-color: var(--surface-white) !important; border-color: var(--whisper) !important; }
  .study-grammar-doc th { background-color: var(--surface-white) !important; color: var(--sumi) !important; border-color: var(--whisper) !important; }
  .study-grammar-doc tr:hover td { background-color: rgba(37, 33, 31, 0.4) !important; }
  .study-grammar-doc strong { color: var(--sumi) !important; }

  /* Study back button */
  button.study-back-btn { border-color: var(--whisper) !important; color: var(--ash) !important; }
  button.study-back-btn:hover { background-color: var(--surface-soft) !important; color: var(--sumi) !important; }

  /* Flashcard */
  .flashcard-back { background: var(--surface-soft) !important; }
  .flashcard-face { background: var(--surface-white) !important; border-color: var(--whisper) !important; }

  /* Music player */
  #music-player #cd-icon { background: var(--hanko) !important; color: var(--on-accent) !important; }
  #music-player #cd-icon:hover { background: var(--accent-hover) !important; }
  #music-popup { background: var(--surface-white) !important; border-color: var(--whisper) !important; }
  .music-icon-btn { background: var(--surface-soft) !important; color: var(--sumi) !important; }
  .music-icon-btn:hover { background: var(--whisper) !important; }

  /* Semantic labels must follow the inverted success/danger surfaces */
  .bg-red-500, .bg-rose-500, .bg-amber-500 { color: var(--on-danger) !important; }
  .bg-green-500, .bg-emerald-500 { color: var(--on-success) !important; }
}

/* Ensure theme toggle button stays visible in dark mode */
[data-theme="dark"] #theme-toggle { border-color: var(--whisper) !important; color: var(--ash) !important; }
[data-theme="dark"] #theme-toggle:hover { background-color: color-mix(in srgb, var(--accent-text) 15%, transparent) !important; color: var(--accent-text) !important; }

/* ============ THEME TOGGLE BUTTON (c4r37 Design System) ============ */
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm, 2px);
  border: 1px solid var(--whisper);
  background-color: var(--surface-white);
  color: var(--ash);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(28, 25, 23, 0.06);
}
.theme-toggle-btn i {
  font-size: 15px;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.2s ease;
}
.theme-toggle-btn:hover {
  border-color: var(--accent-text);
  color: var(--accent-text);
  background-color: color-mix(in srgb, var(--accent-text) 8%, transparent);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(28, 25, 23, 0.1);
}
.theme-toggle-btn:active {
  transform: translateY(0) scale(0.95);
  box-shadow: 0 1px 3px rgba(28, 25, 23, 0.06);
}
[data-theme="dark"] .theme-toggle-btn {
  background-color: var(--surface-soft);
  border-color: var(--whisper);
  color: var(--ash);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
[data-theme="dark"] .theme-toggle-btn:hover {
  background-color: color-mix(in srgb, var(--accent-text) 12%, transparent);
  border-color: var(--accent-text);
  color: var(--accent-text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
[data-theme="dark"] .theme-toggle-btn i.fa-sun {
  color: var(--accent-text);
  transform: rotate(20deg);
}


