:root {
  --grund: #12151a;
  --flaeche: #1c2129;
  --flaeche2: #252c36;
  --linie: #3a4352;
  --text: #ece4d0;
  --matt: #a89f8a;
  --messing: #c9a35b;
  --messing-hell: #e3c27f;
  --gut: #7fc27a;
  --warn: #e0b04a;
  --gefahr: #e0644c;
  --blau: #6fa8dc;
  --seite-breite: 360px;
  --leiste-hoehe: 46px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--grund); touch-action: none; }
button { font: inherit; color: inherit; cursor: pointer; }

#karte { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#karte.ziehen { cursor: grabbing; }
#karte.ziel { cursor: crosshair; }

/* ---------------------------------------------------------- Leiste oben */
#leiste {
  position: fixed; top: 0; left: 0; right: 0; height: 46px;
  display: flex; align-items: center; gap: 6px; padding: 0 8px;
  background: linear-gradient(#232a35, #1a1f27); border-bottom: 1px solid #000;
  box-shadow: 0 2px 8px rgba(0,0,0,.45); z-index: 6; white-space: nowrap;
}
#leiste .titel { font-weight: 700; letter-spacing: .04em; color: var(--messing-hell); margin-right: 6px; font-size: 15px; }
#leiste .waren { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
#leiste .waren::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: baseline; gap: 4px; padding: 3px 7px; border-radius: 6px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.07); font-variant-numeric: tabular-nums;
}
.chip .d { font-size: 11px; color: var(--matt); }
.chip .d.plus { color: var(--gut); }
.chip .d.minus { color: var(--gefahr); }
.chip.knapp { border-color: var(--gefahr); }
.chip.voll { border-color: var(--warn); }
#leiste .zeit { display: flex; gap: 3px; align-items: center; }
.kn {
  background: var(--flaeche2); border: 1px solid var(--linie); border-radius: 6px; padding: 4px 9px; min-width: 32px;
}
.kn:hover { border-color: var(--messing); }
.kn.an { background: var(--messing); color: #1a1408; border-color: var(--messing-hell); font-weight: 600; }
.kn:disabled { opacity: .45; cursor: not-allowed; }
.kn.gefahr { border-color: var(--gefahr); color: #ffd9d0; }
.kn.gross { padding: 7px 12px; }

/* ---------------------------------------------------------- Seitenleiste */
#seite {
  position: fixed; top: var(--leiste-hoehe); right: 0; bottom: 0; width: var(--seite-breite);
  background: rgba(24,28,35,.97); border-left: 1px solid #000; overflow-y: auto; z-index: 4;
  padding: 12px 12px 30px; box-shadow: -4px 0 12px rgba(0,0,0,.35);
}
#seite h2 { margin: 0; font-size: 18px; color: var(--messing-hell); }
#seite h3 { margin: 14px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--matt); }
#seite .unter { color: var(--matt); font-size: 12.5px; margin: 2px 0 8px; }
#seite p { margin: 6px 0; line-height: 1.4; }
.zeile { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.balken { position: relative; height: 14px; background: #0d1014; border-radius: 4px; overflow: hidden; margin: 3px 0 6px; border: 1px solid #000; }
.balken > i { position: absolute; inset: 0 auto 0 0; background: var(--gut); }
.balken > i.warn { background: var(--warn); }
.balken > i.gefahr { background: var(--gefahr); }
.balken > i.blau { background: var(--blau); }
.balken > span { position: absolute; inset: 0; font-size: 10.5px; line-height: 13px; padding-left: 5px; color: #fff; text-shadow: 0 1px 2px #000; }
.werte { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 13px; font-variant-numeric: tabular-nums; }
.werte .k { color: var(--matt); }
.reiter { display: flex; gap: 2px; margin: 12px 0 8px; border-bottom: 1px solid var(--linie); }
.reiter button { background: none; border: 0; padding: 6px 10px; color: var(--matt); border-bottom: 2px solid transparent; }
.reiter button.an { color: var(--text); border-color: var(--messing); }
.reiter button:disabled { opacity: .4; }

.deck { display: grid; gap: 3px; margin: 6px 0 10px; }
.zelle {
  aspect-ratio: 1; background: #2a313c; border: 1px solid #3c4655; border-radius: 4px; position: relative;
  display: flex; align-items: center; justify-content: center; font-size: inherit; padding: 0;
}
.zelle.leer { background: repeating-linear-gradient(45deg, #1d232c 0 6px, #222933 6px 12px); color: #56606e; font-size: 16px; }
.zelle.gewaehlt { outline: 2px solid var(--messing-hell); outline-offset: 1px; }
.zelle .hp { position: absolute; left: 2px; right: 2px; bottom: 2px; height: 3px; background: #000; }
.zelle .hp i { position: absolute; inset: 0 auto 0 0; background: var(--gut); }
.zelle .st { position: absolute; top: 1px; right: 3px; font-size: 9px; color: var(--messing-hell); }
.zelle .bes { position: absolute; top: 1px; left: 3px; font-size: 9px; color: var(--warn); }
.zelle .bes.ruht { color: #aab2bf; }

.liste { display: flex; flex-direction: column; gap: 4px; }
.eintrag {
  display: grid; grid-template-columns: 30px 1fr; gap: 2px 8px; text-align: left; align-items: center;
  background: var(--flaeche2); border: 1px solid var(--linie); border-radius: 6px; padding: 6px 8px;
}
.eintrag:hover:not(:disabled) { border-color: var(--messing); }
.eintrag:disabled { opacity: .5; cursor: not-allowed; }
.eintrag.an { border-color: var(--messing-hell); background: #33301f; }
.eintrag .ic { grid-row: span 2; font-size: 22px; text-align: center; }
.eintrag .nm { font-weight: 600; }
.eintrag .kl { font-size: 11.5px; color: var(--matt); }
/* Arbeit: Schalter Wichtigstes zuerst / Gleichmäßig, Liste „Nicht voll besetzt“, Zeile „Arbeit“ in der Gebäude-Info */
.chip.klickbar { cursor: pointer; }
.chip.klickbar:hover { border-color: var(--messing); }
.zeile.wahl .kn { flex: 1; }
.ruhtliste { display: flex; flex-direction: column; gap: 3px; margin: 6px 0; }
.ruhtliste .abschnitt { font-size: 12px; color: var(--matt); margin: 6px 0 1px; }
.zl {
  display: grid; grid-template-columns: 22px 1fr; gap: 6px; align-items: center; text-align: left;
  background: var(--flaeche2); border: 1px solid var(--linie); border-radius: 6px; padding: 4px 8px; font-size: 12.5px;
}
.zl:hover { border-color: var(--messing); }
.zl .ic { font-size: 16px; text-align: center; }
.zl .st { font-weight: 400; color: var(--matt); }
.zl.fehlt { border-left: 3px solid var(--warn); }
.zl.fehlt .st { color: var(--warn); }
.zl.ruht { opacity: .8; }
.zst.teil, .zst.fehlt { color: var(--warn); }
.zst.ruht { color: var(--matt); }
body.touch .ruhtliste .zl { min-height: 40px; }
.liste.stufen { margin: 10px 0; }
.liste.stufen .eintrag .kl { font-size: 12.5px; line-height: 1.4; }
.kosten { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.kosten .fehlt { color: var(--gefahr); }

.kasten { background: var(--flaeche2); border: 1px solid var(--linie); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.kasten.gefahr { border-color: var(--gefahr); }
.kasten.gut { border-color: var(--gut); }

table.handel { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
table.handel th { text-align: left; color: var(--matt); font-weight: 500; padding: 3px 2px; }
table.handel td { padding: 3px 2px; border-top: 1px solid #2c333e; }
table.handel button { padding: 1px 6px; border-radius: 4px; background: var(--flaeche2); border: 1px solid var(--linie); font-size: 11.5px; }
table.handel button:disabled { opacity: .35; }

.kasten.gesperrt { border-style: dashed; color: var(--matt); font-size: 12.5px; }
.kasten.gesperrt b { color: var(--text); }
.vorschau { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 6px; }
.vorschau span { white-space: nowrap; }

/* ---------------------------------------------------------- Ticker, Hinweis, Minikarte */
#ticker {
  position: fixed; left: 8px; bottom: 8px; width: min(460px, calc(100vw - var(--seite-breite) - 230px));
  display: flex; flex-direction: column; gap: 3px; z-index: 3; pointer-events: none;
}
#ticker .m {
  pointer-events: auto; cursor: pointer; background: rgba(18,21,26,.86); border-left: 3px solid var(--linie);
  padding: 4px 8px; border-radius: 4px; font-size: 12.5px; transition: opacity .6s;
}
#ticker .m.gut { border-color: var(--gut); }
#ticker .m.warnung { border-color: var(--warn); }
#ticker .m.gefahr { border-color: var(--gefahr); background: rgba(60,18,14,.9); }
#ticker .m .t { color: var(--matt); margin-right: 6px; font-size: 11px; }
#ticker .m.alt { opacity: .55; }

#hinweis {
  position: fixed; top: calc(var(--leiste-hoehe) + 8px); left: 50%; transform: translateX(calc(-50% - var(--seite-breite) / 2));
  background: rgba(18,21,26,.92); border: 1px solid var(--messing); border-radius: 8px; padding: 6px 12px;
  z-index: 3; font-size: 13px; max-width: 70vw; text-align: center;
}
#hinweis .rot { color: var(--gefahr); }
#tooltip {
  position: fixed; pointer-events: none; z-index: 6; background: rgba(12,14,18,.92); border: 1px solid var(--linie);
  padding: 3px 7px; border-radius: 4px; font-size: 12px; max-width: 260px;
}
#minikarte {
  position: fixed; right: calc(var(--seite-breite) + 8px); bottom: 8px; width: 192px; height: 128px;
  border: 1px solid #000; box-shadow: 0 2px 8px rgba(0,0,0,.6); image-rendering: pixelated; z-index: 3; cursor: pointer;
}

/* ---------------------------------------------------------- Dialog */
#dialog { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; }
#dialog[hidden] { display: none; }
.dialog-box {
  background: var(--flaeche); border: 1px solid var(--messing); border-radius: 12px; padding: 20px 22px;
  max-width: 620px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
.dialog-box h1 { margin: 0 0 8px; color: var(--messing-hell); font-size: 26px; }
.dialog-box h2 { color: var(--messing-hell); font-size: 16px; margin: 16px 0 6px; }
.dialog-box p, .dialog-box li { line-height: 1.5; }
.dialog-box ul { padding-left: 20px; margin: 6px 0; }
.dialog-box .zeile { justify-content: flex-end; margin-top: 16px; }
kbd { background: #2b323d; border: 1px solid #4a5464; border-radius: 3px; padding: 0 5px; font-size: 12px; }

/* ---------------------------------------------------------- Geführte erste Runde */
#fuehrung {
  position: fixed; left: 12px; top: calc(var(--leiste-hoehe) + 52px); width: 330px; z-index: 5;
  background: rgba(24,28,35,.97); border: 1px solid var(--messing); border-radius: 10px; padding: 8px 12px 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.55); font-size: 13.5px;
}
#fuehrung[hidden] { display: none; }
#fuehrung .kopf { display: flex; align-items: center; gap: 4px; color: var(--matt); font-size: 12px; }
#fuehrung .kopf span { flex: 1; }
#fuehrung .kopf button { background: none; border: 0; color: var(--matt); padding: 2px 6px; font-size: 14px; border-radius: 4px; }
#fuehrung .kopf button:hover { color: var(--text); background: rgba(255,255,255,.08); }
#fuehrung h3 { margin: 6px 0 4px; font-size: 15px; color: var(--messing-hell); }
#fuehrung p { margin: 4px 0; line-height: 1.45; }
#fuehrung .zusatz { color: var(--warn); }
#fuehrung .zusatz .kn { color: var(--text); margin-top: 2px; }
#fuehrung .zaehler { font-weight: 600; margin: 4px 0; }
#fuehrung .klein-titel { font-weight: 600; margin-top: 2px; }
#fuehrung .fortschritt { height: 4px; background: #0d1014; border-radius: 2px; margin: 8px 0; overflow: hidden; }
#fuehrung .fortschritt i { display: block; height: 100%; background: var(--messing); }
#fuehrung .knoepfe { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
#fuehrung .orange { color: #e0a050; }
#fuehrung .gruen { color: var(--gut); }
#fuehrung .rot { color: var(--gefahr); }
.zeiger { outline: 2px solid var(--messing-hell) !important; outline-offset: 2px; animation: zeiger 1.3s ease-in-out infinite; }
@keyframes zeiger { 50% { outline-color: rgba(227,194,127,.2); box-shadow: 0 0 0 5px rgba(227,194,127,.28); } }

/* ---------------------------------------------------------- Titelbild (?titelbild) */
.titelbild #leiste, .titelbild #seite, .titelbild #ticker, .titelbild #minikarte, .titelbild #hinweis, .titelbild #tooltip { display: none !important; }
#titel {
  position: fixed; left: 48px; bottom: 44px; z-index: 6; padding: 18px 26px; border-radius: 14px;
  background: rgba(14,17,22,.82); border: 1px solid var(--messing); box-shadow: 0 8px 30px rgba(0,0,0,.6);
}
#titel[hidden] { display: none; }
#titel h1 { margin: 0; font-size: 64px; letter-spacing: .03em; color: var(--messing-hell); line-height: 1.05; }
#titel p { margin: 6px 0 0; font-size: 22px; color: var(--text); }

/* ---------------------------------------------------------- Handy: allgemein (body.touch) */
html, body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#seite, .dialog-box, #fuehrung { touch-action: pan-y; }
#leiste .waren { touch-action: pan-x; }
#leiste .status { display: flex; gap: 4px; }
#hinweis .gruen { color: var(--gut); }
.nur-touch { display: none; }
.griff { display: none; }
#knoepfe { display: none; }

body.touch .nur-touch { display: inline-flex; align-items: center; justify-content: center; }
body.touch #leiste [data-a="tempo"]:not([data-t="0"]) { display: none; }
body.touch .kn { min-height: 38px; padding: 7px 12px; }
body.touch .kn.gross { min-height: 44px; }
body.touch .reiter button { padding: 10px 12px; }
body.touch .eintrag { padding: 9px 10px; }
body.touch .zelle { min-height: 40px; }
body.touch table.handel button { min-height: 34px; min-width: 42px; padding: 4px 8px; margin: 1px; }
body.touch #fuehrung .kopf button { padding: 6px 12px; font-size: 17px; }
body.touch #ticker .m { padding: 7px 10px; }

/* Daumenknöpfe auf der Karte */
body.touch #knoepfe {
  display: flex; flex-direction: column; align-items: flex-end; justify-content: flex-end; gap: 8px;
  flex-wrap: wrap-reverse; align-content: flex-start;
  position: fixed; top: calc(var(--leiste-hoehe) + 8px); right: calc(var(--seite-breite) + 10px); bottom: 12px;
  z-index: 5; pointer-events: none;
}
/* Am Tablet steht die große Übersichtskarte sonst unter den Knöpfen – sie kommt über 🗺 */
body.touch:not(.mini-offen) #minikarte { display: none; }
/* Hinweiszeile darf die ganze Breite der Karte nutzen */
body.touch #hinweis { left: 8px; right: calc(var(--seite-breite) + 8px); width: fit-content; max-width: none; margin: 0 auto; transform: none; }
#fuehrung .knoepfe { position: sticky; bottom: -10px; background: rgba(24,28,35,.97); padding: 4px 0 2px; }
.fab {
  pointer-events: auto; width: 48px; height: 48px; border-radius: 50%; font-size: 21px; line-height: 1;
  background: rgba(28,33,41,.92); border: 1px solid var(--linie); box-shadow: 0 3px 10px rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.fab.an { background: var(--messing); color: #1a1408; border-color: var(--messing-hell); }
.fab.breit { width: auto; border-radius: 24px; padding: 0 18px; font-size: 16px; font-weight: 700;
  background: var(--messing); color: #1a1408; border-color: var(--messing-hell); }
.fab[hidden] { display: none; }

/* Übersichtskarte als Einblendung */
body.touch.mini-offen #minikarte {
  display: block !important; position: fixed; top: calc(var(--leiste-hoehe) + 8px); left: 10px; right: auto; bottom: auto;
  width: min(300px, 76vw); height: auto; aspect-ratio: 3 / 2; z-index: 7; border: 1px solid var(--messing);
}

/* ---------------------------------------------------------- Handy hochkant: Leiste zweizeilig, Panel als Blatt unten */
body.hochkant { --seite-breite: 0px; }
body.hochkant #leiste {
  height: auto; flex-wrap: wrap; row-gap: 5px; padding: calc(5px + env(safe-area-inset-top)) 8px 5px;
}
body.hochkant #leiste .titel { display: none; }
body.hochkant #leiste .status { order: 1; }
body.hochkant #leiste .zeit { order: 2; margin-left: auto; }
body.hochkant #leiste .waren { order: 3; flex-basis: 100%; }
/* Hochkant zählt jeder Pixel: die Waren samt Tagesänderung sollen ohne Wischen in eine Zeile passen */
body.hochkant .chip { padding: 3px 5px; gap: 3px; }
body.hochkant .chip .d { font-size: 10px; }
body.hochkant #leiste .waren { gap: 3px; }
/* 👷−n am Einwohner-Chip: hochkant als Abzeichen darüber, damit die erste Zeile nicht umbricht */
body.hochkant #c-bew { position: relative; }
body.hochkant #c-bew .arb {
  position: absolute; right: -5px; top: -6px; font-size: 9px; line-height: 1; padding: 1px 3px; border-radius: 6px;
  background: var(--grund); border: 1px solid var(--gefahr);
}
body.hochkant #seite {
  top: auto; left: 0; right: 0; width: auto; height: var(--blatt, 45vh); border-left: 0; border-top: 1px solid var(--messing);
  border-radius: 14px 14px 0 0; padding: 0 12px calc(18px + env(safe-area-inset-bottom)); transition: height .18s ease;
}
body.hochkant.blatt-zieht #seite { transition: none; }
body.hochkant .griff {
  display: flex; justify-content: center; align-items: center; position: sticky; top: 0; z-index: 1;
  height: 26px; margin: 0 -12px 4px; background: rgba(24,28,35,.98); touch-action: none; cursor: grab;
}
body.hochkant .griff i { display: block; width: 46px; height: 5px; border-radius: 3px; background: var(--linie); }
body.hochkant #ticker { bottom: calc(var(--blatt, 45vh) + 8px); left: 8px; width: calc(100vw - 76px); }
body.hochkant #ticker .m:not(:nth-last-child(-n+2)) { display: none; }   /* die zwei neuesten */
body.hochkant #minikarte { display: none; }
body.hochkant #hinweis { transform: translateX(-50%); top: calc(var(--leiste-hoehe) + 6px); max-width: calc(100vw - 16px); }
body.hochkant #knoepfe { bottom: calc(var(--blatt, 45vh) + 10px); }
body.hochkant.blatt-gross #knoepfe, body.hochkant.blatt-gross #ticker { display: none; }
/* Sehr schmale Handys (320 px): Tageszähler weglassen, damit die Leiste zweizeilig bleibt */
@media (max-width: 359px) { body.hochkant #c-tag { display: none; } }
@media (max-width: 379px) {
  body.hochkant .chip { padding: 2px 3px; gap: 2px; font-size: 12.5px; }
  body.hochkant #leiste .waren, body.hochkant #leiste .status { gap: 3px; }
}
/* Niedrige Karte (kleine Handys): ＋/－ weglassen, Zoomen geht mit zwei Fingern – sonst brechen die Knöpfe in eine zweite Spalte über den Ticker */
@media (max-height: 700px) { body.hochkant #knoepfe [data-k="rein"], body.hochkant #knoepfe [data-k="raus"] { display: none; } }
body.hochkant #fuehrung {
  left: 8px; right: 68px; width: auto; top: auto; bottom: calc(var(--blatt, 45vh) + 96px); overflow-y: auto; font-size: 13px;
  max-height: calc(100vh - var(--blatt, 45vh) - var(--leiste-hoehe) - 90px);
}

/* ---------------------------------------------------------- Handy quer: schmales Panel rechts */
body.quer { --seite-breite: 300px; }
body.quer #leiste { height: 40px; padding: 0 calc(8px + env(safe-area-inset-right)) 0 calc(8px + env(safe-area-inset-left)); }
body.quer #leiste .titel { display: none; }
body.quer #seite { width: var(--seite-breite); padding: 8px calc(10px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) 10px; }
body.quer #minikarte { display: none; }
body.quer #ticker { width: calc(100vw - var(--seite-breite) - 84px); left: calc(8px + env(safe-area-inset-left)); }
body.quer #ticker .m:not(:last-child) { display: none; }                  /* nur die neueste */
body.quer #knoepfe { bottom: 8px; }
@media (max-height: 440px) { body.quer #knoepfe [data-k="rein"], body.quer #knoepfe [data-k="raus"] { display: none; } }
body.quer #fuehrung {
  left: calc(8px + env(safe-area-inset-left)); top: calc(var(--leiste-hoehe) + 44px); width: min(300px, calc(100vw - var(--seite-breite) - 84px));
  max-height: calc(100vh - var(--leiste-hoehe) - 110px); overflow-y: auto; font-size: 12.5px;
}


/* Dialoge am Handy: volle Breite, scrollbar, Knöpfe untereinander */
@media (max-width: 560px) {
  .dialog-box { padding: 16px 14px; max-height: 88vh; }
  .dialog-box h1 { font-size: 22px; }
  .dialog-box .zeile { flex-direction: column-reverse; align-items: stretch; }
}
/* Knöpfe bleiben unten sichtbar, auch wenn der Text scrollt */
body.touch .dialog-box .zeile { position: sticky; bottom: -20px; background: var(--flaeche); padding: 8px 0 4px; margin-top: 10px; }
@media (max-width: 560px) { body.touch .dialog-box .zeile { bottom: -16px; } }
/* Quer: niedriger Bildschirm, Dialog kompakter */
body.quer #dialog { padding: 8px; }
body.quer .dialog-box { padding: 12px 18px; max-height: calc(100vh - 16px); }
body.quer .dialog-box h1 { font-size: 20px; margin-bottom: 4px; }
body.quer .dialog-box p { margin: 6px 0; line-height: 1.4; }
body.quer .dialog-box .zeile { bottom: -12px; margin-top: 6px; }
