* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  color-scheme: only light;
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #1b4332;
  color: #f1f1f1;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  cursor: pointer;
}

/* ---------- Leiste oben: Stadtstatus + Warenraster ---------- */
#topbar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 10px 8px;
  padding-top: calc(6px + env(safe-area-inset-top));
  background: linear-gradient(#2d6a4f, #276149);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
  z-index: 2;
}

#topbar-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

#status {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

#status .res {
  padding: 4px 9px;
  font-size: 14px;
  border-radius: 999px;
}

#status .res.money {
  background: rgba(255, 209, 102, .22);
  color: #ffe8a3;
}

#resources {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(66px, 1fr));
  gap: 4px;
}

.res {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  font-size: 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .25);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

#resources .res {
  position: relative;
  overflow: hidden;
  justify-content: space-between;
  padding: 4px 6px 6px;
  border-radius: 8px;
  font-size: 13px;
  white-space: nowrap;
}

#resources .res .trend { font-size: 10px; line-height: 1; }
#resources .res .trend.up { color: #95d5b2; }
#resources .res .trend.down { color: #ffadad; }
#resources .res .bar {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  background: #95d5b2;
  transition: width .4s;
}
#resources .res .bar.high { background: #ffd166; }
#resources .res.full .bar { background: #ff6b6b; }
.res.hidden { display: none; }

#topbar .top-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .25);
  font-size: 18px;
}

/* ---------- Karte ---------- */
#map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

#map {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#map.dragging { cursor: grabbing; }
#map.building { cursor: crosshair; }

#toast {
  position: absolute;
  top: 54px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .8);
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- Auftragsanzeige ---------- */
#quest-tracker {
  position: absolute;
  top: 10px;
  left: 10px;
  max-width: calc(100% - 20px);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .65);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#quest-tracker.ready {
  background: #f4a261;
  color: #222;
  font-weight: 600;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% { transform: scale(1.05); }
}

#quests-count, #research-count {
  font-size: 13px;
  opacity: .6;
}

.quest {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  background: #f1efe7;
}

.quest.done { background: #e3f4d7; }
.quest-title { font-weight: 700; }
.quest-goal { margin: 2px 0 6px; font-size: 14px; }

.quest-bar {
  height: 8px;
  border-radius: 4px;
  background: #d9d5c7;
  overflow: hidden;
}

.quest-bar div {
  height: 100%;
  background: #2d6a4f;
  transition: width .3s;
}

.quest-foot {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 13px;
}

.quest-claim {
  width: 100%;
  margin-top: 8px;
  padding: 8px;
  border-radius: 8px;
  background: #f4a261;
  color: #222;
  font-weight: 700;
}

.tech.done { background: #e3f4d7; }
.tech.locked { opacity: .55; }
.tech.running { background: #dbe9ff; }
.tech.running .quest-bar div { background: #1c7ed6; }

.tech-start {
  width: 100%;
  margin-top: 8px;
  padding: 8px;
  border-radius: 8px;
  background: #2d6a4f;
  color: #fff;
  font-weight: 700;
}

.tech-start.unaffordable { opacity: .45; }

.setting {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #e9ecef;
  color: #555;
  text-align: left;
  font-weight: 600;
}

.setting.on {
  background: #d8f3dc;
  color: #1b4332;
}

.danger {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  border-radius: 8px;
  background: #c0392b;
  color: #fff;
  font-weight: 600;
}

.res.full { background: rgba(192, 57, 43, .75); }

#info-extra:empty { display: none; }
#info-extra { margin-bottom: 10px; }

.trade-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.trade-name { flex: 1; font-size: 14px; }

.trade-btn {
  padding: 7px 8px;
  border-radius: 8px;
  background: #2d6a4f;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

.trade-btn.sell { background: #b08968; }

.tax-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  background: #f1efe7;
}

.tax-label { flex: 1; text-align: center; font-size: 14px; line-height: 1.4; }

.tax-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #2d6a4f;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
}

#event-text { white-space: pre-line; }

.ach-title { margin: 16px 0 8px; font-weight: 700; }

.ach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 6px;
}

.ach {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 10px;
  background: #ece9df;
  color: #222;
  opacity: .45;
  filter: grayscale(1);
}

.ach.done { opacity: 1; filter: none; background: #fff3c4; }
.ach-icon { font-size: 22px; }
.ach-name { font-size: 10px; line-height: 1.2; text-align: center; }

/* ---------- Gebäude-Info ---------- */
#info, #quests, #research, #settings {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  max-width: 360px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 12px;
  background: #fffdf7;
  color: #222;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}

.info-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
}

#info-icon { font-size: 26px; }
#info-name { flex: 1; }

#info-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #eee;
}

#info-text {
  margin: 8px 0 12px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-line;
}

#info-demolish {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  background: #c0392b;
  color: #fff;
  font-weight: 600;
}

#info-action {
  width: 100%;
  margin-bottom: 8px;
  padding: 10px;
  border-radius: 8px;
  background: #1c7ed6;
  color: #fff;
  font-weight: 600;
}

/* ---------- Ereignisse ---------- */
#effects {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  pointer-events: none;
}

/* Kurzinfo zur Auswahl in der Bauleiste – weicht großen Fenstern aus */
#build-info {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  max-width: 420px;
  margin: 0 auto;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 253, 247, 0.96);
  color: #222;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}

.bi-head { display: flex; align-items: center; gap: 6px; font-size: 15px; }
.bi-icon { font-size: 22px; }
.bi-head strong { flex: 1; }
.bi-close { width: 28px; height: 28px; border-radius: 50%; background: #eee; font-size: 13px; }
.bi-desc { margin: 4px 0; color: #444; }
.bi-facts { margin: 0; padding: 0; list-style: none; }
.bi-facts li { margin: 2px 0; }
.bi-status { margin-top: 6px; font-weight: 700; color: #2d6a4f; }
.bi-status.locked, .bi-status.unaffordable { color: #c0392b; }

#quests:not(.hidden) ~ #build-info,
#research:not(.hidden) ~ #build-info,
#settings:not(.hidden) ~ #build-info,
#info:not(.hidden) ~ #build-info { display: none; }

/* Laufende Ereignisse über die Kurzinfo schieben */
#build-info:not(.hidden) ~ #effects,
#move-bar:not(.hidden) ~ #effects { bottom: auto; top: 54px; }

#quests:not(.hidden) ~ #effects,
#research:not(.hidden) ~ #effects,
#settings:not(.hidden) ~ #effects,
#info:not(.hidden) ~ #effects { display: none; }

.effect {
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .65);
  font-size: 13px;
}

#event {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(340px, calc(100% - 32px));
  padding: 18px;
  border-radius: 14px;
  background: #fffdf7;
  color: #222;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .5);
  z-index: 3;
}

#event-icon { font-size: 44px; line-height: 1.1; }
#event-title { display: block; margin-top: 4px; font-size: 20px; }
#event-text { margin: 8px 0 14px; font-size: 15px; line-height: 1.45; }

#event-buttons {
  display: flex;
  gap: 8px;
}

#event-buttons button {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  background: #e9ecef;
  font-weight: 600;
}

#event-buttons button.primary {
  background: #2d6a4f;
  color: #fff;
}

/* Restzeit, bis sich die Meldung selbst schließt */
#event { overflow: hidden; }
#event-timer {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 4px;
  width: 100%;
  background: #95d5b2;
  transform-origin: left;
}
#event-timer.hidden { display: none; }
@keyframes event-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ---------- Bauleiste unten ---------- */
#buildnav {
  background: #2d6a4f;
  box-shadow: 0 -2px 6px rgba(0, 0, 0, .3);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 2;
}

#build-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 6px 0;
  overflow-x: auto;
  background: rgba(0, 0, 0, .18);
}

.build-tab {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 1px 5px;
  border-radius: 10px 10px 0 0;
  background: transparent;
  opacity: .75;
}

.build-tab .icon { font-size: 20px; line-height: 1.1; }
.build-tab .name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 9.5px;
  font-weight: 600;
}
.build-tab.active { background: #2d6a4f; opacity: 1; }
.build-tab.locked { opacity: .35; filter: grayscale(1); }
.build-tab.active.locked { opacity: .8; }

/* Roter Punkt: neu freigeschaltetes Gebäude in diesem Reiter */
.build-tab.new::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 8px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #e63946;
  box-shadow: 0 0 0 2px #2d6a4f;
}

/* Gelber Rand: das gewählte Gebäude liegt in diesem (nicht offenen) Reiter */
.build-tab.has-selected { box-shadow: inset 0 -3px 0 #ffd166; }

#buildbar {
  display: flex;
  justify-content: safe center;
  gap: 6px;
  padding: 8px 8px;
  overflow-x: auto;
}

.build-btn {
  flex: 1 1 0;
  min-width: 0;
  max-width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .25);
  border: 2px solid transparent;
}

.build-btn .icon { font-size: 28px; line-height: 1; }
.build-btn .name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
}
.build-btn .cost { font-size: 10px; line-height: 1.25; text-align: center; opacity: .85; }

/* Scrollbalken der Leisten ausblenden (Wischen/Mausrad geht weiter) */
#build-tabs, #buildbar { scrollbar-width: none; }
#build-tabs::-webkit-scrollbar, #buildbar::-webkit-scrollbar { display: none; }

.build-btn.selected {
  border-color: #ffd166;
  background: rgba(255, 209, 102, .2);
}

.build-btn.unaffordable { opacity: .45; }
.build-btn.locked { opacity: .35; filter: grayscale(1); }

button.res { cursor: pointer; }

#info, #quests, #research, #settings { max-height: 70%; overflow-y: auto; }

@media (hover: hover) {
  .build-btn:hover { background: rgba(255, 255, 255, .12); }
  .build-tab:hover { opacity: 1; }
  .top-btn:hover, #info-close:hover { filter: brightness(1.2); }
}

.hidden { display: none !important; }

/* Fehleranzeige */
#crash {
  position: fixed;
  left: 8px;
  right: 8px;
  top: 8px;
  z-index: 100;
  padding: 10px 12px;
  border-radius: 8px;
  background: #c0392b;
  color: #fff;
  font: 13px/1.4 monospace;
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
}

/* Spielstand übertragen */
.settings-title { margin: 16px 0 4px; font-weight: 700; }

.transfer-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.setting-action {
  flex: 1 1 0;
  min-width: 120px;
  padding: 10px 8px;
  border-radius: 8px;
  background: #e9ecef;
  color: #222;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

.setting-action.primary { background: #2d6a4f; color: #fff; }

#transfer-hint { margin: 10px 0 6px; font-size: 13px; line-height: 1.4; }

#transfer-code {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font: 12px/1.3 monospace;
  word-break: break-all;
  resize: vertical;
  user-select: text;
  -webkit-user-select: text;
}

#info-action.unaffordable { opacity: .6; }

#info-upgrade {
  width: 100%;
  margin-bottom: 8px;
  padding: 10px;
  border-radius: 8px;
  background: #f4a261;
  color: #222;
  font-weight: 700;
  line-height: 1.3;
}

#info-upgrade.unaffordable { opacity: .55; }

/* Abriss-Modus */
#map.demolishing { cursor: cell; }

.build-tab.demolish-tab .name { color: #ffb4a2; }
.build-tab.demolish-tab.active { background: #7a2e2e; }
#buildnav:has(.demolish-tab.active) #build-tabs { background: rgba(0, 0, 0, .18); }

#demolish-bar {
  padding: 8px 10px;
  background: #7a2e2e;
  color: #fff;
}

#demolish-info { font-size: 13px; line-height: 1.35; margin-bottom: 6px; }

.demolish-buttons { display: flex; gap: 6px; }

.demolish-buttons button {
  flex: 1;
  padding: 10px 6px;
  border-radius: 8px;
  font-weight: 700;
  background: rgba(255, 255, 255, .15);
}

#demolish-sell { background: #e63946; }
.demolish-buttons button:disabled { opacity: .45; cursor: default; }

/* Schmale Handys: Reiternamen etwas kleiner, damit alle 8 lesbar bleiben */
@media (max-width: 440px) {
  .build-tab .name { font-size: 8.5px; letter-spacing: -0.2px; }
  .build-tab .icon { font-size: 19px; }
}

/* Speicherplätze */
.slot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f1efe7;
}

.slot.active { background: #d8f3dc; box-shadow: inset 0 0 0 2px #2d6a4f; }
.slot.empty { opacity: .8; }
.slot-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.slot-text span { font-size: 12px; color: #555; }
.slot-buttons { display: flex; gap: 4px; }

.slot-buttons button {
  padding: 7px 9px;
  border-radius: 8px;
  background: #2d6a4f;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

/* Kompaktes Info-Fenster: Zusammenfassung, aufklappbare Details, Knöpfe nebeneinander */
#info { max-height: 46%; padding: 10px 12px; }
#info .info-head { font-size: 16px; }
#info-text { margin: 6px 0 4px; font-size: 13px; line-height: 1.35; }

#info-more {
  margin: 0 0 4px;
  font-size: 12.5px;
  line-height: 1.35;
  color: #444;
  white-space: pre-line;
}

#info-more-toggle {
  margin-bottom: 8px;
  padding: 2px 0;
  background: none;
  color: #2d6a4f;
  font-size: 13px;
  font-weight: 700;
}

.info-buttons { display: flex; gap: 6px; }

.info-buttons #info-upgrade,
.info-buttons #info-demolish {
  flex: 1 1 0;
  min-width: 0;
  width: auto;
  margin: 0;
  padding: 9px 6px;
  font-size: 13px;
  line-height: 1.25;
}

/* Verkaufen wartet auf Bestätigung */
#info-demolish.armed { background: #e63946; animation: pulse 0.8s ease-in-out infinite; }

/* Antippbare Hinweise unten links (z. B. „Arbeiter fehlen“) */
.effect.clickable {
  pointer-events: auto;
  cursor: pointer;
  background: rgba(192, 57, 43, .85);
  font-weight: 600;
}

/* Kurzinfo kompakt: nur eine Zeile, Details erst nach ⓘ */
#build-info { padding: 6px 8px 6px 10px; }
#build-info .bi-head { font-size: 14px; }
#build-info .bi-icon { font-size: 20px; }
#build-info .bi-head strong { flex: 0 1 auto; white-space: nowrap; }
.bi-meta {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
  color: #2d6a4f;
}
.bi-meta.unaffordable { color: #c0392b; }
.bi-more { width: 28px; height: 28px; border-radius: 50%; background: #e3f4d7; font-size: 15px; }
#build-info .bi-details { display: none; margin-top: 4px; }
#build-info.expanded .bi-details { display: block; }
#build-info.expanded .bi-more { background: #2d6a4f; color: #fff; }

/* Hinweis auf neue Version */
#update-banner {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 50%;
  translate: -50% 0;   /* nicht transform – das nutzt die Puls-Animation */
  z-index: 50;
  padding: 9px 14px;
  border-radius: 999px;
  white-space: nowrap;
  font-size: 14px;
  background: #1c7ed6;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
  animation: pulse 1.4s ease-in-out infinite;
}

/* Drehen / Verschieben */
.info-buttons.secondary { margin-top: 6px; }
.info-buttons.secondary button {
  flex: 1 1 0;
  padding: 7px 6px;
  border-radius: 8px;
  background: #e9ecef;
  color: #222;
  font-size: 13px;
  font-weight: 600;
}
.bi-rotate { width: 28px; height: 28px; border-radius: 50%; background: #fff3c4; font-size: 15px; }

#move-bar {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  max-width: 420px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 6px 10px;
  border-radius: 12px;
  background: #fff3c4;
  color: #222;
  font-size: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}
#move-bar.hidden { display: none; }

/* Spielgeschwindigkeit */
#topbar .speed-btn {
  width: auto;
  min-width: 52px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
#topbar .speed-btn.paused { background: #e63946; animation: pulse 1.2s ease-in-out infinite; }
#topbar .speed-btn.fast { background: #f4a261; color: #222; }
#resources .res.full { background: rgba(192, 57, 43, .45); }
