:root {
  --bg: #0b0f14; --panel: #131a22; --panel2: #18212b; --line: #243040;
  --text: #e6edf3; --muted: #8b98a7; --accent: #3fb950; --accent2: #2ea043;
  --warn: #f0b429; --danger: #f85149; --blue: #58a6ff; --violet: #bc8cff;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh; padding-bottom: calc(68px + var(--safe-b));
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; }

/* ---------- Kopf */
#top {
  position: sticky; top: 0; z-index: 20; background: rgba(11, 15, 20, .94);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  padding: calc(8px + var(--safe-t)) 14px 8px;
}
.titlebar { display: flex; justify-content: space-between; align-items: center; max-width: 620px; margin: 0 auto; }
.logo { font-family: var(--mono); font-weight: 800; letter-spacing: .08em; color: var(--accent); font-size: 18px; }
.chapter { font-size: 12px; color: var(--muted); }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 10px; width: 40px; height: 40px; font-size: 20px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; max-width: 620px; margin: 8px auto 0; }
.chip {
  font-family: var(--mono); font-size: 13px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px; white-space: nowrap;
}
.chip b { color: var(--accent); font-weight: 600; }
.chip.dim { color: var(--muted); }

/* ---------- Incident */
.incident {
  position: sticky; top: 92px; z-index: 19; margin: 8px auto 0; max-width: 620px;
  background: #2a1214; border: 1px solid var(--danger); border-radius: 12px; padding: 10px 12px 8px;
  animation: pulse 1.2s ease-in-out infinite; width: calc(100% - 20px);
}
.incident-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.incident-text { font-size: 14px; }
.incident-bar { height: 4px; background: #45191c; border-radius: 4px; margin-top: 8px; overflow: hidden; }
#incident-fill { height: 100%; background: var(--danger); width: 100%; transition: width .2s linear; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(248, 81, 73, .25); } }

/* ---------- Ticker */
.ticker {
  display: block; width: calc(100% - 20px); max-width: 620px; margin: 10px auto 0; text-align: left;
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--blue);
  border-radius: 10px; padding: 8px 12px; font-size: 14px; color: var(--text); min-height: 40px;
}
.ticker .from { color: var(--blue); font-weight: 600; margin-right: 6px; }
.ticker.flash { animation: flash .8s ease-out; }
@keyframes flash { from { background: #1c2c44; } to { background: var(--panel); } }

/* ---------- Inhalt */
main { max-width: 620px; margin: 0 auto; padding: 10px; }
.tab { display: none; }
.tab.active { display: block; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card h2 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 4px 0; }
.row .k { color: var(--muted); font-size: 14px; }
.row .v { font-family: var(--mono); font-size: 15px; text-align: right; }
.big { font-family: var(--mono); font-size: 30px; font-weight: 700; }
.sub { color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.good { color: var(--accent); } .bad { color: var(--danger); } .warnc { color: var(--warn); }

.btn {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: 10px 14px;
  min-height: 44px; cursor: pointer; font-size: 15px; touch-action: manipulation; user-select: none;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { background: var(--accent2); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 700; white-space: nowrap; }
.btn-ghost { background: transparent; }
.btn-small { min-height: 36px; padding: 6px 10px; font-size: 14px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

.main-btn {
  display: block; width: 100%; margin: 12px 0 4px; padding: 18px 14px; border-radius: 16px;
  background: linear-gradient(180deg, #2ea043, #238636); border: 1px solid #3fb950; color: #fff;
  font-size: 20px; font-weight: 800; letter-spacing: .02em; min-height: 76px; touch-action: manipulation;
  user-select: none; -webkit-user-select: none; cursor: pointer; position: relative; overflow: hidden;
}
.main-btn small { display: block; font-size: 12px; font-weight: 400; opacity: .9; margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main-btn:active:not(:disabled) { transform: scale(.985); filter: brightness(1.1); }
.main-btn:disabled { filter: grayscale(.8); opacity: .6; }
.floater { position: absolute; pointer-events: none; font-family: var(--mono); font-weight: 700; color: #d2ffd9;
  animation: floatup .9s ease-out forwards; font-size: 16px; }
@keyframes floatup { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-40px); } }

.bar { height: 10px; background: #0d131a; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin: 6px 0; }
.bar > div { height: 100%; background: var(--accent); width: 0; transition: width .25s; }
.bar.blue > div { background: var(--blue); } .bar.violet > div { background: var(--violet); } .bar.warn > div { background: var(--warn); }

/* Kaufzeilen */
.item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item .info { flex: 1; min-width: 0; }
.item .name { font-weight: 600; }
.item .name .cnt { font-family: var(--mono); color: var(--accent); margin-left: 6px; }
.item .desc { color: var(--muted); font-size: 13px; }
.item .btn { min-width: 112px; font-family: var(--mono); font-size: 14px; }

/* Projekte */
.proj { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.proj.can { border-color: var(--accent); }
.proj .ptitle { font-weight: 700; }
.proj .pdesc { color: var(--muted); font-size: 14px; margin: 4px 0 8px; }
.proj .pfoot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.proj .pcost { font-family: var(--mono); font-size: 13px; }
.proj .pcost span { margin-right: 8px; white-space: nowrap; }
.proj .pcost .miss { color: var(--danger); }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }
details.done-list { color: var(--muted); font-size: 14px; margin-top: 8px; }
details.done-list li { margin: 4px 0; }

/* Preis */
.price-ctl { display: grid; grid-template-columns: 1fr 1fr auto 1fr 1fr; gap: 6px; align-items: center; }
.price-ctl .pv { font-family: var(--mono); font-size: 20px; font-weight: 700; text-align: center; min-width: 96px; }

/* Schalter */
.switch { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }

/* Regler */
.slider { padding: 6px 0; }
.slider label { display: flex; justify-content: space-between; font-size: 14px; }
.slider input[type=range] { width: 100%; accent-color: var(--accent); height: 32px; }

/* Protokoll */
.log-item { border-bottom: 1px solid var(--line); padding: 10px 2px; font-size: 14px; white-space: pre-line; }
.log-item .lf { font-weight: 700; color: var(--blue); }
.log-item .lt { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-left: 6px; }
.log-item.trust .lf { color: var(--accent); }
.log-item.warn .lf { color: var(--warn); }
.log-item.proj .lf { color: var(--violet); }
.log-item.dim { opacity: .7; }

/* Navigation */
#tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(13, 17, 23, .97); border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
#tabs button {
  background: none; border: 0; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center;
  font-size: 12px; color: var(--muted); position: relative; min-height: 60px; cursor: pointer;
}
#tabs button .ti { font-size: 20px; line-height: 1.2; }
#tabs button.active { color: var(--accent); }
.badge {
  position: absolute; top: 4px; left: 55%; background: var(--accent); color: #04140a; font-size: 11px; font-weight: 800;
  border-radius: 999px; padding: 0 6px; min-width: 18px; line-height: 18px;
}
.badge.dot { min-width: 10px; height: 10px; padding: 0; top: 8px; background: var(--blue); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .7); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px; max-width: 520px; width: 100%;
  max-height: 86dvh; overflow: auto; animation: pop .25s ease-out;
}
@keyframes pop { from { transform: scale(.95); opacity: 0; } }
.modal-box h1 { font-family: var(--mono); color: var(--accent); margin: 0 0 6px; font-size: 26px; letter-spacing: .05em; }
.modal-box h3 { margin: 0 0 10px; color: var(--muted); font-weight: 600; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; }
.modal-box p { margin: 10px 0; white-space: pre-line; }
.modal-box .speaker { color: var(--blue); font-weight: 700; }
.modal-box textarea { width: 100%; min-height: 110px; background: #0d131a; color: var(--text); border: 1px solid var(--line); border-radius: 8px; font-family: var(--mono); font-size: 12px; padding: 8px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; }
.term { font-family: var(--mono); font-size: 14px; background: #0d131a; border: 1px solid var(--line); border-radius: 8px; padding: 10px; color: #b9f6c5; white-space: pre-wrap; }
.stars { color: var(--warn); font-size: 22px; letter-spacing: 4px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + var(--safe-b)); z-index: 40;
  background: #1c2433; border: 1px solid var(--violet); border-radius: 12px; padding: 10px 14px; font-size: 14px;
  width: calc(100% - 24px); max-width: 560px; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); animation: pop .2s ease-out;
}
.toast b { color: var(--violet); }

@media (min-width: 700px) { body { font-size: 17px; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
