/* ============================================================
   retropixels — Design des Spiels, aus Kosyn public/css/style.css übernommen.
   Retro-UI im PS1/N64-Stil: Pixelschrift, harte Kanten, harte Schatten ohne Unschärfe,
   Dither-Hintergrund. Pixelgenau, aber funktional. Standard ist dunkel.
   Regeln: border-radius 0, 2–3px Konturen, Schatten `Npx Npx 0 var(--shadow-c)`,
   Drücken = verschieben + Schatten weg, Animationen mit steps().
   KEINE CSS-Verläufe (Software-Renderer rastern sie falsch) — Muster nur als PNG-Kacheln.
   Silkscreen für Überschriften, Knöpfe und Beschriftungen, Systemschrift für Fließtext und Eingaben.
   ============================================================ */

/* Silkscreen zeichnet „…“ (U+2026) wie einen Unterstrich. Deshalb gilt die Schrift für alles außer U+2026: Das
   Auslassungszeichen von text-overflow: ellipsis und in Texten wie „Verbinde …“ kommt aus der Rückfallschrift. */
@font-face {
  font-family: 'Silkscreen';
  src: url('../fonts/silkscreen-400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
  unicode-range: U+0000-2025, U+2027-10FFFF;
}
@font-face {
  font-family: 'Silkscreen';
  src: url('../fonts/silkscreen-700.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
  unicode-range: U+0000-2025, U+2027-10FFFF;
}

/* ============ Tokens ============ */
:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --px: 'Silkscreen', 'Courier New', monospace;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, 'DejaVu Sans Mono', 'Courier New', monospace;
  /* Muster als echte Pixel-Kacheln (aus Kosyn) — helle Kacheln für dunkle Themes */
  --dither: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAAF0lEQVR42mN49+oHFwgzwACGAE4JmAAAEokW0V2G88sAAAAASUVORK5CYII=");
  --hatch:  url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAIklEQVR42mP4//+/BDJmQAf4JMFi+CThCkgxlQGvm2gjCQAJ1WKhiR2W1gAAAABJRU5ErkJggg==");
  --topbar-h: 64px;
  --rooms-w: 260px;
  --side-w: 330px;
}

/* Standard: dunkel („Nacht“) */
:root, :root[data-theme="night"] {
  --bg: #16131f; --surface: #211d30; --surface-2: #2b2640;
  --text: #eeeaf8; --muted: #9a93b0;
  --accent: #9d85ff; --accent-soft: #362e55;
  --border: #3a3452;
  --line: #6a6191;            /* harte Kontur */
  --shadow-c: #0a0810;        /* harter Schatten */
  --danger: #ff6369; --ok: #3dd68c; --warn: #e8a33d;
  color-scheme: dark;
}
:root[data-theme="tinte"] {
  --bg: #0f1720; --surface: #182432; --surface-2: #203040;
  --text: #e6eef6; --muted: #7d92a6;
  --accent: #35b8a5; --accent-soft: #17403c;
  --border: #2a3a4a;
  --line: #4d6e8a; --shadow-c: #05090d;
  --danger: #ff6369; --ok: #3dd68c; --warn: #e8a33d;
  color-scheme: dark;
}

/* ============ Grundlagen ============ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background-color: var(--bg);
  background-image: var(--dither);
  background-size: 4px 4px;
  font-family: var(--font);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
h1, h2, h3 { margin: 0 0 .6em; font-family: var(--px); font-weight: 700; letter-spacing: 0; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .75rem; color: var(--muted); text-transform: uppercase; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.px { font-family: var(--px); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Knöpfe: klobige N64-Menü-Knöpfe ---- */
.btn {
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: 0;
  box-shadow: 3px 3px 0 var(--shadow-c);
  padding: 9px 14px;
  font-family: var(--px);
  font-size: .78rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text); }
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--shadow-c); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-big { padding: 13px 18px; font-size: .9rem; }
.btn-ghost { border: none; background: transparent; box-shadow: none; padding: 6px 8px; }
.btn-ghost:active:not(:disabled) { transform: translate(1px, 1px); }
.btn-sm { padding: 5px 8px; font-size: .66rem; box-shadow: 2px 2px 0 var(--shadow-c); }
.btn-sm:active:not(:disabled) { transform: translate(2px, 2px); }
.btn.on { background: var(--accent); color: #fff; }

/* ---- Eingaben: klare Boxen mit harter Kante ---- */
input[type=text], input[type=number], input[type=url], select, textarea {
  width: 100%;
  border: 2px solid var(--line);
  background: var(--surface);
  border-radius: 0;
  padding: 10px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 3px 3px 0 var(--accent-soft); }
textarea { resize: vertical; min-height: 64px; }
textarea.code { font-family: var(--mono); font-size: .85rem; line-height: 1.45; tab-size: 2; white-space: pre; }
label {
  display: block;
  font-family: var(--px);
  font-size: .68rem;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 12px;
}
label > input, label > select, label > textarea {
  margin-top: 6px;
  font-family: var(--font);
  font-weight: 400;
  font-size: 1rem;
  color: var(--text);
}
label > textarea.code { font-family: var(--mono); font-size: .85rem; }
.form-error { color: var(--danger); font-size: .9rem; min-height: 1.2em; }

/* ---- Karten ---- */
.card {
  background: var(--surface);
  border: 3px solid var(--line);
  box-shadow: 6px 6px 0 var(--shadow-c);
  padding: 20px;
}

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10, 8, 16, .66);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--surface);
  width: 100%; max-width: 480px;
  border: 3px solid var(--line);
  border-bottom: none;
  box-shadow: 6px 6px 0 var(--shadow-c);
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  max-height: 88dvh; overflow: auto;
  animation: slide-up .15s steps(4, end);
}
.modal.modal-wide { max-width: 760px; }
.modal h2 { font-size: .95rem; }
.modal .modal-acts { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
@media (min-width: 560px) {
  .modal-backdrop { align-items: center; }
  .modal { border-bottom: 3px solid var(--line); }
}
@keyframes slide-up { from { transform: translateY(30px); opacity: .5; } }
@keyframes pop { from { transform: scale(.85); opacity: .3; } }

/* Moderations-Menü (app.js memberMenu) */
.mod-title { display: flex; align-items: center; gap: 10px; }
.mod-title .rm-sw { width: 18px; height: 18px; }
.mod-nick { color: var(--pl-color); overflow-wrap: anywhere; min-width: 0; }

/* ============ Toasts ============ */
/* Unten mittig über der Aktionsleiste: verdeckt weder die Zuschauerleiste noch die Ziel-Felder oben; klickt durch */
.toasts {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 80; display: flex; flex-direction: column; align-items: center;
  pointer-events: none; width: min(92vw, 520px);
}
.toast {
  background: var(--surface); color: var(--text);
  border: 2px solid var(--line);
  box-shadow: 4px 4px 0 var(--shadow-c);
  padding: 9px 16px;
  font-family: var(--px); font-size: .72rem; font-weight: 700;
  animation: pop .15s steps(3, end);
  max-width: 100%; text-align: center;
}
.toast.toast-bad { border-color: var(--danger); color: var(--danger); }
/* Auf dem Brett: unten links bis vor die Zoom-Knöpfe, über dem Rand statt über den Feldern oben */
.board-wrap > .toasts { position: absolute; left: 12px; right: 168px; bottom: 12px; width: auto; transform: none; z-index: 5; align-items: flex-start; }
.board-wrap > .toasts .toast { text-align: left; }
.toast.toast-private { background: var(--accent); color: #fff; border-color: #fff; }
.toast.toast-private::before { content: '🤫 Nur für dich: '; }
.toast.toast-out { animation: toast-out .2s steps(3, end) forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ============ Startseite ============ */
.start {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 16px;
  gap: 24px;
}
.start .logo {
  font-family: var(--px); font-weight: 700; font-size: clamp(1.8rem, 6vw, 3rem);
  text-shadow: 4px 4px 0 var(--shadow-c); color: var(--text);
  margin: 0;
}
.start .logo span { color: var(--accent); }
.start .tagline { margin: -12px 0 0; color: var(--muted); text-align: center; }
.start .card { width: 100%; max-width: 520px; }
.game-list { display: grid; gap: 10px; margin: 0 0 16px; padding: 0; list-style: none; }
.game-pick {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  border: 2px solid var(--line); background: var(--surface-2);
  box-shadow: 3px 3px 0 var(--shadow-c); padding: 12px 14px; cursor: pointer;
}
.game-pick:active { transform: translate(3px, 3px); box-shadow: none; }
.game-pick .gp-icon { font-size: 1.6rem; width: 2rem; text-align: center; }
.game-pick .gp-name { font-family: var(--px); font-weight: 700; font-size: .9rem; display: block; }
.game-pick .gp-meta { color: var(--muted); font-size: .85rem; }
.game-pick.on { border-color: var(--accent); background: var(--accent-soft); outline: 2px solid var(--accent); outline-offset: 2px; }
.start .fine { color: var(--muted); font-size: .85rem; max-width: 520px; text-align: center; line-height: 1.5; }

/* ============ Gruppenansicht (wie Discord / Kosyn Coop) ============ */
body.app { height: 100dvh; overflow: hidden; }
.shell {
  height: 100dvh;
  display: grid;
  grid-template-columns: var(--rooms-w) minmax(0, 1fr) var(--side-w);
  grid-template-rows: minmax(0, 1fr);
}
.shell.chat-closed { grid-template-columns: var(--rooms-w) minmax(0, 1fr) 0; }
.shell.chat-closed .chatcol { display: none; }
.scrim { display: none; }
.tag { border: 2px solid var(--line); padding: 1px 4px; color: var(--muted); font-family: var(--px); font-size: .58rem; font-weight: 700; }
.tag-host { color: var(--warn); border-color: var(--warn); }
.hintline { font-size: .82rem; color: var(--muted); line-height: 1.45; margin: 4px 0 12px; }
.spacer { flex: 1; }
.conn { font-family: var(--px); font-size: .62rem; color: var(--muted); white-space: nowrap; }
.conn[data-s="online"] { color: var(--ok); }
.conn[data-s="offline"], .conn[data-s="fatal"] { color: var(--danger); animation: blink 1s steps(2, end) infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* ---- Links: Räume ---- */
.sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface);
  border-right: 3px solid var(--line);
  z-index: 15;
}
.sb-head { padding: 12px; border-bottom: 3px solid var(--border); }
.sb-group { font-size: .95rem; margin: 0 0 10px; overflow-wrap: anywhere; }
.sb-acts { display: flex; align-items: center; gap: 10px; }
.rooms-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 4px; }
.rooms-head h3 { margin: 0; }
.rooms { list-style: none; margin: 0; padding: 4px 8px 12px; overflow-y: auto; flex: 1; min-height: 0; }
.room-item { margin-bottom: 4px; }
.room-row { display: flex; align-items: stretch; gap: 2px; }
.room-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; text-align: left;
  background: transparent; border: 2px solid transparent; padding: 8px 8px; cursor: pointer;
  font-family: var(--px); font-weight: 700; font-size: .72rem; color: var(--muted);
}
.room-btn:hover { color: var(--text); border-color: var(--border); }
.room-item.on .room-btn { color: var(--text); background: var(--accent-soft); border-color: var(--accent); box-shadow: 3px 3px 0 var(--shadow-c); }
.room-hash { color: var(--muted); width: 1em; text-align: center; }
.room-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-more { color: var(--muted); font-size: 1rem; cursor: pointer; }
.game-badge {
  flex-basis: 100%; margin-left: calc(1em + 8px); max-width: calc(100% - 1em - 8px);
  font-size: .56rem; border: 2px solid var(--line); padding: 1px 4px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: max-content;
}
.game-badge[data-phase="lobby"] { color: var(--accent); border-color: var(--accent); }
.game-badge[data-phase="play"] { color: var(--ok); border-color: var(--ok); }
.game-badge[data-phase="over"] { color: var(--warn); border-color: var(--warn); }
.room-members { list-style: none; margin: 2px 0 6px 18px; padding: 0; }
.rm-btn {
  display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: none; text-align: left;
  padding: 3px 6px; cursor: pointer; font-size: .9rem; color: var(--text);
}
.rm-btn:hover { background: var(--surface-2); }
.rm-sw { width: 12px; height: 12px; background: var(--pl-color); border: 2px solid var(--shadow-c); flex: none; }
.rm-nick { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rm-tag { font-family: var(--px); font-size: .56rem; color: var(--muted); }
.rm.offline { opacity: .45; }
.room-away { margin-top: 12px; }
.room-away h3 { padding: 0 8px; margin-bottom: 4px; }

/* Eigenes Profil unten links */
.profile { border-top: 3px solid var(--line); background: var(--surface-2); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.me-line { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.me-sw { width: 20px; height: 20px; border: 2px solid var(--shadow-c); background: var(--accent); flex: none; }
.me-nick { font-family: var(--px); font-weight: 700; font-size: .8rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.av { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.av-note { font-size: .78rem; }

/* ---- Mitte: Bühne ---- */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.stage-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); font-family: var(--px); }
.stage-head {
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 3px solid var(--line);
  box-shadow: 0 4px 0 var(--shadow-c);
  z-index: 5; min-width: 0;
}
.stage-room { margin: 0; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 0 1 auto; }
.phase-badge {
  font-family: var(--px); font-weight: 700; font-size: .6rem;
  border: 2px solid var(--line); padding: 3px 6px; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
/* Im Spiel sagen „Wer ist dran“ und die Reihenfolge mehr als das Abzeichen; ohne es passt die Kopfzeile ungekürzt */
.stage[data-view="board"] .stage-head .phase-badge { display: none; }
.phase-badge[data-phase="lobby"] { color: var(--accent); border-color: var(--accent); }
.phase-badge[data-phase="play"] { color: var(--ok); border-color: var(--ok); }
.phase-badge[data-phase="over"] { color: var(--warn); border-color: var(--warn); }
.stage-head .dot { display: inline-block; width: 8px; height: 8px; background: var(--danger); margin-left: 4px; vertical-align: top; }
.stage-body { flex: 1; min-height: 0; display: flex; position: relative; }
.stage-foot { flex: none; }
.stage-foot.foot-none, .stage[data-view] .stage-foot:not(.actbar):not(.hidden) {
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  padding: 12px; background: var(--surface); border-top: 3px solid var(--line);
}

/* Wer ist dran — groß und eindeutig, in der Farbe der Person */
.turn {
  --turn-color: var(--muted);
  display: flex; align-items: center; gap: 10px;
  border: 3px solid var(--turn-color);
  background: var(--bg);
  box-shadow: 4px 4px 0 var(--shadow-c);
  padding: 6px 14px 6px 8px;
  font-family: var(--px); font-weight: 700; font-size: 1rem;
  white-space: nowrap; min-width: 0; flex: 0 1 auto;
  overflow: hidden;
}
.turn .turn-sw { width: 26px; height: 26px; background: var(--turn-color); border: 2px solid var(--shadow-c); flex: none; }
.turn .turn-txt { overflow: hidden; text-overflow: ellipsis; }
.turn.mine { background: var(--turn-color); color: #fff; text-shadow: 2px 2px 0 rgba(0,0,0,.45); animation: mine-pulse 1.2s steps(2, end) infinite; }
.turn.mine .turn-sw { background: #fff; }
.turn.idle { font-size: .8rem; color: var(--muted); }
@keyframes mine-pulse { 50% { box-shadow: 4px 4px 0 var(--shadow-c), 0 0 0 4px var(--turn-color); } }
.order { display: flex; gap: 6px; min-width: 0; overflow: hidden; }
.ord {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  border: 2px solid var(--border); padding: 2px 6px; font-size: .82rem; color: var(--muted);
}
.ord .ord-sw { width: 10px; height: 10px; background: var(--pl-color); border: 2px solid var(--shadow-c); }
.ord.now { border-color: var(--pl-color); color: var(--text); font-weight: 700; }
.ord.offline { opacity: .45; }

/* Kacheln (Ersatz ohne Video; media/stage.js bringt eigene Stile mit) */
.tiles-wrap { flex: 1; min-width: 0; min-height: 0; position: relative; display: flex; }
.tiles {
  flex: 1; display: grid; gap: 12px; padding: 16px;
  justify-content: center; align-content: center;
}
.tile {
  aspect-ratio: 16 / 10; position: relative;
  background: var(--surface-2); background-image: var(--dither); background-size: 4px 4px;
  border: 3px solid var(--line); box-shadow: 5px 5px 0 var(--shadow-c);
  display: flex; align-items: center; justify-content: center;
  container-type: size; min-width: 0;
}
.tile.me { border-color: var(--accent); }
.tile.off { opacity: .45; }
.tile-av {
  width: 42cqh; height: 42cqh; min-width: 28px; min-height: 28px;
  background: var(--tile-color); border: 3px solid var(--shadow-c); box-shadow: 4px 4px 0 var(--shadow-c);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--px); font-weight: 700; font-size: 26cqh; color: #fff; text-shadow: 3px 3px 0 rgba(0,0,0,.4);
}
.tile-name {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--px); font-weight: 700; font-size: .68rem;
  background: var(--bg); border: 2px solid var(--line); padding: 2px 6px;
}
.tiles-empty { color: var(--muted); font-family: var(--px); align-self: center; justify-self: center; }
.tiles[data-mode="strip"] { display: flex; gap: 8px; padding: 8px 12px; overflow-x: auto; justify-content: flex-start; align-content: stretch; }
.tiles[data-mode="strip"] .tile { height: 72px; flex: none; box-shadow: 3px 3px 0 var(--shadow-c); border-width: 2px; }
.tiles[data-mode="strip"] .tile-name { font-size: .56rem; left: 4px; bottom: 4px; padding: 1px 4px; }

/* Spielpanel in der Lobby */
.game-panel {
  width: 340px; flex: none; overflow-y: auto;
  background: var(--surface); border-left: 3px solid var(--line);
  padding: 16px;
}
.game-panel h2 { font-size: 1rem; }
.seats { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }
.seat { border: 2px dashed var(--border); padding: 7px 10px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .92rem; }
.seat.taken { border: 2px solid var(--pl-color); background: var(--bg); color: var(--text); box-shadow: 3px 3px 0 var(--shadow-c); }
.seat-sw { width: 16px; height: 16px; background: var(--pl-color); border: 2px solid var(--shadow-c); flex: none; }
.gp-acts { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 10px; }
.gp-acts .btn-big { flex: 1; }
.gp-small { margin-top: 16px; padding-top: 12px; border-top: 3px solid var(--border); }

/* Brett-Bereich */
.board-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
/* Zuschauer-Leiste im Spiel: feste Höhe, sonst fällt die Kachelleiste (stage.js misst den Container) in sich zusammen */
.strip-host { flex: none; height: 112px; background: var(--surface); border-bottom: 3px solid var(--line); }
.board-wrap { position: relative; flex: 1; min-height: 0; min-width: 0; }
.board-host { position: absolute; inset: 0; }
.board-wrap.my-turn::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  border: 5px solid var(--turn-color, var(--accent));
  z-index: 3;
}
.board-tools {
  position: absolute; right: 12px; bottom: 12px; z-index: 4;
  display: flex; gap: 6px;
}
.board-tools .btn { min-width: 40px; padding: 8px 10px; }
.banner {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%); z-index: 4;
  background: var(--surface); border: 3px solid var(--line); box-shadow: 4px 4px 0 var(--shadow-c);
  padding: 8px 14px; font-family: var(--px); font-weight: 700; font-size: .75rem;
  max-width: calc(100% - 24px); text-align: center;
}
.banner.banner-spec { border-color: var(--warn); color: var(--warn); }

/* Editor-Werkzeugleiste auf dem Brett */
.edit-bar {
  position: absolute; left: 12px; top: 12px; z-index: 4;
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: var(--surface); border: 3px solid var(--accent); box-shadow: 4px 4px 0 var(--shadow-c);
  padding: 6px; max-width: calc(100% - 24px);
}
.edit-bar .btn { min-width: 38px; padding: 7px 9px; font-size: .95rem; font-family: var(--font); }
.edit-bar .sep { width: 2px; align-self: stretch; background: var(--line); margin: 0 2px; }
.edit-bar .eb-title { font-family: var(--px); font-weight: 700; font-size: .62rem; color: var(--accent); padding: 0 4px; }
.swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.swatch { width: 22px; height: 22px; border: 2px solid var(--shadow-c); cursor: pointer; padding: 0; }
.swatch.on { outline: 2px solid var(--text); outline-offset: 1px; }

/* ---- Aktionsleiste unter dem Brett ---- */
.actbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 12px;
  background: var(--surface);
  border-top: 3px solid var(--line);
  z-index: 4;
}
.btn-roll { font-size: 1.1rem; padding: 14px 26px; min-width: 190px; box-shadow: 5px 5px 0 var(--shadow-c); }
.btn-roll:active:not(:disabled) { transform: translate(5px, 5px); }
.btn-roll:not(:disabled) { background: var(--turn-color, var(--accent)); color: #fff; text-shadow: 2px 2px 0 rgba(0,0,0,.4); border-color: #fff; }
.actbar .custom-acts { display: flex; gap: 8px; flex-wrap: wrap; }
.actbar .custom-acts:empty { display: none; }
.act-hint { color: var(--muted); font-size: .9rem; flex: 1; min-width: 140px; }
.actbar .host-acts { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

/* ---- Rechts: Chat, Log, Editor ---- */
.chatcol {
  display: flex; flex-direction: column;
  background: var(--surface);
  border-left: 3px solid var(--line);
  min-height: 0; min-width: 0;
  z-index: 15;
}
.tabs { display: flex; border-bottom: 3px solid var(--border); flex: none; }
.tab {
  flex: 1; background: transparent; border: none; border-right: 2px solid var(--border);
  padding: 12px 8px; font-family: var(--px); font-size: .68rem; font-weight: 700; color: var(--muted); cursor: pointer;
}
.tab:last-child { border-right: none; }
.tab.on { color: var(--text); background: var(--bg); box-shadow: inset 0 -4px 0 var(--accent); }
.tab.tab-x { flex: 0 0 44px; }
.tab .unread { display: inline-block; min-width: 16px; padding: 0 3px; background: var(--danger); color: #fff; margin-left: 4px; }
.pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.feed { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; font-size: .92rem; line-height: 1.4; }
.feed .ln { overflow-wrap: anywhere; }
.feed .ln-log { color: var(--text); }
.feed .ln-log::before { content: '› '; color: var(--muted); }
.feed .ln-private { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: 4px 8px; }
.feed .ln-private::before { content: '🤫 '; }
.feed .ln-chat .nick { font-weight: 700; color: var(--pl-color, var(--accent)); }
.feed .ln-chat .ts { color: var(--muted); font-size: .75rem; margin-left: 6px; }
.feed .empty { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 6px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 3px solid var(--border); }
.chat-form input { padding: 8px 10px; }

/* Editor-Panel */
.editor { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; }
.editor .ed-empty { color: var(--muted); line-height: 1.5; }
.editor .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.editor .row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 8px; }
.editor .row4 input { padding: 8px 6px; }
.editor .next-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 12px; }
.editor .next-chip { border: 2px solid var(--accent); padding: 3px 6px; font-family: var(--px); font-size: .62rem; display: inline-flex; gap: 6px; align-items: center; }
.editor .next-chip button { background: none; border: none; color: var(--danger); cursor: pointer; padding: 0; font-weight: 700; }
.editor .ed-acts { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.editor .shape-pick { display: flex; gap: 6px; margin: 6px 0 12px; flex-wrap: wrap; }
.editor .hintline { margin: -4px 0 12px; }
.editor .json-bad { border-color: var(--danger) !important; }

/* ============ Brett (BoardView) ============ */
.bv {
  position: relative; overflow: hidden; width: 100%; height: 100%;
  touch-action: none; user-select: none; -webkit-user-select: none;
  cursor: grab;
}
.bv:active { cursor: grabbing; }
.bv-svg, .bv-top { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: hidden; }
.bv-top { pointer-events: none; }
.bv[data-mode="edit"] .bv-top .bv-item, .bv[data-mode="edit"] .bv-top .bv-handle { pointer-events: auto; }
.bv-tokens { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.bv-bgrect { stroke: var(--line); stroke-width: 3; }
.bv-bgshadow { fill: var(--shadow-c); }
.bv-grid { display: none; pointer-events: none; }
.bv[data-mode="edit"] .bv-grid { display: inline; }
.bv-griddot { fill: var(--line); opacity: .7; }
.bv-fieldbody { stroke-width: 3; fill-opacity: .3; }
.bv-fieldinner { stroke: var(--shadow-c); stroke-width: 2; opacity: .5; pointer-events: none; }
.bv-fieldlabel {
  font-family: var(--px); font-weight: 700; fill: var(--text);
  paint-order: stroke; stroke: var(--shadow-c); stroke-width: 4px; stroke-linejoin: miter;
  pointer-events: none;
}
.bv-fieldbadge { fill: #fff; pointer-events: none; font-family: var(--font); }
.bv-fieldscript { font-family: var(--mono); font-weight: 700; fill: var(--accent); pointer-events: none; }
.bv-arrows { pointer-events: none; }
.bv-arrow { stroke: var(--accent); stroke-width: 3; stroke-dasharray: 8 6; opacity: .7; }
.bv-arrowhead { opacity: .85; }
.bv-handle { fill: var(--accent); stroke: var(--bg); cursor: nwse-resize; }
.bv-selrect { fill: none; stroke: var(--accent); pointer-events: none; }
.bv-draft { fill: var(--accent); fill-opacity: .12; stroke: var(--accent); stroke-width: 2; }
.bv-draftline { stroke: var(--accent); stroke-width: 4; stroke-dasharray: 8 6; }
.bi-text { width: 100%; height: 100%; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; }
.bv[data-mode="edit"] { cursor: default; }
.bv[data-mode="edit"][data-tool="select"] .bv-item { cursor: move; }
.bv[data-mode="edit"]:not([data-tool="select"]) { cursor: crosshair; }
.bv[data-mode="edit"][data-tool="connect"] .bv-k-field { cursor: alias; }

/* ---- Figuren (HTML über dem SVG; Vertrag siehe boardview.js) ----
   Die Kameras sind die Spielfiguren und der Blickfang: groß (Mindestgröße am Bildschirm, siehe tokenMetrics), mit
   Rahmen in der Spielerfarbe und hartem Schatten. Sie schweben über dem Brett; Stiel und Fuß zeigen auf ihr Feld. */
.tok {
  position: absolute; left: 0; top: 0;
  width: 88px; height: 88px;
  pointer-events: auto;
  will-change: transform;
  container-type: size;
  z-index: 1;
}
.tok-face {
  position: absolute; inset: 0;
  background: var(--tok-color, var(--accent));
  border: 4px solid var(--tok-color, var(--accent));
  outline: 2px solid var(--shadow-c);
  box-shadow: 6px 6px 0 2px var(--shadow-c);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.tok-face::before {
  content: attr(data-initial);
  font-family: var(--px); font-weight: 700; font-size: 48cqh; line-height: 1;
  color: #fff; text-shadow: 3px 3px 0 rgba(0, 0, 0, .45);
}
/* Video als Figur (media/tokens.js hängt ein <video> in .tok-face) */
.tok-face > video, .tok-face > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tok[data-kind]:not([data-kind="player"]) .tok-face { border-radius: 50%; }
/* Name: Systemschrift (Spitznamen werden gekürzt, Silkscreen kann kein „…“), quer über der Unterkante */
.tok-label {
  position: absolute; left: 50%; top: 100%; z-index: 1;
  transform: translate(-50%, -60%);
  white-space: nowrap; max-width: calc(100% + 12px); overflow: hidden; text-overflow: ellipsis;
  font-family: var(--font); font-weight: 700; font-size: 12px; line-height: 1.3;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--shadow-c); box-shadow: inset 5px 0 0 var(--tok-color, var(--accent));
  padding: 0 5px 0 9px;
  pointer-events: none;
}
.tok-label:empty { display: none; }
.tok-small .tok-label { font-size: 11px; }
.tok-me .tok-label { background: var(--accent); color: #fff; }
/* Stiel und Fuß (SVG hinter dem Gesicht, gezeichnet von boardview.js) */
.tok-stem { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; z-index: -1; pointer-events: none; shape-rendering: crispEdges; }
.tok-stem-bg { stroke: var(--shadow-c); stroke-width: 8; }
.tok-stem-fg { stroke: var(--tok-color, var(--accent)); stroke-width: 4; }
.tok-foot { fill: var(--tok-color, var(--accent)); stroke: var(--shadow-c); stroke-width: 3; }
/* Wer dran ist: etwas größer (boardview.js), weiß umrandet, obenauf — ruhig, ohne Dauerbewegung */
.tok-turn { z-index: 3; }
.tok-turn .tok-face { outline: 3px solid #fff; box-shadow: 7px 7px 0 3px var(--shadow-c); }
.tok-turn .tok-label { border-color: #fff; }
.tok-anim { transition: transform .2s steps(4, end); }
.tok-draggable { cursor: grab; }
.tok-drag { z-index: 6; cursor: grabbing; }
.tok-drag .tok-face { box-shadow: 12px 12px 0 2px var(--shadow-c); }
.tok-hint { opacity: .6; transition: transform .1s steps(2, end); }
.tok-off { visibility: hidden; }
.tok-offline .tok-face { filter: grayscale(1); opacity: .6; }
@keyframes tok-bob { 50% { transform: translateY(-4px); } }

/* ---- Würfel ---- */
.dice-pop {
  position: fixed; inset: 0; z-index: 70; pointer-events: none;
  display: flex; align-items: center; justify-content: center; gap: 24px;
  flex-direction: column;
}
.dice-row { display: flex; gap: 20px; }
.die {
  width: 104px; height: 104px;
  background: #fff; border: 4px solid var(--shadow-c);
  box-shadow: 8px 8px 0 var(--shadow-c);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr);
  padding: 12px; gap: 4px;
}
.die .pip { visibility: hidden; background: var(--shadow-c); width: 18px; height: 18px; place-self: center; }
.die .pip.on { visibility: visible; }
.die.rolling { animation: die-shake .3s steps(3, end) infinite; }
.die.done { animation: pop .2s steps(3, end); border-color: var(--die-color, var(--accent)); box-shadow: 8px 8px 0 var(--shadow-c), 0 0 0 5px var(--die-color, var(--accent)); }
.dice-who {
  font-family: var(--px); font-weight: 700; font-size: 1rem; color: #fff;
  background: var(--die-color, var(--accent)); border: 3px solid var(--shadow-c); box-shadow: 4px 4px 0 var(--shadow-c);
  padding: 6px 12px; text-shadow: 2px 2px 0 rgba(0,0,0,.4);
}
.dice-pop.out { animation: toast-out .25s steps(3, end) forwards; }
@keyframes die-shake {
  0% { transform: translate(0, 0) rotate(0deg); }
  33% { transform: translate(-6px, -4px) rotate(-8deg); }
  66% { transform: translate(6px, 2px) rotate(7deg); }
}

/* ---- Sieg ---- */
.winner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5;
  background: var(--surface); border: 4px solid var(--warn); box-shadow: 8px 8px 0 var(--shadow-c);
  padding: 24px 28px; text-align: center; animation: pop .3s steps(4, end);
  max-width: calc(100% - 32px);
}
.winner .trophy { font-size: 3rem; display: block; animation: tok-bob 1s steps(2, end) infinite; }
.winner .who { font-family: var(--px); font-weight: 700; font-size: 1.3rem; margin: 10px 0 4px; }

/* ---- Schmal (Tablet hochkant, Handy): Räume und Chat als Schubladen ---- */
.only-narrow { display: none !important; }
@media (max-width: 900px) {
  :root { --topbar-h: 56px; }
  .only-narrow { display: inline-block !important; }
  .only-wide { display: none !important; }
  .shell, .shell.chat-closed { grid-template-columns: minmax(0, 1fr); }
  .shell .sidebar, .shell .chatcol, .shell.chat-closed .chatcol {
    display: flex;
    position: fixed; top: 0; bottom: 0; width: min(88vw, 360px); z-index: 40;
    transition: transform .2s steps(4, end);
  }
  .shell .sidebar { left: 0; transform: translateX(-105%); box-shadow: 6px 0 0 var(--shadow-c); }
  .shell .chatcol { right: 0; transform: translateX(105%); box-shadow: -6px 0 0 var(--shadow-c); }
  .shell.rooms-open .sidebar, .shell.chat-open .chatcol { transform: none; }
  .shell.rooms-open .scrim, .shell.chat-open .scrim {
    display: block; position: fixed; inset: 0; z-index: 30; background: rgba(10, 8, 16, .6);
  }
  .stage { grid-column: 1; }
  .stage-head { gap: 8px; padding: 0 8px; }
  .stage-room { max-width: 60vw; }
  .strip-host { height: 84px; }
  .stage-head .phase-badge { display: none; }
  .stage[data-view="board"] .stage-room { display: none; }
  .stage-head .turn:not(.hidden) { flex: 1; font-size: .72rem; }
  .stage-head .turn:not(.hidden) ~ .spacer { display: none; }
  .host-acts .lbl { display: none; }
  .turn { font-size: .78rem; padding: 5px 10px 5px 6px; }
  .turn .turn-sw { width: 20px; height: 20px; }
  .stage-body { flex-direction: column; }
  .game-panel { width: auto; max-height: 58%; border-left: none; border-top: 3px solid var(--line); padding: 12px; }
  .tiles { padding: 10px; gap: 8px; }
  .btn-roll { flex: 1; min-width: 0; }
  .actbar { gap: 8px; padding: 8px; }
  .actbar .act-hint { display: none; }
  .actbar:not(:has(button)) { display: none; }   /* Zuschauende ohne Knöpfe: keine leere Leiste */
  .actbar .host-acts { margin-left: 0; }
  .die { width: 84px; height: 84px; padding: 10px; }
  .die .pip { width: 14px; height: 14px; }
  .edit-bar { right: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; animation-iteration-count: 1 !important; transition-duration: 0s !important; }
}
