*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Fredoka', 'Fredoka One', system-ui, sans-serif;
  color: #fff;
  -webkit-user-select: none; user-select: none;
  background: #8FB7BE;
}
img { -webkit-user-drag: none; user-select: none; pointer-events: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; padding: 0; color: inherit; }

#stage-wrap {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #B5D6DC 0%, #8FB7BE 70%, #6F9098 100%);
}
#stage {
  position: relative;
  width: 100%; height: 100%;
  max-width: min(100vw, calc(100vh * 9 / 16));
  max-height: min(100vh, calc(100vw * 16 / 9));
  background: linear-gradient(180deg, #9DC2C9 0%, #BBDDE3 18%, #BBDDE3 100%);
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
#stage::before {
  content:""; position:absolute; top:0; left:0; right:0; height: 11%;
  background: #9DC2C9;
}

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  padding: 4% 6%;
  transition: opacity .25s ease;
}
.screen.active { display: flex; }

.main-topbar, .game-top {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: #2A2E3A;
  border-radius: 12px;
  color: #fff;
  transition: transform .1s;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 22px; height: 22px; }

.coins-pill {
  display:flex; align-items:center; gap:8px;
  background:#fff; color:#2A2E3A;
  padding: 6px 14px 6px 6px;
  border-radius: 999px;
  font-weight: 600; font-size: 16px;
  box-shadow: 0 3px 0 rgba(0,0,0,0.08);
}
.coins-pill .coin {
  width: 32px; height: 32px;
  background:#F5C76B;
  border-radius:50%;
  display:grid; place-items:center;
  font-size: 14px; color:#A8851A;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,0.1);
  position: relative;
}
.coins-pill .coin::after {
  content:""; position:absolute; right:-4px; bottom:-4px;
  width: 16px; height: 16px; background:#A4C45A; border-radius:50%;
  box-shadow: inset 0 0 0 2px #fff;
}

#screen-main { align-items: center; }
.main-topbar { width:100%; margin-top: 6px; }
.logo {
  margin-top: 6%;
  width: 78%;
  max-width: 360px;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,0.06));
}
.play-btn {
  margin-top: auto;
  width: 60%; max-width: 280px;
  aspect-ratio: 460 / 175;
  background: url('png/main play button.png') center/contain no-repeat;
  transition: transform .12s;
}
.play-btn:active { transform: scale(.95); }

.main-row {
  width: 100%;
  display: flex; justify-content: center; gap: 14px;
  margin: 18px 0 6px;
}
.main-row .square {
  width: 64px; height: 64px;
  border-radius: 16px;
  background: #fff;
  display: grid; place-items: center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
  transition: transform .1s;
}
.main-row .square:active { transform: scale(.93); }
.main-row .square img { width: 70%; height: 70%; object-fit: contain; }

.main-social {
  width: 100%;
  display:flex; justify-content:center; gap: 18px;
  margin-bottom: 4px;
}
.social-btn {
  width: 54px; height: 54px;
  background: #fff; color: #fff;
  border-radius: 16px;
  display:grid; place-items:center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
  transition: transform .1s;
}
.social-btn:active { transform: scale(.93); }
.social-btn.fb { background: #3B5998; }
.social-btn.gg { background: #E55360; }
.social-btn svg { width: 26px; height: 26px; fill: #fff; }

#screen-game .game-top { margin-top: 6px; }

.hud {
  display: flex; align-items: center; gap: 14px;
  margin: 10px 4% 0;
}
.timer-circle {
  --p: 100;
  width: 64px; height: 64px;
  border-radius: 22px;
  background: conic-gradient(#fff calc(var(--p) * 1%), #C95A66 0);
  display:grid; place-items:center;
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  position: relative;
}
.timer-circle::after {
  content:""; position:absolute; inset:6px;
  background:#C95A66; border-radius: 16px;
}
.timer-circle span {
  position: relative; z-index: 2;
  font-size: 22px; font-weight: 700; color:#fff;
}
.score-block { flex: 1; display: flex; flex-direction: column; align-items: center; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,0.1); }
.score-block .label { font-size: 12px; opacity: 0.85; letter-spacing: 2px; }
.score-block .value { font-family: 'Fredoka One', sans-serif; font-size: 32px; line-height: 1; color: #fff; }
.lives { display: flex; gap: 4px; }
.heart { font-size: 22px; }
.heart.lost { opacity: 0.3; }

.flag-card {
  margin: 6% auto 4%;
  width: 78%; max-width: 320px;
  aspect-ratio: 5 / 3;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 10px 0 rgba(0,0,0,0.08), 0 12px 30px rgba(0,0,0,0.1);
  overflow: hidden;
  display: grid; place-items: center;
  position: relative;
}
.flag-card .flag-fill, .flag-card img {
  width: 100%; height: 100%; display:block; object-fit: cover;
  transition: transform .3s ease;
}
.flag-card .flag-fill svg, .flag-card .flag-fill img { width: 100%; height: 100%; display: block; }
.flag-card.pop .flag-fill, .flag-card.pop img { transform: scale(1.06); }

.question {
  text-align: center;
  margin: 4% 0 3%;
  color: #fff;
  font-family: 'Fredoka One', sans-serif;
  font-size: clamp(20px, 5.2vw, 28px);
  text-shadow: 0 3px 0 rgba(0,0,0,0.08);
  line-height: 1.1;
}
.question span { color: #2A2E3A; }

.colors {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3%;
  width: 88%;
  margin: auto auto 6%;
}
.color-btn {
  aspect-ratio: 1/1;
  border-radius: 28%;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,0.12), 0 4px 0 rgba(0,0,0,0.18);
  transition: transform .12s, box-shadow .12s;
  position: relative;
  overflow: hidden;
}
.color-btn:active { transform: scale(.94); }
.color-btn.disabled { pointer-events: none; opacity: .55; }
.color-btn.correct { animation: pulse .35s ease; box-shadow: 0 0 0 4px #fff, 0 6px 18px rgba(0,0,0,0.15); }
.color-btn.wrong { animation: shake .35s ease; box-shadow: 0 0 0 4px #E55360, 0 6px 18px rgba(0,0,0,0.15); }

@keyframes pulse { 0% {transform: scale(1);} 50% {transform: scale(1.1);} 100% {transform: scale(1);} }
@keyframes shake { 0%,100% {transform: translateX(0);} 25% {transform: translateX(-6px);} 50% {transform: translateX(6px);} 75% {transform: translateX(-4px);} }

.boosters {
  display: flex; justify-content: center; gap: 4%;
  width: 88%;
  margin: 0 auto 3%;
}
.booster {
  width: 22%;
  aspect-ratio: 1/1;
  border-radius: 22%;
  background: #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,0.1);
  overflow: hidden;
  display:grid; place-items:center;
  position:relative;
  transition: transform .1s;
}
.booster:active { transform: scale(.94); }
.booster img { width: 100%; height: 100%; object-fit: contain; }
.booster .count {
  position:absolute; top:4px; right:4px;
  background:#E55360; color:#fff;
  border-radius: 999px;
  min-width: 22px; height: 22px; padding: 0 6px;
  display:grid; place-items:center;
  font-size: 12px; font-weight: 700;
  box-shadow: 0 2px 0 rgba(0,0,0,0.15);
}

.popup-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center; justify-content: center;
  z-index: 10;
  animation: fadein .25s ease;
}
.popup-overlay.show { display: flex; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.popup {
  width: 80%; max-width: 320px;
  background: #fff;
  border-radius: 26px;
  padding: 22px 16px 18px;
  text-align: center;
  box-shadow: 0 12px 0 rgba(0,0,0,0.12);
  position: relative;
  animation: pop .35s cubic-bezier(.2,1.3,.5,1);
}
@keyframes pop { 0% {transform: scale(.7); opacity: 0;} 100% {transform: scale(1); opacity: 1;} }
.popup .head-icon {
  width: 84px; height: 84px;
  margin: -52px auto 8px;
  border-radius: 50%;
  display:grid; place-items:center;
  box-shadow: 0 6px 0 rgba(0,0,0,0.1);
}
.popup .head-icon.correct { background: #82B591; }
.popup .head-icon.wrong   { background: #C95A66; }
.popup .head-icon.timeout { background: #6E8AB5; }
.popup .head-icon svg { width: 44px; height: 44px; stroke: #fff; stroke-width: 5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.popup .big-text {
  font-family: 'Fredoka One', sans-serif;
  font-size: 36px;
  color: #7C9DD3;
  margin: 4px 0 6px;
  text-transform: lowercase;
}
.popup .big-text.wrong { color: #C95A66; }
.popup .big-text.timeout { color: #6E8AB5; }
.popup .sub-text { color: #6E7A89; font-size: 15px; margin-bottom: 12px; }
.popup .flag-mini {
  width: 100px; height: 64px;
  margin: 6px auto;
  border-radius: 10px; overflow: hidden;
  box-shadow: 0 4px 0 rgba(0,0,0,0.08);
}
.flag-mini svg, .flag-mini img { width:100%; height:100%; display:block; object-fit: cover; }
.popup .country-name { font-weight: 600; color: #2A2E3A; font-size: 18px; margin: 6px 0 12px; }
.popup .actions { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.btn {
  height: 56px;
  border-radius: 999px;
  color: #fff;
  font-family: 'Fredoka One', sans-serif;
  font-size: 22px;
  box-shadow: 0 5px 0 rgba(0,0,0,0.15);
  transition: transform .1s, box-shadow .1s;
  display:grid; place-items:center;
  text-transform: lowercase;
  letter-spacing: 0.5px;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,0.15); }
.btn.green { background: #A4C45A; }
.btn.red   { background: #C95A66; }

@media (orientation: landscape) and (max-width: 1024px) { #stage { max-width: calc(100vh * 9 / 16); } }
@media (min-width: 700px) and (min-height: 700px) { #stage { border-radius: 28px; } }

.toast {
  position: absolute; left: 50%; bottom: 12%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; opacity: 0; pointer-events:none;
  transition: opacity .25s;
  z-index: 20;
}
.toast.show { opacity: 1; }
