/* ============ DG Treasure Hunt styles ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --dg-blue: #2b3f8c;
  --dg-blue-light: #4a63c4;
  --dg-gold: #ffd35c;
  --dg-pink: #ff8fb6;
  --card-bg: rgba(255, 255, 255, 0.95);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
  background: #0d1030;
  touch-action: none;
  user-select: none;
}

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

.hidden { display: none !important; }

/* ============ overlays ============ */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(13, 16, 48, 0.72);
  backdrop-filter: blur(6px);
  padding: 16px;
  overflow-y: auto;
}

/* ============ start screen ============ */
.start-card {
  width: min(540px, 94vw);
  max-height: 94vh;
  overflow-y: auto;
  background: var(--card-bg);
  border-radius: 26px;
  padding: 28px 30px;
  text-align: center;
  box-shadow: 0 20px 70px rgba(0,0,0,.55), 0 0 0 4px var(--dg-gold), 0 0 0 8px var(--dg-blue);
  animation: pop-in .45s cubic-bezier(.2,1.6,.4,1);
}
@keyframes pop-in { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.logo-badge {
  width: 74px; height: 74px; margin: 0 auto 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, var(--dg-blue-light), var(--dg-blue));
  color: #fff; font-size: 30px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  border: 4px solid var(--dg-gold);
  box-shadow: 0 6px 18px rgba(43,63,140,.45);
}
.start-card h1 { font-size: clamp(26px, 5vw, 38px); color: var(--dg-blue); letter-spacing: 4px; }
.start-card h2 { font-size: 15px; color: #8a8fb5; font-weight: 600; margin-bottom: 14px; }
.intro-text { font-size: 14px; line-height: 1.7; color: #444; margin-bottom: 18px; }
.intro-text b { color: var(--dg-blue); }

.name-entry { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.name-entry label { font-size: 13px; color: #666; font-weight: 600; }
.name-entry input {
  height: 52px; border-radius: 14px;
  border: 3px solid var(--dg-blue-light);
  font-size: 20px; text-align: center; font-weight: 700; color: var(--dg-blue);
  outline: none; background: #f4f6ff;
}
.name-entry input:focus { border-color: var(--dg-gold); box-shadow: 0 0 0 4px rgba(255,211,92,.35); }

#difficulty-row { display: flex; gap: 8px; }
.diff-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 4px;
  border: 3px solid #d6daf0; border-radius: 13px;
  background: #f6f7ff;
  font-size: 14.5px; font-weight: 800; color: #444;
  cursor: pointer;
  transition: all .15s;
}
.diff-btn small { font-size: 10.5px; font-weight: 600; color: #999; }
.diff-btn:hover { border-color: var(--dg-blue-light); }
.diff-btn.selected {
  border-color: var(--dg-blue);
  background: #e8edff;
  color: var(--dg-blue);
  box-shadow: 0 0 0 3px rgba(74,99,196,.25);
}

.big-btn {
  height: 56px; border: none; border-radius: 16px;
  background: linear-gradient(180deg, #ffde7a, var(--dg-gold) 55%, #f0b73c);
  color: #5b3d00; font-size: 19px; font-weight: 800; letter-spacing: 2px;
  cursor: pointer;
  box-shadow: 0 5px 0 #c8922a, 0 10px 22px rgba(0,0,0,.25);
  transition: transform .12s, box-shadow .12s, filter .2s;
}
.big-btn:hover:not(:disabled) { transform: translateY(-2px); }
.big-btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #c8922a; }
.big-btn:disabled { filter: grayscale(.8); opacity: .6; cursor: not-allowed; }

.start-leaderboard { background: #f1f3fc; border-radius: 16px; padding: 12px 18px; margin-bottom: 12px; }
.start-leaderboard h3 { font-size: 15px; color: var(--dg-blue); margin-bottom: 8px; }
.start-leaderboard ol { list-style: none; }
.start-leaderboard li {
  display: flex; justify-content: space-between;
  font-size: 14px; padding: 4px 6px; color: #333;
  border-bottom: 1px dashed #d6daf0;
}
.start-leaderboard li:last-child { border-bottom: none; }
.start-leaderboard li .lb-rank { font-weight: 800; color: var(--dg-blue); width: 30px; }
.start-leaderboard li .lb-name { flex: 1; text-align: left; font-weight: 600; }
.start-leaderboard li .lb-score { font-weight: 800; color: #b8860b; }
.start-leaderboard .lb-empty { justify-content: center; color: #999; }

.controls-hint { font-size: 11.5px; color: #9aa0c5; }

/* ============ HUD ============ */
#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#hud-top-left {
  position: absolute; top: 12px; left: 12px;
  display: flex; flex-direction: column; gap: 7px; align-items: flex-start;
}
.hud-pill {
  background: rgba(20, 24, 66, .82);
  border: 2px solid rgba(255, 211, 92, .8);
  color: #fff; font-size: 15px; font-weight: 700;
  padding: 7px 16px; border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
}
.hud-pill.small { font-size: 13px; padding: 5px 13px; }
#hud-name { border-color: var(--dg-pink); }
button.hud-pill { pointer-events: auto; cursor: pointer; font-family: inherit; }
button.hud-pill:active { transform: scale(.94); }
#time-row { display: flex; gap: 8px; margin: 4px 0 10px; }
#time-row .time-btn { flex: 1; }

#minimap {
  position: absolute; top: 12px; right: 12px;
  border-radius: 16px;
  border: 3px solid rgba(255, 211, 92, .9);
  background: rgba(15, 18, 52, .85);
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

#interact-prompt {
  position: absolute; bottom: 26vh; left: 50%; transform: translateX(-50%);
  background: rgba(20, 24, 66, .9);
  border: 2px solid var(--dg-gold);
  color: #fff; font-size: 17px; font-weight: 700;
  padding: 10px 22px; border-radius: 14px;
  animation: bounce-soft 1s infinite ease-in-out;
}
@keyframes bounce-soft { 0%,100% { transform: translateX(-50%) translateY(0); } 50% { transform: translateX(-50%) translateY(-7px); } }
.key-cap {
  display: inline-block; background: var(--dg-gold); color: #5b3d00;
  border-radius: 7px; padding: 2px 10px; margin-right: 6px;
  font-weight: 900; box-shadow: 0 2px 0 #c8922a;
}

#toast {
  position: absolute; top: 18vh; left: 50%; transform: translateX(-50%);
  background: rgba(255, 211, 92, .96); color: #5b3d00;
  font-size: 18px; font-weight: 800;
  padding: 12px 26px; border-radius: 999px;
  box-shadow: 0 8px 26px rgba(0,0,0,.4);
  animation: toast-in .3s ease-out;
  white-space: nowrap;
}
@keyframes toast-in { from { transform: translateX(-50%) scale(.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }

/* mobile controls */
/* floating joystick: touch ANYWHERE on the lower half (left or
   right) and the stick appears under your thumb */
#joystick-zone {
  position: absolute; left: 0; bottom: 0;
  width: 100vw; height: 48vh;
  pointer-events: auto;
  display: none;
  touch-action: none;
}
#joystick-base {
  position: absolute; left: 60px; bottom: 60px;
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,.12);
  border: 3px solid rgba(255,255,255,.35);
  display: none;
}
#joystick-knob {
  position: absolute; left: 50%; top: 50%;
  width: 56px; height: 56px; border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 30%, #ffe9a8, var(--dg-gold));
  box-shadow: 0 4px 12px rgba(0,0,0,.4);
}
#action-btn {
  position: absolute; right: 36px; bottom: 64px;
  width: 86px; height: 86px; border-radius: 50%;
  border: 4px solid #fff;
  background: radial-gradient(circle at 35% 30%, #ffb3cd, var(--dg-pink));
  font-size: 36px;
  pointer-events: auto;
  box-shadow: 0 6px 20px rgba(0,0,0,.45);
  z-index: 5;            /* stays above the joystick zone */
  touch-action: none;
}
#action-btn:active { transform: scale(.92); }
body.touch-device #joystick-zone { display: block; }

/* ============ quiz ============ */
.quiz-card {
  width: min(560px, 95vw);
  background: var(--card-bg);
  border-radius: 24px;
  padding: 24px 26px;
  box-shadow: 0 20px 70px rgba(0,0,0,.55), 0 0 0 4px var(--dg-blue);
  animation: pop-in .35s cubic-bezier(.2,1.6,.4,1);
}
.quiz-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.cat-badge {
  background: var(--dg-blue); color: #fff;
  font-size: 14px; font-weight: 700;
  padding: 6px 16px; border-radius: 999px;
}
.cat-badge.cat-math { background: #2e7d32; }
.cat-badge.cat-english { background: #c2185b; }
.cat-badge.cat-chinese { background: #c62828; }
.cat-badge.cat-general { background: #6a1b9a; }
#quiz-progress { font-size: 14px; font-weight: 700; color: #777; }

.timer-track {
  height: 14px; border-radius: 999px;
  background: #e3e6f5; overflow: hidden; margin-bottom: 16px;
}
#timer-bar {
  height: 100%; width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #51d06b, #ffd35c 60%, #ff6b6b);
  transition: width .1s linear;
}

#quiz-question {
  font-size: clamp(17px, 2.6vw, 22px); font-weight: 700; color: #222;
  line-height: 1.55; margin-bottom: 18px; min-height: 56px;
}

#quiz-answers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { #quiz-answers { grid-template-columns: 1fr; } }
.answer-btn {
  border: 3px solid #d6daf0; border-radius: 14px;
  background: #f6f7ff;
  padding: 14px 12px; font-size: 16.5px; font-weight: 700; color: #333;
  cursor: pointer; text-align: center;
  transition: all .15s;
}
.answer-btn:hover:not(:disabled) { border-color: var(--dg-blue-light); background: #eef1ff; transform: translateY(-2px); }
.answer-btn.correct { background: #d8f6dd; border-color: #34a853; color: #1d6b33; animation: pulse-good .4s; }
.answer-btn.wrong { background: #ffe1e1; border-color: #e05252; color: #a02525; animation: shake .4s; }
.answer-btn:disabled { cursor: default; }
@keyframes pulse-good { 0% { transform: scale(1); } 50% { transform: scale(1.06); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }

#quiz-feedback { margin-top: 14px; text-align: center; font-size: 18px; font-weight: 800; }
#quiz-feedback.good { color: #2e7d32; }
#quiz-feedback.bad { color: #c62828; }

/* ============ result / victory ============ */
.result-card {
  width: min(520px, 94vw);
  max-height: 94vh; overflow-y: auto;
  background: var(--card-bg);
  border-radius: 26px; padding: 30px;
  text-align: center;
  box-shadow: 0 20px 70px rgba(0,0,0,.55), 0 0 0 4px var(--dg-gold);
  animation: pop-in .4s cubic-bezier(.2,1.6,.4,1);
}
#chest-result-emoji { font-size: 64px; animation: bounce-soft 1.2s infinite; }
.result-card h2 { color: var(--dg-blue); margin: 8px 0 12px; }
.result-card h1 { color: var(--dg-blue); margin: 8px 0 12px; font-size: clamp(22px, 4.5vw, 32px); }
#chest-result-text, #victory-stats { font-size: 16px; line-height: 1.8; color: #444; margin-bottom: 18px; }
.victory-stars { font-size: 52px; animation: bounce-soft 1.4s infinite; }
.result-card .big-btn { width: 100%; margin-top: 10px; }

#orientation-hint {
  position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%);
  z-index: 60;
  background: rgba(20,24,66,.85); color: #ffd35c;
  font-size: 13px; padding: 8px 18px; border-radius: 999px;
}

@media (max-width: 700px) {
  #minimap { width: 120px; height: 120px; }
  .hud-pill { font-size: 13px; padding: 5px 12px; }
}
