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

:root {
  --bg:       #f4f6f9;
  --surface:  #ffffff;
  --surface2: #f0f2f5;
  --border:   #dde1e7;
  --text:     #1a1d23;
  --text2:    #5a6070;
  --text3:    #9aa0ad;
  --accent:   #1565C0;
  --accent2:  #0D47A1;
  --green:    #2E7D32;
  --red:      #C62828;
  --shadow:   rgba(0,0,0,.07);
  --r:        13px;
  --font:     'Nunito','Hiragino Sans','Noto Sans JP',sans-serif;
}
body.dark {
  --bg:       #111318;
  --surface:  #1c1f26;
  --surface2: #252930;
  --border:   #363c47;
  --text:     #edf0f5;
  --text2:    #9aa0ad;
  --text3:    #636b78;
  --shadow:   rgba(0,0,0,.25);
}

*,*::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;
}
button,a { font-family:var(--font); cursor:pointer; }
input    { font-family:var(--font); }

/* ── Screen system ────────────────────────────────────────────────────── */
.screen {
  position:absolute; inset:0; overflow-y:auto;
  opacity:0; pointer-events:none;
  transform:translateY(10px);
  transition: opacity .2s, transform .2s;
}
.screen.active { opacity:1; pointer-events:all; transform:none; }

/* ── App header ───────────────────────────────────────────────────────── */
.app-header {
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 16px;
  background: var(--surface);
  border-bottom:1.5px solid var(--border);
  position:sticky; top:0; z-index:10;
}
.header-left  { display:flex; align-items:center; gap:10px; }
.header-right { display:flex; align-items:center; gap:8px; }
.app-icon  { font-size:28px; }
.app-title { font-size:17px; font-weight:900; }
.app-sub   { font-size:11px; color:var(--text3); font-weight:600; }
.icon-btn  {
  width:36px; height:36px; border-radius:50%; border:none;
  background:var(--surface2); font-size:15px; display:flex;
  align-items:center; justify-content:center; transition:background .15s;
}
.icon-btn:hover { background:var(--border); }
.auth-btn  {
  padding:7px 14px; border-radius:20px; border:none;
  background:var(--accent); color:#fff; font-size:13px; font-weight:700;
  transition:background .15s;
}
.auth-btn:hover    { background:var(--accent2); }
.auth-btn.signed-in{ background:var(--green); }

/* ── Menu ─────────────────────────────────────────────────────────────── */
.menu-body { padding:16px 14px 40px; }
.menu-intro { font-size:14px; color:var(--text2); margin-bottom:14px; font-weight:600; }
.unit-grid {
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(155px,1fr));
  gap:11px;
}
.unit-card {
  display:flex; flex-direction:column; align-items:center;
  padding:18px 10px 14px; border-radius:var(--r);
  background:var(--surface); border:2px solid transparent;
  border-top:4px solid var(--uc, #1565C0);
  box-shadow:0 2px 8px var(--shadow);
  gap:4px; cursor:pointer; transition:all .18s; text-align:center;
}
.unit-card:hover { transform:translateY(-3px); box-shadow:0 6px 16px var(--shadow); border-color:var(--uc,#1565C0); }
.uc-num   { font-size:11px; font-weight:800; color:var(--uc,#1565C0); text-transform:uppercase; letter-spacing:.4px; }
.uc-emoji { font-size:28px; }
.uc-title { font-size:13px; font-weight:800; color:var(--text); line-height:1.2; }
.uc-ja    { font-size:10px; color:var(--text3); font-weight:600; }

/* Stats */
.section-label { font-size:11px; font-weight:800; text-transform:uppercase;
                 letter-spacing:.6px; color:var(--text3); margin-bottom: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:10px;
             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; }

/* ── Unit screen ──────────────────────────────────────────────────────── */
.unit-header {
  padding:20px 16px 24px;
  color:#fff;
  position:relative;
}
.back-btn-white {
  background:rgba(255,255,255,.2); border:1.5px solid rgba(255,255,255,.4);
  color:#fff; padding:7px 14px; border-radius:7px; font-size:13px; font-weight:700;
  margin-bottom:16px; display:inline-block;
}
.unit-header-inner  { display:flex; align-items:center; gap:14px; }
.unit-header-emoji  { font-size:44px; }
.unit-header-num    { font-size:12px; font-weight:800; opacity:.8; }
.unit-header-title  { font-size:22px; font-weight:900; line-height:1.1; }
.unit-header-ja     { font-size:12px; opacity:.8; margin-top:3px; }

.mode-list { padding:12px 14px 40px; display:flex; flex-direction:column; gap:10px; }
.mode-card {
  display:flex; align-items:center; gap:14px;
  padding:16px; border-radius:var(--r);
  background:var(--surface); border:1.5px solid var(--border);
  box-shadow:0 2px 6px var(--shadow); cursor:pointer;
  transition:all .17s; text-decoration:none; color:inherit;
}
.mode-card:hover { border-color:var(--accent); transform:translateX(3px); }
.mode-card--vocab { border-left:4px solid var(--green); }
.mode-card--vocab:hover { border-color:var(--green); }
.mode-icon  { font-size:28px; flex-shrink:0; }
.mode-title { font-size:15px; font-weight:800; }
.mode-desc  { font-size:12px; color:var(--text3); font-weight:600; margin-top:2px; }
.mode-count { margin-left:auto; font-size:12px; font-weight:800; color:var(--text3);
              background:var(--surface2); padding:3px 9px; border-radius:9px; flex-shrink:0; }

/* ── Quiz ─────────────────────────────────────────────────────────────── */
.quiz-header {
  display:flex; align-items:center; gap:10px; padding:10px 14px;
  background:var(--surface); border-bottom:1.5px solid var(--border);
  position:sticky; top:0; z-index:10;
}
.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; }
.progress-text { font-size:12px; font-weight:700; color:var(--text3); flex-shrink:0; }
.quiz-score    { font-size:14px; font-weight:800; flex-shrink:0; }

.quiz-body {
  flex:1; display:flex; flex-direction:column;
  align-items:center; padding:16px;
  gap:14px; min-height: calc(100vh - 50px);
  position:relative;
}
.question-card {
  width:100%; max-width:480px;
  background:var(--surface); border:1.5px solid var(--border);
  border-radius:var(--r); padding:20px 18px;
  text-align:center; box-shadow:0 4px 14px var(--shadow);
}
.question-label { font-size:11px; font-weight:800; text-transform:uppercase;
                  letter-spacing:.5px; color:var(--text3); margin-bottom:10px; }
.question-prompt { font-size:20px; font-weight:800; color:var(--text); line-height:1.4; }
.qp-blank { display:inline-block; min-width:80px; border-bottom:3px solid var(--accent);
             margin:0 4px; color:var(--accent); }
.qp-question { font-size:19px; font-weight:700; color:var(--text); font-style:italic; }
.question-hint { font-size:13px; color:var(--text2); margin-top:8px; font-weight:600; }

.choices-grid {
  display:grid; grid-template-columns:1fr 1fr;
  gap:10px; width:100%; max-width:480px;
}
.choice-btn {
  padding:14px 10px; border-radius:10px;
  background:var(--surface); border:2px solid var(--border);
  font-size:14px; font-weight:700; color:var(--text);
  cursor:pointer; transition:all .15s; text-align:center;
  min-height:56px; display:flex; align-items:center; justify-content:center;
  word-break:break-word; line-height:1.3;
  box-shadow:0 2px 5px var(--shadow);
  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:#2E7D32; background:#f0fdf4; color:#2E7D32; font-weight:900; }
.choice-btn.wrong   { border-color:#C62828; background:#fff5f5; color:#C62828; }
body.dark .choice-btn.correct { background:#1a3a1a; }
body.dark .choice-btn.wrong   { background:#3a1a1a; }

.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(--r);
  gap:8px; backdrop-filter:blur(4px);
  animation:fadeIn .2s;
}
.result-overlay.hidden { display:none; }
.result-icon { font-size:60px; animation:popIn .25s; }
.result-msg  { font-size:17px; font-weight:900; color:#fff;
               text-shadow:0 2px 8px rgba(0,0,0,.4); text-align:center; padding:0 16px; }
@keyframes fadeIn { from{opacity:0} }
@keyframes popIn  { from{transform:scale(.5)} to{transform:scale(1)} }

/* ── Writing ──────────────────────────────────────────────────────────── */
.writing-body { padding:12px 14px 32px; display:flex; flex-direction:column; align-items:center; gap:10px; }
.write-instruction {
  font-size:16px; font-weight:800; text-align:center;
  color:var(--text); padding:6px 12px;
}
.write-word-eg { font-size:13px; color:var(--text2); font-weight:600; }
.write-tabs { display:flex; gap:6px; flex-wrap:wrap; justify-content:center; }
.wtab {
  padding:6px 14px; border-radius:20px; border:1.5px solid var(--border);
  background:var(--surface); color:var(--text2); font-size:13px; font-weight:700;
  cursor:pointer; transition:all .15s;
}
.wtab.active { background:var(--accent); border-color:var(--accent); color:#fff; }

.canvas-wrap {
  position:relative;
  width: min(300px, calc(100vw - 28px));   /* JS overrides for words/sentences */
  height: 300px;
  border-radius:var(--r);
  border:2px solid var(--border);
  background:var(--surface);
  box-shadow:0 4px 16px var(--shadow);
  overflow:hidden;
  transition: width .15s, height .15s;
}
.guide-overlay {
  position:absolute; inset:0;
  display:flex; align-items:center; justify-content:center;
  font-size:200px; font-weight:900;        /* JS overrides per item */
  color:rgba(37,99,235,0.11);              /* slightly more visible */
  pointer-events:none; user-select:none;
  font-family:'Arial Black','Arial','Helvetica Neue',sans-serif;
  transition:opacity .3s, font-size .1s;
  line-height:1;
  overflow:hidden;
  padding:8px 12px;
  word-break:break-word;
  text-align:center;
  white-space:pre-wrap;
}
body.dark .guide-overlay { color:rgba(147,197,253,0.15); }
.write-canvas {
  position:absolute; inset:0;
  width:100%; height:100%;
  touch-action:none;
  cursor:crosshair;
}

.write-controls {
  display:flex; gap:8px; flex-wrap:wrap; justify-content:center;
}
.write-btn {
  padding:9px 18px; border-radius:20px; border:1.5px solid var(--border);
  background:var(--surface); color:var(--text); font-size:13px; font-weight:800;
  transition:all .15s;
}
.write-btn:hover:not(:disabled) { background:var(--surface2); }
.write-btn:disabled { opacity:.4; cursor:default; }
.write-btn--clear { border-color:#fca5a5; color:#C62828; }
.write-btn--clear:hover { background:#fff5f5; }
.write-btn--next { background:var(--accent); color:#fff; border-color:transparent; }
.write-btn--next:hover { background:var(--accent2); }
.mode-toggle-btn {
  padding:6px 12px; border-radius:7px; border:1.5px solid var(--border);
  background:var(--surface2); color:var(--text2); font-size:11px; font-weight:700;
  flex-shrink:0; transition:all .15s;
}
.mode-toggle-btn:hover { border-color:var(--accent); color:var(--accent); }

/* ── Results ──────────────────────────────────────────────────────────── */
.results-body {
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  min-height:100vh; padding:32px 20px; gap:12px; text-align:center;
}
.results-emoji  { font-size:72px; animation:popIn .4s; }
.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,#1565C0,#7c3aed);
                  transition:width .8s ease; }
.results-msg    { font-size:16px; color:var(--text2); font-weight:700; }
.results-sync   { font-size:13px; color:var(--green); font-weight:700; min-height:20px; }
.results-btns   { display:flex; gap:10px; flex-wrap:wrap; justify-content:center; margin-top:8px; }
.result-btn     {
  padding:11px 22px; border-radius:22px; border:1.5px solid var(--border);
  background:var(--surface); color:var(--text); font-size:14px; font-weight:800;
  transition:all .15s;
}
.result-btn:hover { background:var(--surface2); }
.result-btn--primary { background:var(--accent); color:#fff; border-color:transparent; }
.result-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:18px;
  padding:26px 22px; 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); background:none; border:none; }
.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:14px; font-weight:600; }
.modal-err,.modal-ok { padding:10px 12px; border-radius:8px; font-size:13px; margin-bottom:10px; }
.modal-err { background:#fff5f5; border:1px solid #fca5a5; color:#C62828; }
.modal-ok  { background:#f0fdf4; border:1px solid #86efac; color:#2E7D32; }
.modal-err.hidden,.modal-ok.hidden { display:none; }
.modal-tabs { display:flex; border:1.5px solid var(--border); border-radius:8px;
              overflow:hidden; margin-bottom:14px; }
.modal-tab  { flex:1; padding:8px; background:var(--surface2); color:var(--text2);
              border:none; 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:11px; }
.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:8px;
  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-submit {
  width:100%; padding:12px; border-radius:22px; border:none;
  background:var(--accent); color:#fff; font-size:15px; font-weight:800;
  margin-top:4px; transition:background .15s;
}
.modal-submit:hover { background:var(--accent2); }
.modal-submit:disabled { background:#93c5fd; cursor:default; }
.modal-user-info { background:var(--surface2); border-radius:9px; padding:12px;
                   text-align:center; margin-bottom:12px; }
.modal-user-name  { font-size:16px; font-weight:800; }
.modal-user-email { font-size:13px; color:var(--text3); margin-top:2px; }
.modal-dashboard-link {
  display:block; text-align:center; padding:10px;
  background:var(--surface2); border-radius:9px; color:var(--accent);
  font-size:14px; font-weight:700; text-decoration:none; margin-bottom:12px;
}

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

/* Inline with question prompt text */
.question-prompt { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px; }
.qp-tts { margin-left: 8px; }

/* Choice buttons (divs with role=button): text + speaker side by side */
.choice-text { flex: 1; }
.choice-tts { margin-left: 8px; }

/* Writing screen instruction */
.write-instruction { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 4px; }
.write-tts { margin-left: 6px; }
