/* ============================================================
   Mandarin Adventure — UI Styles
   ============================================================ */
:root {
  --red: #e0392b;
  --red-dark: #a81f16;
  --gold: #f5b942;
  --gold-dark: #d18b1c;
  --jade: #2fa874;
  --jade-dark: #1d7a52;
  --blue: #3b82f6;
  --ink: #241c1a;
  --paper: #fff8ec;
  --paper-2: #ffeed6;
  --shadow: 0 10px 30px rgba(60, 20, 10, 0.25);
  --radius: 18px;
  --font-hanzi: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-ui: "Baloo 2", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-ui);
  color: var(--ink);
  background: #12100f;
  -webkit-font-smoothing: antialiased;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

.hidden { display: none !important; }

/* ---------------- Screens ---------------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(245, 185, 66, 0.25), transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(224, 57, 43, 0.35), transparent 50%),
    linear-gradient(160deg, #6d1712 0%, #3b0d0a 55%, #200605 100%);
  overflow: auto;
}
.screen.active { display: flex; }

/* ---------------- Loader ---------------- */
.loader-box { text-align: center; color: var(--paper); }
.loader-hanzi {
  font-family: var(--font-hanzi);
  font-size: 96px;
  font-weight: 900;
  color: var(--gold);
  animation: pulse 1.2s ease-in-out infinite;
}
.loader-text { margin: 12px 0 18px; font-size: 20px; letter-spacing: 1px; }
.loader-bar {
  width: 260px; height: 12px; border-radius: 99px;
  background: rgba(255,255,255,0.2); overflow: hidden; margin: 0 auto;
}
#loader-fill {
  display: block; height: 100%; width: 10%;
  background: linear-gradient(90deg, var(--gold), #ffe08a);
  transition: width 0.4s ease;
}
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }

/* ---------------- Menu ---------------- */
.menu-card, .panel-card {
  background: var(--paper);
  border: 4px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 32px;
  width: min(560px, 94vw);
  animation: pop 0.35s cubic-bezier(.2,1.4,.4,1);
}
.panel-card.wide { width: min(920px, 96vw); }
@keyframes pop { from { transform: scale(0.9) translateY(14px); opacity: 0; } }

.menu-lanterns { display: flex; justify-content: center; gap: 14px; font-size: 34px; }
.mini-lantern { animation: swing 2.4s ease-in-out infinite; transform-origin: top center; display: inline-block; }
.mini-lantern:nth-child(2) { animation-delay: 0.4s; }
.mini-lantern:nth-child(3) { animation-delay: 0.8s; }
@keyframes swing { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }

.game-title {
  text-align: center;
  font-size: clamp(34px, 6vw, 54px);
  font-weight: 800;
  color: var(--red);
  text-shadow: 3px 3px 0 var(--gold);
  margin-top: 6px;
}
.game-subtitle {
  text-align: center;
  font-family: var(--font-hanzi);
  color: var(--jade-dark);
  font-weight: 700;
  font-size: 18px;
  margin-top: 4px;
}
.game-desc { text-align: center; color: #6b5b4f; margin: 12px 0 20px; font-size: 15px; }

.menu-buttons { display: grid; gap: 12px; }

.btn {
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 700;
  border: none;
  border-radius: 14px;
  padding: 13px 18px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s;
  color: #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,0.18);
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.06); }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: linear-gradient(180deg, var(--red), var(--red-dark)); }
.btn-secondary { background: linear-gradient(180deg, var(--jade), var(--jade-dark)); }
.btn-danger { background: linear-gradient(180deg, #ef4444, #b91c1c); }
.btn-ghost {
  background: transparent; color: var(--ink); box-shadow: none;
  font-size: 22px; padding: 4px 10px; line-height: 1;
}
.btn-speak {
  background: linear-gradient(180deg, var(--gold), var(--gold-dark));
  color: #4a2c00;
  font-size: 18px;
  padding: 10px 22px;
  margin-top: 10px;
}
.btn-speak.small { padding: 8px 14px; font-size: 16px; margin-top: 6px; }

.menu-progress {
  margin-top: 18px; font-size: 14px; color: #6b5b4f; text-align: center;
}
.menu-progress b { color: var(--red); }

/* ---------------- Panel head / foot ---------------- */
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
  border-bottom: 3px dashed rgba(0,0,0,0.12); padding-bottom: 10px;
}
.panel-head h2 { font-size: 24px; color: var(--red-dark); }
.panel-foot {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-top: 16px; flex-wrap: wrap;
}
.panel-foot.vertical { flex-direction: column; }
.panel-foot .btn { min-width: 160px; }
.counter { font-weight: 700; color: #6b5b4f; }

/* ---------------- Level grid ---------------- */
.level-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.level-card {
  border: 3px solid rgba(0,0,0,0.1);
  border-radius: 16px; padding: 16px; background: var(--paper-2);
  cursor: pointer; transition: transform 0.15s, border-color 0.15s;
  position: relative;
}
.level-card:hover { transform: translateY(-4px); border-color: var(--gold); }
.level-card.locked { opacity: 0.55; cursor: not-allowed; filter: grayscale(0.5); }
.level-card.current { border-color: var(--red); background: #fff3e9; }
.level-num { font-size: 13px; font-weight: 800; color: var(--jade-dark); letter-spacing: 1px; }
.level-name { font-size: 21px; font-weight: 800; margin: 4px 0; }
.level-desc { font-size: 14px; color: #6b5b4f; min-height: 40px; }
.level-status { margin-top: 10px; display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 700; }
.level-badge { font-size: 22px; }
.lock-tag { font-size: 12px; background: #cbd5e1; padding: 3px 8px; border-radius: 99px; color: #334155; }

/* ---------------- Guide / settings ---------------- */
.guide-body { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.guide-col h3 { color: var(--red-dark); margin: 12px 0 6px; font-size: 18px; }
.guide-col ul { padding-left: 20px; display: grid; gap: 6px; font-size: 15px; }
.tone-quick { display: grid; gap: 8px; font-size: 15px; }
.tone-dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; margin-right: 6px; }
.tone-dot.t1 { background: #ef4444; } .tone-dot.t2 { background: #f59e0b; }
.tone-dot.t3 { background: #22c55e; } .tone-dot.t4 { background: #3b82f6; }
.hint { font-size: 14px; color: #7a6a5e; margin-top: 10px; line-height: 1.5; }
.hint.center { text-align: center; }

.settings-body { display: grid; gap: 12px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--paper-2); padding: 12px 16px; border-radius: 12px;
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.setting-row input { width: 22px; height: 22px; accent-color: var(--red); cursor: pointer; }
.settings-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.settings-actions .btn { flex: 1; min-width: 150px; }

/* ---------------- HUD ---------------- */
#hud {
  position: fixed; inset: 0; z-index: 30; pointer-events: none;
  font-family: var(--font-ui);
}
#hud > * { pointer-events: auto; }
.hud-left, .hud-right {
  position: absolute; top: 14px; display: flex; gap: 8px;
}
.hud-left { left: 16px; }
.hud-right { right: 16px; }
.hud-chip {
  background: rgba(255, 248, 236, 0.94);
  border: 3px solid var(--gold);
  border-radius: 99px; padding: 7px 16px;
  font-weight: 800; font-size: 16px; display: flex; align-items: center; gap: 7px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.hud-chip.mini { font-size: 14px; padding: 4px 12px; border-width: 2px; }
.chip-icon { font-size: 16px; }
.hud-btn {
  width: 46px; height: 46px; border-radius: 50%;
  border: 3px solid var(--gold); background: rgba(255,248,236,0.94);
  font-size: 20px; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: transform 0.12s;
}
.hud-btn:hover { transform: scale(1.1); }
.hud-btn.off { filter: grayscale(1); opacity: 0.7; }

.hud-center {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  width: min(420px, 46vw);
}
.hud-level {
  background: rgba(255,248,236,0.94);
  border: 3px solid var(--gold); border-radius: 99px;
  padding: 6px 16px; display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.hud-level > span:first-child { white-space: nowrap; color: var(--red-dark); }
.progress-track {
  flex: 1; height: 10px; background: #e7dcc9; border-radius: 99px; overflow: hidden;
}
#hud-progress { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--jade), var(--gold)); transition: width 0.35s; }
#hud-progress-text { font-size: 13px; color: #6b5b4f; white-space: nowrap; }

#mission-box {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: rgba(36, 28, 26, 0.86); color: #ffe9b8;
  border: 2px solid var(--gold); border-radius: 99px;
  padding: 9px 20px; font-size: 15px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35); max-width: 90vw;
}
.mission-icon { font-size: 17px; }

#toast {
  position: absolute; left: 50%; top: 74px; transform: translateX(-50%);
  background: rgba(36,28,26,0.94); color: #fff; border-radius: 99px;
  padding: 10px 22px; font-weight: 700; font-size: 16px;
  border: 2px solid var(--gold); box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  animation: drop 0.3s ease; max-width: 90vw; text-align: center;
}
#toast.good { border-color: #4ade80; color: #bbf7d0; }
#toast.bad { border-color: #f87171; color: #fecaca; }
@keyframes drop { from { transform: translate(-50%, -14px); opacity: 0; } }

/* ---------------- Interact prompt ---------------- */
#interact-prompt {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%);
  z-index: 32; display: flex; align-items: center; gap: 10px;
  background: rgba(255,248,236,0.96); border: 3px solid var(--red);
  border-radius: 99px; padding: 8px 18px 8px 10px;
  font-weight: 800; font-size: 16px; box-shadow: var(--shadow);
  animation: bounce 1.4s ease-in-out infinite;
}
@keyframes bounce { 0%,100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -6px); } }
.key-cap {
  background: var(--red); color: #fff; border-radius: 8px;
  min-width: 30px; height: 30px; display: grid; place-items: center;
  font-size: 17px; box-shadow: 0 3px 0 var(--red-dark);
}

/* ---------------- Overlays ---------------- */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(20, 10, 8, 0.62); backdrop-filter: blur(3px);
  padding: 18px; overflow: auto;
}

/* ---------------- Study panel ---------------- */
.study-card { width: min(760px, 96vw); }
.study-nav { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-bottom: 14px; }
.study-nav button {
  border: 2px solid rgba(0,0,0,0.12); background: #fff; border-radius: 10px;
  padding: 5px 11px; font-size: 14px; font-weight: 700; cursor: pointer;
  font-family: var(--font-hanzi); color: var(--ink);
}
.study-nav button.active { background: var(--red); color: #fff; border-color: var(--red-dark); }
.study-main { display: grid; grid-template-columns: 1fr 1.1fr; gap: 18px; align-items: center; }
.hanzi-block {
  background: linear-gradient(160deg, #fff, var(--paper-2));
  border: 3px solid var(--gold); border-radius: 16px;
  padding: 18px; text-align: center;
}
.hanzi {
  font-family: var(--font-hanzi); font-size: 74px; font-weight: 900;
  color: var(--red-dark); line-height: 1.15; word-break: break-word;
}
.hanzi.small { font-size: 52px; }
.pinyin {
  font-size: 22px; font-weight: 700; color: var(--jade-dark); margin-top: 4px;
  font-family: var(--font-ui);
}
.study-info { display: grid; gap: 10px; }
.info-row {
  background: var(--paper-2); border-radius: 12px; padding: 10px 14px;
  border-left: 6px solid var(--jade);
}
.info-label { display: block; font-size: 12px; font-weight: 800; color: var(--jade-dark); letter-spacing: 1px; text-transform: uppercase; }
.info-value { font-size: 17px; font-weight: 600; }
.info-value:empty { display: none; }

/* ---------------- Tones ---------------- */
.tone-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tone-card {
  border-radius: 16px; padding: 14px; text-align: center; color: #fff;
  background: #64748b; box-shadow: inset 0 -6px 0 rgba(0,0,0,0.15);
}
.tone-card.t1 { background: linear-gradient(180deg, #ef4444, #b91c1c); }
.tone-card.t2 { background: linear-gradient(180deg, #f59e0b, #b45309); }
.tone-card.t3 { background: linear-gradient(180deg, #22c55e, #15803d); }
.tone-card.t4 { background: linear-gradient(180deg, #3b82f6, #1d4ed8); }
.tone-mark { font-size: 26px; font-weight: 900; line-height: 1; }
.tone-hanzi { font-family: var(--font-hanzi); font-size: 54px; font-weight: 900; line-height: 1.2; }
.tone-pinyin { font-size: 21px; font-weight: 800; }
.tone-mean { font-size: 15px; opacity: 0.92; }
.tone-desc { font-size: 12px; margin-top: 6px; background: rgba(0,0,0,0.22); border-radius: 99px; padding: 4px 6px; }

/* ---------------- Quiz ---------------- */
.quiz-card { width: min(680px, 96vw); }
.quiz-top { display: flex; align-items: center; gap: 8px; }
.quiz-dots { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
.quiz-dots i {
  width: 16px; height: 16px; border-radius: 50%; background: #e7dcc9;
  border: 2px solid #cbbda9; display: block;
}
.quiz-dots i.current { background: var(--gold); border-color: var(--gold-dark); transform: scale(1.2); }
.quiz-dots i.correct { background: var(--jade); border-color: var(--jade-dark); }
.quiz-dots i.wrong { background: #f87171; border-color: #dc2626; }

.quiz-prompt { font-size: 21px; font-weight: 800; text-align: center; margin-bottom: 6px; }
.quiz-word {
  background: var(--paper-2); border: 3px dashed var(--gold);
  border-radius: 16px; padding: 12px; text-align: center; margin-bottom: 14px;
}
.quiz-word:has(#quiz-hanzi:empty) { display: none; }
.quiz-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quiz-opt {
  font-family: var(--font-ui); font-size: 17px; font-weight: 700;
  padding: 14px 12px; border-radius: 14px; cursor: pointer;
  border: 3px solid #e2d6c3; background: #fff; color: var(--ink);
  transition: transform 0.1s, border-color 0.1s, background 0.1s;
  text-align: center;
}
.quiz-opt:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--gold); }
.quiz-opt.correct { background: #d1fae5; border-color: var(--jade); color: var(--jade-dark); animation: pop 0.3s; }
.quiz-opt.wrong { background: #fee2e2; border-color: #f87171; color: #b91c1c; animation: shake 0.3s; }
.quiz-opt:disabled { cursor: default; }
.quiz-opt.dim { opacity: 0.5; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-7px)} 75%{transform:translateX(7px)} }

.quiz-feedback {
  margin-top: 14px; padding: 12px 16px; border-radius: 14px;
  font-weight: 700; font-size: 16px; animation: drop 0.25s ease;
}
.quiz-feedback.good { background: #d1fae5; color: var(--jade-dark); border: 2px solid var(--jade); }
.quiz-feedback.bad { background: #fee2e2; color: #b91c1c; border: 2px solid #f87171; }
.quiz-feedback .expl { display: block; font-weight: 500; font-size: 15px; margin-top: 5px; color: #4b4038; }

/* ---------------- Activity ---------------- */
.activity-card { width: min(640px, 96vw); }
.activity-body { font-size: 17px; line-height: 1.55; }
.activity-goal {
  background: var(--paper-2); border-left: 6px solid var(--red);
  padding: 12px 14px; border-radius: 10px; font-weight: 700; margin-bottom: 12px;
}
.activity-hint { font-size: 15px; color: #6b5b4f; }
.scramble-box { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 14px 0; min-height: 54px;
  background: var(--paper-2); border: 3px dashed var(--gold); border-radius: 14px; padding: 10px; }
.scramble-bank { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 10px; }
.chip {
  font-family: var(--font-hanzi); font-size: 24px; font-weight: 700;
  padding: 8px 14px; border-radius: 12px; border: 3px solid #e2d6c3;
  background: #fff; cursor: pointer; transition: transform 0.1s;
}
.chip:hover { transform: translateY(-3px); border-color: var(--gold); }
.chip.used { opacity: 0.35; pointer-events: none; }
.chip.placed { background: var(--jade); color: #fff; border-color: var(--jade-dark); }
.color-swatch { display: inline-block; width: 20px; height: 20px; border-radius: 6px; vertical-align: -3px; margin-right: 6px; border: 2px solid rgba(0,0,0,0.2); }
.round-pill {
  display: inline-block; background: var(--red); color: #fff;
  border-radius: 99px; padding: 3px 12px; font-size: 14px; font-weight: 800;
}

/* ---------------- Pause ---------------- */
.pause-card { width: min(420px, 94vw); text-align: center; }
.pause-stats { display: grid; gap: 8px; margin-top: 6px; }
.pause-stats div {
  display: flex; justify-content: space-between; background: var(--paper-2);
  padding: 10px 16px; border-radius: 12px; font-size: 16px;
}
.pause-stats b { color: var(--red-dark); }

/* ---------------- Badge popup ---------------- */
#badge-pop {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center;
  background: rgba(20,10,8,0.55); animation: fade 0.3s ease;
}
@keyframes fade { from { opacity: 0; } }
.badge-inner {
  background: var(--paper); border: 5px solid var(--gold);
  border-radius: 24px; padding: 30px 44px; text-align: center;
  box-shadow: var(--shadow); animation: pop 0.45s cubic-bezier(.2,1.5,.4,1);
}
.badge-star { font-size: 78px; animation: pulse 1s ease-in-out infinite; }
#badge-text { font-size: 24px; font-weight: 800; color: var(--red-dark); margin-top: 8px; }

/* ---------------- Responsive ---------------- */
@media (max-width: 760px) {
  .guide-body, .study-main { grid-template-columns: 1fr; }
  .quiz-options { grid-template-columns: 1fr; }
  .hanzi { font-size: 56px; }
  .hud-center { width: min(320px, 60vw); top: 66px; }
  .menu-card, .panel-card { padding: 20px 18px; }
}
