/* JPN 1011 - Basic Japanese 1 | Ramkhamhaeng University */
/* Mobile-first, Eye-care mode, Print-ready, PWA-ready */

:root {
  --bg: #f8f5f0;
  --bg-card: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #4a4a4a;
  --primary: #c41e3a; /* Japanese red */
  --primary-dark: #9a1830;
  --accent: #1a3a6e; /* Deep blue */
  --border: #e0d8d0;
  --success: #2e7d32;
  --warning: #f57c00;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --font-main: "Sarabun", "Noto Sans Thai", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
  --font-jp: "Noto Sans JP", "Hiragino Sans", "Yu Gothic", "Meiryo", sans-serif;
}

/* Eye-care / Dark mode */
[data-theme="dark"] {
  --bg: #1a1a1a;
  --bg-card: #2a2a2a;
  --text: #e8e4df;
  --text-secondary: #b0a9a0;
  --primary: #e85a6f;
  --primary-dark: #c41e3a;
  --accent: #6b9bd1;
  --border: #3a3a3a;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
}

[data-theme="sepia"] {
  --bg: #f4ecd8;
  --bg-card: #faf6eb;
  --text: #3e2f1c;
  --text-secondary: #6b5a45;
  --primary: #8b4513;
  --primary-dark: #5d2e0c;
  --accent: #4a3728;
  --border: #d4c4a8;
  --shadow: 0 2px 12px rgba(62,47,28,0.1);
}

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

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 0.6rem 1rem;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.05rem;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-family: var(--font-jp);
}

.header-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  color: var(--text);
  transition: all 0.2s;
}

.btn-icon:hover, .btn-icon:active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Navigation */
.nav-drawer {
  position: fixed;
  top: 0;
  left: -280px;
  width: 280px;
  height: 100%;
  background: var(--bg-card);
  z-index: 200;
  transition: left 0.3s ease;
  box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  overflow-y: auto;
  padding: 1rem 0;
}

.nav-drawer.open {
  left: 0;
}

.nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.nav-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.nav-title {
  padding: 0.5rem 1.2rem 1rem;
  font-weight: 700;
  font-size: 1.1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}

.nav-list {
  list-style: none;
}

.nav-list a {
  display: block;
  padding: 0.7rem 1.2rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  border-left: 3px solid transparent;
  transition: all 0.2s;
}

.nav-list a:hover, .nav-list a.active {
  background: rgba(196,30,58,0.08);
  border-left-color: var(--primary);
  color: var(--primary);
}

.nav-list .nav-section {
  padding: 0.8rem 1.2rem 0.3rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  font-weight: 600;
}

/* Main content */
.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.2rem 1rem 4rem;
}

/* Home hero */
.hero {
  text-align: center;
  padding: 2rem 1rem;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: white;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.hero h1 {
  font-size: 1.6rem;
  margin-bottom: 0.4rem;
  line-height: 1.3;
}

.hero p {
  opacity: 0.95;
  font-size: 0.95rem;
}

.hero-badge {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  padding: 0.25rem 0.8rem;
  border-radius: 20px;
  font-size: 0.8rem;
  margin-top: 0.8rem;
}

/* Cards */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 600px) {
  .card-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.card-num {
  display: inline-flex;
  width: 32px;
  height: 32px;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.6rem;
}

.card h3 {
  font-size: 1.05rem;
  margin-bottom: 0.3rem;
}

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

/* Chapter content */
.chapter-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--primary);
}

.chapter-header h1 {
  font-size: 1.5rem;
  color: var(--primary);
  margin-bottom: 0.3rem;
}

.chapter-header .romaji {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-style: italic;
}

.section {
  margin-bottom: 2rem;
}

.section h2 {
  font-size: 1.2rem;
  color: var(--accent);
  margin-bottom: 0.8rem;
  padding-left: 0.6rem;
  border-left: 4px solid var(--primary);
}

.section h3 {
  font-size: 1.05rem;
  margin: 1rem 0 0.5rem;
}

/* Japanese text blocks */
.jp-text {
  font-family: var(--font-jp);
  font-size: 1.35rem;
  line-height: 1.8;
  background: var(--bg);
  padding: 1rem 1.2rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  margin: 0.8rem 0;
}

.jp-large {
  font-size: 2rem;
  text-align: center;
  letter-spacing: 0.1em;
}

.romaji {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-style: italic;
}

.thai-meaning {
  font-size: 0.95rem;
  color: var(--text);
  margin-top: 0.3rem;
}

/* Audio button */
.audio-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--accent);
  color: white;
  border: none;
  padding: 0.45rem 0.9rem;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  margin: 0.3rem 0.3rem 0.3rem 0;
  transition: background 0.2s;
}

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

.audio-btn.playing {
  background: var(--success);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin: 1rem 0;
  border-radius: 10px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  padding: 0.7rem 0.8rem;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

th {
  background: var(--primary);
  color: white;
  font-weight: 600;
}

tr:nth-child(even) {
  background: rgba(0,0,0,0.03);
}

[data-theme="dark"] tr:nth-child(even) {
  background: rgba(255,255,255,0.03);
}

td.jp {
  font-family: var(--font-jp);
  font-size: 1.25rem;
}

/* Vocabulary list */
.vocab-list {
  display: grid;
  gap: 0.6rem;
}

.vocab-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem 1rem;
}

.vocab-jp {
  font-family: var(--font-jp);
  font-size: 1.3rem;
  font-weight: 600;
  min-width: 120px;
}

.vocab-romaji {
  color: var(--text-secondary);
  font-size: 0.9rem;
  min-width: 100px;
}

.vocab-thai {
  flex: 1;
  font-size: 0.95rem;
}

/* Grammar box */
.grammar-box {
  background: linear-gradient(135deg, rgba(196,30,58,0.06), rgba(26,58,110,0.06));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin: 1rem 0;
}

.grammar-box .pattern {
  font-family: var(--font-jp);
  font-size: 1.3rem;
  text-align: center;
  margin-bottom: 0.8rem;
  color: var(--primary);
  font-weight: 600;
}

/* Practice / Quiz */
.quiz-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin: 1.5rem 0;
}

.quiz-progress {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-bottom: 1.2rem;
  overflow: hidden;
}

.quiz-progress-bar {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s;
}

.question-num {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.question-text {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  line-height: 1.6;
}

.question-text .jp {
  font-family: var(--font-jp);
  font-size: 1.25rem;
}

.options {
  display: grid;
  gap: 0.6rem;
}

.option {
  padding: 0.9rem 1rem;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg);
  font-size: 0.98rem;
}

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

.option.selected {
  border-color: var(--primary);
  background: rgba(196,30,58,0.1);
}

.option.correct {
  border-color: var(--success);
  background: rgba(46,125,50,0.15);
}

.option.wrong {
  border-color: #d32f2f;
  background: rgba(211,47,47,0.1);
}

.quiz-actions {
  display: flex;
  gap: 0.8rem;
  margin-top: 1.2rem;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.4rem;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

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

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

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

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

.btn-success {
  background: var(--success);
  color: white;
}

.score-box {
  text-align: center;
  padding: 2rem 1rem;
}

.score-box .score {
  font-size: 3rem;
  font-weight: 700;
  color: var(--primary);
}

/* Footer */
.footer {
  text-align: center;
  padding: 1.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

/* Print styles */
@media print {
  .header, .nav-drawer, .nav-overlay, .header-actions,
  .audio-btn, .quiz-container, .btn, .footer,
  .no-print {
    display: none !important;
  }
  body {
    background: white;
    color: black;
    font-size: 12pt;
  }
  .main {
    max-width: 100%;
    padding: 0;
  }
  .jp-text, .grammar-box, .vocab-item {
    break-inside: avoid;
  }
  a {
    text-decoration: none;
    color: black;
  }
  .chapter-header {
    border-bottom: 2px solid #000;
  }
}

/* Utility */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.flex-wrap { flex-wrap: wrap; }

/* Hiragana / Katakana chart special */
.kana-chart {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.4rem;
  margin: 1rem 0;
}

.kana-cell {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.3rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}

.kana-cell:hover, .kana-cell:active {
  background: var(--primary);
  color: white;
  transform: scale(1.05);
}

.kana-cell .char {
  font-family: var(--font-jp);
  font-size: 1.6rem;
  display: block;
  line-height: 1.3;
}

.kana-cell .roma {
  font-size: 0.7rem;
  opacity: 0.8;
}

@media (max-width: 400px) {
  .kana-chart {
    grid-template-columns: repeat(5, 1fr);
    gap: 0.25rem;
  }
  .kana-cell .char {
    font-size: 1.3rem;
  }
}

/* Install prompt */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--accent);
  color: white;
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  z-index: 90;
  transform: translateY(100%);
  transition: transform 0.3s;
}

.install-banner.show {
  transform: translateY(0);
}

.install-banner button {
  background: white;
  color: var(--accent);
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

/* Loading */
.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-secondary);
}

/* High-yield notes */
.note-block {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 5px solid var(--primary);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 0.8rem 0;
  box-shadow: var(--shadow);
}
.note-block h3 {
  margin-top: 0;
  color: var(--primary);
}
.note-tag {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  margin-bottom: 0.4rem;
}
.note-block ul {
  padding-left: 1.15rem;
}
.note-block li {
  margin: 0.25rem 0;
}
.note-jp {
  font-family: var(--font-jp);
  font-weight: 600;
}

/* 30-minute rest reminder */
.rest-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  background: rgba(12, 18, 28, 0.62);
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
}
.rest-modal.show {
  display: flex;
}
.rest-card {
  background: var(--bg-card);
  color: var(--text);
  width: min(520px, 100%);
  max-height: min(92vh, 760px);
  overflow: auto;
  border-radius: 18px;
  padding: 1.2rem 1.15rem 1.1rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.28);
}
.rest-kicker {
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}
.rest-arabic {
  font-size: 1.7rem;
  line-height: 1.7;
  text-align: center;
  margin: 0.6rem 0 0.2rem;
  direction: rtl;
}
.rest-translit {
  text-align: center;
  color: var(--text-secondary);
  font-style: italic;
}
.rest-meaning {
  text-align: center;
  margin: 0.35rem 0 0.8rem;
}
.rest-card h2 {
  font-size: 1.15rem;
  margin: 0.2rem 0 0.4rem;
}
.rest-card p, .rest-card li {
  font-size: 0.95rem;
}
.rest-card ul {
  padding-left: 1.15rem;
  margin: 0.4rem 0 0.8rem;
}
.rest-cite {
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
  margin-top: 0.4rem;
}
@media (min-width: 640px) {
  .rest-modal { align-items: center; }
}
