/* ==========================================================================
   MapGuesser — game UI (quiz + draw)
   ========================================================================== */

.game-page {
  position: relative;
  height: calc(100dvh - var(--header-h));
  min-height: 560px;
  overflow: hidden;
  background: #061033;
}
.game-page .breadcrumbs {
  position: absolute;
  top: 10px;
  inset-inline-start: 18px;
  z-index: 700;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(6, 16, 51, 0.72);
  backdrop-filter: blur(8px);
  font-size: 0.78rem;
}

.game-shell { position: absolute; inset: 0; }
.game-map-wrap { position: absolute; inset: 0; }
#map, .game-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #061033;
  z-index: 1;
  touch-action: none;
}
#map.drawing { cursor: crosshair; }

/* Leaflet */
.leaflet-container {
  background: #061033;
  font-family: var(--font-body);
  outline: none;
}
.leaflet-control-zoom {
  border: 1px solid var(--line) !important;
  border-radius: 12px !important;
  overflow: hidden;
  box-shadow: var(--shadow-soft) !important;
  margin-top: 96px !important;
}
.leaflet-control-zoom a {
  background: rgba(10, 26, 69, 0.92) !important;
  color: var(--text) !important;
  border-bottom: 1px solid var(--line) !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 32px !important;
  font-size: 18px !important;
}
.leaflet-control-zoom a:hover { background: var(--surface-3) !important; }
.leaflet-control-attribution {
  background: rgba(6, 16, 51, 0.72) !important;
  color: var(--muted-2) !important;
  font-size: 10px !important;
  border-radius: 6px 0 0 0;
}
.leaflet-control-attribution a { color: var(--muted) !important; }

/* HUD */
.game-hud {
  position: absolute;
  top: 12px;
  left: 0;
  right: 0;
  z-index: 520;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  pointer-events: none;
}
.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  background: rgba(8, 18, 50, 0.86);
  border: 1px solid rgba(108, 136, 196, 0.28);
  border-radius: 14px;
  padding: 9px 13px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-soft);
}
.hud-left h1 {
  font-size: 0.95rem;
  margin: 0;
  color: #fff;
  font-weight: 600;
  letter-spacing: 0;
}
.game-round {
  display: block;
  color: var(--sun);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  line-height: 1.2;
}
.hud-score {
  color: var(--sky);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
}
.hud-btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 10px;
  width: 36px;
  height: 34px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1rem;
}
.hud-btn:hover { background: var(--surface-3); }

/* Question bar */
.game-question {
  position: absolute;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 510;
  max-width: min(92vw, 620px);
  text-align: center;
  padding: 10px 22px;
  border-radius: 999px;
  background: rgba(8, 18, 50, 0.9);
  border: 1px solid rgba(108, 136, 196, 0.3);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(0.95rem, 2.2vw, 1.16rem);
  line-height: 1.3;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-soft);
  pointer-events: none;
}

/* Flag card */
.game-flag {
  position: absolute;
  top: 128px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 515;
  background: #fff;
  padding: 7px;
  border-radius: 10px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.7);
}
.game-flag img { display: block; width: clamp(120px, 24vw, 190px); height: auto; border-radius: 4px; }

.game-hint {
  position: absolute;
  bottom: 132px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 515;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 700;
  font-size: 0.9rem;
  text-shadow: 0 2px 10px #000;
  pointer-events: none;
  white-space: nowrap;
}

.game-timer {
  position: absolute;
  top: 78px;
  inset-inline-end: 16px;
  z-index: 515;
  background: rgba(8, 18, 50, 0.9);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  font-family: var(--font-display);
  color: var(--sun);
  font-size: 0.95rem;
  min-width: 62px;
  text-align: center;
}
.game-timer.warn { color: var(--coral); border-color: var(--coral); }

.game-loading {
  position: absolute;
  inset: 0;
  z-index: 530;
  display: grid;
  place-items: center;
  gap: 10px;
  align-content: center;
  background: rgba(6, 16, 51, 0.86);
  color: var(--muted);
  font-weight: 700;
  backdrop-filter: blur(3px);
}
.game-loading[hidden] { display: none; }
.spinner {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 3px solid rgba(168, 190, 232, 0.25);
  border-top-color: var(--sky);
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Bottom controls */
.game-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 520;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  background: linear-gradient(to top, rgba(6, 16, 51, 0.96) 40%, rgba(6, 16, 51, 0));
  pointer-events: none;
}
.game-controls > * { pointer-events: auto; }
.answer-area { width: min(100%, 620px); display: grid; gap: 8px; }
.answer-area:empty { display: none; }

.game-submit {
  width: min(100%, 620px);
  min-height: 54px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(180deg, #8ff0a0, var(--lime) 55%, #2fae49);
  color: #04300f;
  font-family: var(--font-display);
  font-size: 1.06rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(78, 210, 100, 0.3), inset 0 1px 0 rgba(255,255,255,.5);
  transition: transform .15s ease, opacity .15s ease;
}
.game-submit:hover:not(:disabled) { transform: translateY(-2px); }
.game-submit:disabled {
  cursor: not-allowed;
  background: rgba(20, 42, 102, 0.85);
  color: var(--muted-2);
  box-shadow: none;
  border-color: var(--line);
}
.game-submit.next {
  background: linear-gradient(180deg, #ffd97a, var(--sun) 55%, #e5a300);
  color: #2a1c00;
  box-shadow: 0 12px 30px rgba(255, 198, 51, 0.3), inset 0 1px 0 rgba(255,255,255,.5);
}

/* Answer widgets */
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice-btn {
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(14, 32, 82, 0.95);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  min-height: 48px;
}
.choice-btn:hover { background: var(--surface-3); border-color: var(--blue); }
.choice-btn.selected { background: rgba(76, 141, 255, 0.28); border-color: var(--sky); color: #fff; }
.choice-btn.correct { background: rgba(78, 210, 100, 0.28); border-color: var(--lime); color: #fff; }
.choice-btn.wrong { background: rgba(255, 78, 99, 0.25); border-color: var(--coral); color: #fff; }

.type-row { display: flex; gap: 8px; }
.type-row input {
  flex: 1;
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(14, 32, 82, 0.96);
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  padding: 0 16px;
  outline: none;
}
.type-row input:focus { border-color: var(--sky); box-shadow: 0 0 0 3px rgba(79, 214, 245, 0.18); }
.type-row input::placeholder { color: var(--muted-2); }

.pin-status {
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.88rem;
  background: rgba(8, 18, 50, 0.86);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  justify-self: center;
}
.pin-status.ready { color: var(--sky); border-color: rgba(79, 214, 245, .5); }

.org-status {
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
  background: rgba(8, 18, 50, 0.86);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  justify-self: center;
}

/* Feedback sheet */
.game-feedback {
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 540;
  width: min(100%, 680px);
  max-height: 72%;
  overflow: auto;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  border-radius: 24px 24px 0 0;
  background: linear-gradient(180deg, #0d2156, #081438);
  border: 1px solid var(--line);
  border-bottom: 0;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.55);
  animation: sheet-in 0.22s ease;
}
.game-feedback[hidden] { display: none; }
@keyframes sheet-in { from { transform: translate(-50%, 30px); opacity: .4; } }

.feedback-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.feedback-icon {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 1.4rem;
  background: rgba(78, 210, 100, 0.16);
  border: 1px solid rgba(78, 210, 100, 0.5);
}
.feedback-icon.bad { background: rgba(255, 78, 99, 0.14); border-color: rgba(255, 78, 99, 0.5); }
.feedback-head h2 { margin: 0; font-size: 1.4rem; }
.feedback-sub { color: var(--muted); margin: 0 0 12px; }
.feedback-answer {
  background: rgba(14, 32, 82, 0.9);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.feedback-answer img { width: 44px; border-radius: 4px; }
.feedback-points { margin-inline-start: auto; color: var(--lime); font-family: var(--font-display); font-size: 1.15rem; }
.feedback-fact { color: var(--muted); font-size: .92rem; }
.feedback-fact a { white-space: nowrap; }

/* Result / modal */
.game-modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(3, 8, 26, 0.78);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 20px;
}
.game-modal[hidden] { display: none; }
.game-modal-card {
  position: relative;
  width: min(100%, 520px);
  max-height: 86dvh;
  overflow: auto;
  background: linear-gradient(170deg, #10265f, #081438);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 26px;
  box-shadow: var(--shadow);
  animation: pop-in .2s ease;
}
@keyframes pop-in { from { transform: scale(.96); opacity: .5; } }
.modal-close {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.score-ring {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  margin: 6px auto 16px;
  display: grid;
  place-items: center;
  position: relative;
  background: conic-gradient(var(--sun) calc(var(--pct, 0) * 1%), rgba(168, 190, 232, 0.14) 0);
}
.score-ring::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  background: #0a1a45;
  border: 1px solid var(--line);
}
.score-ring .ring-in {
  position: relative;
  text-align: center;
}
.score-ring .ring-score { display: block; font-family: var(--font-display); font-size: 2rem; color: #fff; line-height: 1; }
.score-ring .ring-label { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.result-title { text-align: center; margin-bottom: 4px; }
.result-sub { text-align: center; color: var(--muted); margin-bottom: 18px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.result-stats div {
  background: rgba(14, 32, 82, 0.9);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}
.result-stats b { display: block; font-family: var(--font-display); font-size: 1.1rem; color: #fff; }
.result-stats span { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.result-actions { display: grid; gap: 8px; }
.emoji-grid {
  font-size: 1.5rem;
  letter-spacing: .25em;
  text-align: center;
  margin: 10px 0 18px;
  line-height: 1.2;
}
.share-note { text-align: center; color: var(--muted-2); font-size: .78rem; margin-top: 10px; }

/* Draw mode */
#draw-canvas {
  position: absolute;
  inset: 0;
  z-index: 420;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.draw-toolbar {
  position: absolute;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 525;
  display: flex;
  gap: 4px;
  padding: 6px;
  border-radius: 18px;
  background: rgba(8, 18, 50, 0.92);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-soft);
}
.draw-toolbar button {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 12px;
  min-width: 70px;
  padding: 10px 12px;
  font: inherit;
  font-size: .78rem;
  font-weight: 800;
  cursor: pointer;
  display: grid;
  gap: 3px;
  place-items: center;
}
.draw-toolbar button .ti { display: grid; place-items: center; width: 28px; height: 28px; }
.draw-toolbar button .ti svg { width: 26px; height: 26px; display: block; }
.draw-toolbar button.active { background: rgba(76, 141, 255, 0.24); color: #fff; }
.draw-toolbar button:hover { color: #fff; }

.draw-result-bars { display: grid; gap: 8px; margin: 14px 0 18px; }
.draw-bar { display: grid; grid-template-columns: 74px 1fr 48px; gap: 10px; align-items: center; font-size: .82rem; font-weight: 700; }
.draw-bar .bar { height: 8px; border-radius: 99px; background: rgba(168, 190, 232, .16); overflow: hidden; }
.draw-bar .bar i { display: block; height: 100%; border-radius: 99px; }
.draw-bar.matched i { background: var(--lime); }
.draw-bar.missed i { background: var(--coral); }
.draw-bar.extra i { background: var(--peach); }
.draw-bar b { text-align: end; color: #fff; }

/* Practice start card */
.start-card { text-align: center; }
.start-card h2 { margin-bottom: 6px; }
.start-card p { color: var(--muted); }
.difficulty-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 16px 0; }
.difficulty-row button {
  border: 1px solid var(--line);
  background: rgba(14, 32, 82, 0.9);
  color: var(--muted);
  border-radius: 999px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 800;
  font-size: .86rem;
  cursor: pointer;
}
.difficulty-row button.active { background: rgba(76, 141, 255, 0.26); color: #fff; border-color: var(--sky); }

/* Game copy below the fold */
.game-copy { padding-top: 46px; }
.game-copy .prose ol { color: var(--muted); }
.game-copy .prose li { margin-bottom: 6px; }

/* Responsive */
@media (max-width: 760px) {
  .game-page { height: calc(100dvh - var(--header-h)); min-height: 520px; }
  .game-page .breadcrumbs { display: none; }
  .game-hud { top: 8px; padding: 0 10px; }
  .hud-left { padding: 7px 10px; }
  .hud-left h1 { font-size: .82rem; }
  .game-question { top: 64px; padding: 8px 16px; }
  .game-flag { top: 112px; }
  .game-timer { top: 64px; inset-inline-end: 10px; }
  .leaflet-control-zoom { margin-top: 82px !important; }
  .game-feedback { width: 100%; border-radius: 20px 20px 0 0; }
  .choice-grid { grid-template-columns: 1fr; }
  .draw-toolbar { bottom: 80px; }
  .draw-toolbar button { min-width: 64px; padding: 9px 8px; }
  .draw-toolbar button .ti { width: 26px; height: 26px; }
  .draw-toolbar button .ti svg { width: 24px; height: 24px; }
  .result-stats { grid-template-columns: repeat(3, 1fr); }
}


.emoji-grid .eg {
  display: inline-block;
  width: 22px;
  height: 22px;
  margin: 0 2px;
  border-radius: 5px;
  vertical-align: middle;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25);
}
.emoji-grid .eg-g { background: #4ed264; }
.emoji-grid .eg-y { background: #ffc633; }
.emoji-grid .eg-r { background: #ff4e63; }

/* Keep the drawing reveal compact so the next button stays above the fold. */
.game-feedback img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  width: auto;
  margin-inline: auto;
  border-radius: 12px;
  border: 1px solid var(--line);
}

/* Leaflet's image rules override width/height attributes; the marker box is
   22×32, so the pin must be exactly that or its tip drifts from the click. */
.mg-pin { background: transparent; border: 0; }
.mg-pin img.mg-pin-img {
  width: 22px !important;
  height: 32px !important;
  max-width: none !important;
  display: block;
}

/* Match the Android app's dark-mode dimming of the same terrain tiles. */
.basemap-tiles { filter: brightness(0.82) saturate(0.8); }
