:root {
  --bg: #14121c;
  --panel: #1e1b2c;
  --panel2: #282438;
  --line: #45405e;
  --hi: #5e5880;
  --text: #e8e4f4;
  --dim: #9a94b4;
  --gold: #ffd84a;
  --green: #5ad06a;
  --red: #ff5a5a;
  --blue: #5aa8ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: 'VT323', monospace; font-size: 20px; user-select: none; }
/* inset:0 ohne 100vh – sonst ist die Leinwand auf iOS höher als der sichtbare Bereich */
canvas#game { position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%; display: block; image-rendering: pixelated; cursor: crosshair; }
html, body { position: fixed; inset: 0; }
.hidden { display: none !important; }

.panel, #top, #hotbar, .modal-inner, .login-box, #chat input, #miniwrap {
  background: var(--panel);
  border: 3px solid var(--line);
  box-shadow: inset 0 0 0 1px #000, 4px 4px 0 rgba(0,0,0,.55);
}
.pbtn {
  font-family: 'VT323', monospace; font-size: 20px; color: var(--text);
  background: var(--panel2); border: 2px solid var(--hi); padding: 2px 10px; cursor: pointer;
  box-shadow: inset -2px -2px 0 rgba(0,0,0,.4), inset 2px 2px 0 rgba(255,255,255,.08);
}
.pbtn:hover { background: #363050; border-color: var(--gold); }
.pbtn:active { box-shadow: inset 2px 2px 0 rgba(0,0,0,.4); }
.pbtn.big { font-family: 'Press Start 2P', monospace; font-size: 14px; padding: 12px 18px; background: #3a6a2a; border-color: #7ad05a; }
.pbtn.big:hover { background: #4a8a36; }
.pbtn.danger { border-color: #a04040; }
.pbtn.danger:hover { background: #5a2020; border-color: var(--red); }

/* --------- Topbar --------- */
#top { position: fixed; top: 8px; left: 8px; right: 8px; display: flex; align-items: center; gap: 6px; padding: 4px 8px; flex-wrap: wrap; z-index: 5; }
.stat { padding: 2px 10px; background: #15131f; border: 2px solid #2e2a42; white-space: nowrap; }
.stat.money { color: var(--gold); font-size: 24px; min-width: 120px; }
.stat.power { display: flex; align-items: center; gap: 6px; }
.stat.power .bar { width: 70px; height: 10px; background: #0a0910; border: 1px solid #3a3654; }
.stat.power .bar i { display: block; height: 100%; width: 0; background: var(--green); }
.stat.research { cursor: pointer; color: #c8b8ff; max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.stat.research:hover { border-color: var(--hi); }
#top .pbtn { margin-left: auto; }
#top .pbtn + .pbtn { margin-left: 0; }

#hoverInfo { position: fixed; top: 60px; left: 12px; padding: 2px 8px; background: rgba(20,18,28,.85); border: 2px solid #2e2a42; z-index: 4; pointer-events: none; color: var(--dim); }

/* --------- Hotbar --------- */
#hotbar { position: fixed; bottom: 8px; left: 50%; transform: translateX(-50%); padding: 4px; z-index: 5; max-width: calc(100vw - 420px); }
#cats { display: flex; gap: 2px; margin-bottom: 4px; flex-wrap: wrap; }
#cats button { font-family: 'Press Start 2P', monospace; font-size: 9px; padding: 6px 8px; background: #15131f; color: var(--dim); border: 2px solid #2e2a42; cursor: pointer; }
#cats button.on { color: var(--gold); border-color: var(--gold); background: #2a2438; }
#blist { display: flex; gap: 4px; flex-wrap: wrap; }
.bbtn { position: relative; width: 72px; height: 88px; background: #15131f; border: 2px solid #2e2a42; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 3px; }
.bbtn img { width: 64px; height: 64px; image-rendering: pixelated; }
.bbtn .c { font-size: 16px; color: var(--gold); line-height: 1; margin-top: 2px; }
.bbtn .k { position: absolute; top: 1px; left: 3px; font-size: 14px; color: var(--dim); }
.bbtn:hover { border-color: var(--hi); background: #221e30; }
.bbtn.on { border-color: var(--gold); background: #2e2840; box-shadow: 0 0 0 2px #000, 0 0 10px rgba(255,216,74,.4); }
.bbtn.locked { opacity: .35; cursor: not-allowed; }
.bbtn .wicon { font-size: 40px; line-height: 64px; height: 64px; color: #e0a040; text-shadow: 2px 2px 0 #000; }
.bbtn.locked::after { content: '🔒'; position: absolute; top: 18px; font-size: 18px; }
.bbtn.poor .c { color: var(--red); }

/* --------- Inspector --------- */
#inspector { position: fixed; right: 8px; top: 64px; width: 330px; max-height: calc(100vh - 290px); overflow-y: auto; padding: 10px; z-index: 6; }
#inspector h3 { font-family: 'Press Start 2P', monospace; font-size: 11px; margin: 0 0 6px; color: var(--gold); display: flex; align-items: center; gap: 8px; }
#inspector h3 img { width: 32px; height: 32px; image-rendering: pixelated; }
#inspector .desc { color: var(--dim); font-size: 18px; margin-bottom: 8px; line-height: 1; }
#inspector .sec { margin: 8px 0 4px; color: #c8b8ff; font-size: 18px; border-bottom: 1px solid var(--line); }
.rgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.rbtn { background: #15131f; border: 2px solid #2e2a42; padding: 2px; cursor: pointer; display: flex; align-items: center; justify-content: center; height: 40px; }
.rbtn:hover { border-color: var(--hi); }
.rbtn.on { border-color: var(--gold); background: #2e2840; }
.rbtn img, img.ii { image-rendering: pixelated; vertical-align: middle; }
.recipe { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 18px; }
.recipe .arrow { color: var(--gold); margin: 0 4px; }
.inrow { display: flex; align-items: center; gap: 6px; font-size: 18px; margin: 2px 0; }
.inrow .ok { color: var(--green); } .inrow .no { color: var(--red); }
.pbar { height: 12px; background: #0a0910; border: 1px solid #3a3654; margin: 4px 0; }
.pbar i { display: block; height: 100%; background: linear-gradient(90deg, #4aa84a, #8ae06a); }
.pbar.y i { background: linear-gradient(90deg, #c09020, #ffd84a); }
.pbar.b i { background: linear-gradient(90deg, #3070c0, #5ab8ff); }
.btnrow { display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.pw-none { color: var(--red); } .pw-low { color: #ffb040; } .pw-ok { color: var(--green); }

/* --------- Chat --------- */
#chat { position: fixed; left: 8px; bottom: 8px; width: 340px; z-index: 5; pointer-events: none; }
#chatlog { max-height: 220px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; }
#chatlog div { background: rgba(20,18,28,.8); padding: 0 6px; margin-top: 2px; font-size: 18px; transition: opacity 1s; text-shadow: 1px 1px 0 #000; word-wrap: break-word; }
#chatlog div.old { opacity: 0; }
#chat.open #chatlog div.old { opacity: 1; }
#chat input { pointer-events: auto; width: 100%; margin-top: 4px; font-family: 'VT323', monospace; font-size: 18px; color: var(--text); padding: 3px 6px; outline: none; opacity: .5; }
#chat input:focus { opacity: 1; border-color: var(--gold); }

/* --------- Minimap --------- */
#miniwrap { position: fixed; right: 8px; bottom: 8px; padding: 3px; z-index: 5; }
#minimap { display: block; width: 192px; height: 192px; image-rendering: pixelated; cursor: pointer; }

/* --------- Modals --------- */
.modal { position: fixed; inset: 0; background: rgba(8,6,14,.7); z-index: 20; display: flex; align-items: center; justify-content: center; }
.modal-inner { width: min(1400px, calc(100vw - 32px)); height: calc(100vh - 48px); display: flex; flex-direction: column; }
.modal-inner.small { width: min(720px, calc(100vw - 32px)); height: auto; max-height: calc(100vh - 48px); }
.modal header { display: flex; align-items: center; gap: 16px; padding: 10px 14px; border-bottom: 3px solid var(--line); }
.modal header h2 { font-family: 'Press Start 2P', monospace; font-size: 16px; margin: 0; color: var(--gold); }
.modal header .close { margin-left: auto; }
#techSub { color: var(--dim); }
#techScroll { flex: 1; overflow: auto; position: relative; background: repeating-linear-gradient(0deg, transparent 0 31px, rgba(255,255,255,.025) 31px 32px), repeating-linear-gradient(90deg, transparent 0 31px, rgba(255,255,255,.025) 31px 32px); }
#techTree { position: relative; }
#techTree svg { position: absolute; left: 0; top: 0; pointer-events: none; }
.tnode { position: absolute; width: 190px; padding: 5px 7px; background: #15131f; border: 3px solid #34304a; font-size: 17px; line-height: 1; box-shadow: 3px 3px 0 #000; }
.tnode .tn { font-family: 'Press Start 2P', monospace; font-size: 9px; line-height: 1.3; margin-bottom: 4px; color: var(--text); }
.tnode .tc, .tnode .tu { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; margin-top: 3px; }
.tnode .tu img { width: 22px; height: 22px; image-rendering: pixelated; background: #0c0b12; }
.tnode .td { color: var(--dim); font-size: 15px; margin-top: 3px; }
.tnode.done { border-color: #3a8a4a; background: #142418; }
.tnode.done .tn { color: var(--green); }
.tnode.avail { border-color: #6a60a0; cursor: pointer; }
.tnode.avail:hover { border-color: var(--gold); background: #221e30; }
.tnode.locked { opacity: .45; }
.tnode.cur { border-color: var(--gold); background: #2a2410; box-shadow: 0 0 0 2px #000, 0 0 14px rgba(255,216,74,.5); }
.tnode .pbar { height: 8px; }

.helpbody { padding: 10px 18px 18px; overflow-y: auto; line-height: 1.05; }
.helpbody h3 { font-family: 'Press Start 2P', monospace; font-size: 11px; color: #c8b8ff; margin: 14px 0 6px; }
.helpbody td { padding: 2px 10px 2px 0; vertical-align: top; }
.helpbody td:first-child { color: var(--gold); white-space: nowrap; }
.helpbody b { color: var(--gold); font-weight: normal; }
.helpbody li { margin: 3px 0; }

/* --------- Login --------- */
#login, #disconnected { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 40%, rgba(40,30,70,.75), rgba(8,6,14,.95)); }
.login-box { padding: 26px 30px; width: min(440px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 12px; }
.login-box h1 { font-family: 'Press Start 2P', monospace; font-size: 28px; margin: 0; color: var(--text); text-shadow: 3px 3px 0 #000; text-align: center; }
.login-box h1 span { color: var(--gold); }
.login-box h2 { font-family: 'Press Start 2P', monospace; font-size: 14px; text-align: center; }
.login-box .tag { text-align: center; color: var(--dim); margin: -6px 0 6px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; color: var(--dim); }
.login-box input { font-family: 'VT323', monospace; font-size: 22px; padding: 6px 8px; background: #0e0c16; color: var(--text); border: 2px solid var(--line); outline: none; }
.login-box input:focus { border-color: var(--gold); }
#lColors { display: flex; gap: 6px; flex-wrap: wrap; }
#lColors span { width: 28px; height: 28px; border: 3px solid #000; cursor: pointer; box-shadow: 2px 2px 0 rgba(0,0,0,.5); }
#lColors span.on { border-color: #fff; }
.login-box .hint { color: var(--dim); font-size: 17px; text-align: center; margin: 0; }

/* --------- Toasts / Tooltip --------- */
#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 25; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; }
.toast { background: var(--panel); border: 2px solid var(--red); padding: 4px 14px; box-shadow: 3px 3px 0 #000; animation: tin .15s; }
.toast.good { border-color: var(--gold); color: var(--gold); font-family: 'Press Start 2P', monospace; font-size: 12px; padding: 10px 16px; }
@keyframes tin { from { transform: translateY(-8px); opacity: 0; } }
#tooltip { position: fixed; z-index: 40; pointer-events: none; background: #0e0c16; border: 2px solid var(--hi); padding: 6px 9px; max-width: 320px; font-size: 18px; line-height: 1.05; box-shadow: 3px 3px 0 #000; }
#tooltip b { color: var(--gold); font-weight: normal; }
#tooltip .dim { color: var(--dim); }
#flash { position: fixed; inset: 0; pointer-events: none; z-index: 19; background: #ffd84a; opacity: 0; transition: opacity .6s; }

/* --------- Zeitalter / Rezepte / Aufträge --------- */
.stat.elev, .stat.orders { cursor: pointer; color: #9ad8ff; }
.stat.orders { color: #ffd890; }
.stat.elev:hover, .stat.orders:hover { border-color: var(--hi); }
.alttag { font-size: 13px; background: #6a3a9a; color: #fff; padding: 0 4px; border: 1px solid #a070ff; vertical-align: middle; }
.rbtn.alt { border-color: #5a3a7a; }
.rbtn.alt.on { border-color: #c090ff; }
.tnode .tu img.altimg { outline: 1px solid #a070ff; }
.tnode.era { opacity: .4; }
.erahead { position: absolute; top: 14px; font-family: 'Press Start 2P', monospace; font-size: 10px; color: var(--gold); white-space: nowrap; }
.erahead.closed { color: #8a84a4; }
.order { background: #15131f; border: 2px solid #2e2a42; padding: 4px 6px; margin: 4px 0; }
.order b { font-weight: normal; color: var(--gold); }
.inrow.dim { color: var(--dim); font-size: 16px; }

#book header input { flex: 1; max-width: 320px; font-family: 'VT323', monospace; font-size: 20px; padding: 3px 8px; background: #0e0c16; color: var(--text); border: 2px solid var(--line); outline: none; }
#book header input:focus { border-color: var(--gold); }
.bookbody { flex: 1; display: grid; grid-template-columns: minmax(260px, 42%) 1fr; min-height: 0; }
#bookList { overflow-y: auto; padding: 8px 12px; border-right: 3px solid var(--line); }
#bookDetail { overflow-y: auto; padding: 10px 16px; }
.bgroup { font-family: 'Press Start 2P', monospace; font-size: 9px; color: #c8b8ff; margin: 10px 0 6px; }
.bgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; }
.bitem { height: 44px; display: flex; align-items: center; justify-content: center; background: #15131f; border: 2px solid #2e2a42; cursor: pointer; }
.bitem:hover { border-color: var(--hi); }
.bitem.on { border-color: var(--gold); background: #2e2840; }
.bitem.unk img { opacity: .4; filter: grayscale(.6); }
.bdhead { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.bdhead h3 { font-family: 'Press Start 2P', monospace; font-size: 13px; color: var(--gold); margin: 0 0 6px; }
#bookDetail .sec { margin: 12px 0 6px; color: #c8b8ff; border-bottom: 1px solid var(--line); }
.rcard { background: #15131f; border: 2px solid #2e2a42; padding: 5px 8px; margin: 5px 0; }
.rcard.locked { opacity: .6; border-style: dashed; }
.rcard .rhead { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 3px; }
.rcard .rhead img { width: 26px; height: 26px; image-rendering: pixelated; }
.rcard .rhead b { font-weight: normal; color: var(--text); }
.rcard .lockline { color: #ff8a8a; font-size: 16px; }
#bookDetail img.ii, #bookList img.ii { cursor: pointer; }
@media (max-width: 800px) { .bookbody { grid-template-columns: 1fr; grid-template-rows: 40% 60%; } #bookList { border-right: 0; border-bottom: 3px solid var(--line); } }

/* --------- Touch / Tablet --------- */
canvas#game { touch-action: none; }
body { overscroll-behavior: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
button, .bbtn, .rbtn, .tnode, #cats button { touch-action: manipulation; }
#inspector h3 .iclose { margin-left: auto; font-size: 18px; padding: 0 8px; font-family: 'VT323', monospace; }

#touchbar { position: fixed; left: 8px; top: 50%; transform: translateY(-50%); z-index: 6; display: flex; flex-direction: column; gap: 6px; }
#touchbar button {
  width: 62px; height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--panel); color: var(--text); border: 3px solid var(--line); box-shadow: 3px 3px 0 rgba(0,0,0,.55);
  font-family: 'VT323', monospace; cursor: pointer; padding: 0;
}
#touchbar button b { font-size: 26px; line-height: 1; font-weight: normal; }
#touchbar button small { font-size: 14px; color: var(--dim); }
#touchbar button:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 rgba(0,0,0,.55); }
#touchbar button.on { border-color: var(--gold); background: #3a3018; }
#touchbar button.on small { color: var(--gold); }
#touchbar button[data-act=remove].on { border-color: var(--red); background: #3a1414; }
#touchbar button[data-act=cancel] { border-color: #4a8a3a; }
#touchbar button[data-act=cancel].dim { opacity: .45; }

body.touch .kbd, body.touch .bbtn .k { display: none; }
body.touch #hoverInfo { top: auto; bottom: 120px; left: 80px; }
body.touch #blist { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
body.touch .bbtn { flex: 0 0 auto; }
body.touch #cats button { padding: 10px 10px; }
body.touch #hotbar { max-width: calc(100vw - 180px); }
body.touch #minimap { width: 140px; height: 140px; }
body.touch #chat { left: 80px; width: 260px; bottom: 8px; }
body.touch #chatlog { max-height: 120px; }
body.touch .rbtn { height: 46px; }
body.touch .pbtn { padding: 6px 12px; }
body.touch #inspector { left: auto; max-height: calc(100vh - 240px); }

@media (max-width: 1100px) {
  #hotbar, body.touch #hotbar { left: 8px; right: 8px; transform: none; max-width: none; bottom: 8px; }
  #blist { flex-wrap: nowrap; overflow-x: auto; }
  .bbtn { flex: 0 0 auto; }
  #chat, body.touch #chat { bottom: 132px; width: 240px; }
  #miniwrap { bottom: 132px; }
  #minimap { width: 128px; height: 128px; }
  body.touch #hoverInfo { bottom: 280px; }
  #inspector { width: min(360px, calc(100vw - 96px)); max-height: calc(100vh - 300px); }
  .stat.research { max-width: 180px; }
}
#btnMenu, #phoneMenu, #hbToggle { display: none; }

/* Bauplan-Leiste */
#planbar {
  position: fixed; z-index: 7; left: 50%; transform: translateX(-50%); bottom: 150px;
  display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 12px; white-space: nowrap;
  background: #142238; border: 3px solid #5ab8ff; box-shadow: 4px 4px 0 rgba(0,0,0,.55);
}
#planbar #pbText { font-size: 20px; }
#planbar .ok { color: var(--green); } #planbar .no { color: var(--red); }
#planbar .pbtn.big { padding: 8px 14px; font-size: 12px; }
#planbar .pbtn.big:disabled { opacity: .45; cursor: not-allowed; }
#cats button.dragtoggle { margin-left: auto; border-style: dashed; }
#cats button.dragtoggle.on { color: #5ab8ff; border-color: #5ab8ff; border-style: solid; background: #142238; }
#touchbar button[data-act=drag].on { border-color: #5ab8ff; background: #142238; }
#touchbar button[data-act=cancel].commit { border-color: #7ad05a; background: #2a4a1e; }
#touchbar button[data-act=cancel].commit small { color: #b0ff90; }
body.phone #planbar { bottom: calc(var(--hb-h, 110px) + 58px); max-width: calc(100vw - 12px); padding: 4px 6px 4px 8px; gap: 5px; }
body.phone:not(.tablet) #planbar .pbl { display: none; }
body.phone #planbar #pbText { font-size: 17px; }
body.phone #planbar .pbtn { padding: 5px 8px; }
body.phone #planbar .pbtn.big { padding: 7px 10px; font-size: 10px; }
body.tablet #planbar { bottom: calc(var(--hb-h, 130px) + 72px); }
body.phone.insp-open #planbar { display: none; }

/* =================== HANDY-HUD (body.phone) =================== */
body.phone {
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
  font-size: 18px;
}
/* Topbar: eine schmale Zeile */
body.phone #top {
  top: 0; left: 0; right: 0; padding: calc(4px + var(--sat)) calc(6px + var(--sar)) 4px calc(6px + var(--sal));
  gap: 4px; flex-wrap: nowrap; border-width: 0 0 3px 0; box-shadow: 0 3px 0 rgba(0,0,0,.5);
}
body.phone #top .stat { padding: 1px 6px; font-size: 18px; flex-shrink: 1; min-width: 0; }
body.phone #top .stat.money { font-size: 21px; flex-shrink: 0; }
body.phone #sIncome, body.phone #sOrders, body.phone #sTime, body.phone #sPlayers,
body.phone #btnBook, body.phone #btnTech, body.phone #btnHelp { display: none !important; }
body.phone #sPower .txt { display: none; }
body.phone #sPower { flex-shrink: 0; }
body.phone #sPower .bar { width: 40px; flex-shrink: 0; }
body.phone .stat.elev { flex-shrink: 0; }
#hoverInfo:empty { display: none; }
body.phone .stat.research { max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1 1 auto; }
body.phone .stat.elev { white-space: nowrap; }
body.phone #btnMenu { display: block; margin-left: auto; flex-shrink: 0; font-size: 24px; padding: 0 12px; height: 34px; line-height: 30px; }
body.phone #btnMenu.on { border-color: var(--gold); background: #3a3018; }

/* ☰-Menü */
body.phone #phoneMenu:not(.hidden) {
  display: block; position: fixed; z-index: 15; top: calc(var(--top-h, 44px) + 4px); right: calc(6px + var(--sar));
  width: min(320px, calc(100vw - 12px)); background: var(--panel); border: 3px solid var(--line); box-shadow: 4px 4px 0 rgba(0,0,0,.55); padding: 8px;
}
.pm-info { display: flex; justify-content: space-between; gap: 6px; color: var(--dim); font-size: 17px; margin-bottom: 6px; flex-wrap: wrap; }
.pm-info #pmIncome { color: var(--green); }
.pm-invite { width: 100%; margin-top: 6px; padding: 8px; font-size: 18px; }
body.phone #btnInvite { display: none !important; }
#top #btnInvite { margin-left: auto; }
#top #btnInvite + .pbtn { margin-left: 0; }
.pm-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pm-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; font-family: 'VT323', monospace; font-size: 15px;
  color: var(--text); background: #15131f; border: 2px solid #2e2a42; cursor: pointer; touch-action: manipulation;
}
.pm-grid button b { font-size: 24px; font-weight: normal; line-height: 1; }
.pm-grid button.on { border-color: var(--gold); background: #2e2840; }

/* Bauleiste unten, volle Breite, einklappbar */
body.phone #hotbar {
  left: 0 !important; right: 0 !important; bottom: 0 !important; transform: none !important; max-width: none !important;
  padding: 4px calc(4px + var(--sar)) calc(4px + var(--sab)) calc(4px + var(--sal)); border-width: 3px 0 0 0;
}
body.phone #cats { flex-wrap: nowrap; gap: 3px; margin: 0 40px 4px 0; overflow-x: auto; scrollbar-width: none; }
body.phone #cats button { flex: 1 0 auto; padding: 7px 6px; font-size: 8px; display: flex; align-items: center; justify-content: center; gap: 4px; }
body.phone #cats button .ci { font-size: 18px; font-family: 'VT323', monospace; }
body.phone #cats button .cn { display: none; }
body.phone #cats button.on .cn { display: inline; }
#cats button .ci { margin-right: 4px; }
body.phone #blist { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 4px; }
body.phone .bbtn { flex: 0 0 auto; width: 58px; height: 68px; padding-top: 2px; }
body.phone .bbtn img { width: 48px; height: 48px; }
body.phone .bbtn .wicon { font-size: 30px; line-height: 48px; height: 48px; }
body.phone .bbtn .c { font-size: 15px; }
body.phone .bbtn .k { display: none; }
body.phone #hbToggle {
  display: block; position: absolute; right: calc(4px + var(--sar)); top: 4px; width: 36px; height: 30px;
  background: var(--panel2); color: var(--text); border: 2px solid var(--hi); font-size: 18px; cursor: pointer; touch-action: manipulation;
}
body.phone.hb-collapsed #blist { display: none; }
body.phone.hb-collapsed #cats { margin-bottom: 0; }

/* Werkzeuge: waagerechte Leiste direkt über der Bauleiste */
body.phone #touchbar {
  top: auto; left: 0; right: 0; transform: none; bottom: calc(var(--hb-h, 110px) + 4px);
  flex-direction: row; justify-content: center; gap: 4px; padding: 0 calc(4px + var(--sar)) 0 calc(4px + var(--sal));
}
body.phone #touchbar button { width: auto; flex: 1 1 0; max-width: 64px; height: 46px; }
body.phone #touchbar button b { font-size: 20px; }
body.phone #touchbar button small { font-size: 12px; }
body.phone #touchbar button[data-act=zin], body.phone #touchbar button[data-act=zout] { display: none; }

/* Gebäude-Infos: Panel von unten */
body.phone #inspector {
  left: 0 !important; right: 0 !important; top: auto !important; bottom: 0; width: auto !important;
  max-height: 58vh !important; padding: 8px calc(10px + var(--sar)) calc(10px + var(--sab)) calc(10px + var(--sal));
  border-width: 3px 0 0 0; z-index: 12; animation: sheetUp .18s ease-out;
}
body.phone #inspector::before { content: ''; display: block; width: 44px; height: 5px; background: var(--hi); margin: 0 auto 6px; }
body.phone .rgrid { grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); }
body.phone.insp-open #touchbar, body.phone.insp-open #hotbar { visibility: hidden; }
@keyframes sheetUp { from { transform: translateY(40%); opacity: .3; } }

/* Infozeile, Toasts, Minimap, Chat */
body.phone #hoverInfo { top: calc(var(--top-h, 44px) + 4px) !important; bottom: auto !important; left: calc(6px + var(--sal)) !important; font-size: 16px; padding: 1px 6px; max-width: calc(100vw - 20px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.phone #toasts { top: calc(var(--top-h, 44px) + 30px); width: calc(100vw - 20px); }
body.phone .toast { font-size: 17px; text-align: center; }
body.phone .toast.good { font-size: 10px; }
body.phone #miniwrap { display: none; }
body.phone.map-open #miniwrap { display: block !important; top: calc(var(--top-h, 44px) + 28px); bottom: auto; right: calc(6px + var(--sar)); }
body.phone #minimap { width: 150px !important; height: 150px !important; }
body.phone #chat { display: none !important; }
body.phone.chat-open #chat { display: block !important; left: calc(6px + var(--sal)); right: calc(6px + var(--sar)); width: auto; bottom: calc(var(--hb-h, 110px) + 56px); }
body.phone.chat-open #chatlog div.old { opacity: 1; }
body.phone.chat-open #chat input { opacity: 1; }

/* Fenster im Vollbild */
body.phone .modal { align-items: stretch; }
body.phone .modal-inner, body.phone .modal-inner.small { width: 100vw; height: 100%; max-height: none; border-width: 0; padding-top: var(--sat); padding-bottom: var(--sab); }
body.phone .modal header { padding: 8px 10px; gap: 8px; flex-wrap: wrap; }
body.phone .modal header h2 { font-size: 12px; }
body.phone #techSub { font-size: 15px; width: 100%; order: 3; }
body.phone .helpbody { padding: 8px 12px 16px; font-size: 18px; }
body.phone .helpbody td:first-child { white-space: normal; }
body.phone #book header input { max-width: none; min-width: 0; font-size: 18px; }
body.phone .bookbody { grid-template-columns: 1fr; grid-template-rows: 38% 62%; }
body.phone #bookList { border-right: 0; border-bottom: 3px solid var(--line); padding: 6px 8px; }
body.phone #bookDetail { padding: 8px 10px; }

/* =================== TABLET-HUD (body.phone.tablet) =================== */
body.tablet { font-size: 20px; }
body.tablet #top { padding-top: calc(6px + var(--sat)); padding-bottom: 6px; gap: 6px; }
body.tablet #top .stat { font-size: 20px; padding: 2px 8px; }
body.tablet #top .stat.money { font-size: 24px; }
body.tablet #sIncome, body.tablet #sOrders { display: block !important; flex-shrink: 0; }
body.tablet #sPower .txt { display: inline; white-space: nowrap; }
body.tablet #sPower .bar { width: 60px; }
body.tablet #btnMenu { height: 40px; font-size: 26px; padding: 0 16px; }
body.tablet #phoneMenu:not(.hidden) { width: 380px; }
body.tablet .pm-grid button { padding: 12px 4px; font-size: 17px; }
body.tablet .pm-grid button b { font-size: 30px; }

/* Bauleiste: große Buttons, Kategorienamen sichtbar */
body.tablet #cats button { font-size: 9px; padding: 10px 10px; flex: 0 0 auto; }
body.tablet #cats button .cn { display: inline; }
body.tablet #cats button .ci { font-size: 20px; }
body.tablet .bbtn { width: 72px; height: 88px; }
body.tablet .bbtn img { width: 64px; height: 64px; }
body.tablet .bbtn .wicon { font-size: 40px; line-height: 64px; height: 64px; }
body.tablet .bbtn .c { font-size: 17px; }
body.tablet #hbToggle { width: 46px; height: 38px; font-size: 22px; }

/* Werkzeugleiste: große Buttons inkl. Zoom */
body.tablet #touchbar { gap: 6px; }
body.tablet #touchbar button { height: 58px; max-width: 86px; }
body.tablet #touchbar button b { font-size: 24px; }
body.tablet #touchbar button small { font-size: 14px; }
body.tablet #touchbar button[data-act=zin], body.tablet #touchbar button[data-act=zout] { display: flex; }

/* Infofenster: rechts an der Seite statt von unten */
body.tablet #inspector {
  left: auto !important; right: calc(8px + var(--sar)) !important; top: calc(var(--top-h, 50px) + 8px) !important;
  bottom: auto; width: 390px !important; max-height: calc(100vh - var(--top-h, 50px) - var(--hb-h, 130px) - 90px) !important;
  border-width: 3px; padding: 10px; animation: sheetSide .18s ease-out;
}
body.tablet #inspector::before { display: none; }
body.tablet.insp-open #touchbar, body.tablet.insp-open #hotbar { visibility: visible; }
body.tablet .rgrid { grid-template-columns: repeat(7, 1fr); }
body.tablet .rbtn { height: 46px; }
@keyframes sheetSide { from { transform: translateX(30%); opacity: .3; } }

/* Minimap oben rechts (bei offenem Infofenster ausgeblendet), Chat links über den Werkzeugen */
body.tablet.map-open #miniwrap { top: calc(var(--top-h, 50px) + 8px); }
body.tablet #minimap { width: 180px !important; height: 180px !important; }
body.tablet.insp-open #miniwrap { display: none !important; }
body.tablet.chat-open #chat { right: auto; width: 360px; bottom: calc(var(--hb-h, 130px) + 72px); }
body.tablet #hoverInfo { font-size: 18px; }
body.tablet #toasts { top: calc(var(--top-h, 50px) + 12px); width: auto; }
body.tablet .toast { font-size: 20px; }
body.tablet .toast.good { font-size: 12px; }

/* Fenster: groß, aber nicht randlos */
body.tablet .modal { align-items: center; }
body.tablet .modal-inner { width: calc(100vw - 24px); height: calc(100vh - 24px - var(--sat) - var(--sab)); border-width: 3px; padding: 0; }
body.tablet .modal-inner.small { width: min(720px, calc(100vw - 24px)); height: auto; max-height: calc(100vh - 24px); }
body.tablet .modal header h2 { font-size: 15px; }
body.tablet #techSub { width: auto; order: 0; }
body.tablet .bookbody { grid-template-columns: minmax(280px, 42%) 1fr; grid-template-rows: none; }
body.tablet #bookList { border-right: 3px solid var(--line); border-bottom: 0; }
@media (orientation: portrait) {
  body.tablet .bookbody { grid-template-columns: 1fr; grid-template-rows: 40% 60%; }
  body.tablet #bookList { border-right: 0; border-bottom: 3px solid var(--line); }
  body.tablet .stat.research { max-width: 26vw; }
  body.tablet #sIncome, body.tablet #sPower .txt { display: none !important; }
}

/* Querformat-Handy: Bauleiste niedriger */
@media (max-height: 520px) {
  body.phone .bbtn { width: 52px; height: 58px; }
  body.phone .bbtn img { width: 40px; height: 40px; }
  body.phone #touchbar button { height: 40px; }
  body.phone #touchbar button small { display: none; }
  body.phone #inspector { max-height: 75vh !important; }
}

@media (max-width: 700px) {
  #top { gap: 3px; padding: 3px; }
  .stat { padding: 1px 5px; font-size: 17px; }
  .stat.money { font-size: 20px; min-width: 0; }
  #sTime, #sPlayers { display: none; }
  #chat, body.touch #chat { display: none !important; }
}
