:root {
  color-scheme: dark;
  --bg: #0b0b0f;
  --surface: #15151b;
  --surface-2: #1d1d25;
  --surface-3: #262630;
  --ink: #ededf2;
  --muted: #8b8b98;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --accent: #6e8bff;
  --accent-2: #8a6cff;
  --danger: #ff6b6b;
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overscroll-behavior: none;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(138, 108, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgba(110, 139, 255, 0.10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }
button, input { font: inherit; color: inherit; }

button {
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  border-radius: 9px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
button:hover { background: var(--surface-3); border-color: rgba(255, 255, 255, 0.22); }
button:active { transform: scale(0.98); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px rgba(110, 139, 255, 0.35);
}
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  font-weight: 600;
}
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { background: var(--surface-2); color: var(--ink); }
button.danger { color: var(--danger); }

input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.screen { min-height: 100vh; }

/* Login */
#login { display: grid; place-items: center; padding: 20px; }
.card {
  background: rgba(21, 21, 27, 0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  padding: 32px 28px;
  border-radius: 20px;
  width: min(380px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
}
.card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
.card label, .field { display: flex; flex-direction: column; gap: 7px; font-size: 13px; color: var(--muted); }
.card input, .field input {
  padding: 11px 12px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--ink);
  font-size: 15px;
}
.card button[type="submit"] {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  padding: 12px;
  font-weight: 600;
  border-radius: 10px;
  margin-top: 4px;
  box-shadow: 0 8px 22px rgba(110, 139, 255, 0.3);
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: rgba(21, 21, 27, 0.72);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.topbar h1 { font-size: 19px; margin: 0; flex: 1; font-weight: 650; letter-spacing: -0.01em; }
#docTitle {
  font-size: 16px;
  font-weight: 600;
  border: none;
  outline: none;
  background: transparent;
  flex: 1;
  min-width: 140px;
  padding: 6px 4px;
  border-radius: 8px;
}
#docTitle:focus { background: var(--surface-2); }
.badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  white-space: nowrap;
}

/* Bibliothek */
.library { padding: 28px 22px 60px; max-width: 1100px; margin: 0 auto; }
.grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.doc-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.15s;
}
.doc-card:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.doc-thumb {
  height: 120px;
  display: grid;
  place-items: center;
  font-size: 34px;
  color: var(--muted);
  background:
    radial-gradient(circle at 30% 20%, rgba(138, 108, 255, 0.25), transparent 60%),
    radial-gradient(circle at 80% 90%, rgba(110, 139, 255, 0.2), transparent 60%),
    var(--surface-2);
}
.doc-meta { padding: 12px 14px 12px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.doc-open {
  border: none;
  background: none;
  padding: 0;
  text-align: left;
  font-weight: 600;
  font-size: 15px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-open:hover { background: none; color: #fff; }
.doc-meta .ghost { padding: 2px 0; font-size: 13px; margin-top: 4px; }

/* Neues Dokument */
dialog {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  padding: 26px;
  width: min(560px, 92vw);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); }
dialog h2 { margin: 0 0 14px; font-size: 19px; font-weight: 650; }
dialog .field { margin-bottom: 14px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  padding: 18px;
  border-radius: 14px;
  background: var(--surface-2);
  white-space: normal;
  line-height: 1.4;
}
.choice:hover { border-color: var(--accent); }
.choice .ico { font-size: 26px; color: var(--accent); }
.choice strong { font-size: 15px; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 14px; }

/* Editor */
#editor { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
}
.group label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
}
input[type="color"] {
  width: 30px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: none;
  cursor: pointer;
}
input[type="range"] { accent-color: var(--accent); width: 96px; }
.group > button { border-color: transparent; background: transparent; padding: 6px 10px; }
.group > button:hover { background: var(--surface-3); }
.swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  padding: 0;
  border: 2px solid var(--surface-2);
  box-shadow: 0 0 0 1px var(--line-strong);
}
.swatch:hover { transform: scale(1.12); background: none; }
.zoom button { min-width: 36px; }

#editor.mode-doc .canvas-only { display: none !important; }
#editor.mode-canvas .doc-only { display: none !important; }

/* Dokument (fließend) */
.doc-view { flex: 1; overflow: auto; min-height: 0; }
.doc-body {
  max-width: 760px;
  margin: 0 auto;
  padding: 56px 28px 45vh;
  min-height: 100%;
  font: 17px/1.75 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  outline: none;
  caret-color: var(--accent);
}
.doc-body ::selection, .tcontent ::selection { background: rgba(110, 139, 255, 0.35); }
.doc-body h1 { font-size: 2em; line-height: 1.25; margin: 0.6em 0 0.3em; font-weight: 700; letter-spacing: -0.02em; }
.doc-body ul, .doc-body ol { padding-left: 1.4em; }
.ink-block {
  position: relative;
  width: 100%;
  margin: 14px 0;
  border-radius: 14px;
  border: 1px dashed var(--line-strong);
  background: var(--surface);
  overflow: hidden;
  user-select: none;
}
.ink-block canvas.ink {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  touch-action: none;
}
#editor[data-tool="pen"] canvas.ink,
#editor[data-tool="highlighter"] canvas.ink,
#editor[data-tool="eraser"] canvas.ink {
  pointer-events: auto;
  cursor: crosshair;
}
.blk-del {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.15s;
}
.ink-block:hover .blk-del { opacity: 1; }

/* Zeichenfläche (unendlich) */
.canvas-view {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background: var(--bg);
}
#board {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
.texts {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  pointer-events: none;
}
.tbox {
  position: absolute;
  pointer-events: auto;
  background: rgba(29, 29, 37, 0.92);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  user-select: text;
}
.tbox:focus-within { border-color: var(--accent); }
.thandle {
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  position: relative;
}
.thandle::before {
  content: "";
  width: 36px;
  height: 4px;
  border-radius: 4px;
  background: var(--line-strong);
}
.tdel {
  position: absolute;
  right: 2px;
  top: 0;
  width: 22px;
  height: 22px;
  padding: 0;
  line-height: 1;
  font-size: 15px;
}
.tcontent {
  padding: 4px 12px 12px;
  min-height: 40px;
  outline: none;
  font-size: 17px;
  line-height: 1.5;
  caret-color: var(--accent);
}
#canvasView[data-tool="hand"] { cursor: grab; }
#canvasView[data-tool="pen"],
#canvasView[data-tool="highlighter"],
#canvasView[data-tool="eraser"] { cursor: crosshair; }
#canvasView:not([data-tool="text"]) .tcontent { pointer-events: none; }
#canvasView[data-tool="text"] .tcontent { cursor: text; }

@media (max-width: 600px) {
  .doc-body { padding: 36px 18px 45vh; font-size: 16px; }
  input[type="range"] { width: 72px; }
  .choices { grid-template-columns: 1fr; }
}
