/* Word Quest — light, playful, focused */
:root {
  --bg: #f6f1e8;
  --bg-2: #fffdf8;
  --ink: #1f2a24;
  --muted: #5c6b62;
  --line: #e2d8c8;
  --card: #ffffff;
  --shadow: 0 10px 30px rgba(45, 60, 50, 0.08);
  --shadow-lg: 0 18px 50px rgba(45, 60, 50, 0.12);

  --green: #2f9e6b;
  --green-soft: #e7f7ef;
  --orange: #e8873a;
  --orange-soft: #fff1e4;
  --blue: #3b7ddd;
  --blue-soft: #eaf2ff;
  --red: #e25555;
  --red-soft: #fdecec;
  --purple: #7b5cff;
  --purple-soft: #f0ecff;
  --gold: #d4a017;
  --gold-soft: #fff7df;

  --radius: 18px;
  --radius-sm: 12px;
  --font: "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    system-ui, sans-serif;
  --mono: "SF Mono", "Menlo", "Consolas", monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, #fff7e8 0%, transparent 40%),
    radial-gradient(circle at 90% 0%, #eaf8f0 0%, transparent 35%),
    radial-gradient(circle at 80% 90%, #eef2ff 0%, transparent 40%),
    var(--bg);
}

body {
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px calc(28px + var(--safe-bottom));
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #39c27b, #2a8f60);
  color: white;
  font-size: 22px;
  box-shadow: 0 8px 18px rgba(47, 158, 107, 0.28);
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.stats-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.pill span {
  color: var(--muted);
  font-weight: 500;
}

.pill.xp {
  background: var(--gold-soft);
  border-color: #f0dc9a;
}
.pill.streak {
  background: var(--orange-soft);
  border-color: #f5d0ad;
}
.pill.mastered {
  background: var(--green-soft);
  border-color: #bfe8d2;
}

/* Screens */
.screen {
  display: none;
  animation: fadeIn 0.28s ease;
}
.screen.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.card + .card {
  margin-top: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 12px;
  font-size: 1rem;
}

.section-title small {
  color: var(--muted);
  font-weight: 500;
}

/* Progress rings row */
.progress-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.progress-item {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
}

.progress-item .num {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.1;
}

.progress-item .label {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 4px;
}

.progress-item.unknown .num {
  color: var(--red);
}
.progress-item.learning .num {
  color: var(--orange);
}
.progress-item.known .num {
  color: var(--blue);
}
.progress-item.done .num {
  color: var(--green);
}

.bar-track {
  height: 10px;
  background: #efe7da;
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 4px;
}

.bar-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #49c484, #2f9e6b 55%, #2a7fd4);
  transition: width 0.4s ease;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.8rem;
}

/* Mode grid */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 720px) {
  .mode-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.mode-btn {
  text-align: left;
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s;
  min-height: 118px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mode-btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.mode-btn:active {
  transform: translateY(0);
}

.mode-btn .icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  margin-bottom: 4px;
}

.mode-btn h3 {
  margin: 0;
  font-size: 1rem;
}

.mode-btn p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.mode-btn.flash .icon {
  background: var(--green-soft);
}
.mode-btn.quiz .icon {
  background: var(--blue-soft);
}
.mode-btn.spell .icon {
  background: var(--purple-soft);
}
.mode-btn.grammar .icon {
  background: var(--orange-soft);
}
.mode-btn.verb .icon {
  background: #e8f7ff;
}
.mode-btn.focus .icon {
  background: var(--red-soft);
}
.mode-btn.family .icon {
  background: var(--gold-soft);
}
.mode-btn.browse .icon {
  background: #f3f0ea;
}

/* Filters */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  transition: 0.15s ease;
}

.chip.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.chip:hover {
  border-color: #cbbfaa;
}

/* Play header */
.play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--line);
  font-weight: 600;
  color: var(--muted);
}

.back-btn:hover {
  color: var(--ink);
}

.play-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--bg-2);
  border: 1px solid var(--line);
}

.badge.combo {
  background: var(--orange-soft);
  border-color: #f0c49a;
  color: #b35a12;
}

/* Flashcard */
.flash-stage {
  perspective: 1200px;
  min-height: 300px;
  display: grid;
  place-items: center;
}

.flash-card {
  width: min(100%, 420px);
  min-height: 280px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
  cursor: pointer;
}

.flash-card.flipped {
  transform: rotateY(180deg);
}

.flash-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #fbf8f2 100%);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  text-align: center;
  gap: 10px;
}

.flash-face .speak-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
}

.flash-face.back {
  transform: rotateY(180deg);
  background: linear-gradient(180deg, #f3fff8 0%, #ffffff 55%);
}

.flash-face .pos {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 999px;
}

.flash-face .en {
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 800;
  letter-spacing: 0.01em;
  word-break: break-word;
}

.flash-face .zh {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--green);
}

.flash-face .tip {
  color: var(--muted);
  font-size: 0.92rem;
  max-width: 28ch;
}

.flash-face .hint {
  position: absolute;
  bottom: 14px;
  color: var(--muted);
  font-size: 0.78rem;
}

.flash-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.action-btn {
  padding: 14px 10px;
  border-radius: 14px;
  font-weight: 700;
  border: 1px solid transparent;
  transition: transform 0.12s ease, opacity 0.12s;
}

.action-btn:active {
  transform: scale(0.97);
}

.action-btn.hard {
  background: var(--red-soft);
  color: #b83333;
  border-color: #f2c4c4;
}
.action-btn.flip {
  background: var(--blue-soft);
  color: #2459b0;
  border-color: #c5d8f8;
}
.action-btn.easy {
  background: var(--green-soft);
  color: #1f7a52;
  border-color: #b6e5cd;
}

/* Quiz */
.quiz-progress {
  height: 8px;
  background: #efe7da;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 16px;
}

.quiz-progress > div {
  height: 100%;
  background: linear-gradient(90deg, #49c484, #3b7ddd);
  width: 0%;
  transition: width 0.3s ease;
}

.question-box {
  position: relative;
  text-align: center;
  margin-bottom: 18px;
}

.question-box .q-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.question-box .q-main {
  font-size: clamp(1.4rem, 4vw, 1.9rem);
  font-weight: 800;
}

.question-box .q-sub {
  margin-top: 6px;
  color: var(--muted);
}

.options {
  display: grid;
  gap: 10px;
}

.option-btn {
  text-align: left;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--card);
  font-weight: 600;
  transition: 0.15s ease;
}

.option-btn:hover:not(:disabled) {
  border-color: #b7c9ff;
  background: #f7faff;
}

.option-btn.correct {
  border-color: var(--green);
  background: var(--green-soft);
  color: #176644;
}

.option-btn.wrong {
  border-color: var(--red);
  background: var(--red-soft);
  color: #a12f2f;
}

.option-btn:disabled {
  cursor: default;
}

.feedback {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  display: none;
  font-size: 0.92rem;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.feedback.show {
  display: flex;
}

.feedback.ok {
  background: var(--green-soft);
  color: #176644;
}
.feedback.bad {
  background: var(--red-soft);
  color: #a12f2f;
}

/* Spelling */
.spell-input-row {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.spell-input-row input {
  flex: 1;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: white;
  font-size: 1.1rem;
  outline: none;
}

.spell-input-row input:focus {
  border-color: #8eb0f0;
  box-shadow: 0 0 0 4px rgba(59, 125, 221, 0.12);
}

.primary-btn,
.secondary-btn {
  padding: 12px 18px;
  border-radius: 12px;
  font-weight: 700;
}

.primary-btn {
  background: linear-gradient(145deg, #3ec97f, #2f9e6b);
  color: white;
  box-shadow: 0 8px 18px rgba(47, 158, 107, 0.25);
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.secondary-btn {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--ink);
}

.hint-btn {
  margin-top: 10px;
  color: var(--blue);
  font-weight: 600;
  font-size: 0.9rem;
}

/* Result panel */
.result-panel {
  text-align: center;
  padding: 28px 16px;
}

.result-panel .emoji {
  font-size: 3rem;
  margin-bottom: 8px;
}

.result-panel h2 {
  margin: 0 0 8px;
}

.result-panel p {
  color: var(--muted);
  margin: 0 0 18px;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.result-stats .cell {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 8px;
}

.result-stats .cell b {
  display: block;
  font-size: 1.3rem;
}

.result-stats .cell span {
  color: var(--muted);
  font-size: 0.78rem;
}

/* Browse list */
.browse-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.browse-tools input {
  flex: 1;
  min-width: 180px;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: white;
  outline: none;
}

.word-list {
  display: grid;
  gap: 8px;
  max-height: 62vh;
  overflow: auto;
  padding-right: 2px;
}

.word-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
}

.word-row .en {
  font-weight: 700;
}
.word-row .zh {
  color: var(--muted);
  font-size: 0.9rem;
}
.word-row .meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tag {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
}

.tag.lv0 {
  background: var(--red-soft);
  color: #b83333;
}
.tag.lv1 {
  background: var(--orange-soft);
  color: #b35a12;
}
.tag.lv2 {
  background: var(--blue-soft);
  color: #2459b0;
}
.tag.lv3 {
  background: var(--green-soft);
  color: #1f7a52;
}

/* Family cards */
.family-grid {
  display: grid;
  gap: 12px;
}

.family-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: linear-gradient(180deg, #fff 0%, #fbf8f2 100%);
}

.family-card h4 {
  margin: 0 0 6px;
}
.family-card .tip {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.family-words {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.family-words span,
.family-words .family-word-chip {
  background: var(--purple-soft);
  color: #4a34b0;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.88rem;
}

.family-word-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  position: relative;
  padding-right: 8px;
}

.family-word-chip .speak-btn {
  opacity: 0.55;
  width: 24px;
  height: 24px;
}

.family-word-chip .speak-btn .speak-icon {
  font-size: 0.7rem;
}

/* Multi sense table */
.sense-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.sense-table th,
.sense-table td {
  border: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}
.sense-table th {
  background: var(--bg-2);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: white;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: 0.25s ease;
  z-index: 50;
  max-width: 90vw;
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Confetti bits */
.confetti-layer {
  pointer-events: none;
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 40;
}

.confetti-bit {
  position: absolute;
  width: 8px;
  height: 12px;
  top: -20px;
  border-radius: 2px;
  animation: fall 1.1s ease-in forwards;
}

@keyframes fall {
  to {
    transform: translateY(100vh) rotate(480deg);
    opacity: 0.2;
  }
}

/* Shake */
.shake {
  animation: shake 0.35s ease;
}
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

/* Empty */
.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
}

/* Footer note */
.footer-note {
  margin-top: 18px;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}

/* Settings row */
.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.danger-btn {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid #f2c4c4;
  background: var(--red-soft);
  color: #a12f2f;
  font-weight: 600;
  font-size: 0.82rem;
}

/* Keyboard shortcut hint */
.kbd-hint {
  margin-top: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.78rem;
}
.kbd-hint kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: white;
  font-family: var(--mono);
  font-size: 0.75rem;
}

/* Speak button — corner accessory, not the star */
.speak-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #d5deec;
  background: rgba(255, 255, 255, 0.88);
  color: #6b7f9c;
  box-shadow: 0 1px 4px rgba(45, 60, 50, 0.06);
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease,
    border-color 0.15s ease;
  flex-shrink: 0;
  line-height: 1;
  padding: 0;
  opacity: 0.72;
}

.speak-btn:hover {
  opacity: 1;
  transform: scale(1.05);
  color: #2459b0;
  border-color: #b7c9e8;
  background: #f4f8ff;
}

.speak-btn:active {
  transform: scale(0.96);
}

.speak-btn.playing {
  opacity: 1;
  background: #3b7ddd;
  border-color: #3b7ddd;
  color: white;
  animation: pulse-speak 1s ease infinite;
}

.speak-btn .speak-icon {
  font-size: 0.85rem;
}

.speak-btn.sm {
  width: 28px;
  height: 28px;
  opacity: 0.65;
}

.speak-btn.sm .speak-icon {
  font-size: 0.78rem;
}

.speak-btn.lg {
  width: 36px;
  height: 36px;
}

.speak-btn.lg .speak-icon {
  font-size: 0.95rem;
}

@keyframes pulse-speak {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(59, 125, 221, 0.35);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(59, 125, 221, 0);
  }
}

/* Question area: speaker tucked top-right */
.question-box > .speak-btn {
  position: absolute;
  top: 0;
  right: 0;
}

.en-with-speak {
  display: block;
  text-align: center;
}

.en-with-speak .en-text {
  font-size: inherit;
  font-weight: inherit;
}

.word-row {
  position: relative;
}

.word-row .speak-btn {
  position: absolute;
  top: 10px;
  right: 10px;
}

.word-row .meta {
  padding-right: 28px;
}

.voice-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-2);
}

.voice-toggle button {
  padding: 6px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}

.voice-toggle button.active {
  background: var(--ink);
  color: white;
}

/* Mobile */
@media (max-width: 560px) {
  .progress-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .mode-grid {
    grid-template-columns: 1fr;
  }
  .flash-actions {
    grid-template-columns: 1fr;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
  .stats-pills {
    width: 100%;
    justify-content: flex-start;
  }
}
