/* KERNWACHT – Layout & Stil. Responsiv: Desktop (Leiste rechts),
   Hochkant-Smartphone/Tablet (Leiste unten, einklappbar). */
:root {
  --bg: #05080f; --bg2: #0a1120; --bg3: #101a2e; --line: #1d2a44; --line2: #2a3d63;
  --txt: #dfe9ff; --dim: #8b9bbd; --mute: #5d6b8a;
  --cyan: #5cf2ff; --pink: #ff4d8d; --gold: #ffd34d; --green: #5dffa0; --red: #ff5a6e; --violet: #b27bff;
  --font: "Rajdhani", "Segoe UI", "Roboto", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Consolas", "SFMono-Regular", monospace;
  --panelW: 360px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--txt); font-family: var(--font); overflow: hidden; -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior: none; touch-action: manipulation; }
button { font-family: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* ---------- HUD ---------- */
#hud { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: linear-gradient(180deg, #0c1528, #070c18); border-bottom: 1px solid var(--line2); min-height: 46px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
#hud::-webkit-scrollbar { display: none; }
.logo { font-weight: 800; letter-spacing: 3px; font-size: 18px; color: var(--pink); text-shadow: 0 0 12px rgba(255,77,141,.6); margin-right: 8px; white-space: nowrap; }
.logo span { color: var(--cyan); text-shadow: 0 0 12px rgba(92,242,255,.6); }
.stat { display: flex; align-items: baseline; gap: 4px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 8px; background: rgba(255,255,255,.02); white-space: nowrap; font-size: 17px; font-weight: 700; }
.stat .ic { font-size: 15px; color: var(--dim); }
.stat small { font-size: 12px; color: var(--green); font-weight: 600; }
.ic-c { color: var(--gold) !important; } .ic-l { color: #b6c2d4 !important; } .ic-e { color: var(--cyan) !important; } .ic-core { color: var(--pink) !important; } .ic-s { color: #ffe9a6 !important; }
.stat.warn { border-color: var(--red); background: rgba(255,90,110,.12); animation: blink 1s infinite; }
.stat.flash { animation: flash .5s; }
@keyframes blink { 50% { background: rgba(255,90,110,.28); } }
@keyframes flash { 0% { background: rgba(255,90,110,.6); } }
.spacer { flex: 1; }
.ctrl { display: flex; gap: 4px; }
.ctrl button { min-width: 38px; height: 34px; border: 1px solid var(--line2); background: var(--bg3); border-radius: 8px; font-size: 15px; font-weight: 700; }
.ctrl button.on { background: #1d3a5c; border-color: var(--cyan); color: #fff; box-shadow: 0 0 8px rgba(92,242,255,.35) inset; }

/* ---------- Hauptbereich ---------- */
#main { flex: 1; display: flex; min-height: 0; }
#stage { position: relative; flex: 1; min-width: 0; min-height: 0; overflow: hidden; }
#cv { display: block; touch-action: none; cursor: crosshair; }
#panel { width: var(--panelW); display: flex; flex-direction: column; border-left: 1px solid var(--line2); background: var(--bg2); min-height: 0; }
#tabs { display: flex; border-bottom: 1px solid var(--line2); }
#tabs .tab { flex: 1; padding: 10px 4px; background: none; border: none; border-bottom: 2px solid transparent; font-size: 15px; font-weight: 700; color: var(--dim); letter-spacing: .5px; }
#tabs .tab.on { color: #fff; border-bottom-color: var(--cyan); }
#tabs .tab .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--pink); margin-left: 4px; vertical-align: middle; }
#tabs .tgl { flex: 0 0 40px; display: none; }
#pbody { flex: 1; overflow-y: auto; padding: 10px; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
#abar { padding: 8px 10px; border-top: 1px solid var(--line2); display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Bausteine ---------- */
h3 { margin: 12px 0 6px; font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: var(--dim); font-weight: 700; }
h3:first-child { margin-top: 0; }
.muted { color: var(--dim); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.good { color: var(--green); } .bad { color: var(--red); } .gold { color: var(--gold); }
.card { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left; padding: 8px 10px; margin-bottom: 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg3); transition: border-color .15s, background .15s; }
.card:hover { border-color: var(--line2); background: #14213a; }
.card.active { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan) inset; }
.card.dis { opacity: .55; }
.card.locked { opacity: .45; cursor: default; }
.card.free { border-color: var(--gold); background: linear-gradient(90deg, rgba(255,211,77,.12), var(--bg3)); }
.badge { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: 1px; padding: 1px 6px; border-radius: 4px; background: var(--gold); color: #1a1300; margin-left: 4px; vertical-align: 1px; }
.badge.new { background: var(--pink); color: #fff; }
.badge.cy { background: var(--cyan); color: #00222a; }
.gl { flex: 0 0 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; font-weight: 800; font-size: 19px; background: #0a0f1b; border: 2px solid currentColor; }
.cbody { flex: 1; min-width: 0; }
.ctitle { font-weight: 700; font-size: 16px; display: flex; justify-content: space-between; gap: 8px; }
.cdesc { font-size: 13px; color: var(--dim); line-height: 1.3; margin-top: 2px; }
.cost { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }
.cost .miss { color: var(--red); }
.btn { padding: 9px 14px; border-radius: 9px; border: 1px solid var(--line2); background: var(--bg3); font-size: 15px; font-weight: 700; flex: 1; min-height: 42px; }
.btn:hover { border-color: var(--cyan); }
.btn.pri { background: linear-gradient(180deg, #ff4d8d, #c2185b); border-color: #ff7aa8; color: #fff; box-shadow: 0 0 16px rgba(255,77,141,.35); }
.btn.pri:hover { filter: brightness(1.1); }
.btn.cy { background: linear-gradient(180deg, #1aa6c4, #0c6a80); border-color: var(--cyan); color: #fff; }
.btn.warn { border-color: var(--red); color: #ffc0c8; }
.btn[disabled] { opacity: .45; cursor: not-allowed; filter: grayscale(.6); }
.btn small { display: block; font-size: 11.5px; font-weight: 600; opacity: .85; }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
table.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
table.kv td { padding: 3px 4px; border-bottom: 1px solid rgba(255,255,255,.05); vertical-align: top; }
table.kv td:first-child { color: var(--dim); width: 42%; }
table.kv td.up { color: var(--green); }
.factor { display: flex; justify-content: space-between; font-size: 13.5px; padding: 2px 0; }
.box { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: rgba(255,255,255,.02); margin: 6px 0; font-size: 14px; line-height: 1.35; }
.box.warn { border-color: var(--red); background: rgba(255,90,110,.08); }
.box.info { border-color: var(--line2); }
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button { flex: 1; min-width: 60px; padding: 7px 4px; border-radius: 7px; border: 1px solid var(--line2); background: var(--bg3); font-size: 13px; font-weight: 700; }
.seg button.on { border-color: var(--cyan); background: #163049; color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12.5px; padding: 2px 7px; border-radius: 6px; background: #13203a; border: 1px solid var(--line2); }
.ab { position: relative; overflow: hidden; }
.ab .cdbar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--cyan); }
.grid15 { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.fz { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12.5px; background: var(--bg3); }
.fz b { font-size: 14px; }
.fz.dim { opacity: .5; }

/* ---------- Stage-Overlays ---------- */
#banner { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); max-width: calc(100% - 20px); padding: 7px 14px; border-radius: 10px; background: rgba(40,8,20,.88); border: 1px solid var(--pink); font-weight: 700; font-size: 15px; text-align: center; pointer-events: none; box-shadow: 0 0 22px rgba(255,77,141,.3); }
#banner.cy { background: rgba(4,30,40,.88); border-color: var(--cyan); }
#toasts { position: absolute; left: 50%; top: 52px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 5px; pointer-events: none; width: max-content; max-width: calc(100% - 20px); }
.toast { padding: 6px 12px; border-radius: 8px; background: rgba(10,18,34,.94); border: 1px solid var(--line2); font-size: 14.5px; font-weight: 600; animation: tin .2s, tout .4s 2.2s forwards; text-align: center; }
.toast.err { border-color: var(--red); color: #ffc7cf; }
.toast.ok { border-color: var(--green); }
.toast.big { font-size: 18px; border-color: var(--gold); color: #fff3c2; }
@keyframes tin { from { opacity: 0; transform: translateY(-6px); } }
@keyframes tout { to { opacity: 0; } }
#tip { position: absolute; pointer-events: none; max-width: 260px; padding: 7px 10px; border-radius: 8px; background: rgba(8,14,28,.95); border: 1px solid var(--line2); font-size: 13.5px; line-height: 1.3; z-index: 5; }
#tutorial { margin: 8px 10px 0; padding: 9px 11px; border-radius: 12px; background: rgba(6,24,34,.95); border: 1px solid var(--cyan); box-shadow: 0 0 18px rgba(92,242,255,.2); font-size: 14.5px; line-height: 1.35; }
#tutorial .row { margin: 8px 0 0; }
#tutorial .btn { min-height: 34px; padding: 5px 10px; font-size: 14px; }
#pausedOverlay { position: absolute; inset: 0; display: grid; place-items: center; font-size: 42px; font-weight: 800; letter-spacing: 10px; color: rgba(255,255,255,.75); background: rgba(0,0,0,.35); pointer-events: none; }

/* ---------- Modal ---------- */
#modal { position: fixed; inset: 0; background: rgba(2,4,10,.78); display: grid; place-items: center; z-index: 20; padding: 12px; backdrop-filter: blur(3px); }
.mcard { width: min(760px, 100%); max-height: calc(100% - 10px); overflow-y: auto; background: linear-gradient(180deg, #0d1628, #080e1b); border: 1px solid var(--line2); border-radius: 16px; padding: 18px; box-shadow: 0 0 40px rgba(92,242,255,.12); }
.mcard h2 { margin: 0 0 4px; font-size: 26px; letter-spacing: 1px; }
.mcard .sub { color: var(--dim); margin-bottom: 12px; }
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 12px 0; }
.choice { text-align: left; padding: 12px; border-radius: 12px; border: 1px solid var(--line2); background: var(--bg3); display: flex; flex-direction: column; gap: 6px; min-height: 150px; }
.choice:hover, .choice:focus { border-color: var(--cyan); background: #142441; outline: none; }
.choice .cat { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--dim); font-weight: 700; }
.choice .t { font-size: 17px; font-weight: 700; }
.choice .d { font-size: 13.5px; color: #b9c6e4; line-height: 1.35; }
.choice .gl { width: 42px; height: 42px; }
.choice.relic { border-color: #7a5cff; background: linear-gradient(180deg, #1a1440, #0f1226); }
.title-big { font-size: 46px; font-weight: 800; letter-spacing: 6px; margin: 0; color: var(--pink); text-shadow: 0 0 22px rgba(255,77,141,.6); line-height: 1; }
.title-big span { color: var(--cyan); text-shadow: 0 0 22px rgba(92,242,255,.6); }
.lo { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; margin: 10px 0; }
.lo .choice { min-height: 110px; }
.lo .choice.sel { border-color: var(--pink); box-shadow: 0 0 0 1px var(--pink) inset; }
.lo .choice.lock { opacity: .5; }
input.txt { width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line2); background: #070c17; color: #fff; font-family: var(--mono); font-size: 15px; }
.lb { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.lb td, .lb th { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.lb th { color: var(--dim); font-size: 12px; letter-spacing: 1px; text-transform: uppercase; }
.lb tr.me td { color: var(--gold); }
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 10px 0; }
.sg { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: rgba(255,255,255,.02); }
.sg .k { font-size: 12px; color: var(--dim); letter-spacing: 1px; text-transform: uppercase; }
.sg .v { font-size: 22px; font-weight: 800; }

/* ---------- Hochkant / kleine Bildschirme ---------- */
@media (orientation: portrait), (max-width: 760px) and (max-aspect-ratio: 1/1) {
  #main { flex-direction: column; }
  #panel { width: 100%; border-left: none; border-top: 1px solid var(--line2); max-height: 40vh; }
  #panel.collapsed { max-height: none; }
  #panel.collapsed #pbody { display: none; }
  #tabs .tgl { display: block; }
  #tabs .tab { padding: 8px 2px; font-size: 14px; }
  .logo { display: none; }
  #abar { padding: 6px 8px; }
}
@media (max-width: 1100px) and (orientation: landscape) { :root { --panelW: 300px; } }
@media (max-height: 520px) and (orientation: landscape) {
  :root { --panelW: 280px; }
  #hud { min-height: 38px; padding: 3px 6px; }
  .logo { display: none; }
  .stat { font-size: 14px; padding: 2px 6px; }
  .stat small { display: none; }
  .ctrl button { height: 28px; min-width: 32px; font-size: 13px; }
  #tabs .tab { padding: 6px 2px; font-size: 13px; }
  .btn { min-height: 36px; padding: 5px 8px; font-size: 14px; }
  #pbody { padding: 6px; }
  .card { padding: 5px 7px; }
  .gl { flex-basis: 30px; height: 30px; font-size: 16px; }
}
@media (max-width: 520px) {
  #hud { flex-wrap: wrap; row-gap: 4px; overflow: visible; }
  #hud .spacer { display: none; }
  .ctrl { margin-left: auto; }
  #banner { font-size: 12.5px; padding: 4px 8px; top: 4px; }
  #toasts { top: 40px; }
  .toast { font-size: 13px; padding: 4px 9px; }
  #tutorial { font-size: 13.5px; }
  .stat { font-size: 14.5px; padding: 2px 6px; gap: 3px; }
  .stat small { display: none; }
  .ctrl button { min-width: 32px; height: 32px; font-size: 13px; }
  #hud { gap: 4px; padding: 4px 6px; }
  .title-big { font-size: 34px; letter-spacing: 3px; }
  .mcard { padding: 14px; }
  .choice { min-height: 0; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
