/* ============================================================
   Jayantara Kelas Online — Main Stylesheet
   Design System: Japanese Ink × Modern Web
   ============================================================ */

/* ── 1. CSS Custom Properties (Design Tokens) ──────────────── */
:root {
  /* Color Palette — Dark (default) */
  --ink-900:   #0d0604;
  --ink-800:   #1a0a00;
  --ink-700:   #261209;
  --ink-600:   #3d1f0f;
  --ink-500:   #5c3218;
  --surface:   #1e1108;
  --surface-2: #2b180c;
  --surface-3: #3a2214;

  /* Accent Colors */
  --red:       #c0392b;
  --red2:      #e74c3c;
  --red3:      #ff6b5b;
  --gold:      #f0a500;
  --gold2:     #ffd166;
  --teal:      #00b4a6;
  --teal2:     #4ecdc4;
  --purple:    #8b5cf6;
  --purple2:   #a78bfa;
  --green:     #27ae60;
  --green2:    #55efc4;

  /* Text */
  --text1:  #f5ede4;
  --text2:  #c9a882;
  --text3:  #8a6a4a;
  --text4:  #5a4030;

  /* Borders / Dividers */
  --border:    rgba(240,165,0,0.12);
  --border2:   rgba(240,165,0,0.25);

  /* Shadows */
  --shadow-sm:  0 2px 8px rgba(0,0,0,0.4);
  --shadow-md:  0 4px 20px rgba(0,0,0,0.5);
  --shadow-lg:  0 8px 40px rgba(0,0,0,0.6);

  /* Typography */
  --font-body:    'DM Sans', sans-serif;
  --font-jp:      'Zen Kaku Gothic New', sans-serif;
  --font-serif:   'Noto Serif JP', serif;
  --font-mono:    'DM Mono', monospace;

  /* Spacing */
  --sp-xs: 0.25rem;
  --sp-sm: 0.5rem;
  --sp-md: 1rem;
  --sp-lg: 1.5rem;
  --sp-xl: 2rem;
  --sp-2xl: 3rem;

  /* Radius */
  --r-sm: 6px;
  --r-md: 12px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-full: 9999px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-fast: 150ms;
  --t-med:  250ms;
  --t-slow: 400ms;

  /* Layout */
  --topbar-h:   60px;
  --mobile-nav: 64px;
  --max-w:      1100px;
}

/* Light theme override */
[data-theme="light"] {
  --ink-900:   #fdf8f2;
  --ink-800:   #f5ede0;
  --ink-700:   #ecddc8;
  --ink-600:   #dcc9a8;
  --surface:   #fff8f0;
  --surface-2: #f5ede0;
  --surface-3: #ecddc8;
  --text1:  #1a0a00;
  --text2:  #5c3218;
  --text3:  #8a6a4a;
  --text4:  #c9a882;
  --border:  rgba(92,50,24,0.12);
  --border2: rgba(92,50,24,0.25);
  --shadow-sm: 0 2px 8px rgba(92,50,24,0.1);
  --shadow-md: 0 4px 20px rgba(92,50,24,0.15);
  --shadow-lg: 0 8px 40px rgba(92,50,24,0.2);
}

/* ── 2. Reset & Base ────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: var(--font-body);
  background: var(--ink-800);
  color: var(--text1);
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
  transition: background var(--t-slow) var(--ease), color var(--t-slow) var(--ease);
}

/* Noise texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
}

img, svg { display: block; max-width: 100%; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
a { color: var(--gold); text-decoration: none; transition: color var(--t-fast); }
a:hover { color: var(--gold2); }
ul { list-style: none; }
input { font-family: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ── 3. Loader ──────────────────────────────────────────────── */
#loader {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--ink-900);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--sp-lg);
  transition: opacity var(--t-slow) var(--ease);
}

.loader-kanji {
  font-family: var(--font-jp);
  font-size: clamp(4rem, 12vw, 7rem);
  font-weight: 900;
  color: var(--red);
  animation: loader-pulse 1.5s ease-in-out infinite;
  text-shadow: 0 0 60px rgba(192,57,43,0.5);
}

@keyframes loader-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(0.95); }
}

.loader-text {
  font-family: var(--font-jp);
  font-size: 0.9rem;
  color: var(--text2);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.loader-bar {
  width: 200px; height: 3px;
  background: var(--surface-2);
  border-radius: var(--r-full);
  overflow: hidden;
}
.loader-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red), var(--gold));
  border-radius: var(--r-full);
  animation: loader-fill 1.8s ease-in-out forwards;
}
@keyframes loader-fill {
  0% { width: 0%; }
  60% { width: 75%; }
  100% { width: 100%; }
}

/* ── 4. Login Screen ────────────────────────────────────────── */
#login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-lg);
  background: radial-gradient(ellipse 80% 60% at 50% 20%, rgba(192,57,43,0.12) 0%, transparent 70%),
              var(--ink-900);
  position: relative;
  z-index: 10;
}

#login-screen[hidden] { display: none; }

/* Japanese paper texture bg decoration */
#login-screen::after {
  content: '日本語';
  position: absolute;
  font-family: var(--font-jp);
  font-size: clamp(8rem, 25vw, 18rem);
  font-weight: 900;
  color: rgba(192,57,43,0.04);
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
}

.login-wrap {
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
}

.login-logo {
  text-align: center;
  margin-bottom: var(--sp-xl);
}

.login-kanji {
  display: inline-block;
  font-family: var(--font-jp);
  font-size: 3.5rem;
  font-weight: 900;
  color: var(--red);
  text-shadow: 0 0 40px rgba(192,57,43,0.6);
  margin-bottom: var(--sp-sm);
}

.login-title {
  font-family: var(--font-jp);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text1);
}
.login-title span { color: var(--red2); }

.login-sub {
  font-size: 0.85rem;
  color: var(--text2);
  margin-top: var(--sp-xs);
  letter-spacing: 0.05em;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r-xl);
  padding: var(--sp-xl);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(240,165,0,0.05);
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-xs);
}

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.field input,
.input-wrap input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text1);
  font-size: 0.95rem;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  outline: none;
}

.field input:focus,
.input-wrap input:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(240,165,0,0.15);
}

.field input::placeholder { color: var(--text3); }

.input-wrap {
  position: relative;
}
.input-wrap input { padding-right: 3rem; }
.toggle-pass {
  position: absolute;
  right: 0.75rem; top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  padding: 0.25rem;
  transition: color var(--t-fast);
}
.toggle-pass:hover { color: var(--text2); }

.btn-primary {
  width: 100%;
  padding: 0.85rem 1.5rem;
  background: linear-gradient(135deg, var(--red) 0%, var(--red2) 100%);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--r-md);
  transition: transform var(--t-fast), box-shadow var(--t-fast), opacity var(--t-fast);
  box-shadow: 0 4px 20px rgba(192,57,43,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 25px rgba(192,57,43,0.5); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn-spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

#login-msg { font-size: 0.85rem; min-height: 1.2rem; }
.msg-err { color: var(--red3); }
.msg-ok  { color: var(--green2); }
.msg-load { color: var(--text2); display: flex; align-items: center; gap: var(--sp-xs); }

.spin-inline {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: var(--text2);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.login-footer {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text2);
}

/* ── 5. App Shell ───────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100dvh; }
#app[hidden] { display: none; }

/* ── 6. Topbar ──────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: rgba(13,6,4,0.85);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--sp-md);
  padding: 0 var(--sp-lg);
  z-index: 100;
}

.topbar-logo {
  font-family: var(--font-jp);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text1);
  display: flex; align-items: center; gap: var(--sp-sm);
  flex-shrink: 0;
  white-space: nowrap;
}
.topbar-logo .dot {
  font-size: 1.4rem;
  color: var(--red);
  text-shadow: 0 0 20px rgba(192,57,43,0.6);
}

.topbar-nav {
  display: flex; align-items: center; gap: 2px;
  flex: 1; overflow-x: auto;
  scrollbar-width: none;
}
.topbar-nav::-webkit-scrollbar { display: none; }

.tnav {
  padding: 0.4rem 0.75rem;
  border-radius: var(--r-md);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text2);
  white-space: nowrap;
  transition: background var(--t-fast), color var(--t-fast);
}
.tnav:hover { background: var(--surface-2); color: var(--text1); }
.tnav.active {
  background: rgba(192,57,43,0.2);
  color: var(--red3);
  font-weight: 600;
}

.topbar-right {
  display: flex; align-items: center; gap: var(--sp-sm);
  flex-shrink: 0;
}

.streak-chip, .xp-chip {
  display: flex; align-items: center; gap: 4px;
  padding: 0.3rem 0.7rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text1);
  white-space: nowrap;
}
.xp-chip { color: var(--gold); }

.theme-toggle {
  width: 34px; height: 34px;
  border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  transition: background var(--t-fast), color var(--t-fast);
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text1); }

.avatar {
  width: 34px; height: 34px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--red), var(--gold));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem; color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.avatar:hover { transform: scale(1.1); box-shadow: 0 0 20px rgba(192,57,43,0.4); }

/* ── 7. Mobile Nav ──────────────────────────────────────────── */
.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--mobile-nav);
  background: rgba(13,6,4,0.95);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.mnav {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text3);
  padding: var(--sp-sm) 0;
  transition: color var(--t-fast);
}
.mnav span:first-child { font-size: 1.3rem; line-height: 1; }
.mnav.active { color: var(--red3); }
.mnav:hover { color: var(--text1); }

@media (max-width: 768px) {
  .topbar-nav { display: none; }
  .mobile-nav { display: flex; }
  .topbar { padding: 0 var(--sp-md); }
}

/* ── 8. Sections / Page Layout ──────────────────────────────── */
.section {
  display: none;
  padding-top: calc(var(--topbar-h) + var(--sp-xl));
  padding-bottom: calc(var(--mobile-nav) + var(--sp-xl));
  min-height: 100dvh;
}
.section.active { display: block; }

@media (min-width: 769px) {
  .section {
    padding-bottom: var(--sp-2xl);
  }
}

.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--sp-lg);
}

.pg-title {
  font-family: var(--font-jp);
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 700;
  color: var(--text1);
  margin-bottom: var(--sp-xs);
}
.pg-title span { color: var(--red2); }
.text-accent { color: var(--red2); }

.pg-sub {
  font-size: 0.88rem;
  color: var(--text2);
  margin-bottom: var(--sp-xl);
}

/* ── 9. Dashboard ───────────────────────────────────────────── */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-md);
  margin-bottom: var(--sp-xl);
}

@media (max-width: 768px) {
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
  position: relative;
  padding: var(--sp-lg);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  transition: transform var(--t-med) var(--ease-spring), box-shadow var(--t-med);
}
.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.stat-card .glow {
  position: absolute;
  inset: -50%;
  border-radius: 50%;
  opacity: 0.15;
  filter: blur(30px);
  transition: opacity var(--t-slow);
}
.stat-card:hover .glow { opacity: 0.25; }

.stat-card .icon { font-size: 1.8rem; margin-bottom: var(--sp-sm); }
.stat-card .val {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text1);
  font-variant-numeric: tabular-nums;
}
.stat-card .lbl { font-size: 0.78rem; color: var(--text2); margin-top: 2px; }

.sc-gold .glow { background: var(--gold); }
.sc-gold .val { color: var(--gold2); }
.sc-red .glow { background: var(--red); }
.sc-red .val { color: var(--red3); }
.sc-teal .glow { background: var(--teal); }
.sc-teal .val { color: var(--teal2); }
.sc-purple .glow { background: var(--purple); }
.sc-purple .val { color: var(--purple2); }

/* Ring Progress Grid */
.ring-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: var(--sp-md);
  margin-bottom: var(--sp-xl);
}

.ring-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-lg);
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-sm);
  text-align: center;
}

.ring-wrap { position: relative; width: 80px; height: 80px; }
.ring-wrap svg { transform: rotate(-90deg); }
.ring-wrap circle {
  fill: none;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s var(--ease);
}
.ring-bg { stroke: var(--surface-3); stroke-width: 6; }
.ring-fg { stroke: var(--gold); stroke-width: 6; }
.ring-pct {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700;
  color: var(--text1);
}
.ring-label { font-size: 0.78rem; color: var(--text2); }
.ring-detail { font-size: 0.7rem; color: var(--text3); }

/* Activity Calendar */
.dash-lower {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-lg);
  margin-top: var(--sp-xl);
}
@media (max-width: 640px) {
  .dash-lower { grid-template-columns: 1fr; }
}

.streak-cal, .activity-feed {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-lg);
}

.streak-cal-title, .feed-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-md);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text1);
}
.streak-count-lbl { font-size: 0.75rem; color: var(--green2); }

.streak-days {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 3px;
}
.streak-day {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--surface-3);
  transition: background var(--t-fast);
  cursor: default;
}
.streak-day.active { background: var(--green2); }
.streak-day.today  { background: var(--gold); }

#feed-list li {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--sp-sm) 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  gap: var(--sp-sm);
}
#feed-list li:last-child { border-bottom: none; }
.feed-xp { color: var(--gold); font-weight: 600; white-space: nowrap; }
.feed-time { font-size: 0.72rem; color: var(--text3); }

/* ── 10. Kana Grid ──────────────────────────────────────────── */
.huruf-tabs {
  display: flex; flex-wrap: wrap; gap: var(--sp-xs);
  margin-bottom: var(--sp-lg);
}

.htab {
  padding: 0.4rem 0.9rem;
  border-radius: var(--r-full);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.htab:hover { background: var(--surface-3); color: var(--text1); }
.htab.active {
  background: rgba(192,57,43,0.2);
  border-color: rgba(192,57,43,0.5);
  color: var(--red3);
  font-weight: 600;
}

.kana-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
  gap: var(--sp-sm);
}

.kana-card {
  aspect-ratio: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform var(--t-fast) var(--ease-spring), border-color var(--t-fast), box-shadow var(--t-fast);
}
.kana-card:hover {
  transform: scale(1.05);
  border-color: var(--border2);
  box-shadow: var(--shadow-sm);
}
.kana-card.mastered {
  border-color: rgba(39,174,96,0.5);
  background: rgba(39,174,96,0.08);
}
.kana-card.mastered::after {
  content: '✓';
  position: absolute;
  top: 2px; right: 4px;
  font-size: 0.6rem;
  color: var(--green2);
  font-weight: 700;
}

.kana-char {
  font-family: var(--font-jp);
  font-size: 1.6rem;
  color: var(--text1);
  line-height: 1;
}
.kana-rom {
  font-size: 0.65rem;
  color: var(--text3);
  margin-top: 2px;
  font-family: var(--font-mono);
}

/* ── 11. Kanji Grid ─────────────────────────────────────────── */
.kanji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: var(--sp-md);
}

.kanji-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-md) var(--sp-sm);
  cursor: pointer;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: transform var(--t-fast) var(--ease-spring), border-color var(--t-fast), box-shadow var(--t-fast);
}
.kanji-card:hover {
  transform: translateY(-3px);
  border-color: var(--gold);
  box-shadow: 0 4px 20px rgba(240,165,0,0.15);
}
.kanji-card.mastered { border-color: rgba(39,174,96,0.5); background: rgba(39,174,96,0.06); }

.kanji-char {
  font-family: var(--font-jp);
  font-size: 2rem;
  color: var(--text1);
  line-height: 1;
  margin-bottom: var(--sp-xs);
}
.kanji-on  { font-size: 0.65rem; color: var(--gold);  font-family: var(--font-jp); }
.kanji-kun { font-size: 0.65rem; color: var(--text2); font-family: var(--font-jp); }
.kanji-meaning { font-size: 0.7rem; color: var(--text3); margin-top: 2px; }

/* ── 12. Bab Grid (Minna) ───────────────────────────────────── */
.bab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--sp-md);
}

.bab-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-lg);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform var(--t-med) var(--ease-spring), border-color var(--t-med), box-shadow var(--t-med);
}
.bab-card:hover {
  transform: translateY(-3px);
  border-color: var(--border2);
  box-shadow: var(--shadow-md);
}
.bab-card.completed { border-color: rgba(39,174,96,0.5); }
.bab-card.completed::before {
  content: '完了';
  position: absolute;
  top: 0.75rem; right: 0.75rem;
  font-size: 0.65rem;
  font-family: var(--font-jp);
  background: rgba(39,174,96,0.2);
  color: var(--green2);
  padding: 2px 6px;
  border-radius: var(--r-full);
  font-weight: 600;
}

.bab-num {
  font-size: 0.72rem;
  color: var(--text3);
  font-family: var(--font-mono);
  margin-bottom: var(--sp-xs);
}
.bab-jp {
  font-family: var(--font-jp);
  font-size: 1.4rem;
  color: var(--red2);
  font-weight: 700;
  margin-bottom: var(--sp-xs);
}
.bab-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text1);
  margin-bottom: var(--sp-xs);
}
.bab-sub { font-size: 0.78rem; color: var(--text2); }

.bab-progress-bar {
  height: 4px;
  background: var(--surface-3);
  border-radius: var(--r-full);
  margin-top: var(--sp-md);
  overflow: hidden;
}
.bab-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--green2));
  border-radius: var(--r-full);
  transition: width 0.5s var(--ease);
}

.bab-topics {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: var(--sp-sm);
}
.bab-topic-tag {
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text3);
  border: 1px solid var(--border);
}

/* ── 13. Flashcard ──────────────────────────────────────────── */
.flashcard-wrap {
  max-width: 480px;
  margin: 0 auto;
}

.fc-progress {
  height: 4px;
  background: var(--surface-2);
  border-radius: var(--r-full);
  overflow: hidden;
  margin-bottom: var(--sp-sm);
}
.fc-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--red2));
  border-radius: var(--r-full);
  transition: width 0.4s var(--ease);
}

.fc-counter {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text3);
  font-family: var(--font-mono);
  margin-bottom: var(--sp-lg);
}

.flashcard {
  perspective: 1200px;
  cursor: pointer;
  margin-bottom: var(--sp-lg);
  height: 260px;
}

.flashcard-inner {
  width: 100%; height: 100%;
  transition: transform 0.5s var(--ease);
  transform-style: preserve-3d;
  position: relative;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.fc-front, .fc-back {
  position: absolute; inset: 0;
  background: var(--surface);
  border: 2px solid var(--border2);
  border-radius: var(--r-xl);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--sp-md);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  padding: var(--sp-xl);
  box-shadow: var(--shadow-md);
}
.fc-back { transform: rotateY(180deg); }

.fc-char {
  font-family: var(--font-jp);
  font-size: 5rem;
  font-weight: 700;
  color: var(--text1);
  line-height: 1;
  text-shadow: 0 0 40px rgba(240,165,0,0.2);
}
.fc-hint { font-size: 0.8rem; color: var(--text3); }

.fc-answer { font-size: 2rem; font-weight: 700; color: var(--gold2); }
.fc-sub    { font-size: 0.9rem; color: var(--text2); font-family: var(--font-jp); }

.fc-nav {
  display: flex; gap: var(--sp-md);
  justify-content: center;
}
.fc-btn {
  padding: 0.7rem 1.8rem;
  border-radius: var(--r-lg);
  font-size: 0.9rem;
  font-weight: 600;
  transition: transform var(--t-fast), box-shadow var(--t-fast), opacity var(--t-fast);
}
.fc-btn:hover { transform: translateY(-2px); }
.fc-btn:active { transform: translateY(0); }
.fc-btn-right {
  background: linear-gradient(135deg, var(--green), var(--green2));
  color: #000;
  box-shadow: 0 4px 15px rgba(39,174,96,0.3);
}
.fc-btn-wrong {
  background: var(--surface-2);
  border: 1px solid var(--border2);
  color: var(--text2);
}

#fc-result[hidden] { display: none; }
.fc-result-inner {
  text-align: center;
  padding: var(--sp-2xl);
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r-xl);
}
.fc-result-emoji { font-size: 3rem; margin-bottom: var(--sp-md); }
.fc-result-text  { font-size: 1.1rem; font-weight: 700; color: var(--gold); margin-bottom: var(--sp-lg); }
.fc-restart { padding: 0.7rem 2rem; }

/* ── 14. Quiz ───────────────────────────────────────────────── */
.quiz-area { max-width: 600px; margin: 0 auto; }

.quiz-mode-tabs {
  display: flex; flex-wrap: wrap; gap: var(--sp-xs);
  margin-bottom: var(--sp-lg);
}

.quiz-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--sp-xl);
  box-shadow: var(--shadow-md);
}

.quiz-q {
  font-family: var(--font-jp);
  font-size: 4rem;
  font-weight: 700;
  text-align: center;
  color: var(--text1);
  line-height: 1;
  margin-bottom: var(--sp-sm);
  min-height: 5rem;
  display: flex; align-items: center; justify-content: center;
}
.quiz-hint {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text3);
  margin-bottom: var(--sp-lg);
  font-family: var(--font-jp);
  min-height: 1.2rem;
}

.quiz-opts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-sm);
  margin-bottom: var(--sp-lg);
}

.quiz-opt {
  padding: 0.85rem var(--sp-md);
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  font-size: 1rem;
  font-family: var(--font-jp);
  color: var(--text1);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}
.quiz-opt:hover { border-color: var(--border2); background: var(--surface-3); transform: scale(1.02); }
.quiz-opt.correct { border-color: var(--green2); background: rgba(39,174,96,0.15); color: var(--green2); }
.quiz-opt.wrong   { border-color: var(--red3);   background: rgba(231,76,60,0.15);  color: var(--red3);   }
.quiz-opt:disabled { cursor: default; transform: none; }

.quiz-meta {
  display: flex;
  justify-content: space-around;
  padding: var(--sp-md) 0;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text2);
  margin-bottom: var(--sp-md);
}
.quiz-meta strong { color: var(--text1); }

.btn-next {
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, var(--red), var(--gold));
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--r-md);
  transition: opacity var(--t-fast), transform var(--t-fast);
}
.btn-next:hover { transform: translateY(-1px); }
.btn-next[hidden] { display: none; }

/* ── 15. Profil ─────────────────────────────────────────────── */
.profil-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-lg);
  margin-bottom: var(--sp-lg);
}
@media (max-width: 768px) { .profil-grid { grid-template-columns: 1fr; } }

.db-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-lg);
  margin-bottom: var(--sp-md);
}
.db-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--sp-md);
  padding-bottom: var(--sp-sm);
  border-bottom: 1px solid var(--border);
}

.profile-header {
  display: flex; align-items: center; gap: var(--sp-md);
  margin-bottom: var(--sp-lg);
}
.profile-avatar {
  width: 56px; height: 56px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--red), var(--gold));
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.profile-name { font-size: 1rem; font-weight: 700; color: var(--text1); }
.profile-email { font-size: 0.8rem; color: var(--text2); }
.level-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 0.75rem; font-weight: 600;
  padding: 3px 10px;
  background: rgba(240,165,0,0.15);
  color: var(--gold);
  border-radius: var(--r-full);
  margin-top: 4px;
}

.xp-progress-label {
  display: flex; justify-content: space-between;
  font-size: 0.75rem; color: var(--text2);
  margin-bottom: var(--sp-xs);
}
.xp-bar-wrap {
  height: 8px;
  background: var(--surface-3);
  border-radius: var(--r-full);
  overflow: hidden;
}
.xp-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--red2));
  border-radius: var(--r-full);
  transition: width 0.6s var(--ease);
}

.mastery-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.mastery-table th {
  text-align: left;
  padding: var(--sp-xs) var(--sp-sm);
  color: var(--text3);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}
.mastery-table td {
  padding: var(--sp-sm);
  border-bottom: 1px solid var(--border);
  color: var(--text2);
}
.mastery-table tr:last-child td { border-bottom: none; }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-sm);
}
.stat-mini {
  background: var(--surface-2);
  border-radius: var(--r-md);
  padding: var(--sp-sm) var(--sp-md);
  border: 1px solid var(--border);
}
.stat-mini-val { font-size: 1.2rem; font-weight: 700; color: var(--text1); }
.stat-mini-lbl { font-size: 0.72rem; color: var(--text3); }

#leaderboard li {
  display: flex; align-items: center; gap: var(--sp-sm);
  padding: var(--sp-sm) 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
#leaderboard li:last-child { border-bottom: none; }
.lb-rank { font-weight: 700; color: var(--text3); min-width: 1.5rem; font-family: var(--font-mono); }
.lb-rank.top-3 { color: var(--gold); }
.lb-name { flex: 1; color: var(--text1); font-weight: 500; }
.lb-xp  { color: var(--gold2); font-weight: 600; font-family: var(--font-mono); }

.full-activity { max-height: 250px; overflow-y: auto; }
.full-activity li {
  padding: var(--sp-sm) 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text2);
  display: flex; justify-content: space-between;
}
.full-activity li:last-child { border-bottom: none; }

.sync-section { }
.sync-btns {
  display: flex; gap: var(--sp-sm); flex-wrap: wrap;
}
.btn-sync, .btn-export, .btn-reset, .btn-logout {
  padding: 0.6rem 1.2rem;
  border-radius: var(--r-md);
  font-size: 0.82rem;
  font-weight: 600;
  transition: transform var(--t-fast), opacity var(--t-fast);
}
.btn-sync   { background: rgba(0,180,166,0.2); border: 1px solid rgba(0,180,166,0.4); color: var(--teal2); }
.btn-export { background: rgba(240,165,0,0.15); border: 1px solid rgba(240,165,0,0.35); color: var(--gold2); }
.btn-reset  { background: rgba(192,57,43,0.15); border: 1px solid rgba(192,57,43,0.35); color: var(--red3); }
.btn-logout { background: var(--surface-2); border: 1px solid var(--border2); color: var(--text2); }
.btn-sync:hover, .btn-export:hover, .btn-reset:hover, .btn-logout:hover { transform: translateY(-1px); }

.sync-msg { font-size: 0.8rem; color: var(--text2); margin-top: var(--sp-md); }

/* ── 16. Modals ─────────────────────────────────────────────── */
.modal-ov {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-md);
  animation: modal-fadein var(--t-med) var(--ease);
}
.modal-ov[hidden] { display: none; }

@keyframes modal-fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r-xl);
  max-width: 680px;
  width: 100%;
  max-height: 85dvh;
  overflow-y: auto;
  animation: modal-slidein var(--t-med) var(--ease-spring);
}

@keyframes modal-slidein {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--sp-lg) var(--sp-xl);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0;
  background: var(--surface);
  z-index: 1;
}
.modal-jp {
  font-family: var(--font-jp);
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--red2);
  line-height: 1;
  text-shadow: 0 0 30px rgba(192,57,43,0.3);
}
.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text1);
  margin-top: var(--sp-xs);
}
.modal-sub { font-size: 0.82rem; color: var(--text2); }

.btn-close {
  width: 36px; height: 36px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--t-fast), color var(--t-fast);
}
.btn-close:hover { background: var(--surface-3); color: var(--text1); }

.modal-body { padding: var(--sp-xl); }

/* ── 17. XP Toast ───────────────────────────────────────────── */
.xp-toast {
  position: fixed;
  bottom: calc(var(--mobile-nav) + 20px);
  right: var(--sp-lg);
  background: linear-gradient(135deg, var(--gold), var(--red2));
  color: #fff;
  padding: 0.6rem 1.2rem;
  border-radius: var(--r-full);
  font-size: 0.9rem;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  z-index: 300;
  animation: toast-in var(--t-med) var(--ease-spring);
  pointer-events: none;
}
.xp-toast[hidden] { display: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (min-width: 769px) {
  .xp-toast { bottom: var(--sp-xl); }
}

/* ── 18a. Kana Detail Modal ─────────────────────────────────── */
.kana-detail {
  display: flex;
  flex-direction: column;
  gap: var(--sp-lg);
}

.kana-detail-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--sp-md);
}

.kana-detail-item {
  background: var(--surface-2);
  border-radius: var(--r-md);
  padding: var(--sp-md);
  text-align: center;
  border: 1px solid var(--border);
}

.kana-detail-label {
  font-size: 0.68rem;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--sp-xs);
}

.kana-detail-val {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text1);
}

/* Mastered checkmark overlaid on kana card */
.kana-mastered-check {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.6rem;
  color: var(--green2);
  font-weight: 700;
  pointer-events: none;
}

/* ── 18. Modal Content Components ───────────────────────────── */
.grammar-list { display: flex; flex-direction: column; gap: var(--sp-md); }
.grammar-item {
  background: var(--surface-2);
  border-radius: var(--r-md);
  padding: var(--sp-md);
  border-left: 3px solid var(--gold);
}
.grammar-pattern {
  font-family: var(--font-jp);
  font-size: 1rem;
  font-weight: 700;
  color: var(--gold2);
  margin-bottom: var(--sp-xs);
}
.grammar-desc { font-size: 0.82rem; color: var(--text2); margin-bottom: var(--sp-xs); }
.grammar-ex {
  font-family: var(--font-jp);
  font-size: 0.88rem;
  color: var(--text3);
  font-style: italic;
}

.vocab-table { width: 100%; border-collapse: collapse; margin-top: var(--sp-md); }
.vocab-table th {
  text-align: left;
  padding: var(--sp-xs) var(--sp-sm);
  font-size: 0.75rem;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
}
.vocab-table td {
  padding: var(--sp-sm);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.vocab-table td:first-child { font-family: var(--font-jp); color: var(--gold2); font-size: 1rem; }
.vocab-table td:nth-child(2) { font-family: var(--font-jp); color: var(--text2); }

.mastered-btn {
  width: 100%;
  margin-top: var(--sp-lg);
  padding: 0.85rem;
  background: rgba(39,174,96,0.15);
  border: 2px solid rgba(39,174,96,0.4);
  color: var(--green2);
  border-radius: var(--r-md);
  font-size: 0.95rem;
  font-weight: 600;
  transition: background var(--t-fast), transform var(--t-fast);
}
.mastered-btn:hover { background: rgba(39,174,96,0.25); transform: scale(1.02); }
.mastered-btn.active {
  background: rgba(39,174,96,0.3);
  border-color: var(--green2);
}

/* Kanji detail modal */
.kanji-detail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-lg);
  text-align: center;
}
.kanji-big {
  font-family: var(--font-jp);
  font-size: 5rem;
  color: var(--text1);
  text-shadow: 0 0 40px rgba(240,165,0,0.2);
  line-height: 1;
}
.kanji-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-sm);
  width: 100%;
}
.kanji-info-item {
  background: var(--surface-2);
  border-radius: var(--r-md);
  padding: var(--sp-md);
  text-align: center;
}
.kanji-info-label { font-size: 0.7rem; color: var(--text3); margin-bottom: 2px; }
.kanji-info-val   { font-family: var(--font-jp); font-size: 0.95rem; color: var(--text1); font-weight: 600; }

/* ── 19. Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border2); }

/* ── 20. Utility ────────────────────────────────────────────── */
.hidden { display: none !important; }

/* Focus styles for accessibility */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
