:root {
  --bg: #08100d;
  --bg2: #09120f;
  --panel: #0c1714;
  --line: #1f2e28;
  --text: #ffffff;
  --muted: #9bb3a8;
  --accent: #22d68a;
  --accent2: #22d68a;
  --friend: #22d68a;
  --enemy: #22d68a;
  --watch: #22d68a;
  --neutral: #5f7a6d;
  --radius: 6px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1000px 500px at 20% -10%, rgba(34,214,138,.12) 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
}
h1 { font-size: 20px; margin: 0; letter-spacing: .3px; }
h2 { font-size: 15px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
code { background: #07130e; padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* Kopf */
.top {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 16px 24px; border-bottom: 1px solid var(--line); background: rgba(8,16,13,.88);
  position: sticky; top: 0; z-index: 5; backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 30px; color: var(--accent); }
/* Fail-Popup */
.failwrap { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(40,0,0,.88); backdrop-filter: blur(6px); animation: failflash .5s steps(2) infinite; }
.failbox { width: 100%; max-width: 900px; min-height: 60vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  text-align: center; padding: 32px 20px; background: #0d0303; border: 2px solid #ff3b30; border-radius: 12px;
  box-shadow: 0 0 12px #ff3b30, 0 0 60px rgba(255,59,48,.55), inset 0 0 24px rgba(255,59,48,.3); animation: failshake .12s linear infinite; }
.failtext { font-size: clamp(44px, 12vw, 130px); font-weight: 900; line-height: 1.02; letter-spacing: 2px; color: #fff;
  text-shadow: 0 0 6px #fff, 0 0 18px #ff3b30, 0 0 40px #ff3b30; }
.failskull { font-size: clamp(48px, 10vw, 100px); line-height: 1; }
@keyframes failshake { 0% { transform: translate(0,0) rotate(0); } 25% { transform: translate(-4px,3px) rotate(-.4deg); } 50% { transform: translate(3px,-4px) rotate(.4deg); } 75% { transform: translate(-3px,-2px) rotate(-.2deg); } 100% { transform: translate(0,0) rotate(0); } }
@keyframes failflash { 0% { background: rgba(40,0,0,.88); } 100% { background: rgba(90,0,0,.92); } }

/* Login-Popup */
.loginwrap { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(800px 400px at 50% 0%, rgba(34,214,138,.14), transparent 60%), rgba(4,9,7,.94); backdrop-filter: blur(8px); padding: 16px; }
.loginbox { width: 100%; max-width: 340px; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
  padding: 28px 24px; background: #050b09; border: 1px solid #1f5a40; border-radius: 10px;
  box-shadow: 0 0 8px rgba(34,214,138,.45), 0 0 40px rgba(34,214,138,.18), inset 0 0 8px rgba(34,214,138,.2); }
.loginlogo { font-size: 44px; line-height: 1; }
.loginbox input { width: 100%; margin-top: 6px; text-align: center; letter-spacing: 2px; }
.loginbox .btn { width: 100%; padding: 8px 12px; }
.loginerr { min-height: 18px; font-size: 12px; color: #ff8b84; }
.titlerow { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; padding: 10px 24px 0; overflow-x: auto; }
.tabs button {
  background: none; border: 0; color: var(--muted); padding: 10px 14px; font: inherit; cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--accent); border-color: var(--accent); }

main { padding: 16px 24px 48px; max-width: 1400px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

/* Bedienelemente */
input, select, textarea {
  background: var(--bg2); color: var(--text); border: 1px solid var(--line); border-radius: 7px;
  padding: 7px 9px; font: inherit; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent2); outline-offset: -1px; }
textarea { width: 100%; font-family: Consolas, monospace; resize: vertical; }
.btn {
  background: #0f2019; color: var(--text); border: 1px solid #1f5a40; border-radius: 7px;
  padding: 7px 13px; font: inherit; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #16402d; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #ffffff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: transparent; border-color: #6b2b2b; color: #ff8b84; }
.btn.danger:hover { background: #3a1a1a; }
.btn.small { padding: 3px 9px; font-size: 12px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.space { justify-content: space-between; margin-top: 10px; }
.grow { flex: 1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; font-size: 13px; }
.form { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.form .btn { align-self: flex-start; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 16px;
}
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2 > .panel { margin-bottom: 16px; }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }

/* Kennzahlen */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 26px; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi.enemy .v { color: var(--enemy); }
.kpi.watch .v { color: var(--watch); }
.kpi.friend .v { color: var(--friend); }

/* Grid-Karte */
.gridmap { display: grid; gap: 4px; }
.gridmap .lbl { color: var(--muted); font-size: 11px; display: flex; align-items: center; justify-content: center; }
.cell {
  aspect-ratio: 1; border-radius: 6px; border: 1px solid var(--line); background: #0a1612;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; position: relative; padding: 2px; min-width: 0; transition: transform .08s;
}
.cell:hover { transform: scale(1.04); border-color: var(--accent2); }
.cell.empty { border-style: dashed; background: transparent; cursor: default; opacity: .5; }
.cell.empty:hover { transform: none; border-color: var(--line); }
.cell.err { border-color: #7a3030; background: #2a1518; }
.cell.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.cell .n { font-size: 18px; font-weight: 700; line-height: 1; }
.cell .g { position: absolute; top: 3px; left: 5px; font-size: 10px; color: var(--muted); }
.cell .e { font-size: 11px; color: var(--enemy); font-weight: 600; }
.cell.has-enemy { box-shadow: inset 0 0 0 2px var(--enemy); }
#ungridded { margin-top: 8px; }

/* Listen */
.list { display: flex; flex-direction: column; }
.prow {
  display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 8px 6px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.prow:hover { background: rgba(255, 255, 255, .03); }
.prow .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .sub { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .right { text-align: right; font-size: 12px; color: var(--muted); white-space: nowrap; }
.empty-note { color: var(--muted); padding: 18px 6px; text-align: center; }

.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--neutral); display: inline-block; flex: none; }
.dot.friend { background: var(--friend); }
.dot.enemy { background: var(--enemy); box-shadow: 0 0 6px var(--enemy); }
.dot.watch { background: var(--watch); }
.dot.on { background: var(--friend); }
.dot.off { background: #2a3d35; }

.chip { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: #0f2019; color: var(--text); }
.chip.friend { background: rgba(69, 185, 124, .18); color: var(--friend); }
.chip.enemy { background: rgba(229, 83, 75, .18); color: var(--enemy); }
.chip.watch { background: rgba(232, 163, 61, .18); color: var(--watch); }
.chip.neutral { background: rgba(124, 139, 153, .18); color: #aab7c3; }
.chip.ok { background: rgba(69, 185, 124, .18); color: var(--friend); }
.chip.bad { background: rgba(229, 83, 75, .18); color: var(--enemy); }
#onlineScope { cursor: pointer; }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: rgba(255, 255, 255, .03); }
td.note { color: var(--muted); max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td input.inline { width: 100%; padding: 4px 6px; }
td input.grid-in { width: 52px; }
td input.port-in { width: 90px; flex: none; }

/* Cluster-Generator */
.gen { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin: 10px 0; }
.gen input { width: 150px; }
.gen input[type=number] { width: 110px; }

/* Detail-Schublade */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 10; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); z-index: 11;
  background: var(--bg2); border-left: 1px solid var(--line); overflow-y: auto; padding: 18px 20px 40px;
  box-shadow: -10px 0 40px rgba(0, 0, 0, .4);
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.drawer-head h2 { font-size: 20px; margin: 0; word-break: break-word; }
.close { background: none; border: 0; color: var(--muted); font-size: 24px; cursor: pointer; line-height: 1; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: 12px 0; }
.seg button { flex: 1; background: transparent; border: 0; color: var(--muted); padding: 8px 4px; cursor: pointer; font: inherit; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on.neutral { background: rgba(124, 139, 153, .25); color: var(--text); }
.seg button.on.friend { background: rgba(69, 185, 124, .25); color: var(--friend); }
.seg button.on.enemy { background: rgba(229, 83, 75, .25); color: var(--enemy); }
.seg button.on.watch { background: rgba(232, 163, 61, .25); color: var(--watch); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.stat .v { font-weight: 700; }
.stat .l { color: var(--muted); font-size: 11px; }
.hours { display: flex; align-items: flex-end; gap: 2px; height: 90px; margin-top: 8px; }
.hours div { flex: 1; background: var(--accent2); border-radius: 2px 2px 0 0; min-height: 2px; opacity: .85; }
.hours div:hover { opacity: 1; background: var(--accent); }
.hours-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; margin-top: 3px; }
.drawer h3 { font-size: 13px; color: var(--muted); font-weight: 600; margin: 18px 0 6px; text-transform: uppercase; letter-spacing: .5px; }
.sess { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; }

/* Debug */
#debugTable td, #debugTable th { font-size: 12px; white-space: nowrap; }
#debugTable td.num { text-align: right; font-variant-numeric: tabular-nums; }
#debugTable tr.diff td { background: rgba(232, 163, 61, .08); }
#debugTable tr.detail > td { white-space: normal; background: #050d0a; padding: 12px; }
.dbg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.dbg-grid h4 { margin: 0 0 6px; font-size: 12px; color: var(--accent); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; font-size: 12px; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { word-break: break-all; }
.hex { font: 11px/1.5 Consolas, monospace; background: #07130e; border: 1px solid var(--line); border-radius: 6px;
  padding: 8px; white-space: pre-wrap; word-break: break-all; max-height: 220px; overflow: auto; margin: 0 0 10px; }
.hexcell { font: 11px Consolas, monospace; color: #9bb3a8; }
.flag { color: var(--watch); font-size: 11px; }
.mini { width: auto; }
.mini td, .mini th { padding: 2px 8px; font-size: 12px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #0f2019; border: 1px solid var(--accent); color: var(--text); padding: 10px 16px; border-radius: 8px;
  z-index: 20; transition: .2s; pointer-events: none; white-space: pre-line; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 900px) {
  .overview-grid, .grid2 { grid-template-columns: 1fr; }
  .top, main { padding-left: 16px; padding-right: 16px; }
  .tabs { padding: 8px 16px 0; }
}

/* Ladebalken (Neon, Herzschlag) */
.pollbar { position: relative; height: 26px; margin: 10px 24px 0; border-radius: 10px; background: #050b09;
  border: 1px solid #1f5a40; box-shadow: 0 0 8px rgba(34,214,138,.45), inset 0 0 8px rgba(34,214,138,.2); overflow: hidden; }
#pollFill { position: relative; height: 100%; width: 0; overflow: hidden; transition: width .2s linear;
  background: linear-gradient(90deg, rgba(16,140,90,.25), rgba(91,245,176,.35));
  border-right: 2px solid #5bf5b0; box-shadow: 0 0 14px #22d68a, 0 0 28px rgba(91,245,176,.7); }
.ecg { position: absolute; inset: 0; width: 100%; pointer-events: none;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 140 40' preserveAspectRatio='none'><path d='M0 20 H38 L44 20 L49 8 L55 34 L61 3 L67 20 H82 L87 16 L92 20 H140' fill='none' stroke='%23b6ffdc' stroke-width='2' vector-effect='non-scaling-stroke' stroke-linejoin='round' stroke-linecap='round'/></svg>") repeat-x 0 0 / 140px 100%;
  filter: drop-shadow(0 0 3px #5bf5b0) drop-shadow(0 0 8px #22d68a);
  animation: ecgscroll 1.6s linear infinite; }
@keyframes ecgscroll { to { background-position: -140px 0; } }
.polltext { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; letter-spacing: 3px; text-transform: uppercase; color: #fff;
  text-shadow: 0 0 4px #fff, 0 0 10px #5bf5b0, 0 0 20px #22d68a; animation: neonpulse 1.4s ease-in-out infinite; pointer-events: none; }
@keyframes neonpulse { 0%,100% { text-shadow: 0 0 3px #fff, 0 0 8px #5bf5b0, 0 0 14px #22d68a; } 50% { text-shadow: 0 0 5px #fff, 0 0 16px #5bf5b0, 0 0 32px #22d68a, 0 0 44px #22d68a; } }
@media (max-width: 700px) { .pollbar { margin: 10px 16px 0; } }
.btn.primary { background: #22d68a; border-color: #22d68a; color: #fff; }

/* Design: dunkelgrün, Serif-Überschriften, Mono-Labels */
h1, h2, .drawer h2 { font-family: "Playfair Display", Georgia, "Times New Roman", serif; font-weight: 500; letter-spacing: .2px; }
h1 { font-size: 27.6px; }
h2 { font-size: 18px; }
.logo { color: var(--accent); }
.panel, .kpi { border-color: var(--line); background: var(--panel); }
.kpi { display: flex; flex-direction: column-reverse; gap: 6px; }
.kpi .l, #pollInfo, .tabs button, .panel-head .muted.small {
  font-family: "JetBrains Mono", Consolas, "Courier New", monospace; letter-spacing: .12em; text-transform: uppercase; font-size: 9.5px; }
.kpi .l { color: var(--accent); }
.kpi .v { font-family: "JetBrains Mono", Consolas, "Courier New", monospace; font-size: 27px; font-weight: 500; }
.tabs button { font-size: 11px; }
#pollInfo { color: var(--muted); }
.btn.primary { color: #04130c; font-weight: 700; }

/* Hintergrundbild (Logo, 25 % sichtbar) */
body::before { content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: url(logo.png) center center / 100% 100% no-repeat; opacity: .25; }
.top, .pollbar, .tabs, main { position: relative; z-index: 1; }
.top { position: sticky; }
.panel, .kpi { background: rgba(12, 23, 20, .62); backdrop-filter: blur(2px); }
.kpi { padding: 11px 13px; }

/* Boxen 10 % kleiner */
.kpis, .overview-grid, .tab > .panel { zoom: .9; width: 90%; max-width: 90%; margin-left: auto; margin-right: auto; }

/* Schriftgrößen (Feinabstimmung) */
h1 { font-size: 24px; }
#pollInfo { font-size: 11px; }
.cell .g { font-size: 12px; }
th, #debugTable th, .mini th { font-size: 14px; }

/* Grid-Name unter der Spielerzahl */
.cell .nm { margin-top: 3px; max-width: 100%; padding: 0 3px; font-size: 11px; line-height: 1.1; color: var(--muted);
  text-align: center; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }

/* Reiter oben rechts neben dem Alert-Menü, Ladebalken 5 % schmaler */
.top .tabs { padding: 0; margin-right: 8px; align-items: center; overflow: visible; }
.top .tabs button { padding: 8px 12px; }
.actions { align-items: center; }
.pollbar { height: 24.7px; }
@media (max-width: 700px) { .top .tabs { width: 100%; margin: 0; } }
