@import url('https://fonts.googleapis.com/css2?family=DotGothic16&family=Press+Start+2P&family=VT323&family=Noto+Sans+JP:wght@400;700&display=swap');

:root {
  --bg: #1a1a2e;
  --bg2: #16213e;
  --bg3: #0f3460;
  --card: #1e2a4a;
  --card-hover: #253563;
  --primary: #d4637b;
  --primary-glow: #e8899c;
  --accent: #ffd93d;
  --accent2: #6bcb77;
  --text: #eaf0f6;
  --text2: #a4b0be;
  --pixel-border: #533483;
  --shadow: 0 4px 20px rgba(0,0,0,.4);
  --pixel-shadow: 4px 4px 0 #0d0d1a;
  --radius: 4px;
}

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

html {
  scroll-behavior: smooth; font-size: 16px;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}

body {
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/*
 * VT323: pixel font that supports Vietnamese diacritics
 * Press Start 2P: pixel font for short EN-only labels (LV, XP, etc.)
 * DotGothic16: pixel font for Japanese text
 */
.pixel-font { font-family: 'VT323', 'DotGothic16', monospace; }
.pixel-font-en { font-family: 'Press Start 2P', monospace; }
.jp-font { font-family: 'DotGothic16', 'Noto Sans JP', sans-serif; }

/* ===== Pixel Border Utility ===== */
.pixel-border {
  border: 3px solid var(--pixel-border);
  box-shadow: var(--pixel-shadow);
  image-rendering: pixelated;
}

/* ===== Hide Scrollbar (still scrollable) ===== */
::-webkit-scrollbar { display: none; }

/* ===== Stars Background ===== */
.stars {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(ellipse at 20% 50%, rgba(15,52,96,.3) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 20%, rgba(83,52,131,.2) 0%, transparent 50%);
}
.star-particle {
  position: absolute; width: 2px; height: 2px; background: #fff; border-radius: 50%;
  animation: twinkle var(--dur) ease-in-out infinite alternate;
}
@keyframes twinkle { 0% { opacity: .2; } 100% { opacity: 1; } }

/* ===== Header ===== */
.header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(26,26,46,.92); backdrop-filter: blur(12px);
  border-bottom: 3px solid var(--pixel-border);
  padding: .75rem 1rem;
}
.header-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.logo {
  display: flex; align-items: center; gap: .5rem;
  text-decoration: none; color: var(--text);
}
.logo-icon { font-size: 1.8rem; image-rendering: pixelated; }
.logo-text { font-size: 1rem; letter-spacing: 2px; line-height: 1.3; }
.logo-text span { color: var(--primary); }

/* Nav */
.nav { display: flex; gap: .35rem; }
.nav-btn {
  font-family: 'VT323', monospace;
  font-size: 1.1rem; padding: .5rem .9rem;
  background: transparent; border: 2px solid transparent;
  color: var(--text2); cursor: pointer;
  transition: all .15s;
  position: relative; letter-spacing: 1px;
}
.nav-btn:hover, .nav-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(255,217,61,.08);
}
.nav-btn.active::after {
  content: ""; position: absolute; bottom: -3px; left: 20%; right: 20%;
  height: 3px; background: var(--accent);
}

/* Profile Button */
.profile-btn {
  display: flex; align-items: center; gap: .4rem;
  background: var(--card); border: 2px solid var(--pixel-border);
  color: var(--text); cursor: pointer; padding: .35rem .75rem;
  font-size: .95rem; transition: all .15s;
  box-shadow: 2px 2px 0 rgba(0,0,0,.3);
}
.profile-btn:hover { border-color: var(--accent); color: var(--accent); }
.profile-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: var(--primary); color: var(--bg); font-weight: 700;
  font-size: .85rem;
}

/* Profile Modal */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.7); backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; animation: fadeIn .2s ease; }
.modal-box {
  background: var(--bg2); border: 3px solid var(--pixel-border);
  box-shadow: 8px 8px 0 rgba(0,0,0,.5);
  width: 90%; max-width: 420px; max-height: 80vh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 2px solid var(--pixel-border);
}
.modal-close {
  background: none; border: none; color: var(--text2);
  font-size: 1.3rem; cursor: pointer; padding: .25rem;
}
.modal-close:hover { color: var(--primary); }

/* Profile List */
.profile-list { padding: .5rem; }
.profile-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .75rem 1rem; cursor: pointer;
  border: 2px solid transparent; transition: all .15s; margin-bottom: .25rem;
}
.profile-item:hover { border-color: var(--primary); background: rgba(233,69,96,.05); }
.profile-item.active { border-color: var(--accent); background: rgba(255,217,61,.08); }
.profile-avatar-lg {
  display: flex; align-items: center; justify-content: center;
  width: 2.5rem; height: 2.5rem; border-radius: 50%; flex-shrink: 0;
  background: var(--primary); color: var(--bg); font-weight: 700;
  font-size: 1.2rem;
}
.profile-item.active .profile-avatar-lg { background: var(--accent); }
.profile-info { flex: 1; min-width: 0; }
.profile-name { font-weight: 700; font-size: 1.1rem; }
.profile-stats { font-size: .85rem; color: var(--text2); margin-top: .15rem; }
.profile-del {
  background: none; border: none; color: var(--text2);
  font-size: 1rem; cursor: pointer; padding: .25rem .5rem;
  opacity: .5; transition: all .15s;
}
.profile-del:hover { color: var(--primary); opacity: 1; }

/* Profile Create */
.profile-create {
  display: flex; gap: .5rem; padding: .75rem 1rem;
  border-top: 2px solid var(--pixel-border);
}
.profile-input {
  flex: 1; padding: .6rem .75rem;
  background: var(--card); border: 2px solid var(--pixel-border);
  color: var(--text); font-size: 1rem;
  font-family: 'VT323', sans-serif; outline: none;
}
.profile-input:focus { border-color: var(--primary); }
.profile-input::placeholder { color: var(--text2); }
.profile-create-btn {
  padding: .6rem 1rem; background: var(--accent2);
  border: 2px solid var(--accent2); color: var(--bg);
  cursor: pointer; font-size: 1rem; white-space: nowrap;
  transition: all .15s;
}
.profile-create-btn:hover { background: transparent; color: var(--accent2); }

/* XP Bar */
.xp-bar-wrap {
  display: flex; align-items: center; gap: .5rem;
  font-size: 1rem;
}
.xp-bar {
  width: 90px; height: 12px;
  background: var(--bg); border: 2px solid var(--pixel-border);
  overflow: hidden;
}
.xp-fill {
  height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent));
  transition: width .5s ease;
}
.xp-text { color: var(--accent); white-space: nowrap; }

/* ===== Page Sections ===== */
.page { display: none; padding: 1.5rem 1rem 6rem; max-width: 1200px; margin: 0 auto; position: relative; z-index: 1; }
.page.active { display: block; animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Section Title ===== */
.section-title {
  font-size: 1.4rem; margin-bottom: 1.5rem;
  display: flex; align-items: center; gap: .75rem;
}
.section-title::before {
  content: "▸"; color: var(--primary); font-size: 1.2rem;
}

/* ===== KANA PAGE ===== */
.kana-tabs { display: flex; gap: .5rem; margin-bottom: 1rem; justify-content: center; }
.kana-tab {
  font-family: 'VT323', monospace; font-size: 1.15rem;
  padding: .6rem 1.5rem; cursor: pointer;
  background: var(--card); border: 2px solid var(--pixel-border);
  color: var(--text2); transition: all .15s;
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
}
.kana-tab:hover { border-color: var(--primary); color: var(--primary); }
.kana-tab.active { border-color: var(--accent); color: var(--accent); background: rgba(255,217,61,.1); }

.kana-toggle {
  margin-bottom: 1rem; font-size: .95rem; color: var(--text2);
  text-align: center;
}
.kana-check { cursor: pointer; display: flex; align-items: center; gap: .4rem; }
.kana-check input { accent-color: var(--accent); width: 1rem; height: 1rem; }

/* Desktop: classic grid layout */
.kana-grid.kana-desktop {
  display: grid;
  gap: .4rem;
  margin: 0 auto;
  justify-content: center;
}
.kana-col-header {
  text-align: center; font-size: .8rem; color: var(--text2);
  padding: .2rem 0;
}
.kana-cell {
  aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--card); border: 2px solid var(--pixel-border);
  cursor: pointer; transition: all .2s;
  box-shadow: 2px 2px 0 rgba(0,0,0,.3);
}
.kana-cell:hover {
  border-color: var(--primary); transform: translate(-1px,-1px);
  box-shadow: 3px 3px 0 rgba(0,0,0,.4);
}
.kana-cell.kana-empty { background: transparent; border-color: transparent; box-shadow: none; cursor: default; }
.kana-cell.kana-empty:hover { transform: none; }
.kana-extra { display: flex; gap: .4rem; justify-content: center; padding-top: .3rem; }
.kana-extra .kana-cell { width: 4rem; aspect-ratio: 1; }
.kana-char { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.kana-romaji { font-size: .7rem; color: var(--accent); margin-top: .1rem; }

/* Mobile: row-group layout */
.kana-grid.kana-mobile {
  display: flex; flex-direction: column; gap: .6rem;
  max-width: 400px; margin: 0 auto;
}
.kana-row-group {
  display: flex; align-items: center; gap: .5rem;
}
.kana-row-header {
  flex-shrink: 0; width: 2.8rem;
  font-size: .8rem; color: var(--accent); text-align: center;
  padding: .3rem 0;
  background: rgba(255,217,61,.06); border: 1px solid rgba(255,217,61,.15);
}
.kana-row-cells {
  flex: 1; display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .3rem;
}
.kana-mobile .kana-cell {
  aspect-ratio: 1;
  padding: .2rem;
}
.kana-mobile .kana-char { font-size: 1.3rem; }
.kana-mobile .kana-romaji { font-size: .6rem; }

/* Kana detail card */
.kana-card-content { max-width: 400px; margin: 0 auto; }
.kc-nav {
  display: flex; align-items: center; justify-content: center;
  gap: 1rem; margin-bottom: 1rem;
}
.kc-nav .nav-arrow:disabled { opacity: .3; cursor: default; }
.kc-counter { font-size: 1rem; color: var(--text2); }
.kc-main {
  text-align: center; padding: 2rem;
  background: var(--card); border: 2px solid var(--pixel-border);
  box-shadow: 4px 4px 0 rgba(0,0,0,.4); margin-bottom: 1rem;
}
.kc-char { font-size: 6rem; line-height: 1.1; }
.kc-romaji { font-size: 1.5rem; color: var(--accent); margin: .5rem 0; }
.kc-speak {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1rem; background: transparent;
  border: 2px solid var(--accent); color: var(--accent);
  cursor: pointer; font-size: 1rem; font-family: 'VT323', monospace;
  transition: all .15s;
}
.kc-speak:hover { background: var(--accent); color: var(--bg); }
.kc-speak svg { width: 18px; height: 18px; }

.kc-info {
  display: flex; gap: .75rem;
}
.kc-pair, .kc-stroke {
  flex: 1; text-align: center; padding: 1rem;
  background: var(--card); border: 2px solid var(--pixel-border);
}
.kc-label { font-size: .9rem; color: var(--text2); display: block; margin-bottom: .3rem; }
.kc-pair-char { font-size: 2.5rem; }
.kc-romaji-big { font-size: 2rem; color: var(--accent); }

@media (max-width: 768px) {
  .kc-char { font-size: 4rem; }
  .kc-main { padding: 1.5rem 1rem; }
  .kc-info { gap: .5rem; }
  .kc-pair-char { font-size: 2rem; }
  .kc-romaji-big { font-size: 1.5rem; }
  .kana-card-content { max-width: 100%; }
}
@media (max-width: 500px) {
  .kana-mobile .kana-char { font-size: 1.15rem; }
  .kana-mobile .kana-romaji { font-size: .55rem; }
  .kana-row-header { width: 2.4rem; font-size: .7rem; }
  .kana-row-cells { gap: .2rem; }
  .kc-char { font-size: 3.5rem; }
  .kc-romaji { font-size: 1.2rem; }
  .kc-speak { font-size: .9rem; padding: .4rem .8rem; }
  .kc-pair, .kc-stroke { padding: .7rem .5rem; }
  .kc-pair-char { font-size: 1.8rem; }
  .kc-label { font-size: .8rem; }
  .kana-tabs { gap: .3rem; }
  .kana-tab { font-size: .9rem; padding: .45rem .8rem; }
}
@media (max-width: 375px) {
  .kana-mobile .kana-char { font-size: 1rem; }
  .kana-mobile .kana-romaji { font-size: .45rem; }
  .kana-row-header { width: 2rem; font-size: .6rem; }
  .kc-char { font-size: 3rem; }
}

/* ===== VOCAB PAGE ===== */

/* Category Grid */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: .75rem; margin-bottom: 2rem;
}
.cat-card {
  background: var(--card); border: 2px solid transparent;
  padding: .75rem; cursor: pointer;
  transition: all .2s; text-align: center;
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
}
.cat-card:hover {
  border-color: var(--primary);
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 rgba(0,0,0,.4);
}
.cat-card.active {
  border-color: var(--accent);
  background: rgba(255,217,61,.08);
}
.cat-icon { font-size: 1.8rem; margin-bottom: .25rem; }
.cat-name { font-size: 1rem; color: var(--text2); }
.cat-count { font-size: 1.1rem; color: var(--text); font-weight: 700; margin-top: .15rem; }

/* Search */
.search-wrap {
  position: relative; margin-bottom: 1.5rem;
}
.search-input {
  width: 100%; padding: .85rem 1rem .85rem 2.5rem;
  background: var(--card); border: 2px solid var(--pixel-border);
  color: var(--text); font-size: 1.1rem;
  font-family: 'VT323', 'Noto Sans JP', sans-serif;
  outline: none; transition: border-color .2s;
}
.search-input::placeholder { color: var(--text2); }
.search-input:focus { border-color: var(--primary); }
.search-icon {
  position: absolute; left: .75rem; top: 50%; transform: translateY(-50%);
  color: var(--text2); font-size: 1.1rem;
}

/* Vocab List */
.vocab-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .75rem; }

.vocab-card {
  background: var(--card); border: 2px solid var(--pixel-border);
  padding: 1rem; cursor: pointer;
  transition: all .2s; display: flex; gap: .75rem; align-items: center;
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
}
.vocab-card:hover {
  border-color: var(--primary);
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 rgba(0,0,0,.4);
}
.vocab-card.learned { border-left: 4px solid var(--accent2); }
.vocab-pixel { flex-shrink: 0; width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; }
.vocab-pixel canvas { width: 52px; height: 52px; image-rendering: pixelated; }
.vocab-info { flex: 1; min-width: 0; }
.vocab-jp { font-size: 1.5rem; font-weight: 700; line-height: 1.3; }
.vocab-hi { font-size: .9rem; color: var(--text2); margin-top: .15rem; }
.vocab-meaning { font-size: 1rem; color: var(--accent); margin-top: .3rem; }
.vocab-cat-tag {
  display: inline-block; font-size: .85rem; padding: .1rem .5rem;
  background: rgba(255,255,255,.06); color: var(--text2);
  margin-top: .35rem;
}
/* Speak button — pixel speaker icon */
.speak-btn {
  position: absolute; top: .5rem; right: .5rem;
  background: none; border: none; cursor: pointer;
  opacity: .5; transition: all .15s;
  padding: .2rem; z-index: 2;
  width: 24px; height: 24px;
  color: var(--accent);
}
.speak-btn:hover { opacity: 1; transform: scale(1.15); color: var(--primary); }
.speak-btn:active { transform: scale(.9); }
.speak-btn.speaking { opacity: 1; animation: speakPulse .6s ease infinite; }
@keyframes speakPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2); } }
.speak-btn svg { width: 100%; height: 100%; }
.fc-speak {
  top: .75rem; left: .75rem; right: auto;
  width: 32px; height: 32px; opacity: .5;
}

.vocab-lesson {
  position: absolute; bottom: .4rem; right: .5rem;
  font-size: .75rem; color: var(--text2); opacity: .5;
}
.vocab-card { position: relative; }

/* ===== FLASHCARD PAGE ===== */
.flashcard-area { display: flex; flex-direction: column; align-items: center; gap: 1.5rem; }

.flashcard-controls {
  display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center;
}
.fc-btn {
  font-family: 'VT323', monospace;
  font-size: 1.05rem; padding: .5rem 1rem;
  background: var(--card); border: 2px solid var(--pixel-border);
  color: var(--text); cursor: pointer;
  transition: all .15s;
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
}
.fc-btn:hover { border-color: var(--primary); color: var(--primary); transform: translate(-1px,-1px); }
.fc-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(255,217,61,.08); }

.flashcard-container {
  perspective: 1000px; width: 100%; max-width: 380px;
}
.flashcard {
  width: 100%; aspect-ratio: 3/4; position: relative;
  cursor: pointer; transform-style: preserve-3d;
  transition: transform .5s ease;
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute; inset: 0;
  backface-visibility: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 2rem; text-align: center;
  background: var(--card); border: 3px solid var(--pixel-border);
  box-shadow: 6px 6px 0 rgba(0,0,0,.4);
}
.flashcard-back { transform: rotateY(180deg); }

.fc-pixel { margin-bottom: 1rem; }
.fc-pixel canvas { width: 80px; height: 80px; image-rendering: pixelated; }
.fc-jp { font-size: 2.8rem; font-weight: 700; margin-bottom: .5rem; }
.fc-hi { font-size: 1.2rem; color: var(--text2); }
.fc-meaning { font-size: 1.5rem; color: var(--accent); margin-bottom: .5rem; }
.fc-example { font-size: 1rem; color: var(--text2); line-height: 1.6; }
.fc-number {
  font-size: 1rem; color: var(--text2);
  position: absolute; top: .75rem; right: .75rem;
}
.fc-flip-hint { font-size: 1rem; color: var(--text2); margin-top: 1rem; }

.flashcard-nav {
  display: flex; gap: 1rem; align-items: center;
}
.nav-arrow {
  width: 52px; height: 52px; display: flex; align-items: center; justify-content: center;
  background: var(--card); border: 2px solid var(--pixel-border);
  color: var(--text); cursor: pointer; font-size: 1.4rem;
  transition: all .15s;
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
}
.nav-arrow:hover { border-color: var(--primary); color: var(--primary); }
.nav-arrow:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 rgba(0,0,0,.3); }

.mark-btn {
  font-family: 'VT323', monospace; font-size: 1.1rem;
  padding: .6rem 1.2rem; cursor: pointer;
  border: 2px solid var(--accent2); background: transparent;
  color: var(--accent2); transition: all .15s;
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
  letter-spacing: 1px;
}
.mark-btn:hover { background: var(--accent2); color: var(--bg); }
.mark-btn.learned { background: var(--accent2); color: var(--bg); }

/* Progress ring */
.progress-wrap { text-align: center; margin-top: .5rem; }
.progress-text { font-size: 1rem; color: var(--text2); margin-top: .25rem; }

/* ===== GRAMMAR PAGE ===== */

/* Legend */
.grammar-legend {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: .4rem .75rem; margin-bottom: 1rem; font-size: .95rem;
  max-width: 100%; overflow: hidden;
}
.gl-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .3rem .7rem;
  background: rgba(255,255,255,.04); color: var(--text2);
  border: 1px solid rgba(255,255,255,.08);
  white-space: nowrap; overflow: hidden;
}
.gl-key {
  color: var(--accent); font-weight: 700;
  min-width: 3.5rem; text-align: center;
}
@media (max-width: 768px) {
  .grammar-legend { grid-template-columns: repeat(2, 1fr); }
  .gl-item { white-space: normal; font-size: .85rem; }
  .grammar-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
  .gc-icon { font-size: 1.8rem; margin-bottom: .3rem; }
  .gc-num { font-size: 1.1rem; }
  .gc-subtitle { font-size: .85rem; }
  .grammar-point { flex-direction: column; gap: .5rem; padding: .8rem; }
  .gp-num { width: 1.8rem; height: 1.8rem; font-size: .9rem; }
  .gp-pattern { font-size: 1.1rem; }
  .gp-example { font-size: .95rem; padding: .6rem .8rem; line-height: 1.7; }
  .gp-example .jp-line { font-size: 1.05rem; }
  .gd-bubble { font-size: .95rem; }
  .grammar-detail-header { flex-wrap: wrap; }
  .gd-title { font-size: 1.05rem; }
}
@media (max-width: 480px) {
  .grammar-legend { grid-template-columns: 1fr 1fr; gap: .3rem; font-size: .85rem; }
  .gl-item { padding: .2rem .4rem; gap: .3rem; }
  .gl-key { min-width: 2.5rem; font-size: .85rem; }
  .grammar-tabs { gap: .3rem; }
  .grammar-tab { font-size: 1rem; padding: .5rem .8rem; }
  .grammar-card { padding: .8rem .6rem; }
  .grammar-back { font-size: .95rem; padding: .4rem .8rem; margin-bottom: 1rem; }
  .gd-dialogue { padding: .7rem; }
  .gd-line { gap: .4rem; }
  .gd-speaker { width: 1.6rem; height: 1.6rem; font-size: .75rem; }
  .gd-bubble { padding: .4rem .6rem; font-size: .9rem; line-height: 1.6; }
  .gd-vi { font-size: .8rem; }
  .gp-pattern-vi { font-size: .85rem; }
  .gd-summary { font-size: .85rem; padding: .4rem .6rem; }
  .gd-summary-item { flex-direction: column; gap: .1rem; padding: .35rem .4rem; }
  .gd-summary-label { min-width: auto; }
  .grammar-detail-body { max-width: 100%; }
  .grammar-detail-header { margin-bottom: 1rem; }
  .gp-meaning { font-size: .95rem; }
  .gp-example .vi-line { font-size: .85rem; }
  .speak-btn.gp-speak { width: 20px; height: 20px; }
}

/* Tab buttons */
.grammar-tabs {
  display: flex; gap: .5rem; margin-bottom: 1.5rem;
}
.grammar-tab {
  font-family: 'VT323', monospace; font-size: 1.15rem;
  padding: .6rem 1.5rem; cursor: pointer;
  background: var(--card); border: 2px solid var(--pixel-border);
  color: var(--text2); transition: all .15s;
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
}
.grammar-tab:hover { border-color: var(--primary); color: var(--primary); }
.grammar-tab.active {
  border-color: var(--accent); color: var(--accent);
  background: rgba(255,217,61,.1);
}
.grammar-tab-content { display: none; }
.grammar-tab-content.active { display: block; animation: fadeIn .3s ease; }

/* Lesson grid — visual cards */
.grammar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .85rem;
}
.grammar-card {
  background: linear-gradient(135deg, var(--card) 0%, rgba(83,52,131,.15) 100%);
  border: 2px solid var(--pixel-border);
  padding: 1.25rem 1rem; cursor: pointer;
  text-align: center; transition: all .2s;
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
  position: relative; overflow: hidden;
}
.grammar-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}
.grammar-card:hover {
  border-color: var(--primary);
  transform: translate(-2px, -2px);
  box-shadow: 5px 5px 0 rgba(0,0,0,.4);
}
.gc-icon { font-size: 2.2rem; margin-bottom: .5rem; }
.gc-num { font-size: 1.3rem; color: var(--primary); margin-bottom: .35rem; }
.gc-subtitle { font-size: .95rem; color: var(--text); line-height: 1.4; margin-bottom: .5rem; }
.gc-count { font-size: .85rem; color: var(--accent); opacity: .7; }

/* Grammar detail page */
.grammar-back {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: 1.1rem; padding: .5rem 1rem;
  background: var(--card); border: 2px solid var(--pixel-border);
  color: var(--text2); cursor: pointer;
  transition: all .15s; margin-bottom: 1.5rem;
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
}
.grammar-back:hover { border-color: var(--primary); color: var(--primary); }
.grammar-detail-header {
  display: flex; align-items: center; gap: .75rem;
  margin-bottom: 1.5rem;
}
.gd-icon { font-size: 1.5rem; }
.gd-title { font-size: 1.2rem; color: var(--primary); }
.gd-subtitle { font-size: 1rem; color: var(--text2); }
.gd-title::after { content: " — "; color: var(--text2); }
.grammar-detail-body { max-width: 700px; margin: 0 auto; }

.grammar-point {
  display: flex; gap: .85rem; margin-bottom: 1rem;
  padding: 1rem 1.1rem;
  background: var(--card); border: 2px solid var(--pixel-border);
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
  transition: border-color .2s;
}
.grammar-point:hover { border-color: rgba(212,99,123,.3); }
.gp-num {
  flex-shrink: 0; width: 2.2rem; height: 2.2rem;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: var(--bg); font-size: 1.1rem; font-weight: 700;
}
.gp-content { flex: 1; min-width: 0; }
.gp-pattern {
  font-size: 1.3rem; font-weight: 700;
  color: var(--accent); margin-bottom: .35rem;
  font-family: 'VT323', monospace;
}
.gp-meaning { font-size: 1.05rem; color: var(--text); margin-bottom: .65rem; }
.gp-example {
  font-size: 1.05rem; line-height: 1.9;
  padding: .75rem 1rem; background: rgba(0,0,0,.3);
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
  position: relative;
}
.gp-example .jp-line { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.gp-example .vi-line { color: var(--accent); font-size: .95rem; margin-top: .3rem; }
/* Furigana */
ruby { ruby-align: center; }
ruby rt {
  font-size: .55em; color: var(--text2);
  font-family: 'Noto Sans JP', sans-serif;
  font-weight: 400; letter-spacing: .5px;
}
.gp-example ruby rt { font-size: .5em; }

/* Pattern Vietnamese explanation */
.gp-pattern-vi {
  font-size: .95rem; color: var(--text2); margin-bottom: .5rem;
  padding: .3rem .6rem; background: rgba(255,217,61,.06);
  border-left: 2px solid var(--accent); font-style: italic;
}

/* Summary conjugation table */
.gd-summary {
  padding: .8rem 1rem; margin-bottom: 1.25rem;
  background: var(--card); border: 2px solid var(--pixel-border);
  font-size: .95rem; color: var(--text);
  font-family: 'VT323', monospace;
  display: flex; flex-direction: column; gap: 0;
}
.gd-summary-item {
  padding: .4rem .6rem; line-height: 1.6;
  border-bottom: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: baseline; gap: .5rem;
}
.gd-summary-item:last-child { border-bottom: none; }
.gd-summary-label {
  flex-shrink: 0; color: var(--accent); font-weight: 700;
  min-width: 5rem;
}
.gd-summary-content { color: var(--text); }
.gd-summary-content .jp-hl { color: var(--primary); font-weight: 700; }
.gd-summary-arrow { color: var(--text2); margin: 0 .2rem; }

/* Dialogue */
.gd-dialogue {
  margin-top: 1.5rem; padding: 1rem;
  background: rgba(255,255,255,.02);
  border: 2px solid var(--pixel-border);
}
.gd-dialogue-title { font-size: 1.1rem; color: var(--accent); margin-bottom: .75rem; }
.gd-line { display: flex; gap: .6rem; margin-bottom: .6rem; align-items: flex-start; }
.gd-speaker {
  flex-shrink: 0; width: 2rem; height: 2rem;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: var(--bg); font-size: .9rem;
  border-radius: 50%;
}
.gd-line:nth-child(odd) .gd-speaker { background: var(--accent); }
.gd-bubble {
  flex: 1; padding: .5rem .75rem;
  background: rgba(0,0,0,.2); border-radius: 0 8px 8px 8px;
  font-size: 1.05rem; line-height: 1.7;
}
.gd-vi { font-size: .85rem; color: var(--text2); margin-top: .15rem; }

.gp-tip {
  margin-top: .6rem; padding: .6rem .85rem;
  background: rgba(255,217,61,.08);
  border-left: 3px solid var(--accent);
  border-radius: 0 4px 4px 0;
  font-size: .95rem; color: var(--accent); line-height: 1.6;
}
.gp-example + .gp-example { margin-top: .4rem; }
.gp-highlight {
  color: var(--primary); font-weight: 700;
  background: rgba(212,99,123,.15); padding: .1rem .25rem;
  border-bottom: 2px solid var(--primary);
}
.gp-speak {
  position: absolute; top: .4rem; right: .4rem;
  width: 22px; height: 22px;
}

/* Particle grid */
.particle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: .85rem;
}
.particle-card {
  background: var(--card); border: 2px solid var(--pixel-border);
  padding: 1rem; box-shadow: 3px 3px 0 rgba(0,0,0,.3);
  transition: all .2s;
}
.particle-card:hover {
  border-color: var(--accent);
  transform: translate(-1px, -1px);
}
.particle-symbol {
  font-size: 2.5rem; font-weight: 700; color: var(--primary);
  display: inline-block; margin-right: .5rem;
  text-shadow: 0 0 12px rgba(233,69,96,.3);
}
.particle-func { font-size: 1.05rem; color: var(--accent); font-weight: 700; }
.particle-ex { font-size: 1rem; color: var(--text2); margin-top: .5rem; line-height: 1.7; }

@media (max-width: 768px) {
  .grammar-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .gc-icon { font-size: 1.8rem; }
  .gc-num { font-size: 1.1rem; }
  .gc-subtitle { font-size: .85rem; }
  .grammar-modal-box { max-width: 95%; }
  .particle-grid { grid-template-columns: 1fr; }
}

/* ===== QUIZ PAGE ===== */
.quiz-area { max-width: 600px; margin: 0 auto; text-align: center; }

/* Quiz mode selection */
.quiz-mode-select {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 1rem; margin-bottom: 1.5rem;
}
.quiz-mode-card {
  background: var(--card); border: 2px solid var(--pixel-border);
  padding: 2rem 1rem; cursor: pointer; text-align: center;
  transition: all .2s;
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
}
.quiz-mode-card:hover {
  border-color: var(--primary); transform: translate(-2px,-2px);
  box-shadow: 5px 5px 0 rgba(0,0,0,.4);
}
.qm-icon { font-size: 2.5rem; margin-bottom: .5rem; }
.qm-title { font-size: 1.2rem; color: var(--accent); margin-bottom: .35rem; }
.qm-desc { font-size: .9rem; color: var(--text2); line-height: 1.4; }
@media (max-width: 500px) {
  .quiz-mode-select { grid-template-columns: 1fr; max-width: 300px; margin: 0 auto 1.5rem; }
  .quiz-mode-card { padding: 1.2rem .8rem; }
  .qm-icon { font-size: 2rem; }
  .qm-title { font-size: 1.05rem; }
  .qm-desc { font-size: .8rem; }
  .quiz-card { padding: 1.2rem; }
  .quiz-question { font-size: 2rem; }
  .quiz-hint { font-size: .95rem; margin-bottom: 1rem; }
  .quiz-opt { padding: .75rem 1rem; font-size: 1.05rem; }
  .score-num { font-size: 1.4rem; }
  .score-label { font-size: .85rem; }
  .result-score { font-size: 2.5rem; }
  .result-stars { font-size: 2rem; }
}

.quiz-setup {
  display: flex; flex-direction: column; gap: 1rem; align-items: center;
}
.quiz-type-grid { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }

.quiz-card {
  background: var(--card); border: 3px solid var(--pixel-border);
  padding: 2rem; box-shadow: 6px 6px 0 rgba(0,0,0,.4);
}
.quiz-question { font-size: 2.5rem; font-weight: 700; margin-bottom: .5rem; position: relative; display: inline-block; }
.quiz-speak {
  position: relative; display: inline-block; vertical-align: middle;
  margin-left: .5rem; width: 28px; height: 28px;
  opacity: .6; top: -2px;
}
.quiz-speak:hover { opacity: 1; }
.quiz-hint { font-size: 1.1rem; color: var(--text2); margin-bottom: 1.5rem; }
.quiz-options { display: flex; flex-direction: column; gap: .5rem; }
.quiz-opt {
  padding: 1rem 1.25rem; background: rgba(255,255,255,.04);
  border: 2px solid var(--pixel-border); cursor: pointer;
  text-align: left; font-size: 1.2rem;
  color: var(--text); transition: all .15s;
  font-family: 'VT323', 'Noto Sans JP', sans-serif;
}
.quiz-opt:hover { border-color: var(--primary); background: rgba(233,69,96,.08); }
.quiz-opt.correct { border-color: var(--accent2); background: rgba(107,203,119,.15); color: var(--accent2); }
.quiz-opt.wrong { border-color: var(--primary); background: rgba(233,69,96,.15); color: var(--primary); }

.quiz-score {
  display: flex; gap: 2rem; justify-content: center; margin-bottom: 1rem;
}
.score-item { text-align: center; }
.score-num { font-size: 1.8rem; font-weight: 700; }
.score-label { font-size: 1rem; color: var(--text2); margin-top: .25rem; }
.score-correct .score-num { color: var(--accent2); }
.score-wrong .score-num { color: var(--primary); }

.quiz-progress {
  width: 100%; height: 8px; background: var(--bg);
  border: 1px solid var(--pixel-border); margin-bottom: 1rem;
}
.quiz-progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width .3s ease;
}

.quiz-result {
  padding: 2rem; text-align: center;
}
.result-score { font-size: 3.5rem; font-weight: 700; color: var(--accent); }
.result-text { font-size: 1.2rem; color: var(--text2); margin: .5rem 0 1.5rem; }
.result-stars { font-size: 2.5rem; margin: 1rem 0; letter-spacing: .5rem; }

/* ===== SCROLL TO TOP ===== */
.scroll-top {
  position: fixed; bottom: 3rem; right: 1rem; z-index: 199;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--card); border: 2px solid var(--pixel-border);
  color: var(--accent); font-size: 1.2rem; cursor: pointer;
  box-shadow: 3px 3px 0 rgba(0,0,0,.3);
  opacity: 0; pointer-events: none;
  transition: opacity .3s, transform .15s;
}
.scroll-top.show { opacity: .8; pointer-events: auto; }
.scroll-top:hover { opacity: 1; border-color: var(--accent); transform: translate(-1px,-1px); }
@media (max-width: 480px) {
  .scroll-top { width: 36px; height: 36px; bottom: 2.5rem; right: .5rem; font-size: 1rem; }
}

/* ===== SFX TOGGLE ===== */
.sfx-toggle {
  background: none; border: 1px solid var(--pixel-border);
  color: var(--text); cursor: pointer;
  padding: .3rem; transition: all .15s;
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
}
.sfx-toggle svg { width: 18px; height: 18px; }
.sfx-toggle:hover { border-color: var(--accent); color: var(--accent); }
@media (max-width: 500px) {
  .sfx-toggle { width: 26px; height: 26px; padding: .2rem; }
  .sfx-toggle svg { width: 14px; height: 14px; }
}

/* ===== STREAK ===== */
.streak-wrap {
  display: flex; align-items: center; gap: .2rem;
  padding: .2rem .6rem;
  background: rgba(255,100,0,.08); border: 1px solid rgba(255,150,0,.2);
  color: var(--accent); cursor: default;
}
.streak-icon { font-size: 1rem; }
.streak-num { font-size: 1.1rem; font-weight: 700; color: #ff9500; }
.streak-wrap.hot .streak-icon { animation: streakBurn .5s ease infinite; }
@keyframes streakBurn { 0%,100% { transform: scale(1); } 50% { transform: scale(1.2); } }

/* ===== CATEGORY PROGRESS ===== */
.cat-progress {
  width: 100%; height: 4px; background: rgba(255,255,255,.08);
  margin-top: .4rem; overflow: hidden;
}
.cat-progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent));
  transition: width .3s ease;
}
.cat-learned-text {
  font-size: .75rem; color: var(--text2); margin-top: .15rem;
}
.cat-card.cat-complete { border-color: var(--accent2); }
.cat-card.cat-complete .cat-icon::after { content: " ✓"; color: var(--accent2); font-size: .8rem; }

/* ===== BADGES ===== */
.badge-overlay {
  position: fixed; inset: 0; z-index: 700;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.8); backdrop-filter: blur(6px);
  opacity: 0; pointer-events: none;
  transition: opacity .3s ease;
}
.badge-overlay.show { opacity: 1; pointer-events: auto; }
.badge-popup {
  text-align: center; padding: 2rem 2.5rem;
  background: var(--bg2); border: 3px solid var(--accent);
  box-shadow: 0 0 50px rgba(255,217,61,.3), 6px 6px 0 rgba(0,0,0,.5);
  transform: scale(.5); transition: transform .4s cubic-bezier(.175,.885,.32,1.275);
}
.badge-overlay.show .badge-popup { transform: scale(1); }
.badge-popup-icon { font-size: 3.5rem; margin-bottom: .5rem; }
.badge-popup-title {
  font-size: 1rem; color: var(--accent); letter-spacing: 3px; margin-bottom: .3rem;
}
.badge-popup-name { font-size: 1.4rem; color: var(--text); margin-bottom: .3rem; }
.badge-popup-desc { font-size: 1rem; color: var(--text2); }

/* ===== QUIZ COMBO ===== */
.quiz-combo {
  position: fixed; top: 50%; right: 1.5rem; transform: translateY(-50%);
  z-index: 300; text-align: center;
  animation: comboIn .3s ease;
}
.combo-count {
  display: block; font-size: 2.5rem; font-weight: 700;
  color: var(--accent); text-shadow: 0 0 15px rgba(255,217,61,.5);
}
.combo-label {
  display: block; font-size: .8rem; color: var(--primary); letter-spacing: 2px;
}
@keyframes comboIn { from { transform: translateY(-50%) scale(1.5); opacity: 0; } to { transform: translateY(-50%) scale(1); opacity: 1; } }
.combo-shake { animation: comboShake .3s ease; }
@keyframes comboShake {
  0%,100% { transform: translateY(-50%) rotate(0); }
  25% { transform: translateY(-50%) rotate(-5deg) scale(1.1); }
  75% { transform: translateY(-50%) rotate(5deg) scale(1.1); }
}
@media (max-width: 500px) {
  .quiz-combo { right: .5rem; }
  .combo-count { font-size: 1.8rem; }
  .combo-label { font-size: .65rem; }
  .streak-wrap { padding: .15rem .4rem; }
  .streak-num { font-size: .95rem; }
}

/* ===== CREDIT BADGE ===== */
.credit-badge {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 200;
  display: flex; align-items: center; gap: .35rem;
  font-size: .75rem; color: var(--text2);
  padding: .4rem .85rem;
  background: rgba(26,26,46,.9); border: 1px solid var(--pixel-border);
  backdrop-filter: blur(8px);
  opacity: .7; transition: opacity .3s;
  text-decoration: none;
}
.credit-badge:hover { opacity: 1; }
.credit-badge svg { width: 14px; height: 14px; fill: var(--primary); }
.credit-badge strong { color: var(--text); font-weight: 700; }
.credit-tooltip {
  text-decoration: none; cursor: pointer; display: block;
  position: absolute; bottom: calc(100% + .4rem); left: 0; right: 0;
  padding: .4rem .8rem; text-align: center;
  background: var(--card); border: 2px solid var(--accent);
  color: var(--accent); font-size: .8rem; white-space: nowrap;
  box-shadow: 3px 3px 0 rgba(0,0,0,.4);
  opacity: 0; pointer-events: none;
  transform: translateY(4px);
  transition: opacity .2s, transform .2s;
}
.credit-tooltip::after {
  content: ""; position: absolute; bottom: -.5rem; left: 0; right: 0; height: .5rem;
}
.credit-tooltip:hover { color: var(--text); }
.credit-badge:hover .credit-tooltip {
  opacity: 1; pointer-events: auto; transform: translateY(0);
}

/* ===== Mobile hamburger ===== */
.menu-toggle { display: none; background: none; border: none; color: var(--text); font-size: 1.5rem; cursor: pointer; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header-inner { flex-wrap: wrap; }
  .nav { display: none; width: 100%; justify-content: center; }
  .nav.open { display: flex; flex-wrap: wrap; }
  .menu-toggle { display: block; }
  .xp-bar-wrap { font-size: .85rem; }
  .xp-bar { width: 70px; }
  .cat-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
  .vocab-list { grid-template-columns: 1fr; }
  .section-title { font-size: 1.2rem; }
  .fc-jp { font-size: 2.2rem; }
  .flashcard-container { max-width: 320px; }
  .particle-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .flashcard-container { max-width: 100%; }
  .flashcard-face { padding: 1.5rem 1rem; }
  .fc-jp { font-size: 2rem; }
  .credit-badge { bottom: .5rem; right: .5rem; font-size: .65rem; padding: .3rem .6rem; }
}
@media (max-width: 375px) {
  .nav-btn { font-size: .95rem; padding: .4rem .6rem; }
  .cat-grid { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
  .cat-card { padding: .5rem; }
  .cat-icon { font-size: 1.4rem; }
  .cat-name { font-size: .9rem; }
  .vocab-pixel { width: 40px; height: 40px; }
  .vocab-pixel canvas { width: 40px; height: 40px; }
  .vocab-jp { font-size: 1.3rem; }
  .vocab-hi { font-size: .8rem; }
}

/* ===== Animations ===== */
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: none; }
}
.bounce { animation: bounce .6s ease; }
.slide-up { opacity: 0; animation: slideUp .4s ease forwards; }

/* Confetti */
.confetti {
  position: fixed; top: -10px; z-index: 300; pointer-events: none;
  width: 8px; height: 8px; animation: confettiFall var(--fall) linear forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Level Up Overlay */
.levelup-overlay {
  position: fixed; inset: 0; z-index: 600;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.75); backdrop-filter: blur(6px);
  opacity: 0; transition: opacity .3s ease;
  cursor: pointer;
}
.levelup-overlay.show { opacity: 1; }
.levelup-box {
  text-align: center; padding: 2.5rem 3rem;
  background: var(--bg2); border: 4px solid var(--accent);
  box-shadow: 0 0 40px rgba(255,217,61,.3), 8px 8px 0 rgba(0,0,0,.5);
  transform: scale(.7); transition: transform .4s cubic-bezier(.175,.885,.32,1.275);
}
.levelup-overlay.show .levelup-box { transform: scale(1); }
.levelup-star {
  font-size: 3.5rem; margin-bottom: .5rem;
  animation: levelStar 1s ease infinite;
}
@keyframes levelStar {
  0%,100% { transform: scale(1) rotate(0); }
  25% { transform: scale(1.2) rotate(-10deg); }
  50% { transform: scale(1) rotate(0); }
  75% { transform: scale(1.2) rotate(10deg); }
}
.levelup-title {
  font-size: 1.8rem; color: var(--accent);
  text-shadow: 0 0 20px rgba(255,217,61,.5);
  letter-spacing: 4px; margin-bottom: .5rem;
}
.levelup-level {
  font-size: 3rem; color: var(--text);
  text-shadow: 0 0 15px rgba(255,255,255,.3);
  margin-bottom: .5rem;
}
.levelup-msg {
  font-size: 1rem; color: var(--text2);
}

/* Notification toast */
.toast {
  position: fixed; bottom: 4rem; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 2px solid var(--accent2);
  padding: .6rem 1.5rem; font-size: 1.1rem; color: var(--accent2);
  z-index: 400; box-shadow: 4px 4px 0 rgba(0,0,0,.3);
  animation: toastIn .3s ease, toastOut .3s ease 1.7s forwards;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(20px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(-50%) translateY(-10px); } }
