@import url('https://fonts.googleapis.com/css2?family=Zen+Kaku+Gothic+New:wght@400;700;900&family=Syne:wght@600;700;800&family=DM+Sans:wght@400;500;600;700&display=swap');

:root {
  --bg: #0d0f14;
  --surface: #161922;
  --surface2: #1e2330;
  --border: rgba(255,255,255,0.07);
  --neon-red: #ff3c5f;
  --neon-teal: #00e5cc;
  --neon-gold: #ffd166;
  --neon-blue: #4d9fff;
  --neon-purple: #c77dff;
  --neon-green: #06d6a0;
  --text: #eef0f7;
  --text-dim: #7a8099;
  --radius: 16px;
  --radius-sm: 10px;
  --glow-red: 0 0 20px rgba(255,60,95,0.4);
  --glow-teal: 0 0 20px rgba(0,229,204,0.4);
  --glow-gold: 0 0 20px rgba(255,209,102,0.4);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.022) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  top: -40%;
  left: -20%;
  width: 60%;
  height: 80%;
  background: radial-gradient(ellipse, rgba(255,60,95,0.055) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

/* Header */
header {
  background: rgba(13,15,20,0.88);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 200;
}

.header-inner {
  max-width: 1100px;
  margin: auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

.logo {
  display: none;
}

/* Desktop nav — hidden on mobile by default */
nav {
  display: none;
  gap: 4px;
  flex: 1;
  min-width: 0; /* prevent nav from pushing search/profile off screen */
}

/* Hamburger button — hidden on desktop */
.mobile-menu-btn {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  z-index: 300;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.mobile-menu-btn span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.mobile-menu-btn.active span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}
.mobile-menu-btn.active span:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}
.mobile-menu-btn.active span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* ── Desktop (768px+): show nav, hide hamburger ── */
@media (min-width: 768px) {
  nav {
    display: flex;
  }
  .mobile-menu-btn {
    display: none;
  }
}

/* ── Mobile (<768px): show hamburger, hide nav until active ── */
@media (max-width: 767px) {
  .mobile-menu-btn {
    display: flex;
  }

  nav {
    display: none;
    position: fixed;
    top: 57px;
    left: 0;
    right: 0;
    flex-direction: column;
    background: rgba(13, 15, 20, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px 20px;
    gap: 4px;
    z-index: 199;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    /* slide-down animation */
    animation: none;
  }

  nav.active {
    display: flex;
    animation: navSlideDown 0.25s ease forwards;
  }

  @keyframes navSlideDown {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  nav a {
    width: 100%;
    text-align: center;
    padding: 11px 20px;
    border-radius: 10px;
    font-size: 0.92rem;
  }

  nav a:hover,
  nav a:active {
    background: var(--surface2);
    color: var(--text);
  }
}

nav a {
  color: var(--text-dim);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.87rem;
  padding: 7px 15px;
  border-radius: 30px;
  border: 1px solid transparent;
  transition: all 0.18s;
}

nav a:hover {
  color: var(--text);
  background: var(--surface2);
  border-color: var(--border);
}

nav a.active {
  color: var(--neon-red);
  background: rgba(255,60,95,0.1);
  border-color: rgba(255,60,95,0.3);
}

/* Layout */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 16px 60px;
  position: relative;
  z-index: 1;
}

/* Hero */
.page-hero {
  margin-bottom: 28px;
  text-align: center;
}

.eyebrow {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--neon-red);
  margin-bottom: 8px;
}

.page-hero h1 {
  font-family: 'Syne', sans-serif;
  font-size: clamp(1.8rem, 5vw, 2.9rem);
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.1;
  margin-bottom: 10px;
}

.page-hero p {
  color: var(--text-dim);
  font-size: 0.95rem;
  max-width: 540px;
  line-height: 1.65;
  margin: 0 auto;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 22px;
  border-radius: 30px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  border: none;
  transition: all 0.18s;
  text-decoration: none;
  justify-content: center;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--neon-red);
  color: white;
  box-shadow: var(--glow-red);
}

.btn-teal {
  background: var(--neon-teal);
  color: #0d0f14;
  box-shadow: var(--glow-teal);
}

.btn-gold {
  background: var(--neon-gold);
  color: #0d0f14;
  box-shadow: var(--glow-gold);
}

.btn-ghost {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-green {
  background: var(--neon-green);
  color: #0d0f14;
}

.btn-purple {
  background: var(--neon-purple);
  color: #0d0f14;
}

.btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

/* Progress */
.progress-wrap {
  background: var(--surface2);
  border-radius: 30px;
  height: 8px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 30px;
  background: linear-gradient(90deg, var(--neon-red), var(--neon-gold));
  transition: width 0.6s cubic-bezier(.34,1.56,.64,1);
}

.progress-fill.teal {
  background: linear-gradient(90deg, var(--neon-teal), var(--neon-blue));
}

.progress-fill.purple {
  background: linear-gradient(90deg, var(--neon-purple), #ff6eb4);
}

.progress-fill.green {
  background: linear-gradient(90deg, var(--neon-green), var(--neon-teal));
}

.progress-fill.gold {
  background: linear-gradient(90deg, var(--neon-gold), #ff9f43);
}

/* Tabs */
.tab-bar {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 5px;
  border-radius: 30px;
  margin-bottom: 24px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  padding: 8px 18px;
  border-radius: 30px;
  border: none;
  background: transparent;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-dim);
  transition: all 0.18s;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab-btn.active {
  background: var(--neon-red);
  color: white;
  box-shadow: var(--glow-red);
}

/* Stats row */
.stats-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  justify-content: center;
}

.stat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 7px 14px;
  font-weight: 600;
  font-size: 0.81rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-chip strong {
  color: var(--text);
}

/* Home hero */
.home-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 24px;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
  text-align: center;
}

.home-hero::before {
  content: '日本語';
  position: absolute;
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 8rem;
  font-weight: 900;
  color: rgba(255,60,95,0.055);
  pointer-events: none;
  line-height: 1;
}

.home-hero h1 {
  font-family: 'Syne', sans-serif;
  font-size: clamp(1.9rem, 5vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -1.5px;
  line-height: 1.1;
  margin-bottom: 10px;
}

.home-hero h1 em {
  font-style: normal;
  color: var(--neon-red);
}

.home-hero p {
  color: var(--text-dim);
  font-size: 0.95rem;
  max-width: 480px;
  line-height: 1.65;
  margin: 0 auto 20px;
}

/* Daily Goal Card */
.daily-goal-card {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
}

.daily-goal-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--neon-red), var(--neon-gold), var(--neon-teal));
}

.goal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.goal-icon {
  font-size: 2rem;
  line-height: 1;
}

.goal-header h3 {
  font-family: 'Syne', sans-serif;
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 2px;
}

.goal-subtitle {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0;
}

.streak-badge {
  margin-left: auto;
  background: rgba(255, 60, 95, 0.15);
  border: 1px solid rgba(255, 60, 95, 0.3);
  border-radius: 12px;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.streak-num {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--neon-red);
  line-height: 1;
}

.streak-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.goal-progress-wrap {
  background: rgba(255, 255, 255, 0.05);
  height: 12px;
  border-radius: 20px;
  overflow: hidden;
  margin-bottom: 12px;
  position: relative;
}

.goal-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--neon-red), var(--neon-gold));
  border-radius: 20px;
  transition: width 0.5s ease;
  box-shadow: 0 0 12px rgba(255, 60, 95, 0.4);
}

.goal-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 600;
}

@media (max-width: 600px) {
  .streak-badge {
    padding: 6px 12px;
  }
  
  .streak-num {
    font-size: 1.2rem;
  }
  
  .goal-stats {
    flex-direction: column;
    gap: 4px;
  }
}

/* ========== FIXED GRIDS ========== */
/* Changed from auto-fill to auto-fit to prevent stretching with few items */
/* Added justify-content: center for better alignment */

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  justify-content: center;
}

.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 16px 18px;
  text-decoration: none;
  color: var(--text);
  display: block;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.module-card:hover {
  transform: translateY(-4px);
}

.module-card.red { border-top: 3px solid var(--neon-red); }
.module-card.teal { border-top: 3px solid var(--neon-teal); }
.module-card.green { border-top: 3px solid var(--neon-green); }
.module-card.gold { border-top: 3px solid var(--neon-gold); }
.module-card.purple { border-top: 3px solid var(--neon-purple); }
.module-card.blue { border-top: 3px solid var(--neon-blue); }

.module-card:hover.red { box-shadow: 0 8px 32px rgba(255,60,95,0.15); }
.module-card:hover.teal { box-shadow: 0 8px 32px rgba(0,229,204,0.15); }
.module-card:hover.green { box-shadow: 0 8px 32px rgba(6,214,160,0.15); }
.module-card:hover.gold { box-shadow: 0 8px 32px rgba(255,209,102,0.15); }
.module-card:hover.purple { box-shadow: 0 8px 32px rgba(199,125,255,0.15); }
.module-card:hover.blue { box-shadow: 0 8px 32px rgba(77,159,255,0.15); }

.module-icon {
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 2.3rem;
  font-weight: 900;
  display: block;
  margin-bottom: 10px;
  line-height: 1;
}

.module-card h3 {
  font-family: 'Syne', sans-serif;
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: 5px;
}

.module-card p {
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-bottom: 12px;
}

.module-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}

.module-card.red .module-badge { background: rgba(255,60,95,0.14); color: var(--neon-red); }
.module-card.teal .module-badge { background: rgba(0,229,204,0.14); color: var(--neon-teal); }
.module-card.green .module-badge { background: rgba(6,214,160,0.14); color: var(--neon-green); }
.module-card.gold .module-badge { background: rgba(255,209,102,0.14); color: var(--neon-gold); }
.module-card.purple .module-badge { background: rgba(199,125,255,0.14); color: var(--neon-purple); }
.module-card.blue .module-badge { background: rgba(77,159,255,0.14); color: var(--neon-blue); }

/* Progress section */
.progress-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
}

.progress-section h2 {
  font-family: 'Syne', sans-serif;
  font-size: 1.1rem;
  font-weight: 800;
  margin-bottom: 16px;
}

.progress-item {
  margin-bottom: 14px;
}

.progress-item:last-child {
  margin-bottom: 0;
}

.p-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 7px;
  font-size: 0.84rem;
  font-weight: 600;
}

.p-label span:last-child {
  color: var(--text-dim);
}

/* Section divider */
.section-label {
  font-family: 'Syne', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Kana grid - FIXED */
.kana-section {
  margin-bottom: 28px;
}

.kana-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
  gap: 6px;
  justify-content: center;
  align-items: start;
  align-content: start;
}

.kana-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 6px 10px;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s;
  position: relative;
  overflow: hidden;
  animation: fadeUp 0.3s ease both;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.kana-card:hover {
  border-color: rgba(255,60,95,0.4);
  background: var(--surface2);
  box-shadow: var(--glow-red);
}

.kana-card.learned {
  border-color: rgba(6,214,160,0.4);
  background: rgba(6,214,160,0.05);
}

.kana-card.learned::after {
  content: '✓';
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.65rem;
  color: var(--neon-green);
  font-weight: 700;
}

.kana-card.revealed {
  border-color: rgba(255,209,102,0.4);
  background: rgba(255,209,102,0.05);
}

.kana-char {
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 1.75rem;
  font-weight: 700;
  display: block;
  line-height: 1.1;
  margin-bottom: 4px;
}

.kana-roman {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

.kana-card.revealed .kana-roman {
  color: var(--neon-gold);
}

/* Audio button — mobile-first, large tap target */
.audio-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 1.1rem;
  color: var(--text-dim);
  margin-top: 4px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.audio-btn:hover {
  background: rgba(0,229,204,0.14);
  border-color: var(--neon-teal);
  color: var(--neon-teal);
  box-shadow: var(--glow-teal);
}

.audio-btn.playing {
  background: rgba(0,229,204,0.18);
  border-color: var(--neon-teal);
  color: var(--neon-teal);
  animation: pulse 0.6s ease infinite alternate;
}

@keyframes pulse {
  from {
    box-shadow: 0 0 4px rgba(0,229,204,0.3);
  }
  to {
    box-shadow: 0 0 18px rgba(0,229,204,0.7);
  }
}

/* Flashcard */
.flashcard-scene {
  perspective: 1000px;
  width: 100%;
  max-width: 300px;
  height: 210px;
  cursor: pointer;
  margin: 0 auto;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(.34,1.2,.64,1);
}

.flashcard-scene.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  border: 1px solid var(--border);
}

.flashcard-front {
  background: var(--surface);
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 5rem;
  font-weight: 900;
}

.flashcard-back {
  background: var(--surface2);
  transform: rotateY(180deg);
  gap: 8px;
}

.flashcard-back .big {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--neon-gold);
}

.flashcard-back .small {
  font-size: 0.9rem;
  color: var(--text-dim);
}

/* Vocab grid - FIXED */
.vocab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  justify-content: center;
}

.vocab-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.vocab-card:hover {
  border-color: rgba(255,255,255,0.12);
  transform: translateY(-2px);
}

.vocab-jp {
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 1.7rem;
  font-weight: 700;
  display: block;
  margin-bottom: 2px;
}

.vocab-reading {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.vocab-en {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--neon-gold);
  transition: all 0.2s;
}

.vocab-card.hide-en .vocab-en {
  filter: blur(6px);
  color: transparent;
  background: var(--surface2);
  border-radius: 4px;
  user-select: none;
}

.vocab-cat {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 10px;
}

.vocab-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.vocab-btn {
  font-size: 0.78rem;
  padding: 8px 14px;
  min-height: 36px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-dim);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.vocab-btn:hover {
  border-color: rgba(255,255,255,0.15);
  color: var(--text);
}

.vocab-btn.learned {
  background: rgba(6,214,160,0.1);
  border-color: rgba(6,214,160,0.3);
  color: var(--neon-green);
}

/* Filter chips — horizontal scroll on mobile */
.filter-chips {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 20px;
  padding-bottom: 6px;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }

.chip {
  padding: 8px 16px;
  border-radius: 30px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.79rem;
  cursor: pointer;
  color: var(--text-dim);
  transition: all 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 38px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.chip.active,
.chip:hover {
  background: rgba(255,60,95,0.1);
  border-color: rgba(255,60,95,0.35);
  color: var(--neon-red);
}

/* Quiz */
.quiz-wrap {
  max-width: 620px;
  margin: 0 auto;
}

.quiz-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.quiz-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 6px 14px;
  font-size: 0.79rem;
  font-weight: 700;
  color: var(--text-dim);
}

.streak-pill {
  color: var(--neon-gold);
  border-color: rgba(255,209,102,0.3);
  background: rgba(255,209,102,0.07);
}

.quiz-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 24px;
  text-align: center;
}

.q-label {
  font-size: 0.71rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.q-char {
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: clamp(4rem, 15vw, 6rem);
  font-weight: 900;
  display: block;
  line-height: 1;
  margin: 8px 0 24px;
}

.quiz-opts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.quiz-opt {
  padding: 16px 12px;
  min-height: 54px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface2);
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.quiz-opt:hover:not(:disabled) {
  border-color: rgba(255,60,95,0.4);
  background: rgba(255,60,95,0.08);
  color: var(--neon-red);
}

.quiz-opt.correct {
  background: rgba(6,214,160,0.12);
  border-color: var(--neon-green);
  color: var(--neon-green);
  box-shadow: 0 0 16px rgba(6,214,160,0.2);
}

.quiz-opt.wrong {
  background: rgba(255,60,95,0.1);
  border-color: var(--neon-red);
  color: var(--neon-red);
}

/* Kanji grid - FIXED */
.kanji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  justify-content: center;
  align-items: start;
  align-content: start;
}

.kanji-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 14px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
  animation: fadeUp 0.3s ease both;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.kanji-card:hover {
  border-color: rgba(255,209,102,0.4);
  box-shadow: 0 0 28px rgba(255,209,102,0.1);
  transform: translateY(-3px);
}

.kanji-card.learned {
  border-color: rgba(6,214,160,0.3);
  background: rgba(6,214,160,0.04);
}

.kanji-char {
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: 2.8rem;
  font-weight: 700;
  display: block;
  color: var(--neon-gold);
  margin-bottom: 6px;
  line-height: 1.1;
  text-shadow: 0 0 20px rgba(255,209,102,0.3);
}

.kanji-meaning {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.kanji-readings {
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.6;
}

.kanji-level {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(255,209,102,0.1);
  color: var(--neon-gold);
}

.kanji-card.learned::after {
  content: '✓';
  position: absolute;
  top: 8px;
  left: 8px;
  font-size: 0.65rem;
  color: var(--neon-green);
  font-weight: 700;
}

/* Writing canvas */
.writing-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.canvas-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

canvas {
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.stroke-preview {
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: clamp(5rem, 15vw, 7rem);
  font-weight: 900;
  color: rgba(255,255,255,0.04);
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  user-select: none;
}

.canvas-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* SRS */
.srs-card-scene {
  perspective: 800px;
  width: 100%;
  max-width: 100%;
  height: 200px;
  cursor: pointer;
  margin: 0 auto;
}

.srs-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(.34,1.2,.64,1);
}

.srs-card-scene.flipped .srs-card-inner {
  transform: rotateY(180deg);
}

.srs-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  gap: 5px;
  padding: 16px;
}

.srs-face.back {
  transform: rotateY(180deg);
  background: var(--surface2);
  border-color: rgba(255,209,102,0.25);
}

.srs-jp {
  font-family: 'Zen Kaku Gothic New', sans-serif;
  font-size: clamp(3rem, 10vw, 4.5rem);
  font-weight: 900;
}

.srs-en {
  font-size: clamp(1.2rem, 4vw, 1.55rem);
  font-weight: 700;
  color: var(--neon-gold);
}

.srs-reading {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.srs-rating-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
  flex-wrap: wrap;
}

.srs-btn {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  transition: all 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.srs-btn span {
  font-size: 0.62rem;
  opacity: 0.7;
}

.srs-btn.again {
  background: rgba(255,60,95,0.14);
  color: var(--neon-red);
  border: 1px solid rgba(255,60,95,0.3);
}

.srs-btn.hard {
  background: rgba(255,209,102,0.1);
  color: var(--neon-gold);
  border: 1px solid rgba(255,209,102,0.3);
}

.srs-btn.good {
  background: rgba(0,229,204,0.1);
  color: var(--neon-teal);
  border: 1px solid rgba(0,229,204,0.3);
}

.srs-btn.easy {
  background: rgba(6,214,160,0.1);
  color: var(--neon-green);
  border: 1px solid rgba(6,214,160,0.3);
}

.srs-btn:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.srs-due-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,60,95,0.1);
  border: 1px solid rgba(255,60,95,0.3);
  border-radius: 30px;
  padding: 6px 14px;
  color: var(--neon-red);
  font-weight: 700;
  font-size: 0.85rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 20px;
  border-radius: 30px;
  font-weight: 700;
  font-size: 0.86rem;
  box-shadow: 0 16px 48px rgba(0,0,0,0.5);
  z-index: 999;
  transition: transform 0.35s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* Result */
.result-screen {
  text-align: center;
  padding: 16px;
}

.result-emoji {
  font-size: 4rem;
  display: block;
  margin-bottom: 12px;
}

.result-title {
  font-family: 'Syne', sans-serif;
  font-size: clamp(1.8rem, 6vw, 2.4rem);
  font-weight: 800;
  margin-bottom: 8px;
}

.result-score {
  font-size: clamp(2.5rem, 10vw, 4rem);
  font-weight: 800;
  color: var(--neon-red);
  margin: 8px 0;
  font-family: 'Syne', sans-serif;
}

/* Animations */
@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.pop-in {
  animation: popIn 0.4s cubic-bezier(.34,1.56,.64,1) both;
}

/* Mobile optimizations */
@media (min-width: 640px) {
  nav {
    display: flex;
  }
  
  .container {
    padding: 40px 24px 80px;
  }
  
  .home-hero {
    padding: 44px 48px;
    text-align: left;
  }
  
  .home-hero p {
    margin: 0 0 22px;
  }
  
  .page-hero {
    text-align: left;
  }
  
  .page-hero p {
    margin: 0;
  }
  
  .quiz-opts {
    grid-template-columns: 1fr 1fr;
  }
  
  .quiz-box {
    padding: 40px 36px;
  }
  
  .module-grid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
  }
  
  .kana-grid {
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 10px;
  }
  
  .kanji-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
  }
  
  .vocab-grid {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  }
  
  .stats-row {
    justify-content: flex-start;
  }
  
  .filter-chips {
    justify-content: flex-start;
  }
  
  .srs-card-scene {
    max-width: 480px;
    height: 230px;
  }
}

@media (min-width: 768px) {
  .header-inner {
    padding: 16px 24px;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .btn {
    min-height: 44px;
  }
  
  .tab-btn {
    min-height: 40px;
  }
  
  .kana-card,
  .vocab-card,
  .kanji-card {
    min-height: 40px;
  }
}

/* Tablet kana grid */
@media (min-width: 480px) {
  .kana-grid {
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
    gap: 8px;
  }
  .kana-char { font-size: 1.9rem; }
}

/* Desktop grids */
@media (min-width: 900px) {
  .kanji-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
  }
  .kana-grid {
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
    gap: 8px;
  }
}

/* Mobile hint bar shared style */
.hint-bar {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 16px;
  padding: 8px 12px;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.hint-bar span { color: var(--neon-teal); font-weight: 700; }

/* SRS buttons touch-friendly */
.srs-btn {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ── Back-to-top button: injected via JS with inline styles (see page scripts) ── */

/* ── Landscape mobile fixes ─────────────────────────────────────────────── */
@media (max-width: 767px) and (orientation: landscape) {
  .page-hero h1 { font-size: 1.6rem; }
  .kana-grid    { grid-template-columns: repeat(auto-fit, minmax(60px,1fr)); }
  .kanji-grid   { grid-template-columns: repeat(auto-fit, minmax(120px,1fr)); }
  .module-grid  { grid-template-columns: repeat(auto-fit, minmax(140px,1fr)); }
  nav { max-height: 70vh; overflow-y: auto; }
}

/* ── Mobile kanji font-size fix ─────────────────────────────────────────── */
@media (max-width: 480px) {
  .k-char { font-size: 2rem !important; }
  .kanji-card { min-height: 160px !important; }
  .kanji-grid.compact { grid-template-columns: repeat(3, 1fr) !important; }
}

/* ── Weak-words review banner ───────────────────────────────────────────── */
.weak-banner {
  background: linear-gradient(135deg, rgba(255,60,95,0.10), rgba(255,209,102,0.07));
  border: 1px solid rgba(255,60,95,0.3);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.weak-banner:hover { border-color: rgba(255,60,95,0.6); }
.weak-banner .wb-icon { font-size: 1.4rem; flex-shrink: 0; }
.weak-banner strong  { color: var(--neon-red); }
.weak-banner .wb-btn {
  margin-left: auto;
  padding: 6px 14px;
  border-radius: 20px;
  background: rgba(255,60,95,0.15);
  border: 1px solid rgba(255,60,95,0.4);
  color: var(--neon-red);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

/* ── Quiz score history table ───────────────────────────────────────────── */
.score-history {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.score-history h3 {
  padding: 14px 18px 10px;
  font-family: 'Syne', sans-serif;
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border);
}
.score-history-list { padding: 8px 0; max-height: 220px; overflow-y: auto; }
.sh-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  font-size: 0.83rem;
  border-bottom: 1px solid var(--border);
}
.sh-row:last-child { border-bottom: none; }
.sh-mode  { font-weight: 700; min-width: 80px; }
.sh-score { font-weight: 800; color: var(--neon-gold); margin-left: auto; }
.sh-date  { color: var(--text-dim); font-size: 0.75rem; }
.sh-new   { background: rgba(6,214,160,0.12); border-left: 3px solid var(--neon-green); }

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE & RESPONSIVE ENHANCEMENTS
   ══════════════════════════════════════════════════════════════════════════ */

/* ── 1. SCROLL SNAP FOR HORIZONTAL SCROLLING ────────────────────────────── */
.tab-bar,
.filter-chips,
.stats-row {
  scroll-snap-type: x proximity;
  scroll-padding: 0 16px;
  scroll-behavior: smooth;
}

.tab-btn,
.filter-chip,
.stat-chip {
  scroll-snap-align: start;
}

/* Visual indicator for more content in scrollable areas */
.tab-bar {
  position: relative;
}

.tab-bar::after {
  content: '›';
  position: sticky;
  right: 0;
  padding: 8px 16px;
  background: linear-gradient(90deg, transparent, var(--surface) 30%);
  font-size: 1.5rem;
  color: var(--neon-teal);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  line-height: 1;
  display: flex;
  align-items: center;
}

@media (max-width: 767px) {
  .tab-bar.has-overflow::after {
    opacity: 0.6;
  }
}

/* ── 2. SKELETON LOADING SCREENS ────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface) 0%,
    var(--surface2) 50%,
    var(--surface) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255,255,255,0.03) 50%,
    transparent 100%
  );
  animation: skeleton-shimmer 2s ease-in-out infinite;
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes skeleton-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Skeleton variants for different card types */
.kana-card.skeleton,
.vocab-card.skeleton,
.kanji-card.skeleton {
  min-height: 100px;
  cursor: wait;
  pointer-events: none;
}

.kana-card.skeleton *,
.vocab-card.skeleton *,
.kanji-card.skeleton * {
  opacity: 0;
}

.module-card.skeleton {
  min-height: 160px;
  cursor: wait;
  pointer-events: none;
}

.module-card.skeleton * {
  opacity: 0;
}

/* Reserve space to prevent layout shift */
.module-grid {
  min-height: 400px;
}

.kana-grid,
.vocab-grid {
  align-items: start;
  align-content: start;
}

.kanji-grid {
  align-items: start;
  align-content: start;
}

/* ── 3. GRANULAR RESPONSIVE BREAKPOINTS ─────────────────────────────────── */

/* Very small phones (iPhone SE 1st gen, etc.) - 320px - 374px */
@media (max-width: 374px) {
  .module-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .kana-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
  
  .vocab-grid {
    grid-template-columns: 1fr;
  }
  
  .kanji-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  
  .quiz-opts {
    grid-template-columns: 1fr;
  }
  
  .page-hero h1 {
    font-size: 1.6rem;
  }
  
  .home-hero h1 {
    font-size: 1.8rem;
  }
}

/* Small phones (iPhone SE 2nd/3rd gen, small Android) - 375px - 479px */
@media (min-width: 375px) and (max-width: 479px) {
  .module-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  
  .kana-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .vocab-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .kanji-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Standard phones (iPhone 12/13/14, most Android) - 480px - 767px */
@media (min-width: 480px) and (max-width: 767px) {
  .module-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
  }
  
  .kana-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .vocab-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .kanji-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Tablets portrait - 768px - 1023px */
@media (min-width: 768px) and (max-width: 1023px) {
  .module-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
  }
  
  .kana-grid {
    grid-template-columns: repeat(5, 1fr);
  }
  
  .vocab-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .kanji-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Tablets landscape / small laptops - 1024px - 1279px */
@media (min-width: 1024px) and (max-width: 1279px) {
  .module-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .kana-grid {
    grid-template-columns: repeat(6, 1fr);
  }
  
  .vocab-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  
  .kanji-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* ── 4. PERFORMANCE OPTIMIZATIONS ───────────────────────────────────────── */

/* Only apply backdrop-filter on capable devices */
@supports (backdrop-filter: blur(16px)) {
  header {
    backdrop-filter: blur(16px);
  }
  
  nav {
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
}

/* Fallback for browsers without backdrop-filter */
@supports not (backdrop-filter: blur(16px)) {
  header {
    background: rgba(13,15,20,0.98);
  }
  
  nav {
    background: rgba(13, 15, 20, 0.98);
  }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  
  .pop-in {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* Use transform and opacity for smooth animations (GPU accelerated) */
.kana-card,
.vocab-card,
.kanji-card,
.module-card {
  transform: translateZ(0); /* Force GPU acceleration */
  backface-visibility: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Optimize scroll performance */
.kana-grid,
.vocab-grid,
.kanji-grid,
.module-grid {
  contain: style paint; /* CSS containment for better performance */
}

/* Debounce scroll events */
.container {
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* ── 5. OFFLINE INDICATOR ───────────────────────────────────────────────── */
.offline-indicator {
  position: fixed;
  top: 57px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: rgba(255,60,95,0.95);
  color: white;
  padding: 10px 20px;
  border-radius: 0 0 12px 12px;
  font-weight: 700;
  font-size: 0.85rem;
  z-index: 300;
  transition: transform 0.3s cubic-bezier(.34,1.56,.64,1);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.offline-indicator.show {
  transform: translateX(-50%) translateY(0);
}

.offline-indicator::before {
  content: '⚠️';
  font-size: 1rem;
}

/* Online indicator (temporary) */
.online-indicator {
  position: fixed;
  top: 57px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: rgba(6,214,160,0.95);
  color: #0d0f14;
  padding: 10px 20px;
  border-radius: 0 0 12px 12px;
  font-weight: 700;
  font-size: 0.85rem;
  z-index: 300;
  transition: transform 0.3s cubic-bezier(.34,1.56,.64,1);
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.online-indicator.show {
  transform: translateX(-50%) translateY(0);
}

.online-indicator::before {
  content: '✓';
  font-size: 1rem;
  font-weight: 900;
}

/* Offline mode styling */
body.offline {
  position: relative;
}

body.offline::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: repeating-linear-gradient(
    90deg,
    var(--neon-red) 0px,
    var(--neon-red) 10px,
    transparent 10px,
    transparent 20px
  );
  z-index: 999;
  animation: offline-stripe 1s linear infinite;
}

@keyframes offline-stripe {
  0% { background-position: 0 0; }
  100% { background-position: 20px 0; }
}

/* ── 6. ENHANCED MOBILE TOUCH INTERACTIONS ──────────────────────────────── */

/* Disable text selection on interactive elements */
.btn,
.tab-btn,
.kana-card,
.vocab-card,
.kanji-card,
.module-card,
.filter-chip,
.srs-btn {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Active state feedback for better touch response */
.btn:active,
.tab-btn:active,
.kana-card:active,
.vocab-card:active,
.kanji-card:active,
.module-card:active {
  transform: scale(0.98);
  transition: transform 0.1s;
}

/* Prevent double-tap zoom on specific elements */
.kana-char,
.vocab-jp,
.k-char,
button,
a {
  touch-action: manipulation;
}

/* ── MOBILE-SPECIFIC FONT SIZE IMPROVEMENTS ─────────────────────────────── */
@media (max-width: 767px) {
  /* Ensure minimum readable text size */
  p,
  .text-base,
  .module-card p {
    font-size: max(0.9rem, 14px);
  }
  
  /* Larger Japanese characters for better readability */
  .kana-char {
    font-size: 2.2rem;
  }
  
  .vocab-jp {
    font-size: 1.3rem;
  }
  
  .k-char {
    font-size: 2.5rem;
  }
  
  .sc-jp,
  .fill-jp {
    font-size: 1.2rem;
    line-height: 1.8;
  }
}

/* ── USER MENU / SEARCH BUTTON LAYOUT ──────────────────────────────────── */
/*
  Desktop header order (left → right):
    [Logo]  [Nav links — flex:1]  [🔍 Search btn]  [👤 Profile btn]
  Mobile header order (left → right):
    [Logo]  [🔍 Search btn]  [👤 Profile btn]  [☰ Hamburger]
*/

/* Search button injected by auth-header.js */
#nihon-search-btn {
  flex-shrink: 0;
  order: 10; /* after logo + nav */
}

/* User menu injected by auth-header.js */
#nihon-user-menu {
  flex-shrink: 0;
  order: 11; /* after search btn */
  position: relative;
  z-index: 250;
}

#nihon-avatar-btn {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Desktop: nav(flex:1) | search | profile */
@media (min-width: 768px) {
  .header-inner {
    justify-content: flex-start;
  }
  nav {
    flex: 1;
    order: 1;
  }
  #nihon-search-btn {
    order: 10;
  }
  #nihon-user-menu {
    order: 11;
  }
  .mobile-menu-btn {
    display: none;
  }
}

/* Mobile: [nav spacer] | search | profile | hamburger */
@media (max-width: 767px) {
  .header-inner {
    justify-content: flex-start;
    gap: 8px;
  }
  #nihon-search-btn {
    order: 10;
    margin-left: auto;
  }
  #nihon-user-menu {
    order: 11;
  }
  .mobile-menu-btn {
    order: 12;
    margin-left: 0;
  }
}

/* ── IMPROVED LANDSCAPE MODE ────────────────────────────────────────────── */
@media (max-width: 767px) and (orientation: landscape) {
  /* More compact header */
  .header-inner {
    padding: 8px 16px;
  }
  
  nav a {
    padding: 5px 12px;
    font-size: 0.78rem;
  }
  
  /* Reduce vertical spacing */
  .container {
    padding: 16px 16px 40px;
  }
  
  .page-hero {
    margin-bottom: 16px;
  }
  
  /* More compact grids */
  .module-grid {
    gap: 10px;
  }
  
  .kana-grid,
  .vocab-grid,
  .kanji-grid {
    gap: 6px;
  }
  
  /* Full-screen modals */
  .stroke-modal-overlay.open .stroke-modal,
  .stroke-modal {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    padding: 16px !important;
    box-sizing: border-box !important;
  }
  .modal-sheet {
    width: 100% !important;
    max-width: 100% !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0 !important;
    box-sizing: border-box !important;
  }
}