:root {
  --bg: #0b1d33;
  --panel: rgba(12, 28, 48, 0.88);
  --panel-solid: #10243d;
  --line: rgba(140, 200, 255, 0.22);
  --text: #e8f1fa;
  --muted: #9fb3c8;
  --accent: #36c5b4;
  --accent2: #ffb84d;
  --blue: #2f7fe0;
  --red: #e0482f;
  --danger: #ff6b6b;
  --radius: 12px;
  --hud-h: 52px;
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: block; }

/* ---------- Menü ---------- */
.menu-bg { position: absolute; inset: 0; background: url(/assets/title.jpg) center/cover no-repeat; filter: saturate(1.1); }
.menu-bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(6,16,30,0.92) 0%, rgba(6,16,30,0.65) 38%, rgba(6,16,30,0) 70%); }
.menu-inner { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 4vh 6vw; max-width: 640px; }
.logo { font-size: clamp(2.4rem, 6vw, 4.6rem); margin: 0; letter-spacing: 0.06em; font-weight: 900; line-height: 1;
  background: linear-gradient(180deg, #fff 0%, #bfe9ff 60%, #6cc6ff 100%); -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 4px 30px rgba(0,0,0,0.4); }
.logo span { background: linear-gradient(180deg, #ffd9a3, #ff8a4d); -webkit-background-clip: text; background-clip: text; }
.tagline { color: #cfe3f5; margin: 0.6rem 0 2rem; font-size: 1.1rem; }
.menu-buttons { display: flex; flex-direction: column; gap: 0.7rem; max-width: 380px; }
.credits { color: var(--muted); font-size: 0.8rem; margin-top: 2rem; }

.btn { background: linear-gradient(180deg, rgba(40,80,120,0.9), rgba(20,45,75,0.95)); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.6rem 1rem; cursor: pointer; transition: transform .08s, background .2s, border-color .2s; text-align: left; white-space: nowrap; }
.btn:hover { border-color: rgba(140,220,255,0.6); background: linear-gradient(180deg, rgba(55,105,150,0.95), rgba(25,55,90,0.95)); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.big { font-size: 1.12rem; padding: 0.85rem 1.2rem; }
.btn.primary { background: linear-gradient(180deg, #2fb8a6, #1b7f73); border-color: rgba(160,255,240,0.5); font-weight: 600; }
.btn.primary:hover { background: linear-gradient(180deg, #3fd0bd, #208f82); }
.btn.danger { background: linear-gradient(180deg, #b8402f, #7f2418); }
.btn.small { padding: 0.35rem 0.7rem; font-size: 0.9rem; }
.icon { background: transparent; border: 1px solid transparent; border-radius: 8px; width: 40px; height: 40px; cursor: pointer; font-size: 1.15rem; }
.icon:hover { background: rgba(255,255,255,0.08); border-color: var(--line); }

/* ---------- Spiel ---------- */
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; cursor: default; }
#hud { position: absolute; left: 0; right: 0; top: 0; height: var(--hud-h); display: flex; align-items: center; gap: 0.6rem; padding: 0 0.6rem;
  padding-top: env(safe-area-inset-top); background: linear-gradient(180deg, rgba(8,20,36,0.95), rgba(8,20,36,0.75)); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px); z-index: 5; }
.hud-turn { color: var(--muted); font-size: 0.95rem; }
.hud-player { display: flex; align-items: center; gap: 0.45rem; font-weight: 700; padding: 0.25rem 0.7rem; border-radius: 99px; background: rgba(255,255,255,0.06); }
.hud-player .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 10px currentColor; }
.hud-energy { font-size: 1.05rem; }
.hud-energy small { color: var(--accent); }
.hud-spacer { flex: 1; }
.hud-online { font-size: 0.85rem; color: var(--muted); }
.hud-online .on { color: #69db7c; } .hud-online .off { color: var(--danger); }

#minimap { position: absolute; left: 12px; bottom: 12px; width: 220px; height: 150px; background: rgba(5,15,28,0.85); border: 1px solid var(--line); border-radius: 10px; z-index: 4; cursor: pointer; touch-action: none; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); backdrop-filter: blur(8px); box-shadow: 0 8px 30px rgba(0,0,0,0.35); }
#info { position: absolute; right: 12px; top: calc(var(--hud-h) + 12px); width: 300px; max-height: calc(100% - var(--hud-h) - 100px); overflow: auto; padding: 0.8rem; z-index: 4; font-size: 0.92rem; }
#info:empty { display: none; }
#info h3 { margin: 0 0 0.3rem; font-size: 1.1rem; display: flex; align-items: center; gap: 0.4rem; }
#info .sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.5rem; }
#info .portrait { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; display: block; margin-bottom: 0.6rem; border: 1px solid var(--line); }
#info table { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 0.4rem; }
#info td { padding: 2px 4px; border-bottom: 1px solid rgba(255,255,255,0.06); }
#info td:last-child { text-align: right; font-weight: 600; }
.bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,0.12); overflow: hidden; margin: 4px 0 8px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, #40c057, #94d82d); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 0.4rem 0; }
.chip { font-size: 0.78rem; padding: 2px 7px; border-radius: 99px; background: rgba(255,255,255,0.08); border: 1px solid var(--line); }
.chip.atk { border-color: rgba(255,120,100,0.5); }
.preview { margin-top: 0.6rem; padding: 0.6rem; border-radius: 10px; background: rgba(255,80,60,0.12); border: 1px solid rgba(255,100,80,0.4); }
.preview b { font-size: 1.15rem; }

#actionbar { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 0.5rem; z-index: 5; align-items: flex-end; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100% - 260px); padding-bottom: env(safe-area-inset-bottom); }
#unitActions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }
#banner { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%) scale(0.9); padding: 1rem 2.4rem; font-size: clamp(1.4rem, 4vw, 2.4rem); font-weight: 900; letter-spacing: 0.05em;
  border-radius: 14px; background: rgba(8,20,36,0.85); border: 2px solid var(--accent); opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s; z-index: 8; text-align: center; white-space: nowrap; }
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#banner small { display: block; font-size: 0.5em; font-weight: 500; color: var(--muted); letter-spacing: 0; }
#toast { position: absolute; left: 50%; top: calc(var(--hud-h) + 14px); transform: translateX(-50%); z-index: 9; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast div { background: rgba(8,20,36,0.92); border: 1px solid var(--line); padding: 0.45rem 1rem; border-radius: 99px; animation: toast 3.2s forwards; font-size: 0.95rem; }
#toast div.err { border-color: var(--danger); color: #ffc9c9; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }
#thinking { position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 6; background: rgba(8,20,36,0.9); border: 1px solid var(--line); padding: 0.5rem 1rem; border-radius: 99px; display: flex; gap: 0.5rem; align-items: center; }
.spinner { width: 16px; height: 16px; border: 3px solid rgba(255,255,255,0.2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
#chatBox { position: absolute; right: 12px; bottom: 70px; width: 300px; height: 260px; z-index: 7; display: flex; flex-direction: column; padding: 0.5rem; }
#chatLog { flex: 1; overflow: auto; font-size: 0.9rem; }
#chatLog p { margin: 0.2rem 0; } #chatLog b.p1 { color: #7fb7ff; } #chatLog b.p2 { color: #ff9a7f; }
#chatForm { display: flex; gap: 0.4rem; } #chatInput { flex: 1; }

/* ---------- Dialoge ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(3,10,20,0.6); backdrop-filter: blur(3px); padding: 16px; }
.modal-card { background: var(--panel-solid); border: 1px solid var(--line); border-radius: 16px; padding: 1.3rem 1.4rem; width: min(760px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.modal-card h2 { margin: 0 0 0.8rem; }
.modal-card .row { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; margin: 0.6rem 0; }
.modal-card .actions { display: flex; gap: 0.6rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
input, select { background: #0a1a2e; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.6rem; font: inherit; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.maps { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.7rem; }
.mapcard { border: 2px solid var(--line); border-radius: 12px; padding: 0.5rem; cursor: pointer; background: rgba(255,255,255,0.03); text-align: left; }
.mapcard.sel { border-color: var(--accent); background: rgba(54,197,180,0.12); }
.mapcard canvas { width: 100%; aspect-ratio: 16/10; display: block; border-radius: 8px; background: #08213a; }
.mapcard b { display: block; margin-top: 0.35rem; }
.mapcard small { color: var(--muted); display: block; line-height: 1.3; }
.build-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 0.6rem; }
.build-item { display: flex; gap: 0.6rem; text-align: left; padding: 0.5rem; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.04); cursor: pointer; align-items: center; }
.build-item:hover:not(:disabled) { border-color: var(--accent); background: rgba(54,197,180,0.1); }
.build-item:disabled { opacity: 0.4; cursor: not-allowed; }
.build-item img { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; flex: none; }
.build-item b { display: block; }
.build-item small { color: var(--muted); display: block; font-size: 0.78rem; line-height: 1.3; }
.build-item .cost { color: var(--accent2); font-weight: 700; }
.qr-wrap { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.qr-wrap img { width: 220px; height: 220px; background: #fff; border-radius: 12px; padding: 8px; }
.code { font-size: 2.2rem; font-weight: 900; letter-spacing: 0.25em; color: var(--accent2); }
.linkbox { font-size: 0.85rem; word-break: break-all; color: var(--muted); }
.help h3 { margin: 1rem 0 0.3rem; color: var(--accent); }
.help p, .help li { line-height: 1.5; color: #d5e3f0; }
.help table { border-collapse: collapse; font-size: 0.85rem; width: 100%; }
.help td, .help th { border-bottom: 1px solid rgba(255,255,255,0.08); padding: 3px 5px; text-align: left; }
.big-result { font-size: 2.2rem; font-weight: 900; text-align: center; margin: 0.4rem 0; }
.stats { display: grid; grid-template-columns: 1fr auto auto; gap: 4px 16px; max-width: 360px; margin: 0.8rem auto; }
.handover { text-align: center; }
.handover .big-result { font-size: 2rem; }

/* ---------- Kleine Bildschirme ---------- */
@media (max-width: 760px) {
  :root { --hud-h: 46px; font-size: 15px; }
  .hud-turn { display: none; }
  #hud { gap: 0.3rem; }
  .hud-player { white-space: nowrap; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; padding: 0.2rem 0.5rem; }
  .hud-energy small { display: none; }
  .hud-online { max-width: 22vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .icon { width: 34px; height: 34px; }
  #btnFull, #btnZoomFit { display: none; }
  #minimap { width: 120px; height: 84px; left: 8px; bottom: auto; top: calc(var(--hud-h) + 8px); }
  #info { left: 8px; right: 8px; top: auto; bottom: 64px; width: auto; max-height: 38vh; padding: 0.6rem; }
  #info .portrait { display: none; }
  #actionbar { left: 8px; right: 8px; bottom: 8px; max-width: none; }
  #actionbar .btn { padding: 0.55rem 0.8rem; }
  .menu-bg::after { background: linear-gradient(180deg, rgba(6,16,30,0.55), rgba(6,16,30,0.9)); }
  .menu-inner { justify-content: flex-end; padding-bottom: 6vh; }
  #chatBox { left: 8px; right: 8px; width: auto; bottom: 64px; }
}
@media (min-width: 1800px) { :root { font-size: 18px; } #info { width: 340px; } #minimap { width: 280px; height: 190px; } }
@media (min-width: 2600px) { :root { font-size: 22px; } #info { width: 420px; } #minimap { width: 360px; height: 240px; } }
