/* ── NH Vocab — style.css ──────────────────────────────────────────────────
   Aesthetic: clean scholastic — warm off-white, bold Japanese typography,
   card-based layout, smooth transitions. Dark mode via .dark on body.
─────────────────────────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --bg:          #f7f5f0;
  --bg2:         #ffffff;
  --surface:     #ffffff;
  --surface2:    #f0ede7;
  --border:      #e0dbd2;
  --text:        #1a1814;
  --text2:       #5a5650;
  --text3:       #9a9590;
  --accent:      #2563eb;
  --accent2:     #1d4ed8;
  --green:       #16a34a;
  --red:         #dc2626;
  --orange:      #ea580c;
  --shadow:      rgba(0,0,0,.08);
  --radius:      14px;
  --radius-sm:   8px;
  --font:        'Nunito', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
}

body.dark {
  --bg:          #12111a;
  --bg2:         #1a192a;
  --surface:     #1f1e30;
  --surface2:    #2a2840;
  --border:      #38364e;
  --text:        #f0eeff;
  --text2:       #a8a4c0;
  --text3:       #706c8a;
  --shadow:      rgba(0,0,0,.3);
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  touch-action: pan-y;
}

button { font-family: var(--font); cursor: pointer; border: none; background: none; }
input  { font-family: var(--font); }
a      { color: var(--accent); }

/* ── Screen system ────────────────────────────────────────────────────────── */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  opacity: 0; pointer-events: none;
  transform: translateY(12px);
  transition: opacity .22s ease, transform .22s ease;
  overflow: hidden;
}
.screen.active {
  opacity: 1; pointer-events: all; transform: none;
}

/* ── App header ───────────────────────────────────────────────────────────── */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1.5px solid var(--border);
  flex-shrink: 0;
}
.header-left  { display: flex; align-items: center; gap: 10px; }
.header-right { display: flex; align-items: center; gap: 8px; }
.app-logo  { font-size: 28px; }
.app-title { font-size: 18px; font-weight: 900; color: var(--text); line-height: 1.1; }
.app-sub   { font-size: 11px; color: var(--text3); font-weight: 600; }

.theme-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface2); font-size: 16px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.theme-btn:hover { background: var(--border); }

.auth-btn {
  padding: 7px 14px; border-radius: 20px;
  background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 700;
  transition: background .15s; white-space: nowrap;
}
.auth-btn:hover { background: var(--accent2); }
.auth-btn.signed-in { background: var(--green); }

/* ── Sub header ───────────────────────────────────────────────────────────── */
.sub-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1.5px solid var(--border);
  flex-shrink: 0;
}
.sub-title { font-size: 17px; font-weight: 800; }
.back-btn {
  padding: 6px 12px; border-radius: var(--radius-sm);
  background: var(--surface2); color: var(--text2);
  font-size: 13px; font-weight: 700;
  transition: background .15s; flex-shrink: 0;
}
.back-btn:hover { background: var(--border); }

/* ── Menu main ────────────────────────────────────────────────────────────── */
.menu-main {
  flex: 1; overflow-y: auto;
  padding: 18px 16px 32px;
}
.section-label {
  font-size: 12px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .6px; color: var(--text3);
  margin-bottom: 10px;
}

/* Mode grid */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px; margin-bottom: 24px;
}
.mode-card {
  display: flex; flex-direction: column; align-items: center;
  padding: 18px 12px; border-radius: var(--radius);
  background: var(--surface); border: 1.5px solid var(--border);
  box-shadow: 0 2px 8px var(--shadow);
  gap: 4px; transition: all .18s; text-align: center;
}
.mode-card:hover, .mode-card:active { transform: translateY(-2px); box-shadow: 0 6px 16px var(--shadow); }
.mode-icon  { font-size: 30px; }
.mode-title { font-size: 14px; font-weight: 800; color: var(--text); }
.mode-desc  { font-size: 11px; color: var(--text3); font-weight: 600; }
.mode-card--romaji { background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%); border-color: transparent; }
.mode-card--romaji .mode-title, .mode-card--romaji .mode-desc, .mode-card--romaji .mode-icon { color: #fff; }

/* Stats */
.stats-section { margin-top: 8px; }
.stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.stat-card {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 8px;
  text-align: center;
}
.stat-num { font-size: 22px; font-weight: 900; color: var(--accent); }
.stat-lbl { font-size: 10px; color: var(--text3); font-weight: 700; margin-top: 2px; }

/* ── Category grid ────────────────────────────────────────────────────────── */
.grid-scroll { flex: 1; overflow-y: auto; padding: 14px 14px 32px; }
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.cat-card {
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 8px; border-radius: var(--radius);
  background: var(--surface); border: 1.5px solid var(--border);
  box-shadow: 0 2px 6px var(--shadow);
  gap: 5px; cursor: pointer; transition: all .18s;
  text-align: center; position: relative; overflow: hidden;
}
.cat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
}
.cat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 14px var(--shadow); }
.cat-emoji { font-size: 28px; }
.cat-ja    { font-size: 13px; font-weight: 800; color: var(--text); }
.cat-en    { font-size: 10px; color: var(--text3); font-weight: 700; }
.cat-count { font-size: 10px; background: var(--surface2); padding: 2px 7px;
             border-radius: 10px; color: var(--text3); font-weight: 700; }

/* ── Unit grid ────────────────────────────────────────────────────────────── */
.unit-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.unit-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 18px 8px; border-radius: var(--radius);
  background: var(--surface); border: 1.5px solid var(--border);
  font-size: 22px; font-weight: 900; color: var(--text);
  cursor: pointer; transition: all .18s; gap: 4px;
}
.unit-card:hover { transform: translateY(-2px); background: var(--accent); color: #fff; border-color: transparent; }
.unit-card-label { font-size: 10px; font-weight: 700; color: inherit; opacity: .7; }

/* ── Quiz type ────────────────────────────────────────────────────────────── */
.qtype-wrap { flex: 1; overflow-y: auto; padding: 16px; }
.qtype-info {
  background: var(--surface2); border-radius: var(--radius-sm);
  padding: 12px 16px; margin-bottom: 16px;
  font-size: 13px; font-weight: 700; color: var(--text2);
  display: flex; align-items: center; gap: 8px;
}
.qtype-grid { display: flex; flex-direction: column; gap: 10px; }
.qtype-card {
  display: flex; align-items: center; gap: 14px;
  padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1.5px solid var(--border);
  box-shadow: 0 2px 6px var(--shadow);
  cursor: pointer; transition: all .18s; text-align: left;
}
.qtype-card:hover { border-color: var(--accent); transform: translateX(3px); }
.qtype-icon  { font-size: 28px; flex-shrink: 0; }
.qtype-title { font-size: 15px; font-weight: 800; color: var(--text); display: block; }
.qtype-desc  { font-size: 12px; color: var(--text3); font-weight: 600; display: block; margin-top: 2px; }

/* ── Quiz screen ──────────────────────────────────────────────────────────── */
.quiz-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1.5px solid var(--border);
  flex-shrink: 0;
}
.quiz-progress { flex: 1; display: flex; align-items: center; gap: 8px; }
.progress-bar {
  flex: 1; height: 8px; background: var(--surface2);
  border-radius: 4px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--accent);
  border-radius: 4px; transition: width .4s ease;
}
.progress-text { font-size: 12px; font-weight: 700; color: var(--text3); flex-shrink: 0; }
.quiz-score { font-size: 14px; font-weight: 800; color: var(--text); flex-shrink: 0; }

.quiz-body {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 16px; gap: 16px; position: relative; overflow: hidden;
}
.question-card {
  width: 100%; max-width: 480px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 20px 18px;
  text-align: center; box-shadow: 0 4px 16px var(--shadow);
}
.question-emoji { font-size: 48px; margin-bottom: 6px; }
.question-label { font-size: 11px; font-weight: 800; text-transform: uppercase;
                  letter-spacing: .5px; color: var(--text3); margin-bottom: 6px; }
.question-word  {
  font-size: 28px; font-weight: 900; color: var(--text); line-height: 1.2;
  display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap;
}
.question-hint  { font-size: 14px; color: var(--text3); margin-top: 4px; font-weight: 600; }
.romaji-kana    { font-size: 56px; }

.choices-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; width: 100%; max-width: 480px;
}
.choice-btn {
  padding: 14px 10px; border-radius: var(--radius-sm);
  background: var(--surface); border: 2px solid var(--border);
  font-size: 15px; font-weight: 700; color: var(--text);
  cursor: pointer; transition: all .15s;
  box-shadow: 0 2px 6px var(--shadow); text-align: center;
  min-height: 56px; display: flex; align-items: center; justify-content: center;
  word-break: break-word; user-select: none;
}
.choice-btn:hover:not(.disabled) { border-color: var(--accent); background: var(--surface2); }
.choice-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.choice-btn.disabled { cursor: default; }
.choice-btn.correct  { border-color: var(--green); background: #f0fdf4; color: var(--green); }
.choice-btn.wrong    { border-color: var(--red);   background: #fef2f2; color: var(--red);   }
.dark .choice-btn.correct { background: #14532d30; }
.dark .choice-btn.wrong   { background: #7f1d1d30; }

/* Result overlay */
.result-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,.45); border-radius: var(--radius);
  gap: 8px; backdrop-filter: blur(4px);
  animation: fadeIn .2s ease;
}
.result-overlay.hidden { display: none; }
.result-icon { font-size: 64px; animation: popIn .3s ease; }
.result-msg  { font-size: 20px; font-weight: 900; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,.4); }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes popIn  { from { transform: scale(.5); } to { transform: scale(1); } }

/* ── Flash cards ──────────────────────────────────────────────────────────── */
.flash-body {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 16px; gap: 16px;
}
.flashcard {
  width: 100%; max-width: 400px; height: 240px;
  perspective: 1000px; cursor: pointer;
}
.flashcard-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform .5s ease;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-front, .flashcard-back {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  border-radius: var(--radius); padding: 20px;
  backface-visibility: hidden; gap: 8px;
  box-shadow: 0 6px 24px var(--shadow);
}
.flashcard-front {
  background: var(--surface); border: 2px solid var(--border);
}
.flashcard-back {
  background: linear-gradient(135deg, #1e40af, #3b82f6);
  transform: rotateY(180deg); color: #fff;
}
.flash-emoji    { font-size: 52px; }
.flash-word     {
  font-size: 28px; font-weight: 900; color: var(--text);
  display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap;
}
.flash-tap-hint { font-size: 12px; color: var(--text3); font-weight: 600; }
.flash-ja       { font-size: 24px; font-weight: 900; color: #fff; }
.flash-en-small {
  font-size: 14px; color: rgba(255,255,255,.7); font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap;
}

.flash-controls { display: flex; gap: 10px; }
.flash-nav-btn {
  padding: 11px 24px; border-radius: 24px;
  background: var(--surface); border: 1.5px solid var(--border);
  font-size: 14px; font-weight: 800; color: var(--text);
  transition: all .15s;
}
.flash-nav-btn:hover { background: var(--surface2); }
.flash-nav-btn--next { background: var(--accent); color: #fff; border-color: transparent; }
.flash-nav-btn--next:hover { background: var(--accent2); }

/* ── Romaji ───────────────────────────────────────────────────────────────── */
.romaji-wrap { flex: 1; overflow-y: auto; padding: 12px 14px; }
.romaji-filter { margin-bottom: 12px; }
.romaji-filter-label { font-size: 12px; font-weight: 800; color: var(--text3);
                        text-transform: uppercase; display: block; margin-bottom: 6px; }
.row-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.row-chip {
  padding: 5px 12px; border-radius: 14px;
  background: var(--surface); border: 1.5px solid var(--border);
  font-size: 12px; font-weight: 800; color: var(--text2);
  cursor: pointer; transition: all .15s;
}
.row-chip.active { background: var(--accent); border-color: transparent; color: #fff; }
.romaji-stats {
  display: flex; gap: 16px; justify-content: center;
  margin-top: 12px; font-size: 14px; font-weight: 800;
}

/* ── Results ──────────────────────────────────────────────────────────────── */
.results-body {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px 24px; gap: 12px; text-align: center;
}
.results-emoji { font-size: 72px; animation: popIn .4s ease; }
.results-title { font-size: 28px; font-weight: 900; }
.results-score { font-size: 20px; font-weight: 800; color: var(--accent); }
.results-bar-wrap {
  width: 100%; max-width: 320px; height: 16px;
  background: var(--surface2); border-radius: 8px; overflow: hidden;
}
.results-bar {
  height: 100%; border-radius: 8px;
  background: linear-gradient(90deg, #2563eb, #7c3aed);
  transition: width .8s ease;
}
.results-msg   { font-size: 16px; color: var(--text2); font-weight: 700; }
.sync-status   { font-size: 13px; color: var(--green); font-weight: 700; min-height: 20px; }
.results-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 8px; }
.results-btn {
  padding: 12px 24px; border-radius: 24px;
  font-size: 15px; font-weight: 800;
  background: var(--surface); border: 1.5px solid var(--border);
  color: var(--text); transition: all .15s;
}
.results-btn:hover { background: var(--surface2); }
.results-btn--primary { background: var(--accent); color: #fff; border-color: transparent; }
.results-btn--primary:hover { background: var(--accent2); }

/* ── Auth modal ───────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px; backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--surface); border-radius: 20px;
  padding: 28px 24px; width: 100%; max-width: 360px;
  position: relative; box-shadow: 0 12px 40px rgba(0,0,0,.2);
}
.modal-close {
  position: absolute; top: 14px; right: 16px;
  font-size: 20px; color: var(--text3); line-height: 1;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }
.modal-title { font-size: 20px; font-weight: 900; margin-bottom: 4px; }
.modal-sub   { font-size: 13px; color: var(--text3); margin-bottom: 16px; font-weight: 600; }
.modal-err, .modal-ok {
  padding: 10px 13px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 12px;
}
.modal-err { background: #fef2f2; border: 1px solid #fca5a5; color: #b91c1c; }
.modal-ok  { background: #f0fdf4; border: 1px solid #86efac; color: #166534; }
.modal-err.hidden, .modal-ok.hidden { display: none; }

.modal-tabs { display: flex; gap: 0; border: 1.5px solid var(--border);
              border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 16px; }
.modal-tab {
  flex: 1; padding: 8px; background: var(--surface2);
  color: var(--text2); font-size: 12px; font-weight: 800;
  transition: all .15s;
}
.modal-tab.active { background: var(--accent); color: #fff; }
.modal-tab + .modal-tab { border-left: 1.5px solid var(--border); }

.modal-field { margin-bottom: 12px; }
.modal-field label {
  display: block; font-size: 11px; font-weight: 800;
  text-transform: uppercase; color: var(--text3); margin-bottom: 4px;
}
.modal-field input {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 14px; outline: none;
  transition: border-color .15s;
}
.modal-field input:focus { border-color: var(--accent); }
.modal-forgot {
  display: block; text-align: right; width: 100%;
  font-size: 12px; color: var(--text3); margin-top: 4px; margin-bottom: 8px;
}
.modal-forgot:hover { color: var(--accent); }

.modal-submit {
  width: 100%; padding: 12px; border-radius: 24px;
  background: var(--accent); color: #fff; font-size: 15px; font-weight: 800;
  transition: background .15s; margin-top: 4px;
}
.modal-submit:hover { background: var(--accent2); }
.modal-submit:disabled { background: #93c5fd; cursor: default; }

.modal-user-info { text-align: center; margin-bottom: 16px; padding: 12px;
                   background: var(--surface2); border-radius: var(--radius-sm); }
.modal-user-name  { font-size: 17px; font-weight: 800; }
.modal-user-email { font-size: 13px; color: var(--text3); margin-top: 2px; }
.modal-dashboard-link {
  display: block; text-align: center; padding: 11px;
  background: var(--surface2); border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700; color: var(--accent);
  text-decoration: none; margin-bottom: 12px; transition: background .15s;
}
.modal-dashboard-link:hover { background: var(--border); }

/* ── TTS speaker buttons (added) ─────────────────────────────────────────── */
.tts-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  font-size: 15px; line-height: 1; cursor: pointer;
  transition: all .15s; flex-shrink: 0; padding: 0;
}
.tts-btn:hover { border-color: var(--accent); }
.tts-btn.tts-playing { animation: tts-pulse .9s infinite; border-color: var(--accent); }
@keyframes tts-pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* Choice text + speaker icon laid out side by side inside the choice "button" */
.choice-text { flex: 1; }
.choice-tts  { margin-left: 8px; }

/* Flashcard front/back speaker buttons are sized down slightly */
.flash-tts, .flash-tts-small { width: 26px; height: 26px; font-size: 13px; }
