/* ==========================================
   City Grid & Tiles — Architectural Blueprint
   ========================================== */

/* ---- City Grid ---- */
.city-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 3px;
  background: var(--border-color);
  border: 3px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 3px;
  max-width: 360px;
  margin: 0 auto;
  box-shadow: var(--shadow-md), inset 0 0 0 1px rgba(184, 134, 11, 0.1);
}

.city-grid-cell {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: default;
  transition: all var(--transition-fast);
  background: var(--bg-card);
  min-width: 0;
}

.city-grid-cell.editable {
  cursor: pointer;
}

.city-grid-cell.editable:hover {
  transform: scale(1.05);
  z-index: 1;
  box-shadow: var(--shadow-md);
}

/* Adjacency rule indicators */
.city-grid-cell.cell-valid {
  border-color: var(--accent-gold-light);
  box-shadow: inset 0 0 0 2px rgba(184, 134, 11, 0.2);
}

.city-grid-cell.cell-valid:hover {
  box-shadow: inset 0 0 0 2px rgba(184, 134, 11, 0.5), var(--shadow-md);
}

.city-grid-cell.cell-invalid {
  opacity: 0.3;
  cursor: not-allowed !important;
}

.city-grid-cell.cell-invalid:hover {
  transform: none;
  box-shadow: none;
}

.city-grid-cell.selected {
  outline: 3px solid var(--accent-gold);
  outline-offset: -1px;
}

/* ---- Tile type colors ---- */
.tile-shop {
  background: var(--tile-shop-bg);
  border: 2px solid var(--tile-shop-border);
}

.tile-factory {
  background: var(--tile-factory-bg);
  border: 2px solid var(--tile-factory-border);
}

.tile-tavern,
.tile-tavern_beer,
.tile-tavern_food,
.tile-tavern_music,
.tile-tavern_bed {
  background: var(--tile-tavern-bg);
  border: 2px solid var(--tile-tavern-border);
}

.tile-office {
  background: var(--tile-office-bg);
  border: 2px solid var(--tile-office-border);
}

.tile-park {
  background: var(--tile-park-bg);
  border: 2px solid var(--tile-park-border);
}

.tile-house {
  background: var(--tile-house-bg);
  border: 2px solid var(--tile-house-border);
}

.tile-empty {
  background: var(--bg-secondary);
  border: 2px dashed var(--border-light);
}

/* ---- Tile icon ---- */
.tile-icon {
  width: 85%;
  height: 85%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.tile-icon svg {
  width: 100%;
  height: 100%;
}

/* PNG tile illustration with coloured badge overlay */
.tile-img-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.tile-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 40%;
  height: 40%;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.45));
  pointer-events: none;
}

.tile-badge svg {
  width: 100%;
  height: 100%;
}

/* Badge sizing in picker options */
.tile-picker-option .tile-img-wrap {
  width: 32px;
  height: 32px;
}

.tile-picker-option .tile-badge {
  width: 14px;
  height: 14px;
  bottom: -1px;
  right: -1px;
}

/* Badge sizing in tavern sub-picker */
.tavern-subpicker-option .tile-img-wrap {
  width: 28px;
  height: 28px;
}

.tavern-subpicker-option .tile-badge {
  width: 12px;
  height: 12px;
  bottom: -1px;
  right: -1px;
}

/* ---- Tile label ---- */
.tile-label {
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
  color: var(--text-secondary);
}

/* Tile sub-type badge */
.tile-subtype {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--tile-tavern);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tile-subtype svg {
  width: 10px;
  height: 10px;
  fill: white;
}

/* ---- Duplex tile connector ---- */
.tile-duplex-right {
  border-right: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.tile-duplex-left {
  border-left: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.tile-duplex-bottom {
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.tile-duplex-top {
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}

/* ---- Tile picker overlay ---- */
.tile-picker {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 14, 9, 0.55);
  backdrop-filter: blur(4px);
}

.tile-picker-panel {
  background: var(--bg-card);
  border: 2px solid var(--border-ornate, var(--border-color));
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-xl, var(--shadow-lg));
  max-width: 320px;
  width: 90%;
  position: relative;
}

.tile-picker-panel::before {
  content: '';
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(184, 134, 11, 0.1);
  border-radius: calc(var(--radius-lg) - 2px);
  pointer-events: none;
}

.tile-picker-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  text-align: center;
  margin-bottom: var(--space-md);
  font-weight: 700;
  color: var(--text-heading, var(--text-primary));
}

.tile-picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
}

.tile-picker-option {
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
  padding: var(--space-xs);
}

.tile-picker-option:hover {
  transform: scale(1.08);
  box-shadow: var(--shadow-md);
}

.tile-picker-option .tile-icon {
  width: 32px;
  height: 32px;
}

.tile-picker-option .tile-label {
  font-size: 0.65rem;
}

/* Tavern sub-picker */
.tavern-subpicker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-sm);
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--divider);
}

.tavern-subpicker-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: var(--space-sm);
  border: 2px solid var(--tile-tavern-border);
  border-radius: var(--radius-md);
  background: var(--tile-tavern-bg);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tavern-subpicker-option:hover {
  background: var(--tile-tavern);
  color: white;
}

.tavern-subpicker-option svg {
  width: 24px;
  height: 24px;
}

/* ---- Score annotations ---- */
.tile-score-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  background: var(--bg-dark);
  color: var(--accent-gold-light);
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: var(--radius-sm);
  line-height: 1;
}

/* Highlighted tiles for scoring */
.tile-highlight-shop { box-shadow: inset 0 0 0 3px var(--tile-shop); }
.tile-highlight-factory { box-shadow: inset 0 0 0 3px var(--tile-factory); }
.tile-highlight-tavern { box-shadow: inset 0 0 0 3px var(--tile-tavern); }
.tile-highlight-office { box-shadow: inset 0 0 0 3px var(--tile-office); }
.tile-highlight-park { box-shadow: inset 0 0 0 3px var(--tile-park); }
.tile-highlight-house { box-shadow: inset 0 0 0 3px var(--tile-house); }

/* ---- Responsive grid ---- */
@media (min-width: 480px) {
  .city-grid {
    max-width: 400px;
  }
}

@media (min-width: 768px) {
  .city-grid {
    max-width: 440px;
  }

  .tile-label {
    font-size: 0.65rem;
  }
}
