/* ==========================================================================
   SchuKom Heft-Viewer – Stylesheet
   --------------------------------------------------------------------------
   FARBEN/SCHRIFT AN DIE VERLAGSSEITE ANPASSEN: nur die Variablen direkt
   unter :root ändern (Primär-/Akzentfarbe, Hintergründe, Schrift, Rundungen).
   ========================================================================== */
:root {
  /* Markenfarben (Platzhalter – bitte mit den Hex-Werten von schukom.de abgleichen) */
  --c-primary: #1b6f8a;
  --c-primary-d: #14566b;
  --c-primary-l: #dff0f5;
  --c-accent: #f4a300;
  --c-ok: #2a9d5c;
  --c-danger: #d62839;
  --c-mine: #7b4fb3;

  --bg: #f4efe6;
  --surface: #fffdf8;
  --surface-2: #efe8db;
  --text: #243238;
  --muted: #6b7a80;
  --border: #d9d0bf;
  --work-bg: #cdc6b6;

  --radius: 14px;
  --radius-s: 9px;
  --font: "Nunito", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --shadow: 0 6px 22px rgba(30, 40, 45, .18);
  --ui: 1;                         /* Bedienelement-Skalierung (Einstellungen) */
  --tap: calc(54px * var(--ui));
  --top-h: calc(64px * var(--ui));
}
[data-theme="dark"] {
  --bg: #1d2428; --surface: #273036; --surface-2: #323d44; --text: #eef2f3; --muted: #a2b0b6;
  --border: #44525a; --work-bg: #11171a; --c-primary-l: #1f4452;
}
[data-theme="sepia"] {
  --bg: #efe4cf; --surface: #f8f0de; --surface-2: #e8dbc0; --work-bg: #b9ab8f;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); color: var(--text); background: var(--bg);
  font-size: calc(16px * var(--ui)); line-height: 1.4; -webkit-tap-highlight-color: transparent;
}
body.app { overflow: hidden; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg.ic { width: 1.4em; height: 1.4em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
i[data-icon] { display: inline-flex; }
.grow { flex: 1 1 auto; }
.logo-img { display: block; height: 36px; width: auto; }
.logo-text { font-weight: 800; font-size: 1.3rem; color: var(--c-primary); letter-spacing: .02em; }

/* ------------------------------------------------------------------ Buttons / Formulare */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em; text-decoration: none;
  min-height: 42px; padding: .5em 1.1em; border-radius: var(--radius-s); border: 2px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 700;
}
.btn:hover { border-color: var(--c-primary); }
.btn.primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.btn.primary:hover { background: var(--c-primary-d); }
.btn.danger { color: var(--c-danger); border-color: var(--c-danger); }
.btn.danger:hover { background: var(--c-danger); color: #fff; }
.btn.small { min-height: 34px; padding: .25em .7em; font-size: .9em; }
.btn.big { min-height: 52px; font-size: 1.1em; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
label.f { display: block; margin: 0 0 .9em; font-weight: 700; font-size: .92em; }
label.f > span.sub { display: block; font-weight: 400; color: var(--muted); font-size: .9em; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=search], select, textarea,
.auth input, .f input:not([type=checkbox]):not([type=file]):not([type=range]):not([type=color]) {
  display: block; width: 100%; margin-top: .3em; padding: .6em .75em; border: 2px solid var(--border);
  border-radius: var(--radius-s); background: var(--surface); font-weight: 400;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 3px solid color-mix(in srgb, var(--c-primary) 45%, transparent); outline-offset: 1px; }
textarea { min-height: 6em; resize: vertical; }
.check { display: flex; align-items: center; gap: .6em; font-weight: 600; margin: .4em 0; }
.check input { width: 1.3em; height: 1.3em; margin: 0; }
.row { display: flex; gap: .8em; flex-wrap: wrap; }
.row > * { flex: 1 1 8em; }
.msg { padding: .7em 1em; border-radius: var(--radius-s); margin: 0 0 1em; font-weight: 600; }
.msg.err { background: #fde8ea; color: #8b1523; }
.msg.ok { background: #e2f5ea; color: #1b6a3b; }
.hint { color: var(--muted); font-size: .9em; }

/* ------------------------------------------------------------------ Anmeldeseite */
body.auth-page { display: grid; place-items: center; min-height: 100%; background: linear-gradient(160deg, var(--c-primary-l), var(--bg) 60%); }
.auth { width: min(30rem, 92vw); padding: 2rem 0; }
.auth-card { background: var(--surface); border-radius: 22px; box-shadow: var(--shadow); padding: 2rem 2rem 1.6rem; }
.auth-logo { margin-bottom: 1rem; }
.auth h1 { margin: 0 0 1rem; font-size: 1.6rem; }
.auth .lead { margin-top: 0; color: var(--muted); }
.auth label { display: block; font-weight: 700; margin-bottom: .9em; }
.auth .btn { margin-top: .4em; }
.auth-foot { text-align: center; color: var(--muted); font-size: .85em; }

/* ------------------------------------------------------------------ Gerüst */
#app { height: 100%; display: flex; flex-direction: column; }
#topbar {
  height: var(--top-h); flex: none; display: flex; align-items: center; gap: .5rem; padding: 0 .8rem;
  background: var(--surface); border-bottom: 3px solid var(--c-primary); z-index: 40;
}
.brand { display: flex; align-items: center; margin-right: .4rem; text-decoration: none; }
.tbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em; min-width: calc(44px * var(--ui)); height: calc(46px * var(--ui));
  padding: 0 .8em; border: 2px solid transparent; border-radius: var(--radius-s); background: transparent; font-weight: 700; white-space: nowrap;
}
.tbtn.icon { padding: 0; width: calc(46px * var(--ui)); }
.tbtn:hover { background: var(--surface-2); }
.tbtn.on { background: var(--c-primary-l); border-color: var(--c-primary); color: var(--c-primary-d); }
#btnLibrary { flex: 0 1 auto; min-width: 0; max-width: 28vw; overflow: hidden; }
#heftTitle { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.pagenav, .zoomctl, .toptools, .brand, #btnSpread, #btnFull, #btnPanel, #btnUser { flex: none; }
.toptools { display: flex; align-items: center; gap: .15rem; margin: 0 .3rem; padding: 0 .5rem; border-left: 2px solid var(--border); border-right: 2px solid var(--border); }
.tbtn { position: relative; }
.tbtn .dot { position: absolute; right: 4px; top: 4px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--surface); }
.tbtn:disabled { opacity: .35; }
.pagenav, .zoomctl { display: flex; align-items: center; gap: .15rem; }
.pageinput { display: flex; align-items: center; gap: .35em; background: var(--surface-2); border-radius: var(--radius-s); padding: 0 .6em; height: calc(46px * var(--ui)); font-weight: 700; }
.pageinput input { width: 3.2em; text-align: center; border: 2px solid transparent; background: var(--surface); border-radius: 7px; padding: .2em .1em; font-weight: 800; margin: 0; }
.zlabel { min-width: 4.4em; font-variant-numeric: tabular-nums; }
#userName { max-width: 12vw; overflow: hidden; text-overflow: ellipsis; }

#work { flex: 1 1 auto; min-height: 0; display: flex; position: relative; }
#toolrail {
  flex: none; width: calc(76px * var(--ui)); background: var(--surface); border-right: 1px solid var(--border); z-index: 30;
  display: flex; flex-direction: column; align-items: center; gap: .35rem; padding: .6rem .3rem; overflow-y: auto; scrollbar-width: none;
}
body.toolbar-right #toolrail { order: 3; border-right: 0; border-left: 1px solid var(--border); }
body.toolbar-right #sidepanel { order: 2; }
#viewport {
  flex: 1 1 auto; min-width: 0; position: relative; overflow: auto; background: var(--work-bg); display: flex;
  touch-action: none; outline: none; scrollbar-width: thin; user-select: none; -webkit-user-select: none;
}
#stage { margin: auto; flex: none; display: flex; align-items: flex-start; gap: 0; padding: 16px; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 2rem; }

.tool {
  width: calc(62px * var(--ui)); min-height: calc(62px * var(--ui)); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 2px solid transparent; border-radius: var(--radius); background: transparent; font-size: .7em; font-weight: 800; position: relative; padding: 4px 2px;
}
.tool svg.ic { width: 1.9em; height: 1.9em; }
.tool:hover { background: var(--surface-2); }
.tool.on { background: var(--c-primary); color: #fff; border-color: var(--c-primary-d); box-shadow: 0 3px 10px rgba(27, 111, 138, .35); }
.tool.toggle.on { background: var(--c-primary-l); color: var(--c-primary-d); border-color: var(--c-primary); box-shadow: none; }
.tool.edit.on { background: var(--c-accent); border-color: #b97e00; color: #2a1d00; }
.tool:disabled { opacity: .35; }
.tool .dot { position: absolute; right: 8px; top: 7px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--surface); }
.tsep { width: 70%; height: 1px; background: var(--border); margin: .25rem 0; flex: none; }

/* Optionsleiste (schwebend unter der Oberkante der Arbeitsfläche) */
#optbar {
  position: absolute; z-index: 35; bottom: 14px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; justify-content: center; padding: .5rem .9rem;
  background: var(--surface); border: 2px solid var(--border); border-radius: 999px; box-shadow: var(--shadow);
}
body.toolbar-left #optbar { margin-left: calc(38px * var(--ui)); }
body.toolbar-right #optbar { margin-left: calc(-38px * var(--ui)); }
.optgrp { display: flex; align-items: center; gap: .4rem; }
.optgrp .ol { margin-right: .55em; font-size: .8em; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sw { width: calc(36px * var(--ui)); height: calc(36px * var(--ui)); border-radius: 50%; border: 3px solid var(--surface); box-shadow: 0 0 0 2px var(--border); cursor: pointer; padding: 0; }
.sw.on { box-shadow: 0 0 0 3px var(--c-primary); transform: scale(1.12); }
.sw.custom { background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red); position: relative; overflow: hidden; }
.sw.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; margin: 0; }
.wd { width: calc(42px * var(--ui)); height: calc(42px * var(--ui)); border-radius: 50%; border: 2px solid var(--border); background: var(--surface); display: grid; place-items: center; padding: 0; }
.wd.on { border-color: var(--c-primary); background: var(--c-primary-l); }
.wd i { display: block; border-radius: 50%; background: var(--text); }
.optbar-btn { height: calc(40px * var(--ui)); padding: 0 .9em; border-radius: 999px; border: 2px solid var(--border); background: var(--surface); font-weight: 700; display: inline-flex; align-items: center; gap: .4em; }
.optbar-btn:hover { border-color: var(--c-primary); }
.optbar-btn.on { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
input[type=range] { accent-color: var(--c-primary); width: 8em; }
.hintbar { font-weight: 700; color: var(--c-primary-d); }

/* ------------------------------------------------------------------ Seiten */
.pv { position: relative; flex: none; background: #fff; box-shadow: 0 8px 28px rgba(0, 0, 0, .28); overflow: hidden; }
.pv > * { position: absolute; left: 0; top: 0; }
.pv canvas { width: 100%; height: 100%; display: block; }
.pv .pv-canvas { z-index: 1; }
.pv .pv-foil { z-index: 1; mix-blend-mode: multiply; pointer-events: none; }
.pv .pv-loes { z-index: 2; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.pv .ink-h { z-index: 3; mix-blend-mode: multiply; opacity: .72; pointer-events: none; }
.pv .ink-p { z-index: 4; pointer-events: none; }
.pv .pv-hot { z-index: 5; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.pv .pv-draw { z-index: 6; inset: 0; width: 100%; height: 100%; pointer-events: none; touch-action: none; }
.pv .pv-edit { z-index: 7; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.pv .pv-ribbon { z-index: 8; left: auto; right: 4%; top: 0; width: calc(34px * var(--ui)); height: calc(58px * var(--ui)); pointer-events: none; }
body[data-tool="pen"] .pv-draw, body[data-tool="hl"] .pv-draw, body[data-tool="eraser"] .pv-draw, body[data-tool="text"] .pv-draw, body[data-tool="select"] .pv-draw { pointer-events: auto; }
body[data-tool="select"] .pv-draw { cursor: default; }
.pv .sel-box { z-index: 9; pointer-events: none; border: 2px dashed var(--c-primary); border-radius: 6px; background: rgba(27, 111, 138, .07); }
.pv .sel-del { position: absolute; right: -10px; top: -10px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: var(--c-danger); color: #fff; display: grid; place-items: center; padding: 0; pointer-events: auto; }
.pv .sel-del svg.ic { width: 13px; height: 13px; }
.pv .rs-handle { position: absolute; z-index: 21; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: var(--c-primary); color: #fff; display: grid; place-items: center; padding: 0; cursor: nwse-resize; touch-action: none; box-shadow: 0 1px 4px rgba(0, 0, 0, .35); }
.pv .rs-handle svg.ic { width: 13px; height: 13px; stroke-width: 2.6; transform: scaleX(-1); }
.pv .sel-rs { right: -10px; bottom: -10px; left: auto; top: auto; pointer-events: auto; }
body[data-tool="pen"] .pv-draw, body[data-tool="hl"] .pv-draw { cursor: crosshair; }
body[data-tool="eraser"] .pv-draw { cursor: cell; }
body[data-tool="text"] .pv-draw { cursor: text; }
body[data-tool="hand"] #viewport { cursor: grab; }
body[data-tool="hand"] #viewport.panning { cursor: grabbing; }
body.editing .pv-edit { pointer-events: auto; }
body.editing .pv-draw { pointer-events: none !important; }
body.editing.place #viewport { cursor: crosshair; }

.pv-text-input {
  position: absolute; z-index: 20; min-width: 6em; background: rgba(255, 255, 255, .92); border: 2px dashed var(--c-primary); border-radius: 6px;
  padding: 2px 6px; font-weight: 700; resize: none; overflow: hidden; white-space: pre; line-height: 1.2; outline: none; user-select: text; -webkit-user-select: text;
}

/* Lösungen */
.loes { position: absolute; }
.loes .loes-body { position: absolute; inset: 0; display: none; pointer-events: auto; cursor: pointer; overflow: hidden; border-radius: 4px; animation: pop .22s ease-out; }
.loes.open .loes-body { display: block; }
.loes .loes-body.txt { display: none; align-items: center; justify-content: center; text-align: center; padding: .3em .5em; font-weight: 800; background: #fff6c8; color: #14502c; border: 2px solid #3aa86a; box-shadow: 0 2px 8px rgba(0, 0, 0, .18); white-space: pre-wrap; line-height: 1.15; }
.loes.open .loes-body.txt { display: flex; }
.loes .loes-body img { width: 100%; height: 100%; object-fit: contain; display: block; }
.loes .loes-body canvas { width: 100%; height: 100%; display: block; background: #fff; }
.loes .loes-body.crop { border: 2px solid #3aa86a; box-shadow: 0 2px 10px rgba(0, 0, 0, .22); }
.loes-mark {
  position: absolute; right: 3px; top: 3px; width: calc(24px * var(--ui)); height: calc(24px * var(--ui)); border-radius: 50%; border: 2px solid #fff;
  background: var(--c-ok); color: #fff; display: grid; place-items: center; padding: 0; pointer-events: auto; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); z-index: 2;
  opacity: .42; transition: opacity .15s;
}
.loes-mark:hover, .loes-mark:focus-visible { opacity: 1; }
.loes-mark svg.ic { width: 13px; height: 13px; stroke-width: 3; }
.loes.open .loes-mark { background: #7d8c93; }
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }

/* Hotspots / Links */
.hot { position: absolute; pointer-events: auto; display: grid; place-items: center; cursor: pointer; border-radius: 10px; border: 2px solid transparent; transition: background .15s, border-color .15s; }
.hot:hover, .hot:focus-visible { background: rgba(27, 111, 138, .14); border-color: var(--c-primary); outline: none; }
.hot .hot-ic {
  width: calc(42px * var(--ui)); height: calc(42px * var(--ui)); border-radius: 50%; background: var(--c-primary); color: #fff; display: grid; place-items: center;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .35); border: 3px solid #fff; transition: transform .15s;
}
.hot:hover .hot-ic { transform: scale(1.1); }
.hot .hot-ic svg.ic { width: 55%; height: 55%; stroke-width: 2.4; }
.hot.mine .hot-ic { background: var(--c-mine); }
.hot .hot-lbl { position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, -4px); background: #222; color: #fff; font-size: .78rem; font-weight: 700; padding: 3px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; opacity: 0; transition: opacity .15s; max-width: 18em; overflow: hidden; text-overflow: ellipsis; z-index: 3; }
.hot:hover .hot-lbl { opacity: 1; }
.hide-links .pv-hot { display: none; }

/* Redaktion */
.ed-box { position: absolute; border: 2px dashed; border-radius: 4px; pointer-events: auto; cursor: move; touch-action: none; }
.ed-box.loes { border-color: var(--c-ok); background: rgba(42, 157, 92, .16); }
.ed-box.hot { border-color: var(--c-primary); background: rgba(27, 111, 138, .16); display: block; }
.ed-box.mine { border-color: var(--c-mine); background: rgba(123, 79, 179, .16); }
.ed-box.sel { border-style: solid; box-shadow: 0 0 0 3px rgba(244, 163, 0, .8); }
.ed-box .ed-tag { position: absolute; left: 0; top: 0; transform: translateY(-100%); font-size: .72rem; font-weight: 800; background: #222; color: #fff; padding: 1px 6px; border-radius: 4px 4px 0 0; white-space: nowrap; pointer-events: none; }
.ed-handle { position: absolute; width: 18px; height: 18px; background: var(--c-accent); border: 2px solid #fff; border-radius: 50%; touch-action: none; }
.ed-handle.nw { left: -10px; top: -10px; cursor: nwse-resize; } .ed-handle.ne { right: -10px; top: -10px; cursor: nesw-resize; }
.ed-handle.sw { left: -10px; bottom: -10px; cursor: nesw-resize; } .ed-handle.se { right: -10px; bottom: -10px; cursor: nwse-resize; }
.ed-new { position: absolute; border: 2px solid var(--c-accent); background: rgba(244, 163, 0, .2); pointer-events: none; }

/* Lesezeichen-Band */
.ribbon-svg { width: 100%; height: 100%; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .35)); }

/* ------------------------------------------------------------------ Lupe & Fokus */
#lens {
  position: absolute; z-index: 50; touch-action: none; cursor: move; pointer-events: none; border-radius: 50%; border: 6px solid var(--c-primary);
  box-shadow: 0 10px 34px rgba(0, 0, 0, .45), inset 0 0 0 3px rgba(255, 255, 255, .6); overflow: hidden; background: #fff;
}
#lens.rect { border-radius: 18px; }
#lens canvas { width: 100%; height: 100%; display: block; pointer-events: none; }
.lens-ui { position: absolute; z-index: 51; display: flex; gap: 4px; background: var(--surface); border: 2px solid var(--c-primary); border-radius: 999px; padding: 3px; box-shadow: var(--shadow); touch-action: none; }
.lens-ui button { width: calc(38px * var(--ui)); height: calc(38px * var(--ui)); border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; padding: 0; }
.lens-ui button:hover { background: var(--surface-2); }
.lens-ui .lz { align-self: center; font-weight: 800; min-width: 2.6em; text-align: center; font-size: .9em; }
body[data-tool="lens"] #lens { pointer-events: auto; }
.lens-grip { position: absolute; z-index: 52; width: 34px; height: 34px; border-radius: 50%; background: var(--c-accent); border: 3px solid #fff; cursor: nwse-resize; touch-action: none; box-shadow: 0 2px 8px rgba(0, 0, 0, .4); display: grid; place-items: center; color: #2a1d00; }
.lens-grip svg.ic { width: 16px; height: 16px; }

#spot { position: absolute; z-index: 45; pointer-events: none; inset: 0; overflow: hidden; }
body[data-tool="focus"] #spot .spot-win { pointer-events: auto; }
body[data-tool="focus"] #spot .spot-win .ed-handle { pointer-events: auto; }
#spot .spot-win .ed-handle { pointer-events: none; }
#spot .spot-win { pointer-events: none; position: absolute; border: 3px solid var(--c-accent); border-radius: 12px; box-shadow: 0 0 0 4000px rgba(10, 14, 16, .78); cursor: move; touch-action: none; }
#spot .spot-x { position: absolute; width: 40px; height: 40px; right: -14px; top: -14px; border-radius: 50%; border: 3px solid #fff; background: var(--c-danger); color: #fff; display: grid; place-items: center; padding: 0; pointer-events: auto; }

/* ------------------------------------------------------------------ Seitenleiste */
#sidepanel { flex: none; width: min(360px, 42vw); background: var(--surface); border-left: 1px solid var(--border); display: flex; flex-direction: column; z-index: 30; min-height: 0; }
body.toolbar-right #sidepanel { border-left: 0; border-right: 1px solid var(--border); }
#paneltabs { display: flex; border-bottom: 2px solid var(--border); flex: none; }
#paneltabs button { flex: 1; border: 0; background: transparent; padding: .55em .2em; font-weight: 800; font-size: .78em; display: flex; flex-direction: column; align-items: center; gap: 2px; border-bottom: 4px solid transparent; margin-bottom: -2px; color: var(--muted); }
#paneltabs button.on { color: var(--c-primary-d); border-bottom-color: var(--c-primary); background: var(--c-primary-l); }
#panelbody { flex: 1 1 auto; overflow-y: auto; padding: .8rem; min-height: 0; }
.pn-h { margin: 0 0 .6rem; font-size: 1.05em; font-weight: 800; }
.pn-sec { margin-bottom: 1.2rem; }
.thumbs { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: .7rem; }
.thumb-gap { visibility: hidden; }
.thumb { position: relative; border: 3px solid transparent; border-radius: 8px; background: var(--surface-2); padding: 4px; cursor: pointer; text-align: center; font-weight: 800; font-size: .8em; }
.thumb canvas { width: 100%; height: auto; display: block; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); aspect-ratio: 595/842; }
.thumb.cur { border-color: var(--c-primary); background: var(--c-primary-l); }
.thumb .tb { position: absolute; top: 8px; right: 8px; display: flex; gap: 3px; }
.thumb .tb span { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; color: #fff; border: 1.5px solid #fff; }
.thumb .tb svg.ic { width: 11px; height: 11px; stroke-width: 3; }
.li { display: flex; align-items: center; gap: .6rem; padding: .55rem .6rem; border: 2px solid var(--border); border-radius: var(--radius-s); margin-bottom: .5rem; background: var(--surface); }
.li.click { cursor: pointer; }
.li.click:hover { border-color: var(--c-primary); }
.li .li-t { flex: 1; min-width: 0; font-weight: 700; }
.li .li-t small { display: block; font-weight: 400; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .li-ic { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: var(--c-primary); flex: none; }
.li .li-ic.mine { background: var(--c-mine); } .li .li-ic.ok { background: var(--c-ok); } .li .li-ic.acc { background: var(--c-accent); color: #2a1d00; }
.iconbtn { width: 38px; height: 38px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; padding: 0; color: var(--muted); flex: none; }
.iconbtn:hover { background: var(--surface-2); color: var(--text); }
.iconbtn.del:hover { color: var(--c-danger); }
.empty-note { color: var(--muted); text-align: center; padding: 1.2rem .5rem; }
.seg { display: inline-flex; border: 2px solid var(--border); border-radius: var(--radius-s); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: .5em .9em; font-weight: 700; }
.seg button.on { background: var(--c-primary); color: #fff; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .55rem 0; border-bottom: 1px solid var(--border); }
.set-row > span { font-weight: 700; }
.set-row.stack { flex-direction: column; align-items: stretch; gap: .35rem; }
.set-row.stack .seg { display: flex; }
.set-row.stack .seg button { flex: 1 1 0; min-width: 0; padding: .5em .4em; white-space: normal; hyphens: manual; overflow-wrap: break-word; line-height: 1.15; }
.set-row small { display: block; color: var(--muted); font-weight: 400; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; inset: 0; margin: 0; cursor: pointer; z-index: 2; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: .15s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.switch input:checked + i { background: var(--c-primary); }
.switch input:checked + i::after { transform: translateX(22px); }

/* ------------------------------------------------------------------ Bibliothek */
#libraryRoot:empty { display: none; }
.library { position: fixed; inset: 0; z-index: 80; background: var(--bg); overflow: auto; display: flex; flex-direction: column; }
.lib-top { display: flex; align-items: center; gap: 1rem; padding: .8rem 1.4rem; background: var(--surface); border-bottom: 3px solid var(--c-primary); position: sticky; top: 0; z-index: 2; }
.lib-top h1 { margin: 0; font-size: 1.4rem; flex: 1; }
.lib-body { padding: 1.4rem; max-width: 1200px; width: 100%; margin: 0 auto; }
.lib-series { margin-bottom: 2rem; }
.lib-series h2 { margin: 0 0 .8rem; font-size: 1.25rem; color: var(--c-primary-d); }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1.2rem; }
.card { background: var(--surface); border-radius: 18px; box-shadow: 0 3px 12px rgba(0, 0, 0, .12); border: 3px solid transparent; padding: .8rem; text-align: left; display: flex; flex-direction: column; gap: .5rem; transition: transform .12s, border-color .12s; }
.card:hover { transform: translateY(-3px); border-color: var(--c-primary); }
.card .cov { aspect-ratio: 595/842; background: var(--surface-2); border-radius: 8px; overflow: hidden; display: grid; place-items: center; color: var(--muted); }
.card .cov img, .card .cov canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .ct { font-weight: 800; line-height: 1.2; }
.card .cs { color: var(--muted); font-size: .85em; }
.card.inactive { opacity: .6; }
.card .cov { position: relative; }
.card.outdated { opacity: .82; }
.card.outdated .cov img, .card.outdated .cov canvas { filter: grayscale(.65) opacity(.7); }
.ribbon { position: absolute; top: 20px; left: -44px; width: 165px; transform: rotate(-38deg); background: #b3261e; color: #fff; text-align: center; font-weight: 800; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; padding: 3px 0; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); pointer-events: none; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--c-accent); color: #2a1d00; font-size: .75rem; font-weight: 800; }

/* ------------------------------------------------------------------ Modal / Toast */
.modal-bg { position: fixed; inset: 0; z-index: 100; background: rgba(15, 22, 26, .55); display: grid; place-items: center; padding: 1rem; }
.modal { background: var(--surface); border-radius: 20px; box-shadow: 0 20px 60px rgba(0, 0, 0, .4); width: min(34rem, 100%); max-height: 94vh; display: flex; flex-direction: column; }
.modal.wide { width: min(60rem, 100%); }
.modal.full { width: min(96vw, 1400px); height: 92vh; max-height: 92vh; }
.modal-h { display: flex; align-items: center; gap: .6rem; padding: .9rem 1.2rem; border-bottom: 1px solid var(--border); }
.modal-h h2 { margin: 0; font-size: 1.2rem; flex: 1; }
.modal-b { padding: 1.1rem 1.2rem; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-b.media { padding: 0; background: #111; display: grid; place-items: center; }
.modal-b.media iframe, .modal-b.media img, .modal-b.media video { width: 100%; height: 100%; border: 0; object-fit: contain; background: #222; display: block; }
.modal-b.media audio { width: min(34rem, 90%); margin: 3rem 0; }
.modal-f { display: flex; justify-content: flex-end; gap: .6rem; padding: .8rem 1.2rem; border-top: 1px solid var(--border); flex-wrap: wrap; }
.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: .5rem; }
.progress > i { display: block; height: 100%; width: 0; background: var(--c-primary); transition: width .15s; }
#toastRoot { position: fixed; z-index: 200; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; align-items: center; pointer-events: none; }
.toast { background: #1d2a30; color: #fff; padding: .7em 1.2em; border-radius: 999px; font-weight: 700; box-shadow: var(--shadow); animation: pop .2s; max-width: 90vw; }
.toast.err { background: var(--c-danger); }

/* ------------------------------------------------------------------ Verwaltung */
body.admin-page { background: var(--bg); overflow: auto; height: auto; min-height: 100%; }
.admin-top { display: flex; align-items: center; gap: 1rem; padding: .7rem 1.4rem; background: var(--surface); border-bottom: 3px solid var(--c-primary); position: sticky; top: 0; z-index: 10; }
.admin-top h1 { margin: 0; font-size: 1.3rem; }
.admin-main { max-width: 1100px; margin: 0 auto; padding: 1.2rem; }
.admin-tabs { display: flex; gap: .4rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.admin-tabs button { border: 2px solid var(--border); background: var(--surface); padding: .6em 1.2em; border-radius: 999px; font-weight: 800; }
.admin-tabs button.on { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: 0 2px 10px rgba(0, 0, 0, .08); padding: 1.1rem 1.3rem; margin-bottom: 1.2rem; }
.panel h2 { margin: 0 0 .8rem; font-size: 1.15rem; }
table.t { width: 100%; border-collapse: collapse; }
table.t th, table.t td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.t .acts { text-align: right; white-space: nowrap; }
table.t .mini-cov { width: 44px; height: 62px; border-radius: 4px; background: var(--surface-2); object-fit: cover; display: block; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78rem; font-weight: 800; background: var(--surface-2); }
.pill.ok { background: #d9f2e3; color: #17603a; } .pill.off { background: #fde1e4; color: #8b1523; } .pill.adm { background: #ffe9b8; color: #6b4500; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; flex-wrap: wrap; }
.admin-head h2 { margin: 0; }
pre.code { background: #1d2a30; color: #e9f1f4; padding: 1rem; border-radius: var(--radius-s); overflow: auto; font-size: .82rem; line-height: 1.45; }

/* ------------------------------------------------------------------ Kleine Bildschirme / Vollbild */
@media (max-width: 900px) {
  .lbl, .tlbl { display: none; }
  #sidepanel { position: absolute; right: 0; top: 0; bottom: 0; width: min(380px, 92vw); box-shadow: var(--shadow); }
  #zoomLabel { display: none; }
  #btnFitWidth, #btnFull { display: none; }
}
@media print { body.app { display: none; } }

/* Tooltips: 5 s voll sichtbar, danach 80 % transparent; bei Mausover wieder voll */
.tip { position: fixed; z-index: 100000; max-width: 22rem; padding: .45em .8em; border-radius: 8px; background: #1d2a30; color: #fff; font: 600 .85rem/1.3 system-ui, sans-serif; box-shadow: 0 4px 14px rgba(0, 0, 0, .3); opacity: 1; transition: opacity .6s; pointer-events: auto; }
.tip.faded { opacity: .2; }
.tip.faded:hover { opacity: 1; transition-duration: .1s; }

/* Niedrige Bildschirme (Laptop): Werkzeugleiste etwas kompakter, damit alles sichtbar ist */
@media (max-height: 820px) {
  #toolrail { gap: .1rem; padding: .35rem .3rem; }
  .tool { min-height: calc(52px * var(--ui)); }
  .tool svg.ic { width: 1.6em; height: 1.6em; }
}

/* Ladeanzeige */
#loader { position: absolute; inset: 0; z-index: 60; display: grid; place-items: center; pointer-events: none; background: rgba(240, 236, 228, .72); backdrop-filter: blur(2px); transition: opacity .3s; }
#loader.hide { opacity: 0; }
.ld-card { min-width: min(340px, 80vw); padding: 1.6rem 2rem; background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); text-align: center; }
.ld-t { font-weight: 800; font-size: 1.15em; margin-top: .9rem; }
.ld-s { color: var(--muted); font-size: .9em; margin-top: .5rem; min-height: 1.2em; font-variant-numeric: tabular-nums; }
.ld-bar { height: 14px; margin-top: .9rem; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.ld-bar i { display: block; height: 100%; width: 0; background: var(--c-primary); border-radius: 999px; transition: width .25s ease; }
.ld-spin, .pv.loading::after { width: 46px; height: 46px; border-radius: 50%; border: 5px solid var(--c-primary-l); border-top-color: var(--c-primary); animation: ldspin .9s linear infinite; }
.ld-spin { margin: 0 auto; }
.pv.loading::after { content: ""; position: absolute; left: 50%; top: 50%; margin: -23px 0 0 -23px; z-index: 1; }
@keyframes ldspin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ld-spin, .pv.loading::after { animation-duration: 2.5s; } }

.auth-alt { text-align: center; margin-top: 1rem; font-size: .9rem; }
.checklist { max-height: 14rem; overflow: auto; border: 2px solid var(--border); border-radius: var(--radius-s); padding: .4rem .7rem; margin-top: .3rem; }
.checklist .check { display: flex; margin: .35rem 0; }
.checklist .check.dim { opacity: .6; }

/* Doppelseite: Falz-Schatten in der Mitte wie bei einem aufgeschlagenen Heft */
.pv-l::before, .pv-r::before { content: ""; position: absolute; top: 0; bottom: 0; width: 9%; z-index: 2; pointer-events: none; }
.pv-l::before { right: 0; background: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(0, 0, 0, .07) 55%, rgba(0, 0, 0, .26)); }
.pv-r::before { left: 0; background: linear-gradient(to left, rgba(0, 0, 0, 0), rgba(0, 0, 0, .07) 55%, rgba(0, 0, 0, .26)); }
.pv-l { box-shadow: -6px 8px 28px rgba(0, 0, 0, .28); }
.pv-r { box-shadow: 6px 8px 28px rgba(0, 0, 0, .28); }

/* Kopfleiste bei Laptop-Breiten: etwas enger, damit der Hefttitel Platz behält */
@media (max-width: 1500px) {
  #topbar { gap: .3rem; }
  .tbtn { padding: 0 .6em; }
  .tbtn.icon { padding: 0; }
  .zlabel { min-width: 3.6em; }
  #btnFitWidth { display: none; }
  #btnLibrary { min-width: 6.5rem; }
}

/* Kopfleiste kompakter: kleineres Logo, kleinere Beschriftungen, zusammengefasste Zoom-Knöpfe */
#topbar .logo-img { height: 24px; }
#topbar .logo-text { font-size: 1.1rem; }
.auth-logo { display: flex; justify-content: center; align-items: center; margin-bottom: .4rem; }
.auth-logo .logo-img { height: 40px; margin: 0 auto; }
.toptools .tbtn { font-size: .82rem; padding: 0 .55em; gap: .35em; }
.toptools .tbtn svg.ic { width: 1.25em; height: 1.25em; }
.zoomctl { gap: 0; background: var(--surface-2); border-radius: var(--radius-s); padding: 0 2px; }
.zoomctl .tbtn { height: calc(40px * var(--ui)); }
.zoomctl .tbtn.icon { width: calc(34px * var(--ui)); min-width: 0; }
.zoomctl .zlabel { min-width: 3.2em; padding: 0 .2em; font-size: .9rem; }
#topbar { gap: .3rem; }
.pagenav .tbtn.icon { width: calc(34px * var(--ui)); min-width: 0; }

.mail-hint { display: flex; flex-direction: column; gap: .3rem; margin: -.3rem 0 .8rem; }
.mail-hint-item { display: flex; align-items: center; justify-content: space-between; gap: .6rem; text-align: left; padding: .45em .8em; border: 2px dashed var(--c-primary); border-radius: var(--radius-s); background: var(--c-primary-l); color: var(--c-primary-d); font-weight: 700; cursor: pointer; }
.mail-hint-item kbd { font: 700 .75rem system-ui, sans-serif; padding: .1em .5em; border-radius: 5px; border: 1px solid var(--c-primary); background: #fff; }

/* ------------------------------------------------------------------ Neuauflage / Statistik / Hinweise */
.modal p { white-space: pre-line; }
.edition-box { border: 2px dashed var(--c-primary); border-radius: 14px; padding: .8rem 1rem; margin: .8rem 0; background: color-mix(in srgb, var(--c-primary) 6%, var(--surface)); }
.hint.err { color: #b3261e; font-weight: 700; }
.hint.okc { color: #17603a; font-weight: 700; }
.stat-filter { align-items: flex-end; }
.stat-quick { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; padding-bottom: .4rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.tile { background: var(--surface-2); border-radius: 14px; padding: .8rem 1rem; display: flex; flex-direction: column; }
.tile b { font-size: 2rem; line-height: 1.1; color: var(--c-primary-d); }
.tile span { font-weight: 700; }
.tile small { color: var(--muted); }
.bars { display: flex; gap: .5rem; align-items: flex-end; height: 190px; overflow-x: auto; padding: .5rem 0 0; border-bottom: 2px solid var(--border); }
.bar-col { display: flex; flex-direction: column; align-items: center; min-width: 38px; height: 100%; justify-content: flex-end; font-size: .72rem; color: var(--muted); }
.bar-pair { display: flex; align-items: flex-end; gap: 2px; height: 140px; width: 100%; justify-content: center; }
.bar-pair i, .legend i { display: inline-block; width: 12px; border-radius: 3px 3px 0 0; }
.b1 { background: var(--c-primary); } .b2 { background: var(--c-accent); }
.legend { font-size: .85rem; color: var(--muted); }
.legend i { width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 2px; }

.lib-foot { position: sticky; bottom: 0; margin: 0 0 0 auto; width: max-content; display: flex; align-items: center; gap: .45em; padding: .35rem .8rem; font-size: .8rem; color: var(--muted); background: color-mix(in srgb, var(--surface) 85%, transparent); border-radius: 12px 0 0 0; cursor: pointer; }
.lib-foot input { width: 1.05em; height: 1.05em; margin: 0; }
.lib-foot:hover { color: var(--text); }
.library .lib-body { flex: 1 0 auto; }

/* ------------------------------------------------------------------ Kopfzeile: links Logo + Heft · Mitte Navigation + Darstellung · rechts Funktionen */
#topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: .6rem; }
.tb-left, .tb-center, .tb-right { display: flex; align-items: center; gap: .3rem; min-width: 0; }
.tb-left { justify-content: flex-start; }
.tb-center { justify-content: center; gap: .55rem; }
.tb-right { justify-content: flex-end; }
.tb-left .brand { margin-right: .3rem; }
.tb-right .toptools { margin: 0 .3rem 0 0; padding: 0 .5rem 0 0; border-left: 0; }
.tb-left #btnLibrary { max-width: 100%; }
@media (max-width: 1250px) {
  #topbar { gap: .3rem; }
  .tb-center { gap: .3rem; }
  .toptools .tlbl { display: none; }
  .tb-right #userName { display: none; }
}

/* ------------------------------------------------------------------ Blätterpfeile am Seitenrand */
#vpWrap { flex: 1 1 auto; min-width: 0; position: relative; display: flex; }
#vpWrap > #viewport { flex: 1 1 auto; }
.flip {
  position: absolute; top: 18%; bottom: 18%; width: 58px; z-index: 12; display: grid; place-items: center; padding: 0;
  background: transparent; border: 0; border-radius: 14px; color: #1b2a33; cursor: pointer; opacity: .38; transition: opacity .15s, background .15s;
}
.flip-l { left: 6px; } .flip-r { right: 14px; }
.flip svg { width: 46px; height: 46px; stroke-width: 2.8; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 3px rgba(255, 255, 255, .6)); }
.flip:hover, .flip:focus-visible { opacity: .85; background: rgba(255, 255, 255, .28); }
.flip:active { opacity: 1; }
.flip[hidden] { display: none; }
body.editing .flip { display: none; }
[data-theme="dark"] .flip { color: #f0f4f6; }
[data-theme="dark"] .flip svg { filter: drop-shadow(0 0 3px rgba(0, 0, 0, .6)); }

/* Optionsleiste: dezent transparent, bei Mouseover voll sichtbar */
#optbar { opacity: .5; transition: opacity .15s; }
#optbar:hover, #optbar:focus-within { opacity: 1; }
