:root {
  --bg: linear-gradient(180deg, #fffaf0 0%, #fff4d8 45%, #fde7d9 100%);
  --panel: rgba(255, 255, 255, 0.86);
  --panel-border: rgba(185, 96, 20, 0.16);
  --text: #2f1d15;
  --muted: #7a6658;
  --gold: #f3b63f;
  --peach: #ff8f6b;
  --jade: #67b99a;
  --berry: #b84d6d;
  --shadow: 0 18px 40px rgba(108, 54, 25, 0.12);
  --shadow-sm: 0 8px 18px rgba(108, 54, 25, 0.08);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --gap: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top left, rgba(255, 214, 102, 0.5), transparent 32%),
    radial-gradient(circle at bottom right, rgba(103, 185, 154, 0.28), transparent 32%);
  pointer-events: none;
}

h1, h2, h3, strong {
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
}

.hidden {
  display: none !important;
}

.app {
  position: relative;
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 24px;
}

/* App bar */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: rgba(255, 250, 240, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--panel-border);
}

.app-bar-back {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

.app-bar-trip {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.app-bar-trip strong {
  font-size: 1.02rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar-trip span {
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.app-bar-avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: linear-gradient(150deg, rgba(243, 182, 63, 0.35), rgba(255, 143, 107, 0.3));
  font-size: 1.2rem;
  flex-shrink: 0;
}

.app-bar-logout {
  width: auto;
  flex-shrink: 0;
  padding: 8px 12px;
  font-size: 0.76rem;
  font-weight: 700;
  border-radius: 999px;
  background: rgba(124, 88, 61, 0.08);
  color: var(--muted);
  box-shadow: none;
}

/* Screens */

main {
  padding: 20px 18px 90px;
}

.screen-center {
  display: grid;
  gap: var(--gap);
}

.intro-card {
  padding: 6px 4px 10px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.74rem;
  color: var(--berry);
  margin: 0 0 8px;
}

.intro-card h1 {
  margin: 0 0 8px;
  font-size: clamp(2.1rem, 9vw, 3.2rem);
  line-height: 1;
}

.intro-copy {
  max-width: 34rem;
  color: var(--muted);
  margin: 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 22px;
  backdrop-filter: blur(14px);
}

.card-title {
  margin: 0 0 14px;
  font-size: 1.1rem;
}

.stack {
  display: grid;
  gap: 12px;
}

label span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}

input,
select,
button {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(124, 88, 61, 0.18);
  padding: 13px 15px;
  font: inherit;
}

input,
select {
  background: rgba(255, 255, 255, 0.92);
}

button {
  cursor: pointer;
  background: linear-gradient(135deg, var(--peach), var(--gold));
  color: #411d06;
  font-weight: 800;
  transition: transform 160ms ease, box-shadow 160ms ease;
  box-shadow: var(--shadow-sm);
}

button:hover {
  transform: translateY(-1px);
}

button.secondary {
  background: linear-gradient(135deg, #e7f6ee, #bce2d0);
  color: #1f4e3b;
}

/* Avatar picker */

.avatar-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.avatar-picker input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.avatar-option {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.7);
  border: 2px solid transparent;
  font-size: 1.5rem;
  cursor: pointer;
  transition: border-color 140ms ease, transform 140ms ease;
}

.avatar-picker input:checked + .avatar-option {
  border-color: var(--peach);
  transform: translateY(-2px);
  background: rgba(255, 214, 179, 0.5);
}

/* Trip selection */

.your-trips {
  display: grid;
  gap: 10px;
}

.trip-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--panel-border);
  font-weight: 600;
}

.trip-option-name {
  font-size: 1rem;
}

.trip-option-meta {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 400;
}

/* Score strip */

.score-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  margin-bottom: 6px;
  border-radius: var(--radius-md);
  background: linear-gradient(160deg, rgba(243, 182, 63, 0.9), rgba(255, 143, 107, 0.84));
  color: #40220f;
  box-shadow: var(--shadow-sm);
}

.score-label {
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.68rem;
}

#heroPoints {
  font-size: 1.6rem;
}

#heroStatus {
  font-size: 0.86rem;
  max-width: 55%;
  text-align: right;
}

/* Tabs */

.tab-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
  padding: 6px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
}

.tab-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.86rem;
  padding: 10px 8px;
  border-radius: 999px;
  box-shadow: none;
}

.tab-button:hover {
  transform: none;
}

.tab-button.active {
  background: linear-gradient(135deg, var(--peach), var(--gold));
  color: #411d06;
  box-shadow: var(--shadow-sm);
}

.tab-icon {
  font-size: 1rem;
}

/* Filters */

.filter-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.filter select {
  padding: 10px 12px;
  font-size: 0.86rem;
}

.meta-strip {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0 14px;
}

/* Phrase cards */

.phrase-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}

.phrase-card {
  padding: 16px;
  display: grid;
  gap: 8px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(124, 88, 61, 0.12);
  box-shadow: var(--shadow-sm);
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.phrase-card.used {
  border-color: rgba(103, 185, 154, 0.45);
  background: rgba(236, 252, 244, 0.92);
  transform: translateY(-2px);
}

.phrase-topline {
  display: flex;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 700;
}

.chip.category {
  background: rgba(124, 88, 61, 0.1);
  color: var(--muted);
}

.chip.difficulty.level-1 {
  background: rgba(103, 185, 154, 0.18);
  color: #1a5b45;
}

.chip.difficulty.level-2 {
  background: rgba(243, 182, 63, 0.24);
  color: #7d490f;
}

.chip.difficulty.level-3 {
  background: rgba(184, 77, 109, 0.16);
  color: #8d2148;
}

.phrase-headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mandarin {
  margin: 0;
  font-size: 1.4rem;
}

.speak-button {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 999px;
  background: rgba(124, 88, 61, 0.1);
  color: var(--text);
  font-size: 1rem;
  padding: 0;
  box-shadow: none;
}

.pinyin {
  margin: 0;
  color: var(--berry);
  font-weight: 600;
}

.english {
  margin: 0;
  color: var(--muted);
}

.phrase-footline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.usage-note {
  font-size: 0.76rem;
  color: var(--muted);
  flex-shrink: 0;
}

.phrase-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.toggle-button {
  width: auto;
  padding: 10px 14px;
  font-size: 0.84rem;
}

.toggle-button.used {
  background: linear-gradient(135deg, #bde8d6, #67b99a);
  color: #173427;
}

.undo-button {
  width: auto;
  padding: 8px 10px;
  font-size: 0.72rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(124, 88, 61, 0.18);
  box-shadow: none;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

/* My progress */

.stats-grid {
  display: grid;
  gap: 10px;
}

.stat-summary {
  display: flex;
  gap: 24px;
  padding: 18px;
  border-radius: var(--radius-md);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-sm);
}

.stat-summary strong {
  display: block;
  font-size: 1.6rem;
}

.stat-summary span {
  font-size: 0.78rem;
  color: var(--muted);
}

.stat-heading {
  margin: 10px 0 2px;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-heading.section-heading-first {
  margin-top: 0;
}

.stat-heading.section-heading {
  margin: 22px 0 12px;
  font-size: 1rem;
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: none;
}

.stat-row {
  display: grid;
  grid-template-columns: 96px 1fr 48px;
  align-items: center;
  gap: 10px;
  font-size: 0.84rem;
}

.stat-row-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-row-value {
  text-align: right;
  color: var(--muted);
}

.stat-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(124, 88, 61, 0.12);
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--jade), var(--gold));
}

.stat-row.goal-met .stat-bar-fill {
  background: linear-gradient(90deg, var(--gold), var(--peach));
}

.goal-note {
  margin: 2px 0 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Team leaderboard */

.leaderboard {
  display: grid;
  gap: 12px;
}

.leaderboard-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(124, 88, 61, 0.12);
  box-shadow: var(--shadow-sm);
}

.leaderboard-card.is-me {
  border-color: rgba(255, 143, 107, 0.5);
  background: rgba(255, 244, 232, 0.95);
}

.rank-pill {
  height: 44px;
  width: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(243, 182, 63, 0.22), rgba(255, 143, 107, 0.2));
  font-weight: 800;
  font-size: 1.1rem;
}

.leader-body {
  display: grid;
  gap: 4px;
}

.leader-name {
  font-weight: 800;
}

.leader-meta {
  color: var(--muted);
  font-size: 0.86rem;
}

.leader-score {
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
}

@media (min-width: 640px) {
  .app-bar,
  main {
    padding-left: 28px;
    padding-right: 28px;
  }
}

/* First-completion celebration */

.celebration-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 50;
}

.confetti-piece {
  position: absolute;
  bottom: -10vh;
  transform: translate3d(0, 0, 0);
  animation-name: confetti-rise;
  animation-timing-function: cubic-bezier(0.25, 0.6, 0.4, 1);
  animation-fill-mode: forwards;
  white-space: nowrap;
  will-change: transform, opacity;
}

.confetti-emoji {
  font-size: 1.7rem;
}

.confetti-char {
  font-size: 2.1rem;
  font-weight: 800;
  text-shadow: 0 2px 10px rgba(108, 54, 25, 0.2);
}

.confetti-word {
  font-size: 0.92rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: var(--shadow-sm);
}

.team-goal-banner {
  position: fixed;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  max-width: min(88vw, 420px);
  text-align: center;
  padding: 14px 22px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, rgba(243, 182, 63, 0.95), rgba(255, 143, 107, 0.95));
  color: #3a2210;
  font-weight: 800;
  font-size: 1.02rem;
  box-shadow: var(--shadow);
  animation: team-goal-banner-pop 5s ease forwards;
}

@keyframes team-goal-banner-pop {
  0% {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px) scale(0.92);
  }
  10% {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
  85% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateX(-50%) translateY(-6px) scale(0.98);
  }
}

@keyframes confetti-rise {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg);
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  75% {
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--drift, 0px), -115vh, 0) rotate(var(--rotate, 0deg));
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .confetti-piece {
    animation: none;
    display: none;
  }
}
