:root {
  --game-bg: #f5f7fb;
  --game-panel-bg: rgba(255, 255, 255, 0.9);
  --game-border: rgba(15, 23, 42, 0.12);
  --game-highlight: #0f766e;
  --game-accent: #2563eb;
  --game-text: #1f2933;
  --game-muted: #617081;
}

body.game-body {
  background: linear-gradient(180deg, #e0f2ff 0%, #f8fafc 60%, #ffffff 100%);
  color: var(--game-text);
  min-height: 100vh;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
  margin: 0;
}

.skip-link {
  position: absolute;
  top: -999px;
  left: 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--game-accent);
  color: #ffffff;
  border-radius: 0.5rem;
  z-index: 1000;
  text-decoration: none;
}

.skip-link:focus {
  top: 1rem;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 1.5rem clamp(1.5rem, 4vw, 4rem) 1rem;
  position: sticky;
  top: 0;
  backdrop-filter: blur(16px);
  background: rgba(245, 247, 251, 0.82);
  border-bottom: 1px solid var(--game-border);
  z-index: 10;
}

.game-header__brand {
  display: grid;
  gap: 0.25rem;
}

.game-header__title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--game-text);
  text-decoration: none;
}

.game-header__tagline {
  margin: 0;
  font-size: 0.85rem;
  color: var(--game-muted);
}

@media (max-width: 640px) {
  .game-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
}

.game-main {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  padding: 6rem clamp(1.5rem, 4vw, 4rem) 4rem;
  width: min(100%, 1100px);
  margin: 0 auto;
}

@media (max-width: 1024px) {
  .game-main {
    padding-top: 5rem;
    gap: 2rem;
  }
}

.game-hero {
  margin-bottom: 1.5rem;
}

.game-hero h1 {
  font-family: "Playfair Display", serif;
  font-size: clamp(2rem, 4vw, 3rem);
  margin-bottom: 0.75rem;
}

.game-hero p {
  color: var(--game-muted);
  max-width: 56ch;
  line-height: 1.6;
}

.map-shell {
  position: relative;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 1.25rem;
  padding: 1.5rem;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.15);
  border: 1px solid var(--game-border);
  width: min(100%, 620px);
  margin: 0 auto;
}

.map-stage {
  position: relative;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
}

.map-stage svg {
  display: block;
  width: 100%;
  height: auto;
}

#baseMap path,
#baseMap rect {
  vector-effect: non-scaling-stroke;
}

#drawLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.boundary-outline * {
  fill: none;
  stroke: rgba(15, 23, 42, 0.32);
  stroke-width: 1.1;
  vector-effect: non-scaling-stroke;
}

.debug-toggle {
  margin-top: 0.75rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid rgba(15, 23, 42, 0.15);
  background: rgba(148, 163, 184, 0.14);
  color: var(--game-text);
  border-radius: 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.debug-toggle[aria-pressed='true'] {
  background: rgba(37, 99, 235, 0.15);
  border-color: rgba(37, 99, 235, 0.35);
  color: #1f3a8a;
}

.debug-toggle:focus-visible {
  outline: 2px solid var(--game-accent);
  outline-offset: 2px;
}

.region-layer {
  pointer-events: none;
}

.region-layer path {
  stroke: rgba(30, 41, 59, 0.4);
  stroke-width: 0.7;
}

.region-layer text {
  font-size: 8px;
  fill: rgba(30, 41, 59, 0.85);
  text-anchor: middle;
  font-weight: 600;
}

.city-marker-layer {
  pointer-events: none;
}

.city-dot {
  fill: currentColor;
  opacity: 0.35;
}

.city-label-layer {
  pointer-events: none;
}

.city-label {
  font-size: 10px;
  fill: rgba(30, 41, 59, 0.92);
  text-anchor: middle;
  font-weight: 500;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 1.2px;
}

.drawing-overlay {
  pointer-events: auto;
  cursor: crosshair;
}

.drawing-overlay path {
  fill: rgba(56, 189, 248, 0.16);
  stroke: var(--game-accent);
  stroke-width: 1.1;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.panel-stack {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.panel-lite {
  background: var(--game-panel-bg);
  border-radius: 1.25rem;
  border: 1px solid var(--game-border);
  padding: 1.5rem;
  backdrop-filter: blur(18px);
}

.share-panel {
  width: min(100%, 540px);
  margin: 0 auto;
}

.panel-lite h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.control-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.control-group button,
.control-group select,
.control-group input {
  font: inherit;
  border-radius: 0.75rem;
  border: 1px solid rgba(15, 23, 42, 0.08);
  padding: 0.6rem 1rem;
}

.control-group button {
  background: var(--game-highlight);
  color: #f4f8f9;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
  border-color: transparent;
}

.control-group button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(15, 118, 110, 0.25);
}

.control-group button:disabled {
  background: rgba(148, 163, 184, 0.18);
  color: rgba(148, 163, 184, 0.65);
  cursor: not-allowed;
}

.arrangement-label {
  font-weight: 600;
  color: var(--game-highlight);
  margin: 0 0 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.85rem;
}

#statusMessage {
  font-size: 0.9rem;
  color: var(--game-muted);
}

#clearPlan {
  border: none;
  border-radius: 0.75rem;
  background: var(--game-highlight);
  color: #f4f8f9;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

#clearPlan:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 28px rgba(15, 118, 110, 0.25);
}

.naming-popover {
  position: absolute;
  min-width: 220px;
  max-width: 280px;
  background: #ffffff;
  border-radius: 0.9rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  box-shadow: 0 18px 32px rgba(15, 23, 42, 0.25);
  padding: 0.9rem 1rem;
  display: grid;
  gap: 0.6rem;
  transform: translate(-50%, -100%);
  z-index: 6;
}

.naming-popover label {
  font-size: 0.9rem;
  color: var(--game-muted);
}

.naming-popover select,
.naming-popover input {
  font: inherit;
  border-radius: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.45);
  padding: 0.45rem 0.6rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
}

.chip {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid #d0d7de;
  background: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.chip:hover {
  background: #f0f4f8;
  border-color: #a8b8cc;
}

.chip:active {
  transform: scale(0.98);
}

.chip-selected {
  background: rgba(37, 99, 235, 0.1);
  border-color: rgba(37, 99, 235, 0.5);
  color: #1e40af;
  font-weight: 600;
}

.naming-popover__actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.naming-popover button {
  font: inherit;
  border-radius: 0.6rem;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}

.naming-popover button[type="submit"] {
  background: var(--game-accent);
  color: #f8fafc;
  border: none;
}

.naming-popover button[data-action="cancel"] {
  background: rgba(148, 163, 184, 0.18);
  color: var(--game-text);
  border: none;
}

.region-summary {
  display: grid;
  gap: 1rem;
}

.region-card {
  border-radius: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.3);
  padding: 1rem 1.2rem;
  background: rgba(255, 255, 255, 0.92);
}

.region-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.region-card__title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.region-card .swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.region-card__total {
  font-weight: 600;
  color: var(--game-text);
}

.region-card__body {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.population-pie {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--game-text);
}

.population-pie::after {
  content: attr(data-total);
  position: absolute;
  width: 52px;
  height: 52px;
  background: #ffffff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.2);
}

.population-legend {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--game-muted);
}

.population-legend__item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.population-legend__swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.population-legend__value {
  margin-left: auto;
  color: var(--game-text);
  font-weight: 600;
}

.share-tools {
  display: grid;
  gap: 0.75rem;
}

.share-tools button {
  justify-self: start;
  border-radius: 0.75rem;
  border: none;
  background: var(--game-accent);
  color: #f8fafc;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.25);
}

.share-tools button:hover {
  filter: brightness(1.05);
}

.share-intro {
  margin: 0;
  font-size: 0.9rem;
  color: var(--game-muted);
}

.share-tools small {
  color: rgba(100, 116, 139, 0.8);
}

@media (max-width: 640px) {
  .map-shell {
    padding: 1rem;
  }

  .naming-popover {
    transform: translate(-50%, -110%);
  }
}
