body {
  font-family: sans-serif;
  margin: 0; padding: 0;
  text-align: center;
  background: #e3f2fd;
  user-select: none;
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

h1 {
  margin: 10px;
  flex-shrink: 0;
}

#toolbar {
  margin-bottom: 5px;
  flex-shrink: 0;
}

#toolbar button {
  margin: 3px;
  padding: 8px 12px;
  font-size: 16px;
  cursor: pointer;
}

#mapContainer {
  flex-grow: 1;
  background: #8cc9ff;
  overflow: hidden;
  position: relative;
  border: 2px solid #333;
  margin: 0 10px 10px 10px;
  touch-action: none; /* prevent scrolling on touch devices */
}

#map {
  position: absolute;
  top: 0; left: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, 40px);
  grid-auto-rows: 40px;
  will-change: transform;
  user-select: none;
}

.tile {
  width: 40px;
  height: 40px;
  box-sizing: border-box;
  background-color: #e0f0ff;
  font-size: 26px;
  line-height: 40px;
  text-align: center;
  transition: background-color 0.3s;
  cursor: pointer;
  border: 1px solid #ccc;
}

.no-grid .tile {
  border: none;
}

/* Road tile base and connectors */
.tile.road {
  background-color: #555;
  position: relative;
}

.tile.road::before,
.tile.road::after {
  content: "";
  position: absolute;
  background-color: #ddd;
}

.tile.road::before {
  top: 50%;
  left: 0;
  right: 0;
  height: 12px;
  margin-top: -6px;
  border-radius: 6px;
}

.tile.road::after {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 12px;
  margin-left: -6px;
  border-radius: 6px;
  opacity: 0; /* default no vertical connection */
  transition: opacity 0.3s;
}

/* Horizontal road only */
.tile.road.horizontal::before {
  opacity: 1;
}

.tile.road.vertical::after {
  opacity: 1;
}

.tile.road.cross::before,
.tile.road.cross::after {
  opacity: 1;
}

/* City */
.tile.city {
  background-color: #ffcc33;
}

/* Airport */
.tile.airport {
  background-color: #33ccff;
}

/* Highway */
.tile.highway {
  background-color: #222;
  position: relative;
}

.tile.highway::before,
.tile.highway::after {
  content: "";
  position: absolute;
  background-color: #f4f4f4;
  border-radius: 10px;
}

.tile.highway::before {
  top: 50%;
  left: 0;
  right: 0;
  height: 8px;
  margin-top: -4px;
}

.tile.highway::after {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 8px;
  margin-left: -4px;
  opacity: 0;
  transition: opacity 0.3s;
}

.tile.highway.horizontal::before {
  opacity: 1;
}

.tile.highway.vertical::after {
  opacity: 1;
}

.tile.highway.cross::before,
.tile.highway.cross::after {
  opacity: 1;
}

/* Building */
.tile.building {
  background-color: #9ccc65;
}

/* Water */
.tile.water {
  background-color: #3399ff;
}

/* Mountain */
.tile.mountain {
  background-color: #888;
  color: #444;
  font-weight: bold;
}

