:root {
  --bg: #f4f1ea; --surface: #fffdf8; --surface-2: #f0ebe0; --ink: #2a2620;
  --muted: #8a8172; --line: #e2dccf; --gold: #b8892f; --gold-2: #d9b24a;
  --green: #3f8a54; --red: #b4472f; --blue: #37648f; --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f; --surface: #211c15; --surface-2: #2a231a; --ink: #efe7d6;
    --muted: #9a8f79; --line: #38301f; --gold: #d9b24a; --gold-2: #c8a04a;
    --green: #5cbf78; --red: #e0714f; --blue: #6ea3d6;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 0;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
h1 { margin: .2rem 0; letter-spacing: .5px; }
h2 { font-size: 1.02rem; margin: 0 0 .7rem; }

.logo {
  width: 64px; height: 64px; margin: 0 auto; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--gold-2), var(--gold));
  color: #241b06; font-weight: 800; font-size: 2rem; display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(0,0,0,.25), inset 0 2px 6px rgba(255,255,255,.35);
}
.logo.sm { width: 26px; height: 26px; font-size: .95rem; box-shadow: none; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
#login { max-width: 380px; margin: 12vh auto; }
#login form { display: flex; gap: .6rem; margin-top: 1rem; }
.gbtn { display: flex; justify-content: center; margin: 1.2rem 0 .4rem; min-height: 44px; }
#devlogin { margin-top: 1rem; }

.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .8rem;
  padding: .7rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.coin { color: var(--gold); font-weight: 800; }
.brand { min-width: 0; }
.brand #playerName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 32vw; display: inline-block; vertical-align: bottom; }
.stats { margin-left: auto; display: flex; gap: 1rem; }
.wstat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.wstat .wlabel { font-size: .6rem; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.wstat strong { font-size: 1.02rem; }

.grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;
  max-width: 900px; margin: 1rem auto; padding: 0 1rem;
}
.wide { grid-column: 1 / -1; }
@media (max-width: 640px) { .grid { grid-template-columns: 1fr; } }

.stack { display: flex; flex-direction: column; gap: .6rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; }
.chips { display: flex; gap: .5rem; flex-wrap: wrap; }
.chip {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px;
  padding: .3rem .7rem; font-size: .9rem;
}
.chip b { color: var(--gold); }
.chipval { color: var(--muted); font-size: .72rem; }
.matreq { font-size: .72rem; color: var(--muted); }
.matreq.bad { color: var(--red); }
/* Lager als Tabelle */
.invtable { width: 100%; border-collapse: collapse; font-size: .85rem; }
.invtable th { text-align: left; color: var(--muted); font-weight: 600; font-size: .72rem; text-transform: uppercase; letter-spacing: .4px; padding: .2rem .4rem; border-bottom: 1px solid var(--line); }
.invtable td { padding: .32rem .4rem; border-bottom: 1px solid var(--line); }
.invtable .num { text-align: right; font-variant-numeric: tabular-nums; }
.invtable th.num { text-align: right; }
.invtable .sumrow td { font-weight: 700; color: var(--gold); border-bottom: 0; }

button {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 10px;
  padding: .5rem .9rem; background: var(--gold); color: #241b06; transition: filter .15s;
}
button:hover { filter: brightness(1.07); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); padding: .35rem .6rem; }
button.small { padding: .3rem .6rem; font-size: .82rem; }
button.buy { background: var(--green); color: #fff; }
button.warn { background: transparent; color: var(--red); border: 1px solid var(--red); }
input, select {
  font: inherit; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 10px; background: var(--surface-2); color: var(--ink); min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--gold-2); }

.building { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .6rem; }
/* Kompakte Gebäude-Zeile (BES): so viel wie möglich in eine Zeile, horizontal scrollbar */
.bline { display: flex; align-items: center; flex-wrap: wrap; gap: .25rem .3rem; font-size: .78rem; }
.bline::-webkit-scrollbar { height: 3px; }
.bline b { font-size: .88rem; }
.bline > * { flex: 0 0 auto; }
.bline .cond.good { color: var(--green); }
.bline .cond.bad { color: var(--red); }
.bline button.small { padding: .25rem .5rem; font-size: .72rem; }
.idchip { font-family: ui-monospace, monospace; font-size: .68rem; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 5px; padding: .05rem .35rem; }
/* Sortier-Leiste über der Gebäudeliste */
.sortbar { display: flex; align-items: center; gap: .4rem; margin-bottom: .5rem; font-size: .8rem; }
.sortbar select { padding: .3rem .5rem; font-size: .8rem; }
/* Gebäude als Liste (untereinander) */
#buildings { display: flex; flex-direction: column; gap: .5rem; }
.bline .rowrepair { margin-left: auto; }
/* Klickbare Gebäude-Zeile → Detail-Menü */
.building[data-open] { cursor: pointer; }
.building[data-open]:hover { border-color: var(--gold); }
.prodchip { font-size: .68rem; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: .05rem .35rem; color: var(--gold); font-weight: 600; }
.opencaret { margin-left: .1rem; font-size: 1.1rem; }
/* Detail-Menü */
.menusec { margin: .7rem 0; }
.prodgrid { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .4rem; }
.prodbtn { background: var(--surface-2); color: inherit; border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; font-weight: 600; font-size: .82rem; }
.prodbtn.active { border-color: var(--gold); color: var(--gold); background: color-mix(in srgb, var(--gold) 12%, var(--surface-2)); }
.menurow { margin: .4rem 0; }
.menuactions { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.menuactions button { width: 100%; }
.building .head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.building .bicon { font-size: 1.15rem; }
.prod { font-size: .82rem; color: var(--gold); margin: .1rem 0 .5rem; letter-spacing: .3px; }
.lvlchip { font-size: .66rem; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: .05rem .4rem; color: var(--gold); font-weight: 700; vertical-align: middle; }
.brow { display: flex; gap: .4rem; }
.bar { height: 8px; border-radius: 6px; background: var(--line); margin: .5rem 0; overflow: hidden; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--green), var(--gold-2)); }
.bar.low > span { background: linear-gradient(90deg, var(--red), var(--gold)); }
.buildmenu { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .8rem; }

.offer { display: flex; align-items: center; gap: .6rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .8rem; }
.offer .ogrow { flex: 1; min-width: 0; }
.offer input { width: 68px; }

/* Gebäude-Status */
.building.st-run { border-left: 3px solid var(--green); }
.building.st-idle { border-left: 3px solid #c9962f; }
.building.st-ruin { border-left: 3px solid var(--red); }
.stbadge { font-size: .72rem; white-space: nowrap; }
.bfoot { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-top: .45rem; }

/* Markt-Karten */
.otop { display: flex; align-items: center; gap: .4rem; }
.offer.mine { border-color: var(--gold); background: rgba(217, 178, 74, .1); }
.badge { font-size: .62rem; text-transform: uppercase; letter-spacing: .5px; background: var(--gold); color: #241b06; border-radius: 999px; padding: .05rem .45rem; font-weight: 700; }

/* Level & Ziele */
.lvl { margin-bottom: .8rem; }
.lvlhead { display: flex; align-items: center; gap: .6rem; margin-bottom: .35rem; }
.lvlbadge { background: linear-gradient(90deg, var(--gold), var(--gold-2)); color: #241b06; font-weight: 800; border-radius: 999px; padding: .1rem .7rem; }
.goals-list { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem .9rem; }
.goal { font-size: .9rem; }
.goal.done { color: var(--muted); text-decoration: line-through; }
.daykpi { margin-bottom: .7rem; font-size: .92rem; }
.actrow { display: flex; justify-content: space-between; gap: .5rem; font-size: .88rem; padding: .25rem 0; border-bottom: 1px solid var(--line); }
.actrow:last-child { border-bottom: 0; }
.ovkpis { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: .9rem; }
.ovrow { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px solid var(--line); }
.ovrow:last-child { border-bottom: 0; }
.pday { margin: -.15rem 0 .45rem; }
.lbrow { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.lbrow:last-child { border-bottom: 0; }
.lbrow.mine { color: var(--gold); font-weight: 700; }
b.good { color: var(--green); } b.bad { color: var(--red); }
.onboard { text-align: center; padding: .6rem .3rem; }
.onboard .obig { font-size: 2rem; }
.onboard strong { display: block; margin: .25rem 0 .4rem; font-size: 1.05rem; }
@media (max-width: 640px) { .goals-list { grid-template-columns: 1fr; } }

.econ { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: .6rem; }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .7rem; }
.stat .v { font-size: 1.25rem; font-weight: 700; }
.stat .v.good { color: var(--green); } .stat .v.bad { color: var(--red); }

.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); z-index: 20; max-width: 90vw;
}
footer { padding: 1rem; }

/* Tab-Navigation */
.linkbtn { background: transparent; border: 0; color: var(--muted); padding: 0 .15rem; font-size: .9rem; cursor: pointer; }
.linkbtn.ul { color: var(--gold); text-decoration: underline; font-weight: 600; }
.limitline { margin-top: .35rem; }
.tabwrap { max-width: 640px; margin: 0 auto; padding: 1rem 1rem calc(76px + env(safe-area-inset-bottom)); }
.tabpanel { display: none; flex-direction: column; gap: 1rem; }
.tabpanel.active { display: flex; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 12px rgba(0,0,0,.12);
}
.tabbar button {
  flex: 1; background: transparent; color: var(--muted); border: 0; border-radius: 0;
  padding: .5rem 0 .55rem; display: flex; flex-direction: column; align-items: center; gap: .15rem; font-weight: 600;
}
.tabbar button .ti { font-size: 1.25rem; line-height: 1; }
.tabbar button .tl { font-size: .68rem; }
.tabbar button.active { color: var(--gold); }
.tabbar button:hover { filter: none; }

/* Hilfe / Wiki-Overlay */
.overlay { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.55); display: flex; justify-content: center; align-items: flex-start; overflow-y: auto; padding: 1rem; }
.overlay.hidden { display: none; }
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); max-width: 640px; width: 100%; padding: .3rem 1.2rem 2rem; }
.sheethead { display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; background: var(--surface); padding-top: .6rem; }
#helpBody h3 { margin: 1.3rem 0 .5rem; font-size: 1rem; }
.wikicards { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
@media (max-width: 560px) { .wikicards { grid-template-columns: 1fr; } }
.wikicard { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .7rem; }
.wikihead { margin-bottom: .35rem; }
.wikitab { width: 100%; font-size: .82rem; border-collapse: collapse; }
.wikitab td { padding: .12rem 0; }
.wikitab td:first-child { color: var(--muted); padding-right: .6rem; white-space: nowrap; width: 42%; }
.wikilist { margin: .2rem 0 .2rem 1.1rem; padding: 0; font-size: .9rem; }
.wikilist li { margin: .25rem 0; }

/* Region-Umschaltleiste (BES-137) */
.regionbar { display: flex; gap: .5rem; overflow-x: auto; padding: .55rem .8rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.regionbar:empty { display: none; }
.regbtn {
  flex: 0 0 auto; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: .35rem .8rem; font-weight: 600; font-size: .85rem; white-space: nowrap;
}
.regbtn.active { color: var(--gold); border-color: var(--gold); background: color-mix(in srgb, var(--gold) 12%, var(--surface-2)); }
.regchip { font-size: .68rem; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 .3rem; margin-left: .3rem; white-space: nowrap; }
