:root {
  --red: #ff5a5f;
  --yellow: #ffcd3c;
  --orange: #ff8c42;
  --green: #2ec4b6;
  --green-deep: #1b9e91;
  --blue: #4d8af0;
  --purple: #9b5de5;
  --ink: #2a2a3c;
  --muted: #6b6b80;
  --paper: #fff;
  --bg: #fff7ec;
  --shadow: 0 8px 0 rgba(0, 0, 0, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 205, 60, 0.25), transparent 38%),
    radial-gradient(circle at 88% 12%, rgba(155, 93, 229, 0.18), transparent 40%),
    radial-gradient(circle at 70% 92%, rgba(46, 196, 182, 0.2), transparent 42%),
    var(--bg);
  min-height: 100vh;
}

h1, h2, h3 { font-family: 'Baloo 2', system-ui, sans-serif; margin: 0; }

/* Header & tabs */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 247, 236, 0.92);
  backdrop-filter: blur(8px);
  padding: 14px 20px 0;
  border-bottom: 3px solid rgba(0, 0, 0, 0.06);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-emoji { font-size: 1.8rem; }
.brand h1 { font-size: 1.6rem; color: var(--red); letter-spacing: 0.5px; }
.tabs { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.tab {
  border: none;
  background: transparent;
  font-family: 'Baloo 2', sans-serif;
  font-size: 1rem;
  color: var(--muted);
  padding: 10px 16px;
  border-radius: 14px 14px 0 0;
  cursor: pointer;
  transition: all 0.15s ease;
}
.tab:hover { color: var(--ink); background: rgba(0, 0, 0, 0.04); }
.tab.is-active { color: var(--ink); background: var(--paper); box-shadow: 0 -3px 0 var(--yellow) inset; }

/* Views */
main { max-width: 880px; margin: 0 auto; padding: 24px 20px 60px; }
.view { display: none; animation: pop 0.25s ease; }
.view.is-active { display: block; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.hidden { display: none !important; }

/* Home */
.hero { text-align: center; margin-bottom: 18px; }
.hero h2 { font-size: 2.2rem; color: var(--purple); }
.subtitle { color: var(--muted); font-size: 1.1rem; margin: 4px 0 0; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.stat {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 16px 10px;
  text-align: center;
  box-shadow: var(--shadow);
  border: 3px solid transparent;
}
.stat .num { font-family: 'Baloo 2', sans-serif; font-size: 2rem; line-height: 1; }
.stat .label { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.stat.total { border-color: var(--blue); }
.stat.learned { border-color: var(--green); }
.stat.learning { border-color: var(--orange); }
.stat.new { border-color: var(--purple); }

.progress-card { background: var(--paper); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 22px; }
.progress-bar-label { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 8px; }
.progress-bar { height: 18px; background: #f0eee8; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--green), var(--blue)); border-radius: 999px; transition: width 0.5s ease; }
.progress-hint { color: var(--muted); margin: 10px 0 0; text-align: center; }

.home-actions { display: grid; gap: 14px; }

/* Buttons */
.big-btn {
  border: none;
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.25rem;
  color: #fff;
  padding: 18px;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, filter 0.1s ease;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 4px 0 rgba(0,0,0,0.08); }
.big-btn.play { background: var(--green); }
.big-btn.quiz { background: var(--purple); }
.big-btn.add { background: var(--orange); }
.big-btn:hover { filter: brightness(1.05); }

.btn {
  border: none;
  font-family: 'Baloo 2', sans-serif;
  font-size: 1rem;
  padding: 12px 18px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
  transition: transform 0.1s ease;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,0.08); }
.btn.ghost { background: var(--paper); color: var(--ink); }
.btn.right { background: var(--green); color: #fff; }
.btn.wrong { background: #ffd0d2; color: var(--red); }

/* Toolbars & fields */
.view-toolbar { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 18px; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: 0.85rem; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.field select, .field input, textarea {
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  padding: 10px 12px;
  border: 2px solid #e7e3d8;
  border-radius: 12px;
  background: var(--paper);
  outline: none;
}
.field select:focus, .field input:focus, textarea:focus { border-color: var(--blue); }

/* Empty / done states */
.empty-state, .done-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-emoji, .done-emoji { font-size: 3.5rem; margin: 0; }
.done-state h2 { font-size: 2rem; color: var(--green-deep); margin: 8px 0; }
.done-state { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); }
.done-state .big-btn { margin-top: 16px; }

/* Flashcards */
.deck { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.deck-counter { font-weight: 800; color: var(--muted); }
.flashcard { width: 100%; max-width: 460px; height: 280px; perspective: 1200px; cursor: pointer; }
.flashcard-inner { position: relative; width: 100%; height: 100%; transition: transform 0.5s; transform-style: preserve-3d; }
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  box-shadow: var(--shadow);
  padding: 20px;
}
.flashcard-face.front { background: linear-gradient(160deg, #fff, #fff3d6); border: 4px solid var(--yellow); }
.flashcard-face.back { background: linear-gradient(160deg, #fff, #d9f5f1); border: 4px solid var(--green); transform: rotateY(180deg); }
.lang-tag { font-weight: 800; font-size: 0.8rem; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.word { font-family: 'Baloo 2', sans-serif; font-size: 2.4rem; text-align: center; margin: 0; line-height: 1.1; }
.flip-hint { position: absolute; bottom: 12px; font-size: 0.75rem; color: var(--muted); }
.speak-btn {
  border: none;
  background: rgba(0,0,0,0.05);
  font-size: 1.4rem;
  width: 52px; height: 52px;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.1s ease;
}
.speak-btn:hover { background: rgba(0,0,0,0.1); transform: scale(1.08); }
.speak-btn:active { transform: scale(0.95); }
.deck-actions { display: flex; gap: 14px; }
.deck-actions .btn { font-size: 1.1rem; padding: 14px 22px; }

/* Quiz */
.quiz { display: flex; flex-direction: column; gap: 18px; }
.quiz-top { display: flex; justify-content: space-between; align-items: center; }
.quiz-score { font-family: 'Baloo 2', sans-serif; font-size: 1.2rem; color: var(--purple); }
.quiz-prompt {
  background: linear-gradient(160deg, #fff, #efe6ff);
  border: 4px solid var(--purple);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 20px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.option {
  border: 3px solid #e7e3d8;
  background: var(--paper);
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.15rem;
  color: var(--ink);
  padding: 18px;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease, border-color 0.1s ease;
}
.option:hover:not(:disabled) { border-color: var(--blue); transform: translateY(-2px); }
.option:disabled { cursor: default; opacity: 0.95; }
.option.correct { border-color: var(--green); background: #d9f5f1; }
.option.incorrect { border-color: var(--red); background: #ffdfe0; }
.quiz-feedback { text-align: center; font-family: 'Baloo 2', sans-serif; font-size: 1.3rem; min-height: 28px; }
.quiz-feedback.good { color: var(--green-deep); }
.quiz-feedback.bad { color: var(--red); }

/* My Words */
.words-layout { display: grid; grid-template-columns: 320px 1fr; gap: 22px; align-items: start; }
.add-panel, .list-panel { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.add-panel h2, .list-panel h2 { font-size: 1.3rem; margin-bottom: 14px; }
.add-note { font-size: 0.9rem; color: var(--muted); margin: -6px 0 14px; }
.add-form { display: flex; flex-direction: column; gap: 12px; }
.form-msg { margin: 0; font-size: 0.9rem; min-height: 18px; font-weight: 700; }
.form-msg.ok { color: var(--green-deep); }
.form-msg.err { color: var(--red); }
.bulk { margin-top: 18px; border-top: 2px dashed #e7e3d8; padding-top: 14px; }
.bulk summary { cursor: pointer; font-weight: 800; font-family: 'Baloo 2', sans-serif; }
.bulk-hint { font-size: 0.82rem; color: var(--muted); }
.bulk-hint code { background: #f0eee8; padding: 1px 5px; border-radius: 6px; }
.bulk textarea { width: 100%; margin-bottom: 10px; resize: vertical; }

.list-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.word-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.word-row {
  display: flex; align-items: center; gap: 12px;
  background: #fdfbf6; border: 2px solid #efeadd; border-radius: 16px; padding: 12px 14px;
}
.word-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.row-speak { border: none; background: rgba(0,0,0,0.05); border-radius: 50%; width: 40px; height: 40px; font-size: 1.1rem; cursor: pointer; flex-shrink: 0; }
.row-speak:hover { background: rgba(0,0,0,0.1); }
.word-texts { display: flex; flex-direction: column; min-width: 0; }
.row-spanish { font-family: 'Baloo 2', sans-serif; font-size: 1.15rem; }
.row-english { color: var(--muted); font-size: 0.95rem; }
.word-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.row-category { font-size: 0.78rem; font-weight: 800; color: var(--blue); background: #e8f0ff; padding: 2px 8px; border-radius: 8px; }
.status-pill { font-size: 0.72rem; font-weight: 800; padding: 2px 8px; border-radius: 8px; text-transform: uppercase; }
.status-pill.new { background: #efe6ff; color: var(--purple); }
.status-pill.learning { background: #ffe9d6; color: var(--orange); }
.status-pill.learned { background: #d9f5f1; color: var(--green-deep); }
.word-row-actions { display: flex; gap: 6px; }
.icon-btn { border: none; background: transparent; font-size: 1.1rem; cursor: pointer; padding: 6px; border-radius: 8px; }
.icon-btn:hover { background: rgba(0,0,0,0.06); }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120px);
  background: var(--ink); color: #fff; padding: 14px 22px; border-radius: 14px;
  font-weight: 700; box-shadow: 0 10px 30px rgba(0,0,0,0.25); transition: transform 0.3s ease; z-index: 50;
}
.toast.show { transform: translateX(-50%) translateY(0); }

@media (max-width: 720px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .words-layout { grid-template-columns: 1fr; }
  .brand h1 { font-size: 1.3rem; }
  .word { font-size: 2rem; }
}

/* ---------- Auth / sign-in ---------- */
/* Hide the app until signed in; hide the auth screen once signed in. */
.app-header, main { display: none; }
body.signed-in .app-header { display: block; }
body.signed-in main { display: block; }
body.signed-in #auth-screen { display: none; }

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; }
.auth-brand .brand-emoji { font-size: 2rem; }
.auth-brand h1 { font-size: 1.7rem; color: var(--red); }
.auth-tagline { color: var(--muted); margin: 4px 0 20px; }
.auth-card .field { text-align: left; margin-bottom: 14px; }
.auth-card .big-btn { width: 100%; }
#auth-code { text-transform: uppercase; letter-spacing: 3px; font-size: 1.3rem; text-align: center; font-family: 'Baloo 2', monospace; }
.auth-switch { margin-top: 16px; color: var(--muted); font-size: 0.92rem; }

/* User chip in the header */
.user-chip { display: flex; align-items: center; gap: 10px; justify-content: flex-end; padding: 8px 0; }
.user-code {
  font-family: 'Baloo 2', monospace;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.05);
  padding: 4px 10px;
  border-radius: 10px;
  font-size: 0.9rem;
}
