@font-face {
  font-family: "Fredoka";
  src: url("../fonts/fredoka-latin.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Fredoka";
  src: url("../fonts/fredoka-latin-ext.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Nunito";
  src: url("../fonts/nunito-latin.woff2") format("woff2");
  font-weight: 200 1000;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Fredoka";
  src: url("../fonts/fredoka-latin.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Fredoka";
  src: url("../fonts/fredoka-latin-ext.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Nunito";
  src: url("../fonts/nunito-latin-ext.woff2") format("woff2");
  font-weight: 200 1000;
  font-display: swap;
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --font: "Nunito", "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", ui-rounded, system-ui, -apple-system, "Segoe UI", sans-serif;
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f7f7fc;
  --ink: #1d2140;
  --muted: #6b7091;
  --line: #e4e6f0;
  --accent: #6c5ce7;
  --accent-ink: #ffffff;
  --accent-soft: #eeebff;
  --good: #22b07d;
  --warn: #f2a516;
  --bad: #ec5f67;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(29, 33, 64, .06), 0 8px 24px rgba(29, 33, 64, .08);
  --shadow-lg: 0 2px 6px rgba(29, 33, 64, .08), 0 24px 60px rgba(29, 33, 64, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .dash {
    --bg: #14152a;
    --surface: #1d1f3a;
    --surface-2: #24264a;
    --ink: #eceefe;
    --muted: #a3a7cc;
    --line: #2f3260;
    --accent-soft: #2c2a5c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.i { width: 1.15em; height: 1.15em; flex: none; display: inline-block; vertical-align: -0.2em; }
.h-ico { width: 1.1em; height: 1.1em; margin-right: .45em; color: var(--accent); vertical-align: -0.15em; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: .55em 1.05em; border-radius: 999px; font-weight: 700; cursor: pointer;
  text-decoration: none; transition: transform .12s, box-shadow .12s, background .12s;
}
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: .35em .8em; font-size: .9em; }
.btn:disabled { opacity: .5; cursor: default; }

.field { display: grid; gap: .35em; margin-bottom: 1em; }
.field > span { font-weight: 700; font-size: .92em; }
.field small { color: var(--muted); }
.input, .field input, .field select, .field textarea {
  width: 100%; padding: .65em .85em; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus, .input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { min-height: 7em; resize: vertical; }
.toggle { display: flex; align-items: center; gap: .6em; cursor: pointer; font-weight: 600; margin-bottom: .9em; }
.toggle input { width: 1.15em; height: 1.15em; accent-color: var(--accent); }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.muted { color: var(--muted); }
.error-box { background: #fde8ea; color: #9b1c27; padding: .7em 1em; border-radius: var(--radius-sm); margin-bottom: 1em; }

/* ---------- dialog ---------- */
dialog {
  border: none; border-radius: 22px; padding: 0; width: min(560px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog.wide { width: min(860px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(20, 22, 50, .45); backdrop-filter: blur(3px); }
dialog form, .dialog-body { padding: 24px; }
dialog h2 { margin: 0 0 .8em; font-size: 1.35em; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6em; margin-top: 1.2em; }

/* ---------- dashboard pages ---------- */
.dash { min-height: 100vh; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 14px clamp(16px, 4vw, 40px);
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
}
.brand-mark .i { width: 62%; height: 62%; }
.brand { display: flex; align-items: center; gap: .55em; font-weight: 900; font-size: 1.15em; text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-size: 18px; flex: none;
  background: linear-gradient(135deg, #8b7bff, #6c5ce7); color: #fff; box-shadow: 0 4px 12px rgba(108, 92, 231, .35);
}
.topbar nav { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.topbar nav a { text-decoration: none; color: var(--muted); font-weight: 700; padding: .45em .9em; border-radius: 999px; }
.topbar nav a.active, .topbar nav a:hover { color: var(--ink); background: var(--surface); }
.topbar form { margin: 0; }

main.page { padding: 8px clamp(16px, 4vw, 40px) 64px; max-width: 1240px; margin: 0 auto; }
.hello { margin: 18px 0 28px; }
.hello h1 { font-size: clamp(1.7em, 4vw, 2.4em); margin: 0; letter-spacing: -.02em; line-height: 1.15; }
.hello p { margin: .3em 0 0; color: var(--muted); font-size: 1.05em; }

.section { margin-bottom: 40px; }
.section-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-size: 1.3em; }
.section-head .spacer { flex: 1; }

.grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }

.board-card { overflow: hidden; display: flex; flex-direction: column; text-decoration: none; color: inherit; transition: transform .15s, box-shadow .15s; }
.board-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.board-thumb { aspect-ratio: 16 / 9; position: relative; overflow: hidden; background-size: cover; background-position: center; }
.board-thumb .mini {
  position: absolute; background: rgba(255, 255, 255, .92); border-radius: 6px; box-shadow: 0 2px 6px rgba(0, 0, 0, .12);
  display: grid; place-items: center; overflow: hidden; color: #6c5ce7;
}
.board-thumb .mini .i { width: min(18px, 60%); height: min(18px, 60%); }
.board-meta { padding: 12px 16px 14px; display: flex; align-items: center; gap: 8px; }
.board-meta strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-meta small { color: var(--muted); }
.board-meta .grow { flex: 1; min-width: 0; }
.icon-btn {
  border: none; background: transparent; width: 34px; height: 34px; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center; color: var(--muted); font-size: 16px; flex: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.new-card {
  border: 2px dashed var(--line); background: transparent; box-shadow: none; min-height: 190px;
  display: grid; place-items: center; text-align: center; cursor: pointer; color: var(--muted); font-weight: 800;
  border-radius: var(--radius); transition: border-color .15s, color .15s, background .15s;
}
.new-card:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.new-card .plus { font-size: 2em; line-height: 1; display: block; margin-bottom: .2em; }

.class-card { padding: 16px 18px; display: flex; gap: 14px; align-items: center; cursor: pointer; transition: box-shadow .15s; }
.class-card:hover { box-shadow: var(--shadow-lg); }
.grade-badge {
  width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-weight: 900; font-size: 1.3em;
  background: var(--accent-soft); color: var(--accent); flex: none;
}
.class-card .grow { flex: 1; min-width: 0; }
.class-card strong { font-size: 1.1em; }

.soon-card { padding: 18px; display: flex; gap: 14px; align-items: flex-start; opacity: .85; }
.soon-card .ico { width: 42px; height: 42px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.soon-card .ico .i { width: 22px; height: 22px; }
.soon-card h3 { margin: 0 0 .2em; font-size: 1.05em; }
.soon-card p { margin: 0; color: var(--muted); font-size: .93em; }
.pill { display: inline-block; font-size: .72em; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; padding: .2em .65em; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }

.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.template-option { position: relative; }
.template-option input { position: absolute; opacity: 0; }
.template-option span {
  display: block; border: 2px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; height: 100%;
}
.template-option span b { display: block; }
.template-option span small { color: var(--muted); line-height: 1.3; display: block; margin-top: 2px; }
.template-option input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.template-option input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- timetable editor ---------- */
.tt-editor { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.tt-editor table { border-collapse: collapse; width: 100%; min-width: 640px; }
.tt-editor th { font-size: .8em; color: var(--muted); font-weight: 800; padding: 6px 4px; background: var(--surface-2); }
.tt-editor td { padding: 2px; border-top: 1px solid var(--line); }
.tt-editor input { width: 100%; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 6px 6px; font-size: .9em; outline: none; }
.tt-editor input:focus { border-color: var(--accent); background: var(--surface); }
.tt-editor .time { width: 66px; font-variant-numeric: tabular-nums; color: var(--muted); }
.tt-editor .n { font-weight: 800; color: var(--accent); text-align: center; width: 28px; }
.tt-editor .add { padding: 6px; text-align: left; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, #a8e6ff 0%, #d4f1c5 45%, #f9d8e8 100%); }
.login-card { width: min(400px, 100%); padding: 32px; }
.login-card h1 { margin: .5em 0 .2em; font-size: 1.6em; }
.login-card .btn { width: 100%; margin-top: .4em; padding: .8em; }

/* ---------- settings ---------- */
.settings-grid { display: grid; gap: 22px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }
.settings-grid .card { padding: 22px 24px; }
.settings-grid h2 { margin-top: 0; font-size: 1.2em; }
.steps { padding-left: 1.2em; margin: .6em 0 1em; }
.steps li { margin-bottom: .45em; }
code, .code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: .1em .4em;
}
.copy-row { display: flex; gap: 8px; align-items: stretch; margin: .6em 0; }
.copy-row input { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85em; }
.token-list { list-style: none; padding: 0; margin: 0; }
.token-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.token-list li .grow { flex: 1; min-width: 0; }
.notice { background: #e6f8f0; color: #0f6b47; padding: .8em 1em; border-radius: var(--radius-sm); margin: .6em 0; font-size: .95em; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .notice { background: #12392b; color: #8de0bd; }
  :root:not([data-theme="light"]) .error-box { background: #4a1d24; color: #ffb3ba; }
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10000;
  background: #1d2140; color: #fff; padding: .7em 1.2em; border-radius: 999px; font-weight: 700; box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease-out;
}
.toast.error { background: var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- image picker ---------- */
.media-dialog { width: min(900px, calc(100vw - 32px)); }
.media-dialog h2 { margin-bottom: .6em; }
.media-drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; cursor: pointer;
  display: grid; justify-items: center; gap: 4px; color: var(--muted); transition: border-color .15s, background .15s;
}
.media-drop .i.big { width: 34px; height: 34px; color: var(--accent); }
.media-drop b { color: var(--ink); }
.media-drop:hover, .media-drop.over { border-color: var(--accent); background: var(--accent-soft); }
.media-drop.busy { opacity: .6; pointer-events: none; }
.media-drop.busy b::after { content: " – lädt …"; }
.media-scope { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0 18px; font-weight: 700; font-size: .92em; }
.media-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.media-head .seg { margin-left: auto; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; max-height: 46vh; overflow: auto; }
.media-empty { grid-column: 1 / -1; padding: 18px; text-align: center; }
.media-item { position: relative; border-radius: 12px; overflow: hidden; background: var(--surface-2); aspect-ratio: 4 / 3; }
.media-thumb { border: none; padding: 0; width: 100%; height: 100%; cursor: pointer; background: none; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .15s; }
.media-thumb:hover img { transform: scale(1.05); }
.media-badge { position: absolute; left: 6px; top: 6px; font-size: 10.5px; font-weight: 800; padding: 1px 7px; border-radius: 999px; background: rgba(255,255,255,.9); color: #4b5072; pointer-events: none; }
.media-badge.lib { background: var(--accent); color: #fff; }
.media-actions { position: absolute; right: 6px; bottom: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.media-item:hover .media-actions, .media-item:focus-within .media-actions { opacity: 1; }
.media-actions button { border: none; border-radius: 999px; background: rgba(255,255,255,.95); font-size: 11px; font-weight: 800; padding: 4px 8px; cursor: pointer; display: grid; place-items: center; color: #1d2140; }
.media-actions button .i { width: 14px; height: 14px; }
.seg button:disabled { opacity: .45; cursor: default; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { border: 2px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-weight: 700; cursor: pointer; color: var(--ink); }
.seg button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* ---------- board previews & stacks ---------- */
.board-thumb iframe {
  position: absolute; left: 0; top: 0; width: 1440px; height: 810px; border: 0; pointer-events: none;
  transform: scale(var(--k, .19)); transform-origin: 0 0; background: transparent;
}
.board-card { position: relative; }
.board-card.dragging { opacity: .4; }
.dnd .board-card { cursor: grabbing; }
.board-meta .pill { flex: none; }
.stack { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 14px 16px 16px; margin-bottom: 18px; box-shadow: var(--shadow); }
.stack-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.stack-head .spacer { flex: 1; }
.stack-ico { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.stack-name { font: inherit; font-weight: 800; font-size: 1.1em; border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 3px 6px; min-width: 6ch; field-sizing: content; max-width: 50vw; color: var(--ink); }
.stack-name:hover, .stack-name:focus { border-color: var(--line); background: var(--surface-2); outline: none; }
.stack-row { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 260px); gap: 14px; overflow-x: auto; padding: 4px 2px 6px; border-radius: 16px; min-height: 120px; }
.stack-row .board-card { box-shadow: none; }
.new-card.small { min-height: 0; }
.drop-over { background: var(--accent-soft); outline: 2px dashed var(--accent); outline-offset: 4px; }
.section-sub { font-weight: 800; color: var(--muted); margin: 6px 0 10px; font-size: .95em; }
.stack-hint { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; font-size: .92em; }
.btn .i { width: 1em; height: 1em; }
