/* =========================================================================
   STYLES: "Sunny sticker adventure"
   Bright colors, thick dark outlines, chunky rounded letters. Everything
   looks like a sticker: white or colored shapes with a dark outline and a
   solid "drop" underneath. All colors live in the variables below.
   ========================================================================= */
:root {
  --app-h: 100dvh;            /* updated by JS when the phone keyboard opens */

  /* palette */
  --ink: #1F2937;             /* outlines and text */
  --muted: #5B6472;
  --paper: #FFFDF5;           /* page background */
  --card: #FFFFFF;
  --sun: #FFC93C;             /* yellow: top bar, main buttons */
  --sun-dark: #F2B21B;
  --pink: #FF5DA2;            /* streaks, avatar, highlights */
  --pink-light: #FFE4EF;
  --pink-ink: #B3124F;
  --leaf: #2ECC71;            /* green: found countries, done */
  --leaf-light: #D5F5E3;
  --leaf-ink: #146C3A;
  --sky: #4FC3F7;             /* ocean */
  --sky-light: #DDF3FD;

  /* map */
  --ocean: var(--sky);
  --land: #FFF3C4;
  --land-border: var(--ink);
  --territory: #E5E7EB;
  --found: var(--leaf);
  --found-flash: var(--sun);
  --missed: #FF8FB1;

  /* Conquer the World teams (you are green; each computer team also has a
     pattern and an animal, so it's never color alone) */
  --team-0: var(--leaf);
  --team-1: #FF5DA2;
  --team-2: #A78BFA;
  --team-3: #FB923C;
  --reach: #FFE08A;           /* neutral countries you can attack right now */

  /* sticker look */
  --line: 3px solid var(--ink);
  --line-thick: 4px solid var(--ink);
  --drop: 0 4px 0 var(--ink);         /* solid "sticker" shadow */
  --drop-small: 0 3px 0 var(--ink);
  --font-display: "Arial Rounded MT Bold", ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif;
  --font-body: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  /* no double-tap zoom, no 300ms tap delay */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
h1, h2, h3, .big { font-family: var(--font-display); }

/* ----- Buttons: chunky stickers that "press down" when tapped ----- */
button {
  font: inherit;
  cursor: pointer;
  border: var(--line);
  border-radius: 14px;
  min-height: 48px;             /* big, thumb-friendly tap targets */
  padding: 0 18px;
  font-weight: 800;
  font-size: 17px;
  color: var(--ink);
  background: var(--card);
  box-shadow: var(--drop-small);
  touch-action: manipulation;
  transition: transform 0.06s, box-shadow 0.06s;
}
button:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
button:focus-visible { outline: 3px solid var(--pink); outline-offset: 3px; }
.btn-primary { background: var(--sun); }
.btn-primary:active { background: var(--sun-dark); }
.btn-plain { background: var(--card); }
.btn-danger { background: var(--pink-light); color: var(--pink-ink); }

.screen { display: none; }
.screen.active { display: flex; }

/* ----- Home screen ----- */
#home {
  flex-direction: column;
  align-items: center;
  min-height: 100%;
  padding: 20px 16px 48px;
  gap: 22px;
}
.title-sticker {
  margin-top: 8px;
  display: inline-flex; align-items: center; gap: 12px;
  background: var(--sun);
  border: var(--line-thick);
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--ink);
  padding: 10px 22px;
  transform: rotate(-2deg);
}
#home h1 { margin: 0; font-size: clamp(26px, 7vw, 42px); line-height: 1.1; }
.title-sticker .globe { font-size: clamp(32px, 8vw, 48px); }
.subtitle { margin: 0; color: var(--muted); text-align: center; font-weight: 700; font-size: 17px; }
.card {
  background: var(--card);
  border: var(--line);
  border-radius: 22px;
  box-shadow: var(--drop);
  padding: 16px;
  width: 100%;
  max-width: 640px;
}
.card h2 { margin: 0 0 14px; font-size: 21px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h2 .tag {
  font-family: var(--font-body); font-size: 15px; font-weight: 800;
  background: var(--sky-light); border: 2px solid var(--ink); border-radius: 999px; padding: 2px 10px;
}
.players { display: flex; flex-wrap: wrap; gap: 12px; }
.player-btn { min-width: 100px; display: inline-flex; align-items: center; gap: 8px; padding: 0 16px 0 6px; }
.player-btn .avatar { width: 34px; height: 34px; font-size: 16px; }
.player-btn.selected { background: var(--leaf); }
.player-btn.selected::after { content: "✓"; font-weight: 900; }
.new-player { display: flex; gap: 10px; margin-top: 14px; }
.new-player input { flex: 1; min-width: 0; }
input[type=text] {
  font: inherit;
  font-size: 18px;              /* 16px+ stops iPhone from zooming in on focus */
  font-weight: 700;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  border: var(--line);
  background: #fff;
  color: var(--ink);
  outline: none;
}
input[type=text]::placeholder { color: #9CA3AF; font-weight: 600; }
input[type=text]:focus { box-shadow: 0 0 0 4px var(--sun); }
.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.game-btn {
  min-height: 88px;
  text-align: left;
  display: flex; align-items: center; gap: 14px;
  background: var(--leaf);
  font-size: 20px;
  border-radius: 18px;
  box-shadow: var(--drop);
}
.game-btn .emoji { font-size: 40px; }
.game-btn small { display: block; font-weight: 700; font-size: 14px; }
.game-btn:disabled { background: var(--territory); color: var(--muted); cursor: not-allowed; }
.game-btn:disabled:active { transform: none; box-shadow: var(--drop); }
.hint { color: var(--muted); font-size: 15px; font-weight: 700; margin: 10px 0 0; }

table.board { width: 100%; border-collapse: separate; border-spacing: 0 6px; font-size: 18px; font-weight: 700; }
table.board td { padding: 8px 10px; background: var(--paper); border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); }
table.board td:first-child { border-left: 2px solid var(--ink); border-radius: 12px 0 0 12px; }
table.board td:last-child { border-right: 2px solid var(--ink); border-radius: 0 12px 12px 0; }
table.board td.rank { width: 44px; text-align: center; font-size: 22px; }
table.board td.score { text-align: right; font-family: var(--font-display); font-size: 20px; }
table.board tr.me td { background: var(--land); }
table.board td.hint { border: none; background: none; }

/* ----- Trophy case: a sticker book ----- */
.trophies { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 16px 12px; }
.trophy {
  position: relative;
  text-align: center;
  padding: 12px 6px;
  border-radius: 22px;
  background: var(--sticker, var(--sun));
  border: var(--line);
  box-shadow: var(--drop-small);
  transform: rotate(var(--tilt, -3deg));
}
.trophies .trophy:nth-child(3n+2) { --tilt: 3deg; }
.trophies .trophy:nth-child(3n) { --tilt: -1.5deg; }
.trophy .t-emoji { font-size: 36px; display: block; line-height: 1.1; }
.trophy .t-name { font-size: 13px; font-weight: 800; display: block; margin-top: 6px; line-height: 1.2; }
.trophy.locked {
  background: #F3F4F6;
  border: 3px dashed #9CA3AF;
  box-shadow: none;
  color: var(--muted);
  transform: none;
}
.trophy.locked .t-emoji { filter: grayscale(1); opacity: 0.35; }
.trophy.locked::after {         /* not just grey: a lock badge too */
  content: "🔒";
  position: absolute; top: -10px; right: -6px;
  font-size: 18px;
  background: #fff; border: 2px solid #9CA3AF; border-radius: 50%;
  width: 30px; height: 30px; line-height: 26px;
}

/* ----- Game screen ----- */
#game {
  flex-direction: column;
  height: var(--app-h);         /* exactly the visible area, even with keyboard up */
  overflow: hidden;
  background: var(--paper);
}
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--sun);
  border-bottom: var(--line-thick);
  flex: none;
}
.icon-btn {
  width: 48px; height: 48px; min-height: 48px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fff;
  border-radius: 14px;
  flex: none;
}
.icon-btn svg { width: 26px; height: 26px; }
.chips { flex: 1; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 0 4px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  font-size: 14px; font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff;
  border: 2.5px solid var(--ink);
  white-space: nowrap;
}
.chip.done { background: var(--leaf); }

.map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;                /* lets the map shrink when the keyboard is up */
  background: var(--ocean);
  overflow: hidden;
}
.map-wrap svg { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.land { stroke: var(--land-border); stroke-width: 0.9px; stroke-linejoin: round; }
.country { fill: var(--land); transition: fill 0.25s; }
.territory { fill: var(--territory); stroke-width: 0.6px; }
.dot { fill: var(--land); stroke: var(--ink); stroke-width: 2px; }
.country.found, .dot.found { fill: var(--found); }
/* missed countries: pink AND striped, so it's clear without color */
.country.missed, .dot.missed { fill: url(#missed-stripes); }
.country.flash, .dot.flash { animation: flash 1s ease-out; }
@keyframes flash {
  0%   { fill: var(--found-flash); stroke-width: 4px; }
  60%  { fill: var(--found-flash); stroke-width: 3px; }
  100% { fill: var(--found); }
}

/* Confetti that bursts out of a country you just named */
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i {
  position: absolute;
  width: 10px; height: 6px;
  border: 1.5px solid var(--ink);
  border-radius: 2px;
  animation: confetti 0.9s cubic-bezier(.2,.7,.4,1) forwards;
}
.confetti i.round { width: 8px; height: 8px; border-radius: 50%; }
.confetti i.star {
  width: 16px; height: 16px; border: none; border-radius: 0;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
@keyframes confetti {
  0%   { transform: translate(-50%, -50%) rotate(0) scale(0.6); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--spin)) scale(1); opacity: 0; }
}

/* Lightning bolt from the answer bubble to the country.
   It's a filled shape (fat in the middle, thin at the ends), not a line. */
.bolts { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.bolt .body { fill: var(--sun); stroke: var(--ink); stroke-width: 2.5px; stroke-linejoin: round; }
.bolt .hot  { fill: #FFFFFF; }
.bolt .spark { fill: #FFFFFF; stroke: var(--ink); stroke-width: 2.5px; transform-box: fill-box; transform-origin: center;
  animation: spark 0.35s ease-out forwards; }
.bolt { animation: bolt-flicker linear forwards; }
@keyframes bolt-flicker {   /* flash, flicker, flash again, then fade */
  0%, 25% { opacity: 1; }
  30% { opacity: 0.25; }
  36% { opacity: 1; }
  48% { opacity: 0.4; }
  54%, 70% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes spark {
  0% { opacity: 1; transform: scale(0.3); fill: #FFFFFF; }
  50% { opacity: 1; transform: scale(1.6); fill: var(--sun); }
  100% { opacity: 0; transform: scale(2); }
}

/* Map controls: + and − on the right, with game buttons (sound) below */
.map-controls {
  position: absolute; right: 10px; top: 10px;
  display: flex; flex-direction: column; gap: 10px;
}
.map-controls .gap { height: 6px; }
.map-controls .sound { background: var(--sun); }

/* Bubbles: the "you got it!" names that pop out of the input box */
.bubbles {
  position: absolute; left: 10px; right: 70px; bottom: 10px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px;
  pointer-events: none;         /* never blocks taps on the map */
}
.bubble-row { display: flex; align-items: center; gap: 8px; max-width: 100%; transition: opacity 0.4s, transform 0.4s; }
.bubble {
  background: #fff;
  border: var(--line);
  border-radius: 16px;
  box-shadow: var(--drop-small);
  padding: 6px 12px;
  font-size: 18px; font-weight: 700;
  max-width: 100%;
  transform: rotate(var(--tilt, -2deg));
  animation: pop-in 0.22s ease-out, wiggle 0.5s 0.22s ease-in-out;
}
.bubble .typed { color: var(--muted); }
.bubble .name { font-weight: 900; }
.bubble .check {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; margin-left: 6px;
  background: var(--leaf); border: 2px solid var(--ink); border-radius: 50%;
  font-size: 13px; font-weight: 900; vertical-align: 1px;
}
.bubble.info { background: var(--sky-light); }
.streak {
  background: var(--pink); color: #fff;
  border: var(--line); border-radius: 999px;
  padding: 3px 12px;
  font-size: 15px; font-weight: 900; white-space: nowrap;
  --tilt: 5deg;
  transform: rotate(var(--tilt));
  animation: pop-in 0.3s 0.1s ease-out both;
}
.streak.tricky { background: var(--sun); color: var(--ink); --tilt: -4deg; }
.bubble-row.fade { opacity: 0; transform: translateY(-8px); }
@keyframes pop-in {
  0%   { transform: scale(0.5) translateY(14px); opacity: 0; }
  70%  { transform: scale(1.1); opacity: 1; }
  100% { transform: rotate(var(--tilt, -2deg)) scale(1); }
}
@keyframes wiggle {
  0%, 100% { transform: rotate(var(--tilt, -2deg)); }
  25% { transform: rotate(4deg); }
  50% { transform: rotate(-5deg); }
  75% { transform: rotate(2deg); }
}

/* Bottom bar: input, score, timer, give up (always visible) */
.bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: var(--line-thick);
  flex: none;
}
.bar input { flex: 1; min-width: 0; }
.stat { text-align: center; min-width: 58px; line-height: 1.05; }
.stat b { display: block; font-size: 22px; font-family: var(--font-display); }
.stat span { font-size: 12px; font-weight: 700; color: var(--muted); }
.timer.low b { color: var(--pink-ink); animation: tick 1s steps(1) infinite; }
.timer.low span::before { content: "⏰ "; }   /* low time shows an alarm clock, not just red */
@keyframes tick { 50% { transform: scale(1.12); } }
.bar .btn-danger { padding: 0 12px; font-size: 15px; }

/* Overlay panels (ready / confirm / end screen) sit on top of the map */
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
  background: rgba(31, 41, 55, 0.45);
}
.overlay[hidden] { display: none; }
.overlay[data-panel="end"] { position: fixed; z-index: 10; background: var(--sky); }  /* results get the whole screen */
.panel {
  background: #fff;
  border: var(--line-thick);
  border-radius: 26px;
  box-shadow: 0 6px 0 var(--ink);
  padding: 22px 20px;
  width: 100%; max-width: 520px;
  max-height: 100%;
  overflow-y: auto;
  text-align: center;
  animation: pop-in 0.25s ease-out;
}
.panel h2 { margin: 0 0 8px; font-size: 28px; }
.panel p { font-size: 17px; font-weight: 600; }
.panel .row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
.panel.wide { max-width: 980px; }
.score-sticker {
  display: inline-block;
  margin: 6px 0 10px;
  padding: 6px 26px;
  background: var(--sun);
  border: var(--line-thick); border-radius: 22px;
  box-shadow: var(--drop);
  font-size: 56px; line-height: 1.1;
  transform: rotate(-2deg);
}
.score-sticker small { font-size: 24px; }
.results { text-align: left; margin-top: 20px; }
.results h3 { font-size: 20px; margin: 20px 0 8px; display: flex; align-items: center; gap: 8px; }
.results h3 span {
  font-family: var(--font-body); font-size: 15px; font-weight: 800;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; padding: 1px 10px;
}
.results h3 span.done { background: var(--leaf); }
.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.cell { font-size: 15px; padding: 6px 9px; border-radius: 10px; line-height: 1.25; font-weight: 700; }
.cell.got { background: var(--leaf-light); color: var(--leaf-ink); border: 2px solid var(--leaf-ink); }
.cell.miss { background: #fff; color: var(--pink-ink); border: 2px dashed var(--pink); }
.confirm .panel { max-width: 400px; }
.confirm p { font-size: 22px; font-weight: 800; margin: 6px 0 4px; font-family: var(--font-display); }
.player-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 16px 4px 4px;
  border-radius: 999px;
  background: var(--paper);
  border: var(--line);
  font-weight: 900; font-size: 18px;
  margin-bottom: 12px;
  transform: rotate(-2deg);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--pink); color: #fff;
  border: 2px solid var(--ink);
  font-size: 16px; font-weight: 900; flex: none;
}
.btn-big { min-height: 60px; min-width: 210px; font-size: 24px; border-radius: 18px; box-shadow: var(--drop); }
.new-badges { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; margin-top: 12px; }
.new-badges .trophy { min-width: 116px; animation: pop-in 0.45s ease-out; }
.show-results {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
}
.show-results:active { transform: translateX(-50%) translateY(3px); }
.show-results[hidden] { display: none; }

/* Continent chips are buttons now (tap to zoom to that continent) */
button.chip { min-height: 36px; box-shadow: none; cursor: pointer; font: inherit; font-size: 14px; font-weight: 800; color: var(--ink); }
button.chip:active { transform: translateY(1px); }

/* Home: edit/delete players */
.edit-players { min-height: 40px; padding: 0 12px; font-size: 15px; margin-left: auto; }
.edit-players[hidden] { display: none; }
.player-btn.deleting { background: var(--pink-light); border-style: dashed; }
.player-btn .delete-x {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--pink); color: #fff; border: 2px solid var(--ink); font-size: 13px;
}
.new-player[hidden] { display: none; }
.overlay.fixed { position: fixed; z-index: 20; }

/* Sticker book pages */
.sticker-page { font-size: 18px; margin: 18px 0 10px; display: flex; align-items: center; gap: 8px; }
.sticker-page:first-child { margin-top: 0; }
.sticker-page span {
  font-family: var(--font-body); font-size: 14px; font-weight: 800;
  background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; padding: 1px 10px;
}
.trophies { display: block; }
.trophies-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 16px 12px; }
.trophies-grid .trophy:nth-child(3n+2) { --tilt: 3deg; }
.trophies-grid .trophy:nth-child(3n) { --tilt: -1.5deg; }
.trophy .t-desc { display: block; font-size: 11.5px; font-weight: 700; margin-top: 4px; line-height: 1.2; opacity: 0.85; }

/* "Which places count?" */
.why-btn { margin-top: 14px; width: 100%; }
.panel.why { text-align: left; max-width: 600px; }
.panel.why h2 { text-align: center; }
.panel.why h3 { margin: 16px 0 4px; font-size: 19px; }
.panel.why p, .panel.why li { font-size: 16px; line-height: 1.45; font-weight: 600; }
.panel.why ul { padding-left: 20px; }
.panel.why .row { justify-content: center; }

.country.picked, .dot.picked { stroke: var(--pink-ink); stroke-width: 3.5px; }

/* Spelling helper switch on the start panel */
.switch {
  display: inline-flex; align-items: center; gap: 12px;
  margin-top: 6px; padding: 0 18px 0 8px;
  background: var(--card);
}
.switch .knob {
  width: 52px; height: 30px; flex: none;
  border: var(--line); border-radius: 999px;
  background: var(--territory);
  position: relative;
  transition: background 0.15s;
}
.switch .knob::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff; border: 2px solid var(--ink);
  transition: left 0.15s;
}
.switch[aria-checked="true"] { background: var(--land); }
.switch[aria-checked="true"] .knob { background: var(--leaf); }
.switch[aria-checked="true"] .knob::after { left: 24px; }
.switch[aria-checked="true"] .knob::before {   /* "ON" text, not just color */
  content: "ON"; position: absolute; left: 5px; top: 3px; font-size: 11px; font-weight: 900;
}
.switch-note { margin-top: 6px; }
.ready .panel p { margin: 8px 0; }
/* Short screens (small laptops, phones sideways): keep Start in view */
@media (max-height: 700px) {
  .ready .panel { padding: 14px 16px; }
  .ready .panel h2 { font-size: 23px; margin-bottom: 2px; }
  .ready .player-pill { margin-bottom: 6px; }
  .ready .panel .row { margin-top: 10px; }
}
@media (max-height: 560px) {
  .ready .panel .hint { display: none; }   /* very short screens: drop the tips, keep Start */
}
.bulb { margin-right: 6px; font-size: 16px; }

.setting-label { margin: 14px 0 6px !important; font-weight: 900 !important; }
.seg { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.seg button { min-width: 84px; }
.seg button.selected { background: var(--leaf); }
.seg button.selected::before { content: "✓ "; }
.board-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: -4px 0 10px; }
.board-tabs button { min-height: 44px; font-size: 15px; padding: 0 12px; }
.board-tabs button.selected { background: var(--sun); }

/* Phones: slightly smaller stickers so the map stays visible */
@media (max-width: 520px) {
  .bubble { font-size: 15px; padding: 4px 10px; }
  .bubble .check { width: 20px; height: 20px; font-size: 11px; }
  .streak { font-size: 13px; padding: 2px 9px; }
  .bubbles { gap: 6px; }
  .chip { font-size: 13px; }
  .stat { min-width: 48px; }
  .stat b { font-size: 20px; }
}
