:root {
  --parchment: #fbf0d4;
  --paper: #fffaf0;
  --ink: #20304f;
  --muted: #6b7895;
  --gold: #f3a626;
  --gold-deep: #b96f08;
  --leaf: #2fb69d;
  --leaf-deep: #197c6e;
  --rose: #ff6f59;
  --violet: #7457e8;
  --line: #e5cf9c;
  --locked: #d8d8d8;
  --shadow: 0 18px 45px rgba(48, 37, 18, 0.16);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Nunito", sans-serif;
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 111, 89, 0.16), transparent 32rem),
    radial-gradient(circle at 88% 4%, rgba(47, 182, 157, 0.18), transparent 28rem),
    linear-gradient(135deg, #fff8e8 0%, var(--parchment) 45%, #f4dfb5 100%);
}

button, input, textarea { font: inherit; }

.hidden { display: none !important; }

/* ============ Overlays (auth / pending / popup) ============ */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(32, 48, 79, 0.55);
  backdrop-filter: blur(3px);
}

.overlay-card {
  width: min(440px, 100%);
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 28px;
  text-align: center;
}

.overlay-card h2 {
  font-family: "Baloo 2", sans-serif;
  margin: 6px 0 10px;
  font-size: 1.7rem;
}

.auth-form {
  display: grid;
  gap: 14px;
  text-align: left;
  margin-top: 16px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.error-text {
  color: var(--rose);
  font-weight: 800;
  font-size: 0.88rem;
  min-height: 18px;
}

.popup-overlay .overlay-card { text-align: center; }
.popup-card {
  border-color: var(--violet);
}
.popup-avatar {
  width: 56px;
  height: 56px;
  margin: 0 auto 10px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--violet), #a88dff);
  font-size: 1.7rem;
}
.popup-card b {
  display: block;
  font-family: "Baloo 2", sans-serif;
  font-size: 1.1rem;
  margin-bottom: 8px;
}
.popup-card p {
  color: #3d4b68;
  font-weight: 700;
  line-height: 1.6;
  margin-bottom: 18px;
}

/* ============ Shell / hero ============ */

.app-shell {
  width: min(1040px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 72px;
}

.hero { text-align: center; padding: 26px 12px 18px; }

.eyebrow, .section-kicker {
  margin: 0 0 10px;
  color: var(--gold-deep);
  font-family: "Press Start 2P", monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2, h3 { font-family: "Baloo 2", sans-serif; line-height: 1.05; }
h1 { margin: 0; font-size: clamp(2.4rem, 8vw, 5.8rem); }
h2 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.5rem); }
h3 { margin: 10px 0; font-size: 1.45rem; }

.hero-copy, .muted { color: var(--muted); font-weight: 700; }

.card, .stat-card, .party-card, .quest-card {
  background: rgba(255, 250, 240, 0.92);
  border: 2px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

label { display: grid; gap: 7px; color: var(--muted); font-size: 0.92rem; font-weight: 800; }

input, textarea {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
  outline: none;
}
input:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(243, 166, 38, 0.18);
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
  font-weight: 900;
  color: var(--ink);
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(32, 48, 79, 0.15); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(135deg, var(--gold), #ffd46d); }
.btn.secondary { background: linear-gradient(135deg, var(--leaf), #8becd9); }
.btn.ghost { background: #ececec; color: #5f6675; }
.btn.dark { background: var(--ink); color: #fff; }

/* ============ Dashboard / level bar ============ */

.dashboard {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  position: sticky;
  top: 10px;
  z-index: 5;
  margin: 18px 0;
}
.stat-card { padding: 14px 16px; }
.stat-card span {
  display: block; color: var(--muted); font-size: 0.78rem; font-weight: 900; text-transform: uppercase;
}
.stat-card strong {
  display: block; margin-top: 4px; font-family: "Baloo 2", sans-serif; font-size: 1.45rem;
}
.level-bar {
  margin-top: 8px; height: 10px; border-radius: 8px; background: #ece2c4; overflow: hidden;
}
.level-bar-fill {
  height: 100%; width: 0%; background: linear-gradient(90deg, var(--gold), var(--rose)); transition: width .35s ease;
}

/* ============ Party ============ */

.party { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 18px 0; }
.party-card { display: flex; align-items: center; gap: 12px; padding: 16px; }
.avatar {
  display: grid; width: 48px; height: 48px; place-items: center; border-radius: 16px;
  background: linear-gradient(135deg, var(--violet), #a88dff); color: #fff; font-size: 1.35rem;
}
.party-card.player .avatar { background: linear-gradient(135deg, var(--rose), var(--gold)); }
.party-card span { display: block; color: var(--muted); font-size: 0.86rem; font-weight: 800; }

/* ============ Story / quests ============ */

.story-card, .feedback, .admin { padding: 24px; margin-top: 22px; }
.story-copy { display: grid; gap: 14px; margin-top: 14px; color: #3d4b68; font-size: 1.06rem; font-weight: 700; line-height: 1.8; }
.story-copy p { margin: 0; }

.quests { display: grid; gap: 16px; margin-top: 22px; }
.quest-card { padding: 20px; }
.quest-card.resolved { border-color: var(--leaf); background: rgba(240, 250, 247, 0.9); }
.quest-card.resolved.decimal { border-color: var(--locked); background: rgba(250, 250, 250, 0.94); }
.quest-card.active { border-color: var(--gold); }
.quest-card.victory { text-align: center; border-color: var(--gold); background: linear-gradient(135deg, #fff8e0, #ffe9c2); }

.quest-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.quest-label, .xp-pill {
  display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 10px;
  font-family: "Press Start 2P", monospace; font-size: 8px;
}
.quest-label { color: #fff; background: var(--violet); }
.xp-pill { color: var(--gold-deep); background: #fff2c6; border: 1px solid var(--gold); }

.quest-story { color: #3d4b68; font-size: 1.02rem; font-weight: 750; line-height: 1.7; }
.chinese-line {
  margin: 12px 0; border-left: 5px solid var(--gold); border-radius: 12px; padding: 12px 14px;
  color: #69480a; background: #fff3d3; font-weight: 900;
}
.answer-field { margin-top: 12px; }
.quest-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.wrong-note { color: var(--rose); font-weight: 900; font-size: 0.9rem; }
.review-note { min-height: 22px; margin: 14px 0 0; color: var(--leaf-deep); font-weight: 900; }

/* ============ Admin ============ */

.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.admin-login { display: flex; gap: 10px; align-items: center; }
.admin-login input { min-width: 180px; }
.admin-panel { display: grid; gap: 16px; margin-top: 18px; }

.admin-pending-list { display: grid; gap: 8px; }
.admin-pending-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border-radius: 14px; background: #fff3d3; border: 1px solid var(--gold);
  font-weight: 800; flex-wrap: wrap;
}
.admin-pending-actions { display: flex; gap: 8px; }

.admin-student { padding: 16px; border: 2px solid #dfe2e8; border-radius: 18px; background: #f7f7f7; }
.admin-student h3 { margin-top: 0; }
.review-grid { display: grid; gap: 10px; }
.review-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  padding: 10px; border-radius: 14px; background: #fff;
}
.review-row .half { color: #888; font-size: 0.8rem; font-weight: 900; }
.bonus-controls { display: flex; gap: 6px; align-items: center; }
.bonus-controls input { padding: 6px 8px; border-radius: 8px; }

.feedback-list { display: grid; gap: 8px; padding-left: 18px; }
.logout-btn { display: block; margin: 30px auto 0; }

/* ============ Music mute button ============ */

.mute-btn {
  position: fixed; bottom: 18px; right: 18px; z-index: 40;
  width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--line);
  background: var(--paper); font-size: 1.2rem; cursor: pointer; box-shadow: var(--shadow);
}

@media (max-width: 760px) {
  .app-shell { width: min(100% - 22px, 1040px); padding-top: 18px; }
  .party, .dashboard { grid-template-columns: 1fr; }
  .dashboard { position: static; }
  .admin-head, .admin-login { align-items: stretch; flex-direction: column; }
  .btn { width: 100%; }
  .review-row { grid-template-columns: 1fr; }
}
