:root {
  --bg: #0E0F13;
  --surface: #171920;
  --surface2: #1F222B;
  --line: #2A2D36;
  --text: #ECEDF2;
  --muted: #A3A7B3;
  --accent: #7AA2FF;
  --danger: #FF6B6B;
  --ok: #5FD3B0;
  --warn: #F2B55C;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); overflow: hidden; overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
input, select { font: inherit; color: inherit; -webkit-user-select: text; user-select: text; }
svg { display: block; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { position: fixed; inset: 0; padding: calc(var(--safe-t) + 4px) 4px calc(var(--safe-b) + 4px); }
#board { position: relative; width: 100%; height: 100%; display: flex; flex-direction: column; gap: 4px; }

/* ---------- Tisch: Reihen und Zellen ---------- */
.row { flex: 1 1 0; display: flex; gap: 4px; min-height: 0; }
.cell { flex: 1 1 0; position: relative; min-width: 0; container-type: size; overflow: hidden; border-radius: 18px; }
.rot { position: absolute; left: 50%; top: 50%; width: 100cqw; height: 100cqh; transform: translate(-50%, -50%); }
.rot.r90, .rot.r270 { width: 100cqh; height: 100cqw; }
.rot.r90 { transform: translate(-50%, -50%) rotate(90deg); }
.rot.r180 { transform: translate(-50%, -50%) rotate(180deg); }
.rot.r270 { transform: translate(-50%, -50%) rotate(-90deg); }

.pc {
  --pc: #7AA2FF;
  position: absolute; inset: 0; container-type: size;
  display: flex; flex-direction: column;
  background: color-mix(in oklab, var(--pc) 22%, #111318);
  border: 1px solid color-mix(in oklab, var(--pc) 30%, transparent);
  border-radius: 18px; overflow: hidden;
  transition: filter .2s;
}
.cell.active .pc { border: 2px solid var(--pc); box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--pc) 40%, transparent); }
.pc.out { filter: grayscale(.85) brightness(.55); }

.ptop { position: relative; z-index: 2; display: flex; align-items: center; gap: 6px; padding: 6px 6px 0 6px; min-height: 36px; }
.pname {
  display: flex; align-items: center; gap: 6px; min-width: 0; flex: 0 1 auto;
  height: 32px; padding: 0 10px 0 8px; border: none; border-radius: 10px;
  background: rgba(0,0,0,.22); font-weight: 650; font-size: clamp(12px, 5.5cqmin, 16px);
}
.pname span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--pc); flex: none; }
.badges { display: flex; gap: 4px; margin-left: auto; align-items: center; flex: none; }
.ptop .more { width: 40px; height: 32px; }
.ptop .more svg { width: 18px; height: 18px; }
.badge {
  display: flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  border-radius: 8px; background: rgba(0,0,0,.28); color: #F2D45C;
}
.badge.ini { color: #FF9F5A; } .badge.bless { color: #9FE3FF; } .badge.lock { color: var(--muted); }
.badge svg { width: 16px; height: 16px; }
.pass {
  height: 32px; border: none; border-radius: 10px; padding: 0 10px;
  background: var(--pc); color: #0E0F13; font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 4px;
}
.pass svg { width: 14px; height: 14px; }

.pmid { position: relative; flex: 1; min-height: 0; container-type: size; }
.half {
  position: absolute; top: 0; bottom: 0; width: 50%; border: none; background: transparent;
  display: flex; align-items: center; padding: 0 6%; color: rgba(255,255,255,.28);
  font-size: clamp(20px, 12cqmin, 44px); font-weight: 300;
}
.half.minus { left: 0; justify-content: flex-start; }
.half.plus { right: 0; justify-content: flex-end; }
.half:active, .half.flash { background: rgba(255,255,255,.06); }
.half[disabled] { color: transparent; cursor: default; }
.life {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none;
  font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -0.04em; line-height: 1;
  font-size: clamp(26px, min(82cqh, 30cqw), 170px);
}
.delta {
  position: absolute; left: 0; right: 0; top: 4%; text-align: center; pointer-events: none;
  font-weight: 750; font-size: clamp(15px, 9cqmin, 28px); color: var(--pc); opacity: 0; transition: opacity .25s;
}
.delta.show { opacity: 1; }
.outlbl {
  position: absolute; left: 0; right: 0; bottom: 6%; text-align: center; pointer-events: none;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text);
}

.pbot { position: relative; z-index: 2; display: flex; align-items: flex-end; gap: 4px; padding: 0 6px 6px; min-height: 34px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; align-content: flex-end; overflow: hidden; flex: 1; min-width: 0; max-height: 60px; }
.chip {
  display: flex; align-items: center; gap: 3px; height: 28px; padding: 0 7px; border-radius: 8px; flex: none;
  background: rgba(0,0,0,.3); border: none; font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums;
}
.chip svg { width: 14px; height: 14px; }
.chip.st.mon { color: #F2D45C; } .chip.st.ini { color: #FF9F5A; } .chip.st.bless { color: #9FE3FF; }
.chip.st span { color: var(--text); font-size: 12px; }
.chip.lethal { background: var(--danger); color: #1A0B0B; }
.more {
  width: 44px; height: 32px; border-radius: 10px; border: none; flex: none;
  background: rgba(0,0,0,.3); display: flex; align-items: center; justify-content: center;
}
.more svg { width: 20px; height: 20px; }

/* ---------- Menü-Knopf ---------- */
.fab {
  position: absolute; left: 50%; top: 50%; width: 60px; height: 60px; margin: -30px 0 0 -30px; z-index: 5;
  border-radius: 50%; border: 4px solid var(--bg); background: var(--text); color: var(--bg);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.fab[hidden] { display: none; }
.fab svg { width: 24px; height: 24px; }
.fab::after {
  content: ""; position: absolute; right: -2px; top: -2px; width: 14px; height: 14px; border-radius: 50%;
  border: 3px solid var(--bg); background: transparent; display: none;
}
.fab.on::after { display: block; background: var(--ok); }
.fab.wait::after { display: block; background: var(--warn); }
.fab.top { top: calc(var(--safe-t) + 10px); left: auto; right: 10px; margin: 0; width: 48px; height: 48px; }

/* ---------- Mein-Platz-Ansicht ---------- */
.seathead { display: flex; align-items: center; gap: 8px; padding: 4px 64px 2px 6px; min-height: 52px; color: var(--muted); font-size: 14px; }
.seathead b { color: var(--text); }
.minis.one { grid-template-columns: 1fr; }
.minis { max-height: 55%; overflow-y: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; flex: none; }
.mini {
  --pc: #7AA2FF;
  display: flex; align-items: center; gap: 8px; min-height: 58px; min-width: 0; padding: 6px 10px; border-radius: 14px; text-align: left;
  border: 1px solid color-mix(in oklab, var(--pc) 30%, transparent);
  background: color-mix(in oklab, var(--pc) 16%, #111318);
}
.mini.active { border: 2px solid var(--pc); }
.mini.out { filter: grayscale(.85) brightness(.55); }
.mini .mn { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mini .mn span:first-child { font-weight: 650; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini .mn .mis { font-size: 12px; color: var(--text); display: flex; gap: 3px; align-items: center; flex-wrap: wrap; }
.mi { display: inline-flex; align-items: center; gap: 2px; height: 20px; padding: 0 5px; border-radius: 6px; background: rgba(0,0,0,.3); font-style: normal; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mi svg { width: 12px; height: 12px; }
.mi.mon { color: #F2D45C; } .mi.ini { color: #FF9F5A; } .mi.bless { color: #9FE3FF; } .mi.dim { color: var(--muted); }
.mi.lethal { background: var(--danger); color: #1A0B0B; }
.mi.out { color: var(--text); text-transform: uppercase; font-size: 11px; letter-spacing: .04em; }
.mini .ml { font-size: 28px; font-weight: 750; font-variant-numeric: tabular-nums; }
.mine { flex: 1; display: flex; min-height: 0; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 24px);
}
.modal[hidden] { display: none; }
.modal.flip .modal-in { transform: rotate(180deg); }
.modal-in { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.mhead { display: flex; align-items: center; gap: 10px; }
.mhead h1 { margin: 0; font-size: 24px; flex: 1; line-height: 1.15; }
.iconbtn {
  width: 44px; height: 44px; flex: none; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  display: flex; align-items: center; justify-content: center;
}
.iconbtn svg { width: 20px; height: 20px; }
.sec { display: flex; flex-direction: column; gap: 10px; }
.sec h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 650; }
.hint { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }

.btn {
  min-height: 48px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  font-weight: 600; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: #0B1020; border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.on { background: var(--text); color: var(--bg); border-color: transparent; }
.btn[disabled] { opacity: .4; cursor: default; }
.btn.block { width: 100%; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tile {
  min-height: 76px; border-radius: 16px; border: 1px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 6px; padding: 12px;
  font-weight: 600; font-size: 15px; text-align: left;
}
.tile svg { width: 22px; height: 22px; color: var(--accent); }
.tile small { color: var(--muted); font-weight: 500; font-size: 12px; }
.tile[disabled] { opacity: .4; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg .btn { flex: 1 1 0; min-width: 56px; }

/* Lebenspunkte im Spieler-Blatt */
.bigrow { display: flex; align-items: center; justify-content: center; gap: 6px; }
.biglife { font-size: 72px; font-weight: 750; font-variant-numeric: tabular-nums; min-width: 140px; text-align: center; letter-spacing: -0.04em; }
.steps { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.steps .btn { padding: 0; }

/* Zähler-Karten */
.ctr { display: flex; flex-direction: column; gap: 8px; }
.ctr .ct { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.ctr .ct svg { width: 16px; height: 16px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper .btn { width: 48px; padding: 0; flex: none; font-size: 22px; }
.stepper .val { flex: 1; text-align: center; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stepper .val small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; line-height: 1.2; white-space: nowrap; }
.ctr.lethal { border-color: var(--danger); }
.ctr.lethal .val { color: var(--danger); }

/* Commander-Schaden */
.cmdrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.cmdrow:first-of-type { border-top: none; }
.cmdrow .who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-weight: 600; }
.cmdrow .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdrow .stepper { width: 172px; flex: none; }
.cmdrow .stepper .btn { width: 44px; min-height: 44px; }
.cmdrow .stepper .val { font-size: 22px; }
.cmdrow.lethal .val { color: var(--danger); }
.cmdsub { font-size: 12px; color: var(--muted); }

.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; }
.swatch.sel { border-color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.input {
  height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-size: 16px; width: 100%;
}
.prow { display: flex; gap: 8px; align-items: center; }
.prow .swatch { width: 48px; height: 48px; flex: none; border: none; }
.code { font-size: 34px; font-weight: 800; letter-spacing: .18em; text-align: center; font-variant-numeric: tabular-nums; }
.qr { width: min(72vw, 280px); aspect-ratio: 1; margin: 0 auto; border-radius: 16px; background: #fff; padding: 8px; }
.qr img { width: 100%; height: 100%; display: block; }
.tog { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; }
.tog span { flex: 1; font-size: 15px; }
.tog small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.switch { width: 52px; height: 32px; border-radius: 16px; border: none; background: var(--line); position: relative; flex: none; }
.switch::after { content: ""; position: absolute; left: 4px; top: 4px; width: 24px; height: 24px; border-radius: 50%; background: var(--muted); transition: left .15s; }
.switch[aria-pressed="true"] { background: var(--accent); }
.switch[aria-pressed="true"]::after { left: 24px; background: #0B1020; }
.seatlist { display: flex; flex-direction: column; gap: 6px; }
.seat { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); text-align: left; }
.seat .sn { flex: 1; font-weight: 600; }
.seat .ss { font-size: 13px; color: var(--muted); }
.seat.mine { border-color: var(--accent); }
.loglist { display: flex; flex-direction: column; }
.logi { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 15px; align-items: baseline; }
.logi time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; flex: none; }
.dice-res { font-size: 96px; font-weight: 800; text-align: center; min-height: 110px; line-height: 110px; font-variant-numeric: tabular-nums; }
.dice-sub { text-align: center; color: var(--muted); min-height: 22px; }
.turnbar { display: flex; align-items: center; gap: 8px; }
.turnbar .tinfo { flex: 1; text-align: center; }
.turnbar .tinfo b { display: block; font-size: 18px; }
.turnbar .tinfo small { color: var(--muted); }
.rolechip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: var(--surface2); font-size: 13px; color: var(--muted); }
.rolechip svg { width: 14px; height: 14px; }
.foot { display: flex; gap: 16px; justify-content: center; font-size: 13px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 24px); transform: translate(-50%, 20px); z-index: 40;
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.ask { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 24px; }
.askbox { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.askbox p { margin: 0; font-size: 16px; line-height: 1.45; }

/* Commander-Schaden direkt im Feld */
.minilife, .cmdclose, .cmdgrid, .cmdhint { display: none; }
.pc.cmdmode .more { display: none; }
.pc.cmdmode .life, .pc.cmdmode .delta, .pc.cmdmode .half, .pc.cmdmode .outlbl,
.pc.cmdmode .badges, .pc.cmdmode .chips { display: none; }
.pc.cmdmode .minilife { display: block; margin-left: auto; font-weight: 750; font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pc.cmdmode .cmdclose {
  display: flex; align-items: center; height: 32px; padding: 0 12px; border: none; border-radius: 10px;
  background: var(--text); color: var(--bg); font-weight: 700; font-size: 13px; flex: none;
}
.pc.cmdmode .cmdgrid { display: block; position: absolute; inset: 4px 6px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.cmdgrid-in { display: grid; gap: 4px; min-height: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: minmax(56px, 1fr); }
.cmdgrid-in.one { grid-template-columns: minmax(0, 1fr); }
@container (min-width: 420px) { .cmdgrid-in.many { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.pc.cmdmode .cmdhint { display: block; flex: 1; min-width: 0; font-size: 12px; color: rgba(255,255,255,.7); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cb {
  position: relative; display: flex; min-width: 0; min-height: 0; border-radius: 10px; overflow: hidden;
  border: 2px solid transparent; background: color-mix(in oklab, var(--oc) 50%, #111318); color: #fff;
}
.cb button {
  flex: 1 1 0; min-width: 0; border: none; background: transparent; color: rgba(255,255,255,.85);
  font-size: clamp(20px, 9cqmin, 34px); font-weight: 500; display: flex; align-items: center; padding: 0 8px;
}
.cb .cbm { justify-content: flex-start; background: rgba(0,0,0,.18); }
.cb .cbp { justify-content: flex-end; }
.cb button:active { background: rgba(255,255,255,.18); }
.cb button[disabled] { color: transparent; cursor: default; }
.cbc {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none; padding: 0 30px;
}
.cb .cn { font-size: clamp(10px, 4.5cqmin, 14px); font-weight: 600; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .9; }
.cb .cv { font-size: clamp(18px, 10cqmin, 44px); font-weight: 750; line-height: 1.05; font-variant-numeric: tabular-nums; }
.cb.lethal { border-color: var(--danger); background: color-mix(in oklab, var(--danger) 45%, #111318); }
.cb:has(button[disabled]) { opacity: .45; }
@container (max-width: 260px) {
  .pc.cmdmode .pname span { display: none; }
  .pc.cmdmode .pname { padding: 0 10px; }
}

/* Kleine Felder: Texte in Statuschips und Zug-Knopf weglassen */
@container (max-width: 300px) {
  .chip { height: 24px; padding: 0 5px; font-size: 12px; border-radius: 7px; }
  .chip svg { width: 12px; height: 12px; }
  .chips { gap: 3px; max-height: 51px; }
  .chip.st span { display: none; }
  .pass { padding: 0 8px; font-size: 0; gap: 0; }
  .pass svg { width: 16px; height: 16px; }
}
