:root {
  --bg: #f4f4f1;
  --panel: #ffffff;
  --raised: #ffffff;
  --ink: #1a1a1c;
  --ink-2: #66666c;
  --ink-3: #a3a3a8;
  --line: #e4e4df;
  --line-2: #efefea;
  --hover: #f0f0ec;
  --accent: #3653d4;
  --accent-ink: #ffffff;
  --accent-soft: #e9edfc;
  --ok: #23925a;
  --ok-soft: #e3f4ea;
  --danger: #c63a2b;
  --danger-soft: #fbe9e6;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 4px 14px rgb(0 0 0 / .05);
  --shadow-lg: 0 10px 40px rgb(0 0 0 / .14), 0 2px 6px rgb(0 0 0 / .06);
  --radius: 14px;
  --t-pdf: #fbe7e4; --t-pdf-ink: #b8402f;
  --t-doc: #e6edfb; --t-doc-ink: #2f58b8;
  --t-sheet: #e3f3e8; --t-sheet-ink: #24814f;
  --t-slide: #fcecdf; --t-slide-ink: #b65b1d;
  --t-media: #efe8fb; --t-media-ink: #6b46c1;
  --t-audio: #fbe7f1; --t-audio-ink: #b03a78;
  --t-other: #eeeeea; --t-other-ink: #66666c;
  --t-text: #fbfaf5;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --panel: #1c1c1f;
    --raised: #232327;
    --ink: #f1f1f3;
    --ink-2: #a2a2a9;
    --ink-3: #6c6c73;
    --line: #2e2e33;
    --line-2: #26262a;
    --hover: #29292e;
    --accent: #7d93ff;
    --accent-ink: #10132b;
    --accent-soft: #252b4a;
    --ok: #4cc283;
    --ok-soft: #1d3327;
    --danger: #ff7a6b;
    --danger-soft: #3a2220;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 4px 14px rgb(0 0 0 / .25);
    --shadow-lg: 0 10px 40px rgb(0 0 0 / .5);
    --t-pdf: #3a2522; --t-pdf-ink: #ff9a8a;
    --t-doc: #222c44; --t-doc-ink: #93b1ff;
    --t-sheet: #1f3529; --t-sheet-ink: #7fd6a3;
    --t-slide: #3b2b1e; --t-slide-ink: #ffb57f;
    --t-media: #2d2442; --t-media-ink: #c2a6ff;
    --t-audio: #3a2231; --t-audio-ink: #ff9ccc;
    --t-other: #2a2a2e; --t-other-ink: #a2a2a9;
    --t-text: #202023;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Kopfzeile ---------- */

.app { display: flex; flex-direction: column; height: 100%; }
.bar {
  display: flex; align-items: center; gap: 8px;
  min-height: 58px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 17px; letter-spacing: -.01em; margin-right: 8px; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: var(--ink); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; left: 5px; right: 5px; top: 9px; height: 4px; border-radius: 2px; background: var(--bg); }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 13px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--ink);
  font-weight: 520; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.btn.primary:hover { opacity: .9; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.icon { width: 38px; padding: 0; }
.btn.danger { color: var(--danger); }
.btn.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn.warn { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn .label-sm { display: inline; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 11px; border-radius: 99px;
  background: var(--hover); color: var(--ink-2); font-size: 13.5px; white-space: nowrap;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 11px; background: var(--hover); }
.seg button {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 11px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink-2); font-size: 14px; font-weight: 520; white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--raised); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

select.select {
  height: 38px; padding: 0 30px 0 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 11px center;
  appearance: none; -webkit-appearance: none; max-width: 220px; font-weight: 520;
}

/* ---------- Fläche + Kacheln ---------- */

.main { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; position: relative; min-width: 0; display: flex; flex-direction: column; }
.canvas { flex: 1; overflow: auto; min-height: 0; -webkit-overflow-scrolling: touch; }
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 16px;
  padding: 22px max(22px, env(safe-area-inset-right)) 96px max(22px, env(safe-area-inset-left));
  align-content: start;
}

.tile {
  position: relative; display: flex; flex-direction: column;
  background: var(--raised); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; cursor: pointer; text-align: left;
  border: 1px solid transparent;
  animation: tile-in .28s ease-out;
  transition: transform .14s ease, box-shadow .14s ease;
}
@media (hover: hover) { .tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); } }
@keyframes tile-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.tile.is-new { border-color: var(--accent); }
.new-pill {
  display: inline-block; padding: 0 6px; margin-right: 6px; border-radius: 99px; vertical-align: 1px;
  background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 650; line-height: 17px;
}

.tile-media { aspect-ratio: 4 / 3; display: grid; place-items: center; background: var(--t-other); position: relative; overflow: hidden; }
.tile-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-ext { font-weight: 720; font-size: 22px; letter-spacing: .02em; color: var(--t-other-ink); }
.tile-media .i { width: 30px; height: 30px; stroke-width: 1.5; }
.t-pdf { background: var(--t-pdf); } .t-pdf .tile-ext, .t-pdf .i { color: var(--t-pdf-ink); }
.t-doc { background: var(--t-doc); } .t-doc .tile-ext, .t-doc .i { color: var(--t-doc-ink); }
.t-sheet { background: var(--t-sheet); } .t-sheet .tile-ext, .t-sheet .i { color: var(--t-sheet-ink); }
.t-slide { background: var(--t-slide); } .t-slide .tile-ext, .t-slide .i { color: var(--t-slide-ink); }
.t-media { background: var(--t-media); } .t-media .tile-ext, .t-media .i { color: var(--t-media-ink); }
.t-audio { background: var(--t-audio); } .t-audio .tile-ext, .t-audio .i { color: var(--t-audio-ink); }
.t-image { background: var(--t-media); } .t-image .tile-ext, .t-image .i { color: var(--t-media-ink); }
.tile-media.t-text {
  background: var(--t-text); place-items: start; padding: 14px 15px 0; text-align: left;
  font-size: 15px; line-height: 1.42; white-space: pre-wrap; overflow-wrap: anywhere;
  -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent);
}
.tile-media.t-text a { pointer-events: none; }

.tile-foot { padding: 10px 12px 11px; min-width: 0; }
.tile-name { font-weight: 560; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-meta { color: var(--ink-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.tile-meta b { font-weight: 600; color: var(--ink); }

.tile-actions { position: absolute; right: 8px; top: 8px; display: flex; gap: 6px; z-index: 2; }
.tile-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 0;
  display: grid; place-items: center;
  background: rgb(255 255 255 / .9); color: #1a1a1c;
  box-shadow: 0 1px 3px rgb(0 0 0 / .15);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  text-decoration: none;
}
.tile-btn .i { width: 17px; height: 17px; }
@media (hover: hover) {
  .tile .tile-actions { opacity: 0; transition: opacity .12s; }
  .tile:hover .tile-actions, .tile:focus-within .tile-actions { opacity: 1; }
}

.tile.uploading { cursor: default; }
.tile.uploading .tile-media { background: var(--line-2); }
.progress { position: absolute; left: 14px; right: 14px; bottom: 14px; height: 5px; border-radius: 3px; background: rgb(0 0 0 / .08); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .15s; }

.empty {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 32px;
  color: var(--ink-3); pointer-events: none;
}
.empty-box {
  border: 2px dashed var(--line); border-radius: 22px; padding: 44px 40px; max-width: 440px;
}
.empty-title { font-size: 17px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }

.dropchip {
  position: absolute; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 99px;
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 540; white-space: nowrap; max-width: calc(100% - 40px); overflow: hidden; text-overflow: ellipsis;
  z-index: 3; border: 0;
}
.dropchip .i { width: 16px; height: 16px; }
.dropchip.none { background: var(--danger); color: #fff; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  pointer-events: none; opacity: 0; transition: opacity .12s;
}
.drop-overlay.show { opacity: 1; }
.drop-overlay > div {
  border: 2.5px dashed var(--accent); border-radius: 26px; padding: 40px 56px;
  background: var(--panel); color: var(--ink); text-align: center; box-shadow: var(--shadow-lg);
}
.drop-overlay .big { font-size: 22px; font-weight: 650; }
.drop-overlay .small { color: var(--ink-2); margin-top: 4px; }

/* ---------- Dialoge, Menüs, Hinweise ---------- */

dialog {
  border: 0; padding: 0; border-radius: 20px; background: var(--panel); color: var(--ink);
  box-shadow: var(--shadow-lg); width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
}
dialog::backdrop { background: rgb(10 10 12 / .38); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.dlg { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 18px 20px 6px; }
.dlg-title { font-size: 17px; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlg-body { padding: 8px 20px 4px; overflow: auto; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding: 14px 20px 18px; }
.dlg-foot .hint { color: var(--ink-3); font-size: 13px; margin-right: auto; }
textarea.input, input.input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  padding: 12px 14px; outline: none; font-size: 16px; resize: vertical;
}
textarea.input { min-height: 160px; line-height: 1.45; }
textarea.input:focus, input.input:focus { border-color: var(--accent); background: var(--panel); }
.viewer-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; line-height: 1.5; padding-bottom: 6px; }

.menu {
  position: fixed; z-index: 60; min-width: 190px; padding: 6px;
  background: var(--raised); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg);
  animation: pop .12s ease-out;
}
@keyframes pop { from { opacity: 0; transform: scale(.97); } }
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  height: 40px; padding: 0 12px; border: 0; border-radius: 9px; background: none; text-align: left; font-weight: 500;
}
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }

.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(24px, env(safe-area-inset-bottom)); z-index: 70; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow-lg); font-size: 14px; animation: pop .15s ease-out; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); color: #fff; }

.conn { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 80; }
.conn .chip { background: var(--danger-soft); color: var(--danger); font-weight: 560; }

/* ---------- Auswahllisten (Empfänger) ---------- */

.picklist { display: grid; gap: 2px; margin: 4px -8px; }
.pick {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 10px; border-radius: 10px;
  border: 0; background: none; text-align: left; width: 100%;
}
.pick:hover { background: var(--hover); }
.check {
  width: 22px; height: 22px; border-radius: 7px; border: 1.8px solid var(--ink-3); flex: none;
  display: grid; place-items: center; color: transparent; transition: background .1s, border-color .1s;
}
.check .i { width: 14px; height: 14px; stroke-width: 3; }
[aria-checked="true"] > .check { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pick-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-all { font-weight: 600; }
.sep { height: 1px; background: var(--line); margin: 6px 10px; }

/* ---------- Anmeldung (Schüler) ---------- */

.center { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.card {
  width: min(400px, 100%); background: var(--panel); border-radius: 24px; box-shadow: var(--shadow);
  padding: 34px 30px 30px;
}
.card .brand { justify-content: center; margin: 0 0 26px; font-size: 20px; }
.card .brand-mark { width: 26px; height: 26px; border-radius: 8px; }
.card .brand-mark::after { left: 6px; right: 6px; top: 11px; }
.card h1 { font-size: 22px; letter-spacing: -.01em; margin: 0 0 6px; text-align: center; }
.card p { color: var(--ink-2); margin: 0 0 22px; text-align: center; }
.card form { display: grid; gap: 12px; }
.card .btn { height: 48px; font-size: 16px; }
.card .error { color: var(--danger); text-align: center; font-size: 14px; min-height: 20px; margin: 0; }
.card .link { background: none; border: 0; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; display: block; margin: 18px auto 0; }
.pulse { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); margin: 4px auto 18px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.1); } }

@media (max-width: 640px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; padding: 14px 14px 90px; }
  .bar { gap: 6px; }
  .btn .label-sm { display: none; }
  .btn:has(.label-sm) { width: 38px; padding: 0; }
}

/* ---------- Lehreransicht ---------- */

.banner { padding: 10px 18px; background: var(--danger-soft); color: var(--danger); font-weight: 560; border-bottom: 1px solid var(--line); }
.linkbtn { max-width: 280px; color: var(--ink-2); }
.linkbtn .label-sm { overflow: hidden; text-overflow: ellipsis; }
.seg .count.badge {
  display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 5px; margin-left: 2px;
  border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 650;
}
.btn.sm { height: 32px; font-size: 13.5px; }
.btn.icon.sm { width: 32px; }
.btn.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.muted { color: var(--ink-3); font-weight: 500; font-size: 13px; }

.side {
  width: 330px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-left: 1px solid var(--line);
}
.side-scroll { flex: 1; overflow: auto; padding: 12px 12px max(24px, env(safe-area-inset-bottom)); }
.side-sec + .side-sec { margin-top: 10px; }
.side-sec.waiting { background: var(--accent-soft); border-radius: 14px; padding: 4px 6px 8px; }
.side-title { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 6px; font-weight: 650; font-size: 14px; }
.side-empty { padding: 8px 6px; color: var(--ink-2); }
.side-empty p { margin: 0 0 12px; }
.master { display: flex; flex-direction: column; gap: 6px; padding: 4px 6px 12px; }
.master-label { font-size: 12.5px; color: var(--ink-2); font-weight: 560; }
.master .seg { width: 100%; }
.master .seg button { flex: 1; justify-content: center; padding: 0 6px; }
.row { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 0 4px 0 10px; border-radius: 10px; }
.row.student { cursor: pointer; }
.row.student:hover { background: var(--hover); }
.waiting .row { background: var(--panel); margin-top: 4px; padding-right: 6px; }
.waiting .row .pick-name { font-weight: 560; }
.pick-hint { color: var(--ink-3); font-size: 12.5px; font-weight: 450; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); opacity: .45; flex: none; }
.dot.on { background: var(--ok); opacity: 1; }
.seg.mini { padding: 2px; border-radius: 9px; }
.seg.mini button { width: 30px; height: 28px; padding: 0; justify-content: center; border-radius: 7px; }
.seg.mini .i { width: 15px; height: 15px; }
.seg.mini button[aria-pressed="true"] { color: var(--accent); }
.side-toggle { display: none; }
.side-toggle.attn { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.side-scrim { display: none; }

.share { display: grid; justify-items: center; gap: 14px; padding: 6px 0 4px; }
.share .qr { width: min(360px, 68vw); aspect-ratio: 1; border-radius: 16px; background: #fff; padding: 10px; image-rendering: pixelated; }
.share-url { font-size: 20px; font-weight: 650; letter-spacing: -.01em; text-align: center; overflow-wrap: anywhere; }
.share-help p { margin: 4px 0 10px; }
.share-help pre { background: var(--bg); border-radius: 10px; padding: 12px 14px; font: 14px ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 10px; }
.confirm-text { margin: 4px 0 6px; color: var(--ink-2); }

@media (max-width: 1000px) {
  .teacher .side {
    position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; width: min(360px, 92vw);
    transform: translateX(100%); transition: transform .2s ease; box-shadow: var(--shadow-lg);
    padding-top: env(safe-area-inset-top);
  }
  .side-open .side { transform: none; }
  .side-open .side-scrim { display: block; position: fixed; inset: 0; z-index: 39; background: rgb(0 0 0 / .25); }
  .side-toggle { display: inline-flex; }
  .teacher .linkbtn .label-sm { display: none; }
}
@media (max-width: 760px) {
  .teacher .bar .seg button { padding: 0 8px; }
}

/* ---------- Schüleransicht ---------- */

.sendbar { display: flex; align-items: center; gap: 8px; }
.chip.me { background: transparent; color: var(--ink-2); font-weight: 520; }
.chip.me .i, .muted-chip .i { width: 15px; height: 15px; }
.empty-sub { max-width: 320px; margin: 0 auto; }
@media (max-width: 640px) {
  .chip.me { display: none; }
  .sendbar .select { max-width: 150px; }
}
