/* ─────────────────────────────────────────────────────────────────
   VocabTrainer — shared stylesheet
   pages: index.html  ·  user_select.html  ·  help.html
   ───────────────────────────────────────────────────────────────── */

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

/* ── Design tokens ── */
:root {
  --app-bg:         #f0f4f8;
  --surface:        #ffffff;
  --border:         #d8dfe8;
  --text-primary:   #1f2937;
  --text-secondary: #6b7280;
  --text-label:     #9ca3af;
  --mark-bg:        #fde68a;
  --mark-text:      #92400e;
  --btn-bg:         #1f2937;
  --btn-text:       #ffffff;
  --streak:         #f59e0b;
  --correct-bg:     #d1fae5;
  --correct-text:   #065f46;
  --wrong-bg:       #fee2e2;
  --wrong-text:     #7f1d1d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --app-bg:         #1e2433;
    --surface:        #252d3d;
    --border:         #2e3649;
    --text-primary:   #f1f5f9;
    --text-secondary: #94a3b8;
    --text-label:     #64748b;
    --mark-bg:        #78350f;
    --mark-text:      #fde68a;
    --btn-bg:         #f1f5f9;
    --btn-text:       #1e2433;
    --streak:         #f59e0b;
    --correct-bg:     #064e3b;
    --correct-text:   #a7f3d0;
    --wrong-bg:       #450a0a;
    --wrong-text:     #fca5a5;
  }
}

/* ── Base ── */
html, body { min-height: 100dvh; }

body {
  background: var(--app-bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  -webkit-text-size-adjust: 100%;
}

/* quiz page: exact height so layout respects visual viewport (keyboard fix) */
body:has(.phone) { height: 100dvh; }

/* user-select page: column so .container can flex-grow to fill the screen */
body.select { flex-direction: column; align-items: center; }


/* ═══════════════════════════════════════════════════════════════
   QUIZ  (index.html)
   ═══════════════════════════════════════════════════════════════ */

.phone {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: 100dvh;        /* overridden by JS via visualViewport */
  background: var(--app-bg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.05), 0 8px 40px rgba(0,0,0,0.10);
}

.quiz-header {
  background: var(--app-bg);
  padding: 14px 20px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.quiz-header .name   { font-size: 14px; font-weight: 700; color: var(--text-primary); }
.quiz-header .stats  { display: flex; gap: 14px; align-items: center; }
.quiz-header .score  { font-size: 13px; color: var(--text-secondary); }
.quiz-header .streak { font-size: 14px; font-weight: 700; color: var(--streak); }

.settings-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--text-label);
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}
.settings-btn:hover { color: var(--text-secondary); }

.skip-btn,
.reveal-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 46px;
  height: 46px;
  font-size: 18px;
  color: var(--text-secondary);
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.quiz-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px 16px;
  display: flex;
  flex-direction: column;
  position: relative;
}

.direction-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-label);
  margin-bottom: 20px;
}

.sentence {
  font-size: 22px;
  line-height: 1.7;
  color: var(--text-primary);
  flex: 1;
}

/* shared highlight style — used in quiz (.sentence strong) and help (.example mark) */
.sentence strong,
.example mark {
  background: var(--mark-bg);
  color: var(--mark-text);
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 700;
}

.listen-btn {
  margin-top: 24px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 9px 20px;
  font-size: 15px;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
}

.answer-bar {
  flex-shrink: 0;
  padding: 16px 24px 20px;
  background: var(--app-bg);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: center;
}
.answer-bar input {
  flex: 1;
  border: none;
  border-bottom: 2px solid var(--text-secondary);
  background: transparent;
  padding: 8px 0;
  font-size: 17px;
  color: var(--text-primary);
  outline: none;
}
.answer-bar input::placeholder { color: var(--text-label); }

.submit-btn {
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  border-radius: 10px;
  width: 46px;
  height: 46px;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.switch-user {
  text-align: center;
  /* env(safe-area-inset-bottom) keeps the links above the iPhone home indicator */
  padding: 10px 0 calc(16px + env(safe-area-inset-bottom, 0px));
  font-size: 14px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  gap: 18px;
}
.switch-user a { color: var(--text-label); text-decoration: underline; }

.feedback-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px;
}
/* color-mix() avoids a separate dark-mode media query here */
.feedback-overlay.correct { background: color-mix(in srgb, var(--correct-bg) 95%, transparent); }
.feedback-overlay.wrong   { background: color-mix(in srgb, var(--wrong-bg)   95%, transparent); }
.feedback-overlay .fb-icon { font-size: 52px; line-height: 1; }
.feedback-overlay .fb-msg  { font-size: 26px; font-weight: 800; }
.feedback-overlay .fb-ans  { font-size: 17px; }
.feedback-overlay.correct .fb-msg,
.feedback-overlay.correct .fb-ans { color: var(--correct-text); }
.feedback-overlay.wrong   .fb-msg,
.feedback-overlay.wrong   .fb-ans { color: var(--wrong-text); }

.countdown-bar {
  width: 80px;
  height: 4px;
  background: rgba(0,0,0,0.12);
  border-radius: 2px;
  margin-top: 8px;
  overflow: hidden;
  position: relative;
}
.countdown-bar-fill {
  position: absolute;
  left: 0; top: 0;
  height: 100%;
  width: 100%;
  background: rgba(0,0,0,0.25);
  border-radius: 2px;
  transform-origin: left;
  animation: countdown 3s linear forwards;
}
@keyframes countdown {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

.feedback-overlay .fb-sentence {
  font-size: 18px;
  line-height: 1.55;
  text-align: center;
  max-width: 100%;
}
.feedback-overlay .fb-yours { font-size: 16px; opacity: 0.85; }
.feedback-overlay.correct .fb-sentence,
.feedback-overlay.correct .fb-yours { color: var(--correct-text); }
.feedback-overlay.wrong   .fb-sentence,
.feedback-overlay.wrong   .fb-yours { color: var(--wrong-text); }

.fb-next {
  margin-top: 8px;
  padding: 14px 36px;
  border: none;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  /* Derived from the text colour so it stays legible in light AND dark mode */
  background: color-mix(in srgb, currentColor 16%, transparent);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.feedback-overlay.correct .fb-next { color: var(--correct-text); }
.feedback-overlay.wrong   .fb-next { color: var(--wrong-text); }

.fb-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}
.fb-action {
  padding: 10px 18px;
  border: 1.5px solid color-mix(in srgb, currentColor 45%, transparent);
  border-radius: 99px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  background: color-mix(in srgb, currentColor 12%, transparent);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.fb-action:disabled { opacity: 0.7; cursor: default; }
.feedback-overlay.correct .fb-action { color: var(--correct-text); }
.feedback-overlay.wrong   .fb-action { color: var(--wrong-text); }

/* ── Icons (inline SVG, stroke = currentColor) ── */
.icon { width: 22px; height: 22px; flex-shrink: 0; }
.settings-btn .icon { width: 20px; height: 20px; }
.listen-btn .icon   { width: 18px; height: 18px; }
.fb-action .icon    { width: 17px; height: 17px; }
.fb-next .icon      { width: 19px; height: 19px; }
.fb-icon .icon      { width: 56px; height: 56px; stroke-width: 2.5; }
.feedback-overlay.correct .fb-icon { color: var(--correct-text); }
.feedback-overlay.wrong   .fb-icon { color: var(--wrong-text); }

/* ── Muted words on stats page ── */
.section-note {
  font-size: 15px;
  color: var(--text-secondary, #6b7280);
  margin-bottom: 10px;
}
.unmute-btn {
  padding: 8px 16px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 99px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: inherit;
}
.unmute-btn:disabled { opacity: 0.5; }

/* ── Login (user_select.html) ── */
.user-entry { margin-bottom: 4px; }
.password-row {
  display: flex;
  gap: 8px;
  padding: 8px 4px 4px;
}
.password-row.hidden { display: none; }
.password-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 12px;
  font-size: 16px; /* ≥16px stops iOS Safari from zooming in on focus */
}
.password-go {
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  background: #1f2937;
  color: #fff;
}
.login-status { font-size: 14px; padding: 4px; min-height: 18px; }
.login-error  { color: #b91c1c; font-weight: 600; }

.settings-hint { font-weight: 400; font-size: 12px; color: var(--text-label); }

/* ── Level filter on stats page ── */
.stats-level-row { margin-bottom: 20px; flex-wrap: wrap; }

/* ── Head-to-head on stats page ── */
.versus-table { display: flex; flex-direction: column; gap: 2px; }
.versus-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 16px;
}
.versus-row:nth-child(even) { background: rgba(0, 0, 0, 0.03); }
.versus-row span:first-child { color: var(--text-secondary, #6b7280); }
.versus-head { font-weight: 700; }
.versus-head span:first-child { color: inherit; }
.versus-you { font-weight: 700; }

/* compact layout when software keyboard is open */
@media (max-height: 500px) {
  .quiz-header     { padding: 8px 20px; }
  .quiz-body       { padding: 12px 24px 8px; }
  .direction-label { margin-bottom: 10px; }
  .sentence        { font-size: 18px; line-height: 1.55; }
  .listen-btn      { margin-top: 10px; padding: 6px 16px; }
  .answer-bar      { padding: 10px 24px 12px; }
  .switch-user     { padding: 6px 0 calc(10px + env(safe-area-inset-bottom, 0px)); }
}

.status-msg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text-secondary);
  padding: 24px;
  text-align: center;
}


/* ═══════════════════════════════════════════════════════════════
   USER SELECT  (user_select.html)
   All colours via CSS variables — dark mode is free.
   ═══════════════════════════════════════════════════════════════ */

.select .container {
  width: 100%;
  max-width: 480px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.select .page-header {
  text-align: center;
  padding: 48px 0 32px;
}

.select .app-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.select h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

#user-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.user-btn {
  width: 100%;
  min-height: 64px;
  padding: 0 20px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.user-btn:hover  { border-color: var(--text-label); background: var(--app-bg); }
.user-btn:active { background: var(--border); }
.user-btn:focus-visible { outline: 2px solid #0d6efd; outline-offset: 2px; }

.avatar {
  width: 44px;
  height: 44px;
  background: var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.chevron {
  margin-left: auto;
  color: var(--text-label);
  font-size: 22px;
  line-height: 1;
}

.status-block {
  width: 100%;
  min-height: 64px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}
.loading-block { background: var(--surface); color: var(--text-secondary); }
.error-block {
  background: var(--wrong-bg);
  border: 1px solid var(--wrong-text);
  color: var(--wrong-text);
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  text-align: center;
}

.retry-btn {
  background: none;
  border: none;
  color: var(--wrong-text);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
}
.retry-btn:focus-visible { outline: 2px solid #0d6efd; outline-offset: 2px; }

.select footer {
  padding: 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-label);
}


/* ═══════════════════════════════════════════════════════════════
   HELP  (help.html)
   ═══════════════════════════════════════════════════════════════ */

.page {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--app-bg);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.05), 0 8px 40px rgba(0,0,0,0.10);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.page > header {
  padding: 16px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.page > header a    { color: var(--text-secondary); text-decoration: none; font-size: 20px; line-height: 1; }
.page > header h1   { font-size: 17px; font-weight: 700; color: var(--text-primary); }

.page > main {
  flex: 1;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

section h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-label);
  margin-bottom: 10px;
}
section p,
section li {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-secondary);
}
section ul {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.example {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-top: 10px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-primary);
}
.example .answer { margin-top: 8px; font-size: 13px; color: var(--text-secondary); }

.buckets        { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.bucket-row     { display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--text-secondary); }
.bucket-dot     { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-new        { background: #f59e0b; }
.dot-learning   { background: #3b82f6; }
.dot-known      { background: #10b981; }


/* ═══════════════════════════════════════════════════════════════
   STATS  (stats.html)
   ═══════════════════════════════════════════════════════════════ */

.stats-greeting {
  padding: 4px 0 8px;
}
.stats-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
}

/* ── stat cards ── */
.stat-cards {
  display: flex;
  gap: 12px;
  margin-top: 10px;
}
.stat-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-card--wide { flex: 1 1 100%; }

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}
.streak-val { color: var(--streak); }
.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-label);
}

/* ── accuracy bar ── */
.accuracy-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.accuracy-sub {
  font-size: 13px;
  color: var(--text-secondary);
}
.acc-bar-track {
  margin-top: 10px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.acc-bar-fill {
  height: 100%;
  background: #10b981;
  border-radius: 3px;
  transition: width 0.6s ease;
}

/* ── progress bucket bar ── */
.progress-summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 10px;
  margin-bottom: 8px;
}
.progress-fraction {
  font-size: 15px;
  color: var(--text-secondary);
}
.progress-pct {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-label);
}

.bucket-bar-track {
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  display: flex;
  background: var(--border);
}
.bucket-bar-seg {
  height: 100%;
  transition: width 0.6s ease;
}
.seg-new      { background: #f59e0b; }
.seg-learning { background: #3b82f6; }
.seg-known    { background: #10b981; }

.bucket-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

/* ── weak words ── */
.weak-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.weak-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface);
  gap: 10px;
}
.weak-row + .weak-row {
  border-top: 1px solid var(--border);
}
.weak-words {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.weak-en {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.weak-de {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.weak-acc {
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}
.acc-bad { color: #ef4444; }
.acc-ok  { color: var(--text-secondary); }


/* ═══════════════════════════════════════════════════════════════
   SETTINGS PANEL  (index.html slide-up sheet)
   ═══════════════════════════════════════════════════════════════ */

.settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: flex-end;
  z-index: 10;
}
.settings-backdrop.hidden { display: none; }

.settings-sheet {
  width: 100%;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px 36px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.settings-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
}

.settings-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-label);
  margin-bottom: 8px;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  background: var(--app-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.pill.active {
  background: var(--btn-bg);
  border-color: var(--btn-bg);
  color: var(--btn-text);
}

.settings-close {
  background: var(--app-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  text-align: center;
}


/* ═══════════════════════════════════════════════════════════════
   SUGGEST FORM  (suggest.html)
   ═══════════════════════════════════════════════════════════════ */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.field input,
.field select,
.field textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  color: var(--text-primary);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus { border-color: var(--text-secondary); }

.field textarea { resize: vertical; min-height: 80px; }

.required { color: #ef4444; }
.optional  { font-weight: 400; color: var(--text-label); }

.form-status {
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 8px;
  display: none;
}
.form-status.success {
  display: block;
  background: var(--correct-bg);
  color: var(--correct-text);
}
.form-status.error {
  display: block;
  background: var(--wrong-bg);
  color: var(--wrong-text);
}

#suggest-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

#suggest-form .submit-btn {
  width: 100%;
  height: auto;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 700;
}
