:root {
  color-scheme: dark;
  --bg: #070c17;
  --bg-2: #0f172a;
  --card: rgba(17, 25, 42, 0.86);
  --card-solid: #152035;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.3);
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #818cf8;
  --gold: #f59e0b;
  --green: #10b981;
  --danger: #ef4444;
  --radius: 18px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body.lobby-page {
  background:
    radial-gradient(circle at 14% 10%, rgba(56, 189, 248, 0.16) 0%, transparent 40%),
    radial-gradient(circle at 86% 12%, rgba(129, 140, 248, 0.14) 0%, transparent 42%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 100%);
  min-height: 100vh;
}

body.board-page {
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  background: #0b1220;
  user-select: none;
  -webkit-user-select: none;
}

a {
  color: inherit;
  text-decoration: none;
}

.hidden {
  display: none !important;
}

/* Scrollbars */
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.28); border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(56, 189, 248, 0.72); }
*::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: rgba(148, 163, 184, 0.35) transparent; }
}

/* === Shared Controls === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--card-solid);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.14s, border-color 0.14s, transform 0.1s;
}

.btn:hover { background: #22324f; border-color: var(--border-strong); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  border-color: transparent;
  color: #060b16;
  font-weight: 800;
}
.btn-primary:hover { background: linear-gradient(135deg, #7dd3fc, #818cf8); }

.btn-ghost {
  background: rgba(20, 30, 48, 0.65);
  color: var(--muted);
}
.btn-ghost:hover { color: var(--text); }

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.26); }

.btn-sm { padding: 6px 10px; font-size: 0.78rem; border-radius: 9px; }

.input, .textarea, .select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: rgba(10, 16, 30, 0.88);
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
}
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); font-weight: 600; margin-bottom: 5px; }
.inline-row { display: flex; align-items: center; gap: 8px; }

/* === Lobby Page === */
.shell {
  max-width: 1020px;
  margin: 0 auto;
  padding: 26px 18px 46px;
}

.lobby-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(135deg, #38bdf8, #818cf8);
  color: #060b16;
  font-size: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand h1 { font-size: 1.5rem; font-weight: 900; letter-spacing: -0.02em; }
.brand-sub { font-size: 0.82rem; color: var(--muted); }

.lobby-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 18px;
  align-items: start;
}

@media (max-width: 820px) {
  .lobby-grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-title {
  font-size: 0.84rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.theme-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.theme-opt {
  padding: 10px 12px;
  border-radius: 11px;
  border: 2px solid var(--border);
  background: rgba(10, 16, 30, 0.72);
  color: var(--text);
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.theme-opt.active {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.14);
}

.recent-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(10, 16, 30, 0.62);
  border: 1px solid var(--border);
  transition: border-color 0.15s;
}
.recent-item:hover { border-color: rgba(56, 189, 248, 0.45); }

.code-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 7px;
  background: rgba(56, 189, 248, 0.15);
  color: #7dd3fc;
}

/* === Board Canvas & Floating UI === */
#boardCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

#boardCanvas.cursor-grab { cursor: grab; }
#boardCanvas.cursor-grabbing { cursor: grabbing; }
#boardCanvas.cursor-default { cursor: default; }
#boardCanvas.cursor-text { cursor: text; }

/* Floating Top Bar */
.board-topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 50;
}

.floating-panel {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 15px;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-strong);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.38);
}

.board-title-input {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-weight: 800;
  font-size: 0.94rem;
  padding: 4px 7px;
  border-radius: 8px;
  width: 170px;
  min-width: 90px;
}
.board-title-input:hover { border-color: var(--border); }
.board-title-input:focus { outline: none; border-color: var(--accent); background: rgba(10, 16, 30, 0.8); }

.user-avatars {
  display: flex;
  align-items: center;
  gap: 4px;
}

.avatar-pill {
  height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
  color: #060b16;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

/* Floating Left / Bottom Main Toolbar */
.tool-dock {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  max-width: calc(100vw - 20px);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.48);
  z-index: 60;
  overflow-x: auto;
}

.tool-sep {
  width: 1px;
  height: 26px;
  background: rgba(148, 163, 184, 0.22);
  flex-shrink: 0;
  margin: 0 2px;
}

.tool-btn {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: transparent;
  color: #cbd5e1;
  font-size: 1.12rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.14s, color 0.14s, border-color 0.14s, transform 0.1s;
  position: relative;
}

.tool-btn:hover { background: rgba(148, 163, 184, 0.14); color: #ffffff; }
.tool-btn:active { transform: scale(0.94); }
.tool-btn.active {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.26), rgba(99, 102, 241, 0.28));
  border-color: rgba(56, 189, 248, 0.65);
  color: #ffffff;
}

.tool-btn .kbd-hint {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 0.56rem;
  font-weight: 800;
  opacity: 0.55;
  pointer-events: none;
}

/* Style Bar (Farben & Strichstärke über dem Tool-Dock) */
.style-bar {
  position: fixed;
  left: 50%;
  bottom: 74px;
  transform: translateX(-50%);
  max-width: calc(100vw - 20px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-strong);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 55;
  overflow-x: auto;
}

.swatch-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s, border-color 0.12s;
}
.swatch:hover { transform: scale(1.14); }
.swatch.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px #38bdf8;
  transform: scale(1.12);
}

.width-slider {
  width: 78px;
  accent-color: #38bdf8;
  cursor: pointer;
}

.fill-toggle-btn {
  padding: 4px 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(10, 16, 30, 0.7);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.fill-toggle-btn.active {
  border-color: #38bdf8;
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.16);
}

/* Zoom Controls (Bottom Right) */
.zoom-bar {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 55;
}

.zoom-label {
  font-size: 0.78rem;
  font-weight: 800;
  min-width: 44px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  color: var(--text);
}

/* Selection Action Pill */
.selection-bar {
  position: fixed;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 58;
}

/* Live Cursors Overlay */
.cursors-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}

.remote-cursor {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  align-items: flex-start;
  gap: 3px;
  will-change: transform;
  transition: transform 65ms linear;
}

.remote-cursor-tag {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  color: #060b16;
  white-space: nowrap;
  margin-top: 12px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

/* Modals & Toast */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 18, 0.74);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

.modal-card {
  width: 100%;
  max-width: 430px;
  background: #111c30;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.modal-card h3 { font-size: 1.1rem; margin-bottom: 12px; }

.qr-box {
  background: #ffffff;
  padding: 12px;
  border-radius: 14px;
  width: 200px;
  height: 200px;
  margin: 12px auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qr-box svg { width: 100%; height: 100%; display: block; }

.toast {
  position: fixed;
  left: 50%;
  top: 72px;
  transform: translateX(-50%) translateY(-160%);
  background: #0f172a;
  border: 1px solid rgba(56, 189, 248, 0.5);
  border-radius: 12px;
  padding: 9px 15px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  z-index: 300;
  transition: transform 0.25s ease;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.empty-msg { font-size: 0.86rem; color: var(--muted); text-align: center; padding: 18px 8px; }

/* Mobile Responsive Adjustments for Board */
@media (max-width: 780px) {
  .board-topbar {
    top: 8px;
    left: 8px;
    right: 8px;
    flex-wrap: wrap;
    gap: 6px;
  }

  .floating-panel {
    padding: 5px 7px;
    gap: 5px;
    border-radius: 13px;
  }

  .board-title-input {
    width: 115px;
    font-size: 0.84rem;
  }

  .hide-mobile {
    display: none !important;
  }

  .zoom-bar {
    right: 8px;
    bottom: 132px;
    padding: 4px 6px;
  }

  .tool-dock {
    bottom: 8px;
    padding: 5px 7px;
    gap: 4px;
    border-radius: 15px;
  }

  .tool-btn {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  .tool-btn .kbd-hint { display: none; }

  .style-bar {
    bottom: 62px;
    padding: 5px 9px;
    gap: 6px;
  }
}
