:root {
  --accent: #3b5bdb;
  --accent-soft: #e7ebff;
  --ink: #1f2330;
  --muted: #5f6577;
  --line: #e3e5ec;
  --panel: #fff;
  --canvas: #f4f5f8;
  --hover: #f0f1f5;
  --danger: #c92a2a;
  --shadow: 0 2px 10px rgba(20, 24, 40, 0.12), 0 0 0 1px rgba(20, 24, 40, 0.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
[hidden] { display: none !important; }
body:not(.mod) .mod-only { display: none !important; }
button { font: inherit; color: inherit; }

/* --- Formulare und Karten (Startseite und Beitritt) --- */

.card {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px;
  width: min(400px, calc(100vw - 32px));
}
.card h1 { margin: 0 0 4px; font-size: 22px; }
.card p { margin: 0 0 20px; color: var(--muted); line-height: 1.4; }
.card label { display: block; font-weight: 600; font-size: 13px; margin: 14px 0 6px; }
.card input {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid #cfd3de;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
.card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.pwfield { position: relative; }
.card .pwfield input { padding-right: 80px; }
.pwbuttons { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); display: flex; gap: 2px; }
.pwbuttons button { width: 34px; height: 34px; border: 0; border-radius: 6px; background: none; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.pwbuttons button:hover { background: var(--hover); color: var(--ink); }
.pwbuttons button.on { color: var(--accent); }
.error { color: var(--danger); font-size: 14px; margin-top: 12px; min-height: 1em; }

.primary {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%;
  margin-top: 20px;
  padding: 11px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.primary:hover { background: #3049b8; }
.primary:disabled { opacity: 0.6; cursor: default; }
.secondary {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}
.secondary:hover { background: var(--hover); }

.linkbtn { border: 0; background: none; padding: 0; margin-top: 14px; color: var(--accent); font-size: 14px; cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }

.linkrow { display: flex; gap: 8px; margin-top: 8px; }
.linkrow input { flex: 1; min-width: 0; }

body.home {
  display: grid;
  place-items: center;
  background: var(--canvas);
  background-image: radial-gradient(circle, #c9ccd6 1px, transparent 1.2px);
  background-size: 24px 24px;
  padding: 16px;
}
/* Board-Übersicht */
.card.wide { width: min(920px, calc(100vw - 32px)); }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.admin-head .brand { margin: 0; }
.admin-head .btn-primary { text-decoration: none; }
#boards { width: 100%; border-collapse: collapse; font-size: 14px; }
#boards th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); }
#boards td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
#boards td a { color: var(--ink); font-weight: 600; text-decoration: none; }
#boards td a:hover { color: var(--accent); }
#boards td small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
#boards .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
#boards .actions button { padding: 6px 10px; font-size: 13px; }
.secondary.danger { color: var(--danger); }
@media (max-width: 640px) {
  #boards th:nth-child(3), #boards td:nth-child(3), #boards th:nth-child(4), #boards td:nth-child(4) { display: none; }
}
.homelink { display: block; margin-top: 16px; text-align: center; font-size: 14px; color: var(--accent); text-decoration: none; }
.homelink:hover { text-decoration: underline; }

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.brand-mark { width: 28px; height: 28px; border-radius: 6px; background: #fff59d; box-shadow: 0 1px 3px rgba(0,0,0,.2); transform: rotate(-6deg); }

/* --- Board --- */

body.board { overflow: hidden; background: var(--canvas); overscroll-behavior: none; }

#viewport {
  position: fixed;
  inset: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background-color: var(--canvas);
  background-image: radial-gradient(circle, #c3c7d3 1px, transparent 1.3px);
}
#viewport[data-tool="hand"], #viewport.panning { cursor: grab; }
#viewport.grabbing { cursor: grabbing; }
#viewport[data-tool="sticky"] { cursor: crosshair; }

#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }

.item { position: absolute; left: 0; top: 0; }
.item.selected { outline: calc(2px / var(--z, 1)) solid var(--accent); outline-offset: calc(3px / var(--z, 1)); }

.sticky {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #1f2330;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 6px 14px rgba(0, 0, 0, 0.08);
}
.note-text {
  width: 100%;
  min-height: 1.25em;
  max-height: 100%;
  overflow: hidden;
  text-align: center;
  white-space: pre-wrap;
  line-height: 1.25;
  outline: none;
}
.note-text[contenteditable="plaintext-only"] { user-select: text; -webkit-user-select: text; cursor: text; }

.sticky.has-tags { padding-bottom: 44px; }
.tags { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; gap: 4px; overflow: hidden; }
.item.dimmed { opacity: 0.18; }

.tag {
  --tc: #495057;
  display: inline-flex; align-items: center; gap: 5px;
  flex: none; max-width: 100%;
  padding: 5px 9px;
  border-radius: 5px;
  background: var(--tc);
  color: #fff;
  font-size: 13px; font-weight: 600; line-height: 1;
  white-space: nowrap;
}
.tag-label { overflow: hidden; text-overflow: ellipsis; }
.tag button { border: 0; background: none; color: #fff; padding: 0; font-size: 16px; line-height: 1; cursor: pointer; opacity: 0.8; }
.tag button:hover { opacity: 1; }
.tag small { font-size: 11px; opacity: 0.8; font-weight: 500; }
.tags .tag { font-size: 14px; }
.tag.target { outline: 2px solid var(--tc); outline-offset: 2px; }
.swatch.small { width: 22px; height: 22px; }
.swatch.on { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--accent); }
.tag.pick { cursor: pointer; }
.tag.off { opacity: 0.35; }

.taglist { display: flex; flex-wrap: wrap; gap: 6px; }
.taglist:empty { display: none; }
.hint { font-size: 12px; color: var(--muted); }
.suggest { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 10px; font-size: 13px; cursor: pointer; }
.suggest:hover { background: var(--hover); }

#tagbox { width: 290px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
#tagbox input { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid #cfd3de; border-radius: 8px; }
#tagbox input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
#tagfilter { top: 64px; left: 12px; padding: 14px; width: min(420px, calc(100vw - 24px)); display: flex; flex-direction: column; gap: 10px; }
#tagfilter p { margin: 0; font-size: 13px; color: var(--muted); }
#tagfilter-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Linien und Pfeile: eine gemeinsame SVG-Ebene über den Objekten */
#lines { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; z-index: 999990; pointer-events: none; }
#lines.drawing .line { pointer-events: none; }
.line .hit { stroke: transparent; stroke-width: calc(16px / var(--z, 1)); fill: none; pointer-events: stroke; cursor: pointer; }
.line .stroke { stroke-width: 2.5; fill: none; stroke-linecap: round; pointer-events: none; }
.line .head { pointer-events: none; }
.line.selected { outline: none; }
.line.selected .hit { stroke: rgba(59, 91, 219, 0.3); }
#viewport[data-tool="line"], #viewport[data-tool="shape"], #viewport[data-tool="text"] { cursor: crosshair; }

/* Rahmen: Fläche lässt Klicks durch, angefasst wird am Titel */
.item.frame { pointer-events: none; box-shadow: 0 0 0 1px #d5d8e0, 0 1px 3px rgba(20, 24, 40, 0.06); }
.frame-title {
  position: absolute; left: 0; bottom: 100%;
  margin-bottom: calc(6px / var(--z, 1));
  max-width: 100%;
  font-size: calc(14px / var(--z, 1));
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: auto;
  cursor: move;
  outline: none;
  min-width: 2em;
}
.frame-title[contenteditable="plaintext-only"] { cursor: text; color: var(--ink); user-select: text; -webkit-user-select: text; }
.item.frame.selected .frame-title { color: var(--accent); }
#viewport[data-tool="frame"] { cursor: crosshair; }

/* Stift */
.item.path { pointer-events: none; }
.path svg { display: block; width: 100%; height: 100%; overflow: visible; }
.path .stroke { fill: none; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.path .hit { fill: none; stroke: transparent; stroke-width: calc(14px / var(--z, 1)); vector-effect: non-scaling-stroke; pointer-events: stroke; cursor: pointer; }
.item.path.selected { outline-style: dashed; }
.pen-preview { fill: none; stroke-linecap: round; stroke-linejoin: round; }
#viewport[data-tool="pen"] { cursor: crosshair; }
#penbar { left: 72px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px; }
#penbar .swatchrow { flex-direction: column; }
#penbar .sep { width: 24px; height: 1px; margin: 2px 0; }
#penwidths span { display: block; border-radius: 50%; background: currentColor; }
#penwidths .on { background: var(--accent-soft); color: var(--accent); }

/* Formen */
.shape { display: flex; align-items: center; justify-content: center; padding: 12px; }
.shape.inset { padding: 18% 16%; }
.shape-bg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.shape .note-text { position: relative; }

/* Textfelder und Bilder */
.text-content {
  min-height: 1.3em;
  line-height: 1.3;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  outline: none;
}
.text-content[contenteditable="plaintext-only"] { user-select: text; -webkit-user-select: text; cursor: text; }
.item.text.selected { outline-offset: calc(6px / var(--z, 1)); }
.image img { display: block; width: 100%; height: 100%; object-fit: fill; pointer-events: none; border-radius: 2px; }

/* Anfasser zum Ändern der Größe, auf dem Bildschirm immer gleich groß */
#resizer { position: absolute; left: 0; top: 0; z-index: 999999; pointer-events: none; }
.handle {
  position: absolute;
  width: calc(12px / var(--z, 1)); height: calc(12px / var(--z, 1));
  margin: calc(-6px / var(--z, 1)) 0 0 calc(-6px / var(--z, 1));
  background: #fff;
  border: calc(2px / var(--z, 1)) solid var(--accent);
  border-radius: 50%;
  pointer-events: auto;
}
.handle.nw { left: 0; top: 0; cursor: nwse-resize; }
.handle.ne { left: 100%; top: 0; cursor: nesw-resize; }
.handle.sw { left: 0; top: 100%; cursor: nesw-resize; }
.handle.se { left: 100%; top: 100%; cursor: nwse-resize; }
.handle.w { left: 0; top: 50%; cursor: ew-resize; }
.handle.e { left: 100%; top: 50%; cursor: ew-resize; }
#resizer:not([data-type="text"]) .handle.w, #resizer:not([data-type="text"]) .handle.e { display: none; }
#resizer[data-type="text"] .handle.nw, #resizer[data-type="text"] .handle.ne,
#resizer[data-type="text"] .handle.sw, #resizer[data-type="text"] .handle.se { display: none; }

#marquee {
  position: absolute;
  border: 1px solid var(--accent);
  background: rgba(59, 91, 219, 0.08);
  pointer-events: none;
}

#cursors { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.cursor { position: absolute; left: 0; top: 0; color: var(--c); transition: transform 90ms linear; }
.cursor svg { display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,.3)); }
.cursor span {
  position: absolute;
  left: 14px;
  top: 16px;
  background: var(--c);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
}

.panel {
  position: fixed;
  z-index: 10;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
}
.panel input { user-select: text; -webkit-user-select: text; }

/* Oben links: Titelleiste */
#topbar { top: 12px; left: 12px; height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 12px; max-width: calc(100vw - 360px); }
#topbar .brand-mark { width: 22px; height: 22px; flex: none; }
#title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.vsep { width: 1px; height: 24px; background: var(--line); flex: none; }
#tagfilter-btn.active { background: var(--accent-soft); color: var(--accent); }
.filterpill { display: inline-flex; align-items: center; gap: 4px; flex: none; padding: 4px 4px 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 600; }
.filterpill button { border: 0; background: none; color: inherit; font-size: 16px; line-height: 1; width: 20px; height: 20px; border-radius: 50%; cursor: pointer; }
.filterpill button:hover { background: rgba(59, 91, 219, 0.15); }

/* Oben rechts: Teilnehmer, Moderation, Teilen */
#rightbar { top: 12px; right: 12px; height: 48px; display: flex; align-items: center; gap: 8px; padding: 0 8px; }
.btn-primary { border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; padding: 8px 16px; cursor: pointer; }
.btn-primary:hover { background: #3049b8; }
.menu-btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px; border: 0; border-radius: 8px; background: none; font-size: 14px; font-weight: 500; cursor: pointer; }
.menu-btn:hover { background: var(--hover); }
.menu-btn.open { background: var(--accent-soft); color: var(--accent); }

/* Ausklappmenü und kleine Fenster unter den Leisten */
.menu { top: 68px; right: 12px; width: 300px; padding: 6px; display: flex; flex-direction: column; }
.menu-item { color: inherit; text-decoration: none; box-sizing: border-box; display: flex; align-items: flex-start; gap: 12px; width: 100%; padding: 10px; border: 0; border-radius: 8px; background: none; text-align: left; font-size: 14px; font-weight: 500; cursor: pointer; }
.menu-item:hover { background: var(--hover); }
.menu-item:disabled { opacity: 0.45; cursor: default; background: none; }
.menu-item svg { flex: none; margin-top: 1px; color: var(--muted); }
.menu-item small { display: block; margin-top: 2px; font-size: 12px; font-weight: 400; color: var(--muted); }
.menu-item.active, .menu-item.active svg { color: var(--accent); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }
#mebox, #sharebox, #timerbox, #votebox { top: 68px; right: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
#sharebox { width: min(400px, calc(100vw - 24px)); }
#mebox { width: min(320px, calc(100vw - 24px)); }
#mebox input { flex: 1; min-width: 0; font: inherit; padding: 8px 10px; border: 1px solid #cfd3de; border-radius: 8px; }
#mebox .linkrow { margin-top: 6px; }
#mebox .error { margin-top: 6px; min-height: 0; }
#timerbox { width: 280px; }
#votebox { width: 320px; }
#sharebox p { margin: 0; font-size: 13px; color: var(--muted); }
#sharebox input { flex: 1; min-width: 0; font: inherit; padding: 8px 10px; border: 1px solid #cfd3de; border-radius: 8px; }
#sharebox .linkrow, #timerbox .linkrow, #votebox .linkrow { margin: 0; }

#tools { left: 12px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; padding: 6px; gap: 4px; }
.tool {
  width: 40px; height: 40px;
  border: 0; border-radius: 8px;
  background: none;
  display: grid; place-items: center;
  cursor: pointer;
}
.tool:hover { background: var(--hover); }
.tool[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

#people { display: flex; align-items: center; padding-left: 8px; }
.avatar {
  width: 32px; height: 32px;
  margin-left: -8px;
  border-radius: 50%;
  border: 2px solid #fff;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  display: grid; place-items: center;
}
.avatar:hover { transform: translateY(-2px); z-index: 1; }
.avatar.me { box-shadow: 0 0 0 2px var(--accent); }
.avatar.more { background: #e9ebf0; color: var(--ink); cursor: default; }

#historybar { left: 12px; bottom: 12px; display: flex; padding: 4px; gap: 2px; }
#zoombar { right: 12px; bottom: 12px; display: flex; padding: 4px; gap: 2px; }
#zoombar button { border: 0; background: none; border-radius: 6px; min-width: 34px; height: 34px; padding: 0 8px; cursor: pointer; }
#zoombar button:hover { background: var(--hover); }
#zoom-reset { min-width: 58px !important; font-variant-numeric: tabular-nums; }

#selbar { display: flex; flex-wrap: wrap; align-items: center; padding: 6px; gap: 4px; max-width: calc(100vw - 16px); }
.swatchrow { display: flex; gap: 4px; align-items: center; }
#selbar select { font: inherit; font-size: 13px; height: 32px; padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); cursor: pointer; }
#sel-font { max-width: 140px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.18); cursor: pointer; padding: 0; }
.swatch:hover { transform: scale(1.12); }
.sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
.iconbtn { border: 0; background: none; border-radius: 6px; width: 32px; height: 32px; display: grid; place-items: center; cursor: pointer; }
.iconbtn:hover { background: var(--hover); }
.iconbtn:disabled { opacity: 0.3; cursor: default; background: none; }
.iconbtn.danger { color: var(--danger); }

#status {
  left: 50%; top: 64px; transform: translateX(-50%);
  padding: 8px 14px;
  background: #fff4e6;
  color: #7a3a00;
  font-size: 14px;
}

/* Oben in der Mitte: laufender Timer und laufendes Voting */
#workbar { top: 12px; left: 50%; transform: translateX(-50%); height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 8px 0 12px; white-space: nowrap; }
#timer-run { display: flex; align-items: center; gap: 2px; }
#timer-time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 20px; min-width: 70px; text-align: center; padding: 0 4px; }
#timer-add { font-weight: 600; font-size: 13px; }
#timer-run:not([hidden]) + #vote-run { border-left: 1px solid var(--line); padding-left: 10px; }
#workbar.ending #timer-time { color: var(--danger); }
#workbar.done { background: var(--danger); color: #fff; animation: pulse 0.8s ease-in-out 4; }
#workbar.done .iconbtn:hover { background: rgba(255, 255, 255, 0.15); }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.08); } }
#vote-run { display: flex; align-items: center; gap: 8px; font-size: 14px; }
#vote-points { width: 64px; font: inherit; padding: 8px 10px; border: 1px solid #cfd3de; border-radius: 8px; }
#timer-minutes { flex: 1; min-width: 0; font: inherit; padding: 8px 10px; border: 1px solid #cfd3de; border-radius: 8px; }
.presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

#followbar { top: 68px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px; background: var(--accent); color: #fff; font-size: 14px; white-space: nowrap; }
#followbar .secondary { border-color: transparent; color: var(--ink); }
body.following #viewport { box-shadow: inset 0 0 0 4px var(--accent); }

body.voting .item { cursor: pointer; }
.votes {
  position: absolute; top: -14px; right: -14px;
  min-width: 34px; height: 34px; padding: 0 9px;
  border-radius: 17px;
  background: var(--accent); color: #fff;
  font-size: 18px; font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.votes.result { background: var(--ink); }

/* Ist oben nicht genug Platz, wandert der Status nach unten in die Mitte. */
@media (max-width: 1180px) {
  #workbar { top: auto; bottom: 12px; }
}
/* Schmale Bildschirme: Status über den unteren Leisten, Menütext weg */
@media (max-width: 760px) {
  #topbar { max-width: calc(100vw - 230px); }
  #mod-btn { font-size: 0; gap: 2px; }
  #workbar { bottom: 64px; }
  #toast { bottom: 124px; }
  #selbar { gap: 2px; padding: 4px; }
  .tool[data-tool="frame"], .tool[data-tool="shape"], .tool[data-tool="line"] { display: none; }
  #selbar .swatch { width: 20px; height: 20px; }
  #selbar .sep { margin: 0 2px; }
}

#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  max-width: calc(100vw - 32px); text-align: center;
  z-index: 50;
  background: var(--ink); color: #fff;
  padding: 9px 16px; border-radius: 8px; font-size: 14px;
}

.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: rgba(244, 245, 248, 0.86);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 16px;
}
