/* Fill the Map. Everything is scoped under .mapgame. */

.mapgame {
  --mg-unnamed: #d3dfea;
  --mg-shown: #b3bbc6;
  --mg-c0: #ffd6a5;
  --mg-c1: #caf0c0;
  --mg-c2: #9fe3f0;
  --mg-c3: #c9c0ff;
  --mg-c4: #ffc9ee;
  --mg-c5: #fff1a8;
  max-width: 560px;
  margin: 0 auto;
  padding: 4px 12px 24px;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.mapgame [hidden] { display: none !important; }
.mapgame *, .mapgame *::before, .mapgame *::after { box-sizing: border-box; }

/* ---------- header ---------- */

.mapgame .mg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}
.mapgame .mg-back {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
  color: var(--primary);
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
}
.mapgame .mg-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 19px;
  line-height: 1.1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mapgame .mg-pill {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-ink);
  font-weight: 800;
  font-size: 15px;
  white-space: nowrap;
}
.mapgame .mg-loading {
  margin: 40px 0;
  text-align: center;
  color: var(--muted);
  font-size: 17px;
}

/* ---------- map ---------- */

.mapgame .mg-mapbox {
  position: relative;
  width: 100%;
  aspect-ratio: 960 / 600;
  overflow: hidden;
  background: var(--stage);
  border-radius: var(--radius);
}
.mapgame .mg-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.mapgame .mg-region {
  fill: var(--mg-unnamed);
  stroke: #fff;
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  outline: none;
}
.mapgame .mg-region:focus-visible {
  stroke: var(--primary);
  stroke-width: 2.5px;
}
.mapgame .mg-region.is-shown, .mapgame .mg-dcdot.is-shown, .mapgame .mg-tile-path.is-shown { fill: var(--mg-shown); }
.mapgame .is-named.mg-c0 { fill: var(--mg-c0); }
.mapgame .is-named.mg-c1 { fill: var(--mg-c1); }
.mapgame .is-named.mg-c2 { fill: var(--mg-c2); }
.mapgame .is-named.mg-c3 { fill: var(--mg-c3); }
.mapgame .is-named.mg-c4 { fill: var(--mg-c4); }
.mapgame .is-named.mg-c5 { fill: var(--mg-c5); }

.mapgame .mg-dcdot {
  fill: var(--mg-unnamed);
  stroke: var(--ink);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.mapgame .mg-labels text {
  fill: var(--ink);
  font-weight: 800;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.mapgame .mg-selpath {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3px;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  animation: mg-pulse 1.1s ease-in-out infinite;
}
@keyframes mg-pulse {
  0%, 100% { stroke-width: 2.5px; stroke-opacity: 1; }
  50% { stroke-width: 4.5px; stroke-opacity: .75; }
}

.mapgame .mg-flashpath {
  fill: var(--accent);
  fill-opacity: 0;
  stroke: var(--accent);
  stroke-width: 3px;
  stroke-opacity: 0;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
.mapgame .mg-flashpath.go { animation: mg-flash .9s ease-out; }
@keyframes mg-flash {
  0% { fill-opacity: .85; stroke-opacity: 1; }
  100% { fill-opacity: 0; stroke-opacity: 0; }
}

/* Zoom trigger and hit areas */
.mapgame .mg-zoomhit { fill: transparent; cursor: pointer; }
.mapgame .mg-svg.is-zoomed .mg-zoomhit { pointer-events: none; }
.mapgame .mg-hit { fill: transparent; stroke: none; cursor: pointer; }
.mapgame .mg-hit-zoom { pointer-events: none; }
.mapgame .mg-svg.is-zoomed .mg-hit-zoom { pointer-events: all; }

.mapgame .mg-zoombox { pointer-events: none; }
.mapgame .mg-svg.is-zoomed .mg-zoombox { display: none; }
.mapgame .mg-zoomframe {
  fill: none;
  stroke: var(--primary);
  stroke-width: 1.5px;
  stroke-dasharray: 5 4;
  vector-effect: non-scaling-stroke;
}
.mapgame .mg-zoombadge { fill: var(--primary); }
.mapgame .mg-zoomlens {
  fill: none;
  stroke: #fff;
  stroke-width: 2px;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.mapgame .mg-zoomout {
  position: absolute;
  top: 6px;
  right: 6px;
  min-height: 44px;
  padding: 0 14px;
  border: 2px solid var(--primary);
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary);
  font: inherit;
  font-weight: 800;
  font-size: 15px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* ---------- panel ---------- */

.mapgame .mg-panel {
  margin-top: 10px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 2px solid var(--primary);
  box-shadow: var(--shadow);
  text-align: center;
}
.mapgame .mg-panel-title { margin: 0 0 4px; font-size: 24px; }
.mapgame .mg-stars { font-size: 36px; line-height: 1.1; color: var(--accent); letter-spacing: 4px; }
.mapgame .mg-counts { margin: 6px 0 12px; color: var(--muted); font-size: 16px; }
.mapgame .mg-panel-btns { display: flex; flex-direction: column; gap: 8px; }

.mapgame .mg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 8px 16px;
  border: 2px solid var(--primary);
  border-radius: 12px;
  background: var(--surface);
  color: var(--primary);
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  text-decoration: none;
  cursor: pointer;
}
.mapgame .mg-btn.primary { background: var(--primary); color: var(--primary-ink); }
.mapgame .mg-btn.is-armed { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }

/* ---------- prompt ---------- */

.mapgame .mg-prompt {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-top: 6px;
  padding: 4px 4px 4px 8px;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
}
.mapgame .mg-prompt-text { flex: 1 1 auto; min-width: 0; }
.mapgame .mg-prompt.is-ok { color: var(--good); }
.mapgame .mg-prompt.is-bad { color: var(--bad); }
.mapgame .mg-prompt.is-info { color: var(--primary); }
.mapgame .mg-x {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--stage);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}

/* ---------- typing ---------- */

.mapgame .mg-form { margin: 0; }
.mapgame .mg-chips { display: flex; min-height: 0; margin-bottom: 4px; }
.mapgame .mg-chips:empty { display: none; }
.mapgame .mg-chip {
  min-height: 44px;
  padding: 0 16px;
  border: 2px solid var(--primary);
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary);
  font: inherit;
  font-weight: 800;
  font-size: 17px;
  cursor: pointer;
}
.mapgame .mg-inputrow { display: flex; gap: 8px; }
.mapgame .mg-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 52px;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 18px;
}
.mapgame .mg-input:focus { outline: none; border-color: var(--primary); }
.mapgame .mg-go {
  flex: 0 0 auto;
  min-width: 68px;
  height: 52px;
  border: 0;
  border-radius: 12px;
  background: var(--good);
  color: #fff;
  font: inherit;
  font-weight: 800;
  font-size: 18px;
  cursor: pointer;
}
.mapgame .mg-shake { animation: mg-shake .32s ease; border-color: var(--bad) !important; }
@keyframes mg-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

.mapgame .mg-choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.mapgame .mg-choice {
  min-height: 56px;
  padding: 6px 8px;
  border: 2px solid var(--primary);
  border-radius: 12px;
  background: var(--surface);
  color: var(--primary);
  font: inherit;
  font-weight: 800;
  font-size: 17px;
  line-height: 1.15;
  cursor: pointer;
}
.mapgame .mg-choice[disabled] {
  opacity: .45;
  border-color: var(--line);
  color: var(--muted);
  text-decoration: line-through;
  cursor: default;
}
.mapgame .mg-choices .mg-link { display: block; margin: 6px auto 0; }

/* ---------- lifelines ---------- */

.mapgame .mg-life {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.mapgame .mg-life-btn {
  flex: 1 1 auto;
  min-height: 44px;
  padding: 6px 12px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #1b2430;
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
}
.mapgame .mg-life-btn[disabled] { opacity: .45; cursor: default; }
.mapgame .mg-life-btn.is-armed { background: var(--bad-bg); color: var(--bad); box-shadow: inset 0 0 0 2px var(--bad); }

/* ---------- bonus tiles ---------- */

.mapgame .mg-bonus { margin-top: 14px; }
.mapgame .mg-bonus-title { margin: 0 0 6px; color: var(--muted); font-size: 14px; font-weight: 700; }
.mapgame .mg-tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.mapgame .mg-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  width: auto;
  min-width: 0;
  min-height: 84px;
  padding: 4px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.mapgame .mg-tile.is-sel { border-color: var(--ink); animation: mg-tile-pulse 1.1s ease-in-out infinite; }
.mapgame .mg-tile.is-flash { background: #ffe6cf; border-color: var(--accent); }
@keyframes mg-tile-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(27, 36, 48, .35); }
  50% { box-shadow: 0 0 0 4px rgba(27, 36, 48, .2); }
}
.mapgame .mg-tile-svg { width: 52px; height: 52px; display: block; }
.mapgame .mg-tile-path {
  fill: var(--mg-unnamed);
  stroke: var(--muted);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}
.mapgame .mg-tile-name { font-size: 10px; font-weight: 700; line-height: 1.1; text-align: center; overflow-wrap: anywhere; }
.mapgame .mg-tile.is-named { width: 82px; }

/* ---------- footer links ---------- */

.mapgame .mg-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
}
.mapgame .mg-link {
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  text-decoration: underline;
  cursor: pointer;
}
.mapgame .mg-link.is-armed { color: var(--bad); }

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .mapgame .mg-selpath { animation: none; }
  .mapgame .mg-tile.is-sel { animation: none; box-shadow: 0 0 0 3px rgba(27, 36, 48, .3); }
  .mapgame .mg-flashpath.go { animation: none; fill-opacity: .6; stroke-opacity: 1; }
  .mapgame .mg-shake { animation: none; }
}

@media (max-width: 340px) {
  .mapgame { padding-left: 8px; padding-right: 8px; }
  .mapgame .mg-title { font-size: 16px; }
  .mapgame .mg-pill { padding: 6px 9px; font-size: 14px; }
}
