:root {
  --ink: #2b2a33;
  --panel: rgba(255, 252, 245, 0.94);
  --panel-line: rgba(60, 50, 40, 0.14);
  --accent: #f2a541;
  --accent-dark: #c97f1c;
  --muted: #6d6a73;
  --chip: rgba(40, 36, 48, 0.72);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #bfe0ee; color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
}
#app { position: fixed; inset: 0; height: 100dvh; overflow: hidden; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.topbar {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) 8px calc(10px + var(--safe-l));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.spacer { flex: 1; pointer-events: none !important; }
.brand {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--panel-line);
  padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: 15px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.logo { font-size: 17px; }
.chip {
  background: var(--chip); color: #fff; border-radius: 999px;
  padding: 5px 11px; font-size: 13px; font-variant-numeric: tabular-nums;
  backdrop-filter: blur(4px);
}
.iconbtn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--panel-line);
  background: var(--panel); font-size: 19px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.iconbtn:active { transform: scale(0.94); }
.hint {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + var(--safe-b)); max-width: calc(100% - 24px);
  background: var(--chip); color: #fff; font-size: 13px; text-align: center;
  padding: 7px 14px; border-radius: 12px; transition: opacity 0.8s;
  pointer-events: none !important;
}
.hint.fade { opacity: 0; }

/* ---------- Panels ---------- */
.panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 24px)); max-height: calc(100% - 40px); overflow: auto;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 18px;
  padding: 16px 18px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.panel[hidden], .chip[hidden] { display: none; }
.panel h2 { margin: 0 0 12px; font-size: 19px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; font-size: 15px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--panel-line); border-radius: 10px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; padding: 7px 11px; font: inherit; font-size: 14px; cursor: pointer; color: var(--ink);
}
.seg button + button { border-left: 1px solid var(--panel-line); }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.small { font-size: 12.5px; color: var(--muted); min-height: 1em; margin: 6px 0 12px; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 12px; padding: 11px;
  background: var(--accent); color: #fff; font: inherit; font-weight: 700; font-size: 15px; cursor: pointer;
  box-shadow: 0 3px 0 var(--accent-dark);
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--accent-dark); }

/* ---------- Laden ---------- */
#loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: #bfe0ee; color: var(--ink); font-size: 15px; text-align: center; padding: 20px; transition: opacity 0.4s;
}
#loading.done { opacity: 0; pointer-events: none; }
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 4px solid rgba(0, 0, 0, 0.12); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 380px) {
  .brand { font-size: 13px; padding: 5px 10px; }
  .row { font-size: 14px; }
  .seg button { padding: 6px 8px; font-size: 13px; }
}

/* ---------- Geld ---------- */
.money {
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 999px;
  padding: 6px 14px; font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); color: #2d6a32;
}
.money.bump { animation: bump 0.25s ease-out; }
@keyframes bump { 50% { transform: scale(1.12); } }
@media (max-width: 640px) { .brand span:not(.logo) { display: none; } }

/* ---------- Ziel / Anleitung ---------- */
.goal {
  position: absolute; left: 50%; transform: translateX(-50%); top: calc(62px + var(--safe-t));
  background: var(--panel); border: 2px solid var(--accent); border-radius: 14px; padding: 7px 14px;
  font-weight: 700; font-size: 15px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15); white-space: nowrap;
  max-width: calc(100% - 20px); overflow: hidden; text-overflow: ellipsis; pointer-events: none !important;
}
.goal[hidden] { display: none; }
.goal::before { content: '➜ '; color: var(--accent); }

/* ---------- Joystick ---------- */
.joy {
  position: absolute; width: 110px; height: 110px; margin: -55px 0 0 -55px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.22); border: 3px solid rgba(255, 255, 255, 0.6);
  pointer-events: none !important; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}
.joy[hidden] { display: none; }
.knob {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.85); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* ---------- Meldungen & Geld-Popups ---------- */
.toast {
  position: absolute; left: 50%; top: calc(108px + var(--safe-t)); transform: translateX(-50%);
  background: #2d6a32; color: #fff; padding: 8px 16px; border-radius: 12px; font-size: 15px; font-weight: 700;
  pointer-events: none !important; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  width: max-content; max-width: calc(100% - 24px); text-align: center;
}
.toast[hidden] { display: none; }
#popups { position: absolute; inset: 0; pointer-events: none !important; overflow: hidden; }
.pop {
  position: absolute; transform: translate(-50%, -50%); font-weight: 800; font-size: 16px; color: #2d6a32;
  text-shadow: 0 1px 0 #fff, 0 0 6px rgba(255, 255, 255, 0.9); animation: popup 1.1s ease-out forwards; white-space: nowrap;
}
@keyframes popup { from { opacity: 1; margin-top: 0; } 70% { opacity: 1; } to { opacity: 0; margin-top: -40px; } }
.maxlabel {
  position: absolute; transform: translate(-50%, -100%); background: #b8372c; color: #fff; font-weight: 800; font-size: 12px;
  padding: 2px 7px; border-radius: 7px; pointer-events: none !important;
}
.maxlabel[hidden] { display: none; }
.ghostbtn { background: #fff; color: #b8372c; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12); margin-bottom: 10px; border: 1px solid var(--panel-line); }
@media (orientation: landscape) and (max-height: 500px) {
  .goal { font-size: 13px; padding: 5px 12px; top: calc(56px + var(--safe-t)); }
  .toast { top: calc(96px + var(--safe-t)); font-size: 13px; }
}

/* ---------- Hauptmenü ---------- */
.menu {
  position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(30, 28, 40, 0.15), rgba(30, 28, 40, 0.55));
  padding: calc(12px + var(--safe-t)) 16px calc(12px + var(--safe-b));
}
.menu[hidden] { display: none; }
.menucard {
  width: min(380px, 100%); max-height: 100%; overflow: auto; text-align: center;
  background: var(--panel); border-radius: 22px; padding: 18px 20px 14px; box-shadow: 0 14px 50px rgba(0, 0, 0, 0.3);
  animation: menuIn 0.45s ease-out;
}
@keyframes menuIn { from { transform: translateY(20px) scale(0.96); opacity: 0; } }
.menulogo { font-size: 46px; line-height: 1; }
.menucard h1 { margin: 4px 0 2px; font-size: 26px; letter-spacing: 0.3px; }
.tagline { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.btn.big { font-size: 19px; padding: 14px; }
.menurow { display: flex; gap: 8px; margin: 10px 0; }
.btn2 {
  flex: 1; border: 1px solid var(--panel-line); background: #fff; border-radius: 12px; padding: 10px 6px;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; color: var(--ink);
}
.kofi {
  display: block; margin: 6px 0 4px; padding: 9px 10px; border-radius: 12px; background: #fff3e0; color: #8a4b00;
  font-size: 13.5px; font-weight: 600; text-decoration: none; border: 1px solid #f6d3a5;
}
.kofi:hover { background: #ffe7c4; }
.ver { font-size: 11px; color: var(--muted); margin-top: 6px; }
.panel { z-index: 10; }
.credits { font-size: 13.5px; line-height: 1.45; margin-bottom: 12px; }
.credits p { margin: 0 0 8px; }
.credits a { color: var(--accent-dark); }
@media (orientation: landscape) and (max-height: 500px) {
  .menucard { padding: 10px 16px 8px; }
  .menulogo { font-size: 30px; }
  .menucard h1 { font-size: 21px; }
  .tagline { margin-bottom: 8px; }
  .btn.big { padding: 10px; font-size: 17px; }
  .menurow { margin: 6px 0; }
}

/* ---------- Kundenauftrag ---------- */
.order {
  position: absolute; left: calc(10px + var(--safe-l)); top: calc(58px + var(--safe-t));
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px; padding: 6px 10px 7px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.14); font-size: 13.5px; font-weight: 700; min-width: 170px; pointer-events: none !important;
}
.order[hidden] { display: none; }
.order .orow { display: flex; justify-content: space-between; gap: 10px; white-space: nowrap; }
.order .otime { color: var(--muted); font-variant-numeric: tabular-nums; }
.order.hurry .otime { color: #b8372c; }
.order .obar { height: 5px; background: rgba(0, 0, 0, 0.08); border-radius: 3px; margin-top: 5px; overflow: hidden; }
.order .obar > i { display: block; height: 100%; width: 0; background: #5cb85c; transition: width 0.3s; }
.order.bumped { animation: bump 0.35s ease-out; }
@media (orientation: portrait) { .order { top: calc(104px + var(--safe-t)); } }
@media (orientation: landscape) and (max-height: 500px) { .order { top: calc(54px + var(--safe-t)); font-size: 12.5px; padding: 4px 9px 5px; } .goal { left: auto; right: calc(60px + var(--safe-r)); transform: none; } }

/* ---------- Info-Karte (in der Nähe einer Maschine / eines Kauf-Felds) ---------- */
.near {
  position: absolute; left: calc(10px + var(--safe-l)); bottom: calc(12px + var(--safe-b));
  max-width: min(330px, calc(100% - 20px)); background: var(--panel); border: 1px solid var(--panel-line); border-radius: 12px;
  padding: 7px 11px; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.14); font-size: 13px; pointer-events: none !important;
  display: flex; flex-direction: column; gap: 1px; animation: nearIn 0.2s ease-out;
}
.near[hidden] { display: none; }
.near b { font-size: 14px; }
#nearState { color: var(--muted); font-size: 12px; }
#nearState.bad { color: #b8372c; font-weight: 600; }
#nearState.good { color: #2d6a32; font-weight: 600; }
@keyframes nearIn { from { opacity: 0; transform: translateY(6px); } }
@media (orientation: portrait) { .near { bottom: calc(70px + var(--safe-b)); } }

/* ---------- Erfolge ---------- */
.stats { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 4px 10px; font-size: 13px; background: rgba(0,0,0,0.04); border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; }
.stats b { font-variant-numeric: tabular-nums; text-align: right; }
.achlist { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.ach { display: grid; grid-template-columns: 34px 1fr auto; gap: 2px 8px; align-items: center; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--panel-line); background: #fff; }
.ach .ai { font-size: 22px; text-align: center; grid-row: span 3; }
.ach .an { font-weight: 700; font-size: 14px; }
.ach .ad { font-size: 12px; color: var(--muted); grid-column: 2; }
.ach .ar { font-size: 12px; font-weight: 700; color: #2d6a32; grid-row: span 3; text-align: right; }
.ach .ab { grid-column: 2; height: 4px; background: rgba(0,0,0,0.08); border-radius: 2px; overflow: hidden; }
.ach .ab > i { display: block; height: 100%; background: var(--accent); }
.ach.done { background: #f0f8ee; border-color: #bfe0b8; }
@media (max-width: 420px) { .stats { grid-template-columns: 1fr auto; } }

/* ---------- Rand-Pfeil zum Ziel außerhalb des Bildschirms ---------- */
.edge {
  position: absolute; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25); pointer-events: none !important;
  animation: edgePulse 1s ease-in-out infinite;
}
.edge[hidden] { display: none; }
.edge.gift { background: #5cb85c; }
@keyframes edgePulse { 50% { box-shadow: 0 3px 16px rgba(242, 165, 65, 0.8); } }

/* ---------- Filiale (Neustart mit Bonus) ---------- */
.star { background: #f4cf4a; color: #5a4500; font-weight: 800; }
.star[hidden] { display: none; }
.prtext { font-size: 14px; line-height: 1.45; margin: 0 0 12px; }
#prestigePanel .menurow { align-items: stretch; }
#prestigePanel .btn { flex: 1.3; margin: 0; }

/* ---------- Garderobe ---------- */
.wardrobe { top: auto; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%); max-height: 58%; }
.wardrobe h3 { margin: 10px 0 6px; font-size: 14px; color: var(--muted); }
.wgrid { display: flex; flex-wrap: wrap; gap: 6px; }
.witem {
  min-width: 64px; border: 2px solid var(--panel-line); background: #fff; border-radius: 12px; padding: 5px 6px 4px;
  font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.witem .wi { font-size: 22px; line-height: 1.1; }
.witem .wp { font-size: 11px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.witem.owned .wp { color: #2d6a32; }
.witem.on { border-color: var(--accent); background: #fff6e6; }
.witem.poor { opacity: 0.5; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(0,0,0,0.15); }
@media (orientation: landscape) and (max-height: 500px) {
  .wardrobe { left: auto; right: calc(10px + var(--safe-r)); transform: none; width: min(380px, 55%); max-height: calc(100% - 20px); bottom: 10px; }
  .witem { min-width: 54px; padding: 3px 4px; }
  .witem .wi { font-size: 18px; }
}

/* ---------- Ladebildschirm & Sprachwahl ---------- */
.loadlogo { font-size: 46px; animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-8deg); } }
.loadtitle { font-size: 24px; font-weight: 800; letter-spacing: 0.3px; margin-top: -6px; }
.loadbar { width: min(260px, 70vw); height: 10px; border-radius: 99px; background: rgba(0, 0, 0, 0.1); overflow: hidden; }
.loadbar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width 0.2s; }
#loading .spinner { width: 22px; height: 22px; border-width: 3px; }
.seg.langs { display: grid; grid-template-columns: repeat(3, 1fr); }
.seg.langs button { border-left: 0; padding: 6px 8px; }
.seg.langs button:nth-child(3n + 2), .seg.langs button:nth-child(3n + 3) { border-left: 1px solid var(--panel-line); }
.seg.langs button:nth-child(n + 4) { border-top: 1px solid var(--panel-line); }
.menulangs { width: 100%; margin: 4px 0 8px; font-size: 13px; }
.menulangs button { font-size: 13px; padding: 5px 4px; }
.chip { white-space: nowrap; }
@media (max-width: 380px) {
  .topbar { gap: 5px; padding-left: calc(6px + var(--safe-l)); padding-right: calc(6px + var(--safe-r)); }
  .iconbtn { width: 34px; height: 34px; font-size: 16px; }
  #btnFull { display: none; }   /* sehr schmales Hochformat: kein Platz, Vollbild über Querformat/Start */
  .brand:has(~ #fps:not([hidden])) { display: none; }   /* sehr schmal + FPS-Anzeige: Logo weglassen */
  .money { font-size: 16px; padding: 5px 10px; }
  .chip { font-size: 11.5px; padding: 4px 8px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .seg.langs.menulangs { grid-template-columns: repeat(6, 1fr); margin: 2px 0 6px; }   /* flaches Querformat: eine Zeile */
  .seg.langs.menulangs button { font-size: 11.5px; padding: 4px 2px; border-top: 0 !important; border-left: 1px solid var(--panel-line) !important; }
  .seg.langs.menulangs button:first-child { border-left: 0 !important; }
}

/* ---------- Hauptmenü: Werbung für weitere Spiele ---------- */
.promo { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 5px 6px; margin: 6px 0 2px; font-size: 12px; color: var(--muted); }
.promo a {
  display: inline-block; padding: 4px 9px; border-radius: 999px; background: #eef4f8; border: 1px solid #cfe0ea;
  color: #2b5d7a; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.promo a:hover { background: #ddebf3; }
@media (orientation: landscape) and (max-height: 500px) {
  .promo { margin: 4px 0 0; font-size: 11.5px; }
  .promo a { padding: 3px 8px; }
  .menucard .ver { display: none; }
  .promo > span { display: none; }   /* flaches Querformat: nur die drei Links in einer Zeile */
  .kofi { padding: 6px 10px; margin: 4px 0 2px; }
}
@media (orientation: landscape) and (max-height: 340px) {
  .menulogo, .tagline { display: none; }   /* sehr flache Handys: Platz für Sprachwahl + Links */
}
.flag-at { display: inline-block; width: 18px; height: 12px; vertical-align: -1px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0,0,0,0.15);
  background: linear-gradient(#c8102e 0 33.3%, #fff 33.3% 66.6%, #c8102e 66.6%); }   /* Österreich-Fahne (Emoji zeigt Windows nur als „AT“) */

/* Auftrag ablehnen */
.order .oskip {
  pointer-events: auto; border: 0; background: rgba(0, 0, 0, 0.07); color: var(--muted); border-radius: 50%;
  width: 22px; height: 22px; font-size: 12px; line-height: 22px; padding: 0; cursor: pointer; margin: -2px -4px 0 2px;
}
.order .oskip:active { transform: scale(0.9); }

/* ---------- Bestenliste ---------- */
#lbPanel .lbsub { margin: -8px 0 8px; }
#lbPanel .lblist { max-height: min(46vh, 320px); margin-bottom: 4px; }
#lbPanel .btn2 { width: 100%; margin: 6px 0 8px; }
.achlb { width: 100%; margin-bottom: 10px; }
.lbsub { font-size: 12px; color: var(--muted); margin: 1px 0 6px; }
.lblist { list-style: none; margin: 0; padding: 0; max-height: 210px; overflow: auto; font-size: 13.5px; }
.lblist li { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 6px; padding: 3px 6px; border-radius: 7px; }
.lblist li:nth-child(odd) { background: rgba(255, 255, 255, 0.7); }
.lblist li.me { background: #fff3e0; outline: 1px solid #f6d3a5; font-weight: 700; }
.lblist li b { color: var(--muted); }
.lblist li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lblist li i { font-style: normal; font-variant-numeric: tabular-nums; font-weight: 700; }
.lblist .lbempty { display: block; color: var(--muted); }
.lblist li em { font-style: normal; font-size: 12px; color: var(--muted); }
.lbme { font-size: 12.5px; color: var(--muted); margin-top: 5px; min-height: 1em; }
.donetime { font-size: 17px; font-weight: 700; margin: 2px 0 8px; }
.lbform { display: flex; gap: 8px; }
.lbform[hidden] { display: none; }
.lbform input { flex: 1; min-width: 0; border: 1px solid var(--panel-line); border-radius: 10px; padding: 9px 10px; font: inherit; font-size: 15px; }
.lbform .btn { width: auto; padding: 9px 16px; }
#donePanel .btn2 { width: 100%; }
.menurow .btn2 { padding: 10px 4px; font-size: 13.5px; white-space: nowrap; }
@media (max-width: 400px) { .menurow .btn2 { font-size: 12.5px; } }
