:root {
  --bg: #14202c;
  --bg2: #1c2b3a;
  --bg3: #243749;
  --line: #3a5068;
  --ink: #ecf0f1;
  --muted: #95a5a6;
  --gold: #f39c12;
  --gold2: #f7dc6f;
  --red: #e74c3c;
  --green: #2ecc71;
  --blue: #5dade2;
  --violet: #9b59b6;
  --fossil: #7f6a55;
  --atom: #f1c40f;
  --renew: #27ae60;
  --import: #8e44ad;
  --font: ui-monospace, 'Cascadia Mono', 'DejaVu Sans Mono', Menlo, Consolas, monospace;
  --px: 3px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button, input, select { font-family: inherit; font-size: inherit; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; height: 100dvh; max-width: 1400px; margin: 0 auto; }

/* ---------- Pixel-Rahmen ---------- */
.box {
  background: var(--bg2);
  border: var(--px) solid var(--line);
  box-shadow: inset calc(-1 * var(--px)) calc(-1 * var(--px)) 0 #0e1720, inset var(--px) var(--px) 0 #2c4359;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 14px; cursor: pointer; color: var(--ink);
  background: var(--bg3); border: var(--px) solid var(--line);
  box-shadow: inset calc(-1 * var(--px)) calc(-1 * var(--px)) 0 #0e1720, inset var(--px) var(--px) 0 #3d5873;
  text-align: left;
}
.btn:hover:not(:disabled) { background: #2d4560; }
.btn:active:not(:disabled) { box-shadow: inset var(--px) var(--px) 0 #0e1720; transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: #9a5b00; border-color: #c27500; box-shadow: inset -3px -3px 0 #5c3a00, inset 3px 3px 0 #f5b041; font-weight: bold; }
.btn.primary:hover:not(:disabled) { background: #b36a00; }
.btn.danger { background: #7b241c; border-color: #a93226; }
.btn.small { min-height: 34px; padding: 4px 10px; }
.btn.chip { min-height: 38px; padding: 4px 10px; }
.btn.chip.on { background: #1e5f3a; border-color: #2ecc71; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--gold2); outline-offset: 2px; }

/* ---------- HUD ---------- */
#hud { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; background: #0f1922; border-bottom: var(--px) solid var(--line); }
#hud .who { display: flex; gap: 8px; align-items: center; cursor: pointer; }
#hud .who canvas { width: 48px; height: 48px; border: 2px solid var(--line); background: #2c3e50; }
#hud .who b { color: var(--gold2); display: block; }
#hud .who small { color: var(--muted); }
#hud .stats { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.stat { min-width: 92px; cursor: help; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat .v { font-weight: bold; }
.stat .v.good { color: var(--green); }
.stat .v.bad { color: var(--red); }
.bar { height: 7px; background: #0b121a; border: 1px solid var(--line); margin-top: 2px; position: relative; }
.bar > i { display: block; height: 100%; }
.bar .mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: #fff; opacity: .6; }
#hud .tools { display: flex; gap: 6px; }

/* ---------- Hauptbereich ---------- */
#main { flex: 1; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(340px, 1fr); gap: 8px; padding: 8px; min-height: 0; }
#mapPane { display: flex; flex-direction: column; align-items: center; min-height: 0; gap: 6px; }
#map { background: #182430; border: var(--px) solid var(--line); cursor: pointer; max-width: 100%; touch-action: manipulation; }
#mapLegend { width: 100%; font-size: 12px; color: var(--muted); }
#side { display: flex; flex-direction: column; min-height: 0; }
#tabs { display: flex; gap: 4px; }
#tabs button { flex: 1; min-height: 40px; background: var(--bg2); color: var(--muted); border: var(--px) solid var(--line); border-bottom: none; cursor: pointer; }
#tabs button.on { background: var(--bg3); color: var(--gold2); }
#tabs .badge, #mobileNav .badge { display: inline-block; background: var(--red); color: #fff; padding: 0 5px; margin-left: 4px; font-size: 11px; }
#panel { flex: 1; overflow: auto; padding: 10px; background: var(--bg3); border: var(--px) solid var(--line); }

#footer { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 8px; background: #0f1922; border-top: var(--px) solid var(--line); }
#ap { display: flex; gap: 6px; align-items: center; color: var(--muted); }
#ap .pip { width: 28px; height: 28px; background: var(--gold); box-shadow: inset -4px -4px 0 #9a5b00; display: inline-block; border: none; padding: 0; }
#ap .pip.used { background: #2c3e50; box-shadow: inset -4px -4px 0 #1b2631; outline: 2px dashed var(--gold); outline-offset: -6px; cursor: pointer; }
#ap .pip.used:hover { background: #3d5873; }
#endWeek { min-width: 200px; }

#mobileNav { display: none; }

/* Rechtliches: immer sichtbar, ganz unten (auf Mobil unter der Navigation) */
#legal { text-align: center; font-size: 11px; line-height: 1; background: #0f1922; padding-bottom: env(safe-area-inset-bottom); }
#legal a { display: inline-block; padding: 6px 12px; color: var(--muted); }
#legal a:hover, #legal a:focus-visible { color: var(--gold2); }

/* ---------- Panel-Inhalte ---------- */
h2 { font-size: 15px; color: var(--gold2); margin: 4px 0 8px; text-transform: uppercase; letter-spacing: 0.05em; }
h3 { font-size: 13px; color: var(--blue); margin: 14px 0 6px; text-transform: uppercase; }
p { margin: 6px 0; line-height: 1.45; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.good { color: var(--green); }
.bad { color: var(--red); }
.warn { color: var(--gold); }

.actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.actions .btn { flex-direction: column; align-items: flex-start; }
.actions .btn .t { font-weight: bold; }
.actions .btn .d { font-size: 11px; color: var(--muted); font-weight: normal; }
.actions .btn .ap { font-size: 11px; color: var(--gold2); }

.card { background: var(--bg2); border: 2px solid var(--line); padding: 8px 10px; margin-bottom: 8px; }
.card .from { font-size: 11px; color: var(--muted); }
.card .title { font-weight: bold; color: var(--gold2); margin: 2px 0; }
.card .row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.card.offer { border-color: #7d6608; }
.card.event { border-color: #1f618d; }

.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 6px 0; border-bottom: 1px dashed var(--line); }
.prog { height: 6px; background: #0b121a; margin-top: 4px; }
.prog i { display: block; height: 100%; background: var(--gold); }
.prog.blocked i { background: var(--red); }

.feed li { display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: start; }
.feed canvas { width: 24px; height: 24px; }
.feed .h { font-size: 11px; color: var(--muted); }
.news li.crisis { color: #f5b7b1; }
.news li.bad { color: #f0b27a; }
.news li.good { color: #abebc6; }
.news li.big { color: var(--gold2); }
.news li.warn { color: #f9e79f; }
.news li.money { color: #f7dc6f; }

table.t { width: 100%; border-collapse: collapse; font-size: 12px; }
table.t th, table.t td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: right; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t th { color: var(--muted); font-weight: normal; }

.mix { display: flex; height: 14px; border: 2px solid var(--line); background: #0b121a; position: relative; }
.mix i { display: block; height: 100%; }
.mixlegend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11px; margin-top: 4px; color: var(--muted); }
.mixlegend b { display: inline-block; width: 10px; height: 10px; margin-right: 4px; vertical-align: -1px; }

/* ---------- Diagramme ---------- */
.chart { position: relative; width: 100%; margin-top: 4px; }
.chart svg { display: block; touch-action: pan-y; }
.chart svg .ax { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart svg .lbl { fill: var(--ink); font-size: 11px; font-family: var(--font); }
.chart .tip { position: absolute; top: 4px; z-index: 2; background: #0f1922; border: 2px solid var(--line); padding: 6px 8px; font-size: 12px; line-height: 1.5; pointer-events: none; white-space: nowrap; box-shadow: 3px 3px 0 #000; }
.chart .tip .sw { display: inline-block; width: 9px; height: 9px; margin-right: 5px; border-radius: 2px; vertical-align: 0; }
details > summary { list-style: none; display: inline-flex; }
details > summary::-webkit-details-marker { display: none; }

/* ---------- Modal ---------- */
#modal { position: fixed; inset: 0; background: rgba(5, 10, 15, 0.78); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 10px; }
.modal-box { width: min(760px, 100%); max-height: 92dvh; overflow: auto; background: var(--bg2); border: var(--px) solid var(--gold); box-shadow: 0 0 0 3px #000, 8px 8px 0 #000; padding: 14px 16px; position: relative; }
.modal-box .close { position: absolute; top: 6px; right: 6px; min-height: 36px; min-width: 36px; }
.modal-box h2 { padding-right: 40px; }
.form { display: grid; gap: 10px; }
.form label.l { font-size: 12px; color: var(--muted); text-transform: uppercase; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 8px; background: var(--bg3); border: 2px solid var(--line); cursor: pointer; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--gold); flex: none; margin-top: 1px; }
.check small { display: block; color: var(--muted); }
input[type=range] { width: 100%; accent-color: var(--gold); height: 32px; }
select { background: var(--bg3); color: var(--ink); border: 2px solid var(--line); min-height: 44px; padding: 6px; width: 100%; }
.preview { background: #0f1922; border: 2px dashed var(--line); padding: 10px; display: grid; gap: 4px; }
.headline { font-family: Georgia, 'Times New Roman', serif; background: #f4ecd8; color: #1b1b1b; padding: 8px 10px; font-size: 16px; font-weight: bold; border-left: 6px solid #922b21; }
.headline small { display: block; font-family: var(--font); font-size: 10px; font-weight: normal; color: #6e6e6e; text-transform: uppercase; }
.err { color: var(--red); }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 10px; }

.draft { background: var(--bg3); border: 2px solid var(--line); padding: 8px; margin-bottom: 8px; }
.draft .by { font-size: 11px; color: var(--muted); }
.para { display: block; width: 100%; text-align: left; margin-top: 6px; }
.para small { display: block; color: var(--muted); font-weight: normal; }
.lawbox { background: #0f1922; border: 2px solid var(--gold); padding: 10px; }
.lawname { color: var(--gold2); font-weight: bold; word-break: break-word; }

.receipt { background: #fbfaf5; color: #222; font-family: var(--font); padding: 14px 18px; max-width: 380px; margin: 10px auto; box-shadow: 4px 4px 0 #000; position: relative; }
.receipt::after { content: ''; position: absolute; left: 0; right: 0; bottom: -8px; height: 8px; background: linear-gradient(-45deg, transparent 6px, #fbfaf5 0) 0 0 / 12px 8px repeat-x, linear-gradient(45deg, transparent 6px, #fbfaf5 0) 0 0 / 12px 8px repeat-x; }
.receipt h3 { color: #222; text-align: center; margin: 0 0 8px; }
.receipt .r { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dotted #aaa; padding: 3px 0; font-size: 13px; }
.receipt .sum { font-weight: bold; font-size: 16px; border-top: 2px solid #222; border-bottom: none; margin-top: 6px; }

/* ---------- Start ---------- */
#start { flex: 1; overflow: auto; padding: 16px; }
#start .logo { width: min(640px, 92vw); display: block; margin: 10px auto 2px; }
#start .sub { text-align: center; color: var(--muted); margin-bottom: 16px; }
.chars { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; max-width: 900px; margin: 0 auto; }
.char { cursor: pointer; padding: 12px; text-align: left; display: block; width: 100%; }
.char.on { border-color: var(--gold); box-shadow: inset -3px -3px 0 #5c3a00, inset 3px 3px 0 #f5b041; }
.char .top { display: flex; gap: 12px; align-items: center; }
.char canvas { width: 96px; height: 96px; background: #2c3e50; border: 2px solid var(--line); }
.char ul { margin: 6px 0; padding-left: 18px; font-size: 12px; }
.char .pro li::marker { content: '+ '; color: var(--green); }
.char .con li::marker { content: '− '; color: var(--red); }
.startrow { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 16px auto; max-width: 900px; }
.hall { max-width: 900px; margin: 10px auto; }

/* ---------- Toast & Tooltip ---------- */
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 60; display: grid; gap: 6px; width: min(520px, 92vw); pointer-events: none; }
#toast div { background: #0f1922; border: 2px solid var(--gold); padding: 8px 12px; box-shadow: 4px 4px 0 #000; animation: pop 3.6s forwards; }
#toast div.bad { border-color: var(--red); }
@keyframes pop { 0% { opacity: 0; transform: translateY(8px); } 8% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }
#tip { position: fixed; z-index: 70; max-width: 300px; background: #0f1922; border: 2px solid var(--blue); padding: 8px 10px; font-size: 12px; box-shadow: 4px 4px 0 #000; pointer-events: none; }

/* ---------- Mobil ---------- */
@media (max-width: 860px) {
  :root { --px: 2px; }
  #hud { grid-template-columns: 1fr auto; padding: 4px 6px; gap: 4px 8px; }
  #hud .who { grid-column: 1; grid-row: 1; }
  #hud .who canvas { width: 36px; height: 36px; }
  #hud .who b { font-size: 13px; }
  #hud .who small { font-size: 11px; }
  #hud .tools { grid-column: 2; grid-row: 1; }
  #hud .tools .btn { min-height: 36px; min-width: 36px; padding: 2px 8px; }
  #hud .stats { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px 8px; }
  .stat { min-width: 0; }
  .stat .k { font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .stat .v { font-size: 12px; white-space: nowrap; }
  .bar { height: 5px; }
  #main { grid-template-columns: 1fr; padding: 4px; }
  #main.view-map #side { display: none; }
  #main:not(.view-map) #mapPane { display: none; }
  #tabs { display: none; }
  #footer { padding: 6px; }
  #endWeek { min-width: 0; flex: 1; }
  #mobileNav { display: flex; background: #0f1922; border-top: var(--px) solid var(--line); }
  #mobileNav button { flex: 1; min-height: 52px; background: none; border: none; color: var(--muted); font-size: 12px; cursor: pointer; }
  #mobileNav button.on { color: var(--gold2); background: var(--bg2); }
  .modal-box { max-height: 100dvh; height: 100dvh; width: 100%; border-width: 2px; }
  #modal { padding: 0; }
  .actions { grid-template-columns: 1fr 1fr; }
  #toast { bottom: auto; top: 8px; }
}
@media (max-width: 420px) {
  .actions { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  #toast div { animation: none; }
}
