/* ============================================
   JPN 1211 - วัฒนธรรมญี่ปุ่น
   Mobile-first · Dark Mode · Print-ready
   ============================================ */

:root {
  /* Light Theme */
  --bg: #faf8f5;
  --bg-card: #ffffff;
  --bg-soft: #f3efe9;
  --text: #1a1a1a;
  --text-secondary: #5c5c5c;
  --text-muted: #8a8a8a;
  --primary: #c41e3a;
  --primary-dark: #9e1830;
  --primary-light: #e85a6f;
  --accent: #2d5a4a;
  --accent-light: #3d7a64;
  --border: #e8e2d9;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 56px;
  --bottom-nav-h: 64px;
  --font-th: 'Noto Sans Thai', system-ui, sans-serif;
  --font-jp: 'Noto Sans JP', 'Hiragino Sans', sans-serif;
  --transition: 0.25s ease;
}

/* Dark Theme - Eye Protection */
[data-theme="dark"] {
  --bg: #121212;
  --bg-card: #1e1e1e;
  --bg-soft: #2a2a2a;
  --text: #e8e6e3;
  --text-secondary: #b0aea9;
  --text-muted: #7a7874;
  --primary: #e85a6f;
  --primary-dark: #c41e3a;
  --primary-light: #ff8a9a;
  --accent: #5aab8f;
  --accent-light: #7bc9ad;
  --border: #333330;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-th);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  font-size: 16px;
  min-height: 100vh;
  padding-bottom: calc(var(--bottom-nav-h) + 16px);
  transition: background var(--transition), color var(--transition);
}

/* Typography */
h1, h2, h3, h4 {
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
}

.jp-text {
  font-family: var(--font-jp);
  font-weight: 500;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--primary-dark); }

/* ========== Header ========== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  transition: background var(--transition), border-color var(--transition);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 16px;
  max-width: 960px;
  margin: 0 auto;
}

.logo {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}
.logo-jp {
  color: var(--primary);
  font-size: 1.15rem;
  letter-spacing: 0.5px;
}
.logo-num {
  font-size: 1.15rem;
  color: var(--text-secondary);
}

.menu-toggle {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  width: 40px;
}
.menu-toggle span {
  display: block;
  width: 22px;
  height: 2.5px;
  background: var(--text);
  border-radius: 2px;
  transition: var(--transition);
}

.header-actions {
  display: flex;
  gap: 4px;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover {
  background: var(--bg-soft);
  color: var(--text);
}
.btn-icon svg {
  width: 22px;
  height: 22px;
}

/* Dark mode icon toggle */
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ========== Sidebar ========== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  max-width: 85vw;
  height: 100%;
  background: var(--bg-card);
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.3s ease, background var(--transition);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
  font-size: 1.1rem;
}
.sidebar-close {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 4px 8px;
}

.nav-list {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}
.nav-section {
  padding: 12px 20px 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  transition: background var(--transition);
}
.nav-link:hover,
.nav-link.active {
  background: var(--bg-soft);
  color: var(--primary);
}
.nav-icon {
  font-size: 1.15rem;
  width: 28px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}
.sidebar-footer .version {
  margin-top: 2px;
  font-size: 0.75rem;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}
.sidebar-overlay.show {
  opacity: 1;
  visibility: visible;
}

/* ========== Main ========== */
.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.container {
  width: 100%;
}

/* Hero */
.hero {
  text-align: center;
  padding: 32px 8px 40px;
}
.hero-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: 20px;
  margin-bottom: 16px;
  letter-spacing: 0.03em;
}
.hero h1 {
  font-size: 1.75rem;
  margin-bottom: 12px;
}
.hero h1 .jp-text {
  font-size: 1.4rem;
  color: var(--primary);
  display: block;
  margin: 4px 0;
}
.hero-desc {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 480px;
  margin: 0 auto 24px;
}
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-family: var(--font-th);
  font-size: 0.95rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-dark);
  color: #fff;
}
.btn-secondary {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--border);
  color: var(--text);
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 40px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-num {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}
.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Features */
.section-title {
  font-size: 1.3rem;
  margin-bottom: 20px;
  text-align: center;
}
.feature-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 40px;
}
.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.feature-icon {
  font-size: 1.8rem;
  margin-bottom: 8px;
}
.feature-card h3 {
  font-size: 1.05rem;
  margin-bottom: 6px;
}
.feature-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Chapters */
.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 40px;
}
.chapter-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: all var(--transition);
}
.chapter-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}
.chapter-num {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  min-width: 32px;
}
.chapter-info {
  flex: 1;
}
.chapter-info h3 {
  font-size: 1rem;
  margin-bottom: 2px;
}
.chapter-info p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}
.chapter-arrow {
  color: var(--text-muted);
  font-size: 1.2rem;
}

/* Install */
.install-section {
  margin-bottom: 30px;
}
.install-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
}
.install-icon { font-size: 2rem; }
.install-text { flex: 1; min-width: 180px; }
.install-text h3 { color: #fff; margin-bottom: 4px; }
.install-text p { font-size: 0.9rem; opacity: 0.9; }
.install-card .btn-primary {
  background: #fff;
  color: var(--primary);
}
.install-card .btn-primary:hover {
  background: #f0f0f0;
}

/* Footer */
.footer {
  text-align: center;
  padding: 24px 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.footer-note {
  margin-top: 6px;
  font-size: 0.75rem;
}

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-h);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 90;
  padding-bottom: env(safe-area-inset-bottom, 0);
  transition: background var(--transition), border-color var(--transition);
}
.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  text-decoration: none;
  padding: 6px 10px;
  min-width: 56px;
  transition: color var(--transition);
}
.bottom-nav-item small {
  font-size: 0.65rem;
  font-family: var(--font-th);
}
.bottom-nav-item.active,
.bottom-nav-item:hover {
  color: var(--primary);
}

/* ========== Content Pages ========== */
.page-header {
  margin-bottom: 28px;
}
.page-header h1 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}
.page-header .jp-title {
  font-family: var(--font-jp);
  color: var(--primary);
  font-size: 1.15rem;
  margin-bottom: 8px;
}
.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.breadcrumb a { color: var(--text-secondary); }

.content-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.content-card h2 {
  font-size: 1.2rem;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
  display: inline-block;
}
.content-card h3 {
  font-size: 1.05rem;
  margin: 16px 0 8px;
  color: var(--accent);
}
.content-card p,
.content-card li {
  margin-bottom: 10px;
  color: var(--text);
}
.content-card ul, .content-card ol {
  padding-left: 1.4em;
  margin-bottom: 12px;
}
.content-card li { margin-bottom: 6px; }

/* Pronunciation Table */
.sound-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin: 12px 0;
  overflow-x: auto;
  display: block;
}
.sound-table th,
.sound-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: center;
}
.sound-table th {
  background: var(--bg-soft);
  font-weight: 600;
}
.sound-table .jp {
  font-family: var(--font-jp);
  font-size: 1.2rem;
  font-weight: 500;
}
.sound-table .romaji {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Audio Button */
.audio-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text);
  transition: all var(--transition);
  font-family: var(--font-th);
}
.audio-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.audio-btn.playing {
  background: var(--primary);
  color: #fff;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Vocabulary Cards */
.vocab-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.vocab-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.vocab-jp {
  font-family: var(--font-jp);
  font-size: 1.25rem;
  font-weight: 500;
  min-width: 80px;
}
.vocab-romaji {
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.vocab-th {
  flex: 1;
  font-size: 0.95rem;
}
.vocab-actions {
  display: flex;
  gap: 6px;
}

/* Quiz */
.quiz-container {
  max-width: 640px;
  margin: 0 auto;
}
.quiz-progress {
  height: 6px;
  background: var(--bg-soft);
  border-radius: 3px;
  margin-bottom: 20px;
  overflow: hidden;
}
.quiz-progress-bar {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s ease;
  border-radius: 3px;
}
.quiz-question {
  font-size: 1.1rem;
  margin-bottom: 20px;
  line-height: 1.5;
}
.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quiz-option {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  font-family: var(--font-th);
  font-size: 0.95rem;
  color: var(--text);
}
.quiz-option:hover {
  border-color: var(--primary-light);
}
.quiz-option.selected {
  border-color: var(--primary);
  background: rgba(196, 30, 58, 0.08);
}
.quiz-option.correct {
  border-color: #2d8a4e;
  background: rgba(45, 138, 78, 0.12);
}
.quiz-option.wrong {
  border-color: #c41e3a;
  background: rgba(196, 30, 58, 0.12);
}
.quiz-result {
  text-align: center;
  padding: 30px 20px;
}
.quiz-score {
  font-size: 3rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}
.quiz-score-label {
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* ========== Print Styles ========== */
@media print {
  .header,
  .sidebar,
  .sidebar-overlay,
  .bottom-nav,
  .btn-icon,
  .menu-toggle,
  .hero-actions,
  .install-section,
  .footer,
  .audio-btn,
  .quiz-options button,
  .no-print {
    display: none !important;
  }
  body {
    background: #fff;
    color: #000;
    font-size: 12pt;
    padding: 0;
    line-height: 1.5;
  }
  .main {
    max-width: 100%;
    padding: 0;
  }
  .content-card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  a { color: #000; text-decoration: none; }
  .page-header h1 { font-size: 18pt; }
  h2 { font-size: 14pt; }
  .chapter-item { border: 1px solid #ccc; }
}

/* ========== Responsive ========== */
@media (min-width: 480px) {
  .stats {
    grid-template-columns: repeat(4, 1fr);
  }
  .feature-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .vocab-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) {
  body {
    padding-bottom: 0;
  }
  .bottom-nav {
    display: none;
  }
  .hero h1 {
    font-size: 2.2rem;
  }
  .hero h1 .jp-text {
    font-size: 1.7rem;
  }
  .feature-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .main {
    padding: 28px 24px 60px;
  }
}

@media (min-width: 960px) {
  /* เมนูข้างถาวรบนจอใหญ่ */
  .menu-toggle {
    display: none;
  }
  .sidebar {
    transform: translateX(0);
    box-shadow: 1px 0 0 var(--border);
  }
  .sidebar-overlay {
    display: none !important;
  }
  .header {
    padding-left: 280px;
  }
  .header-inner {
    max-width: none;
  }
  .main {
    margin-left: 280px;
    max-width: none;
    padding-left: 32px;
    padding-right: 32px;
  }
  .footer {
    margin-left: 280px;
  }
  body {
    padding-bottom: 0;
  }
}
