:root {
  --blue: #1b5bbf; --blue-dark: #154a9c; --blue-soft: #e8f0fc; --ink: #1c1c1e; --muted: #6b7280; --line: #e3e6ea; --bg: #f3f4f6;
  --danger: #c62828; --ok: #1b7f3b; --radius: 10px; --top: 52px;
  --c-blue: #2f6fd6; --c-green: #2e9e5b; --c-red: #d64545; --c-orange: #e8892b; --c-purple: #8454c9; --c-teal: #1f9aa8; --c-brown: #8a6340; --c-gray: #6b7280;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); -webkit-text-size-adjust: 100%; }
h1, h2 { font-weight: 600; margin: 0; }
a { color: var(--blue); }
.ic { width: 22px; height: 22px; flex: none; vertical-align: middle; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.sep { width: 1px; height: 24px; background: rgba(128,128,128,.35); margin: 0 6px; flex: none; }
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-weight: 500; padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; }
.btn:hover { background: #f7f8fa; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent; color: inherit; cursor: pointer; }
.icon-btn:hover { background: rgba(0,0,0,.07); }
.icon-btn.light { color: #fff; } .icon-btn.light:hover { background: rgba(255,255,255,.16); }
.icon-btn.danger:hover { color: var(--danger); }
.icon-btn:disabled, .tool:disabled { opacity: .35; cursor: default; }
.flip .ic { transform: scaleX(-1); }
.notice { margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.notice-error { background: #fdecea; color: #8c1d18; } .notice-ok { background: #e7f5ec; color: #14532d; }
input, select { font: inherit; padding: 9px 11px; border: 1px solid #cfd4da; border-radius: 8px; background: #fff; color: var(--ink); min-width: 0; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }

/* pasek gorny */
.topbar { display: flex; align-items: center; gap: 4px; height: var(--top); padding: 0 12px; padding-top: env(safe-area-inset-top); background: var(--blue); color: #fff; position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 600; font-size: 17px; }
.top-link { display: inline-flex; align-items: center; gap: 6px; color: #fff; text-decoration: none; padding: 8px 10px; border-radius: 8px; }
.top-link:hover { background: rgba(255,255,255,.16); }
.who { margin: 0 6px; opacity: .9; }
.topbar form { margin: 0; }

/* logowanie */
.login-page { display: grid; place-items: center; min-height: 100%; background: linear-gradient(160deg, #e8f0fc, #f6f8fb 55%); padding: 16px; }
.login-card { width: min(380px, 100%); background: #fff; border-radius: 16px; padding: 28px; box-shadow: 0 10px 40px rgba(20,50,100,.14); text-align: center; }
.login-logo { width: 56px; height: 56px; margin: 0 auto 8px; border-radius: 14px; background: var(--blue); color: #fff; display: grid; place-items: center; }
.login-logo .ic { width: 30px; height: 30px; }
.login-card h1 { font-size: 24px; } .login-card p { margin: 4px 0 16px; }
.login-form { display: grid; gap: 12px; text-align: left; }
.login-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.login-form label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.login-form .btn { justify-content: center; padding: 11px; }

/* biblioteka */
.library { max-width: 1180px; margin: 0 auto; padding: 24px 16px 60px; }
.library-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.library-head h1 { font-size: 26px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 22px; }
.empty { grid-column: 1 / -1; color: var(--muted); padding: 40px 0; text-align: center; }
.nb-card { display: flex; flex-direction: column; gap: 8px; }
.nb-cover { position: relative; aspect-ratio: 3 / 4; border-radius: 6px 12px 12px 6px; overflow: hidden; display: flex; align-items: flex-end; text-decoration: none; color: #fff; box-shadow: 0 6px 18px rgba(0,0,0,.18), inset 8px 0 0 rgba(0,0,0,.14); transition: transform .12s; }
.nb-cover:hover { transform: translateY(-3px); }
.nb-thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .0; }
.nb-cover { background-image: none; }
.nb-title { position: relative; width: 100%; padding: 28px 12px 12px 20px; font-weight: 600; font-size: 17px; line-height: 1.25; background: linear-gradient(transparent, rgba(0,0,0,.35)); overflow-wrap: anywhere; }
.nb-meta { display: flex; align-items: center; gap: 2px; }
.nb-info { flex: 1; min-width: 0; display: grid; font-size: 14px; } .nb-info strong, .nb-info span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .nb-info span { font-size: 12.5px; }
.cover-blue { background: var(--c-blue); } .cover-green { background: var(--c-green); } .cover-red { background: var(--c-red); } .cover-orange { background: var(--c-orange); }
.cover-purple { background: var(--c-purple); } .cover-teal { background: var(--c-teal); } .cover-brown { background: var(--c-brown); } .cover-gray { background: var(--c-gray); }

/* dialogi i panele */
.dialog { border: 0; border-radius: 14px; padding: 22px; width: min(440px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dialog::backdrop { background: rgba(20,24,30,.45); }
.dialog h2 { font-size: 20px; margin-bottom: 14px; } .dialog p { margin: 0 0 14px; color: #3d434b; }
.dialog label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.choices { border: 0; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; } .choices legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 6px; float: left; width: 100%; }
.swatch-choice, .paper-choice { margin: 0 !important; cursor: pointer; display: inline-flex !important; align-items: center; }
.swatch-choice input, .paper-choice input { position: absolute; opacity: 0; }
.swatch { display: block; width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px #cbd0d6; }
.swatch-choice input:checked + .swatch { box-shadow: 0 0 0 3px var(--blue); }
.paper-choice { flex-direction: column; gap: 4px; font-size: 12px; } .paper-choice em { font-style: normal; color: var(--ink); }
.paper-sample { display: block; width: 58px; height: 70px; border: 1px solid #cbd0d6; border-radius: 4px; background-color: #fff; }
.paper-choice input:checked + .paper-sample { box-shadow: 0 0 0 3px var(--blue); }
.paper-grid { background-image: linear-gradient(#dbe3ec 1px, transparent 1px), linear-gradient(90deg, #dbe3ec 1px, transparent 1px); background-size: 10px 10px; }
.paper-lines { background-image: linear-gradient(#cfd8e3 1px, transparent 1px); background-size: 100% 11px; }
.paper-dots { background-image: radial-gradient(#b8c3d1 1px, transparent 1.2px); background-size: 10px 10px; }
.paper-blank { background-image: none; }
.panel { background: #fff; border-radius: 12px; padding: 18px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.06); overflow-x: auto; }
.panel h2 { font-size: 18px; margin-bottom: 12px; }
.table { width: 100%; border-collapse: collapse; } .table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; } .table th { font-size: 13px; color: var(--muted); font-weight: 500; }
.inline-form { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; margin: 0; } .inline-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

/* edytor */
.editor-page { overflow: hidden; background: #dfe3e8; overscroll-behavior: none; }
.editor { display: flex; flex-direction: column; height: 100dvh; }
.editor-top { position: relative; flex: none; gap: 2px; }
.nb-name { font-size: 15px; font-weight: 500; max-width: 18vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0 10px 0 4px; opacity: .95; }
.tools { display: flex; align-items: center; gap: 2px; background: rgba(255,255,255,.12); border-radius: 10px; padding: 3px; overflow-x: auto; scrollbar-width: none; }
.tool { display: grid; place-items: center; width: 40px; height: 36px; border: 0; background: transparent; color: #fff; border-radius: 8px; cursor: pointer; flex: none; }
.tool:hover { background: rgba(255,255,255,.18); } .tool.active { background: #fff; color: var(--blue); } .tool[aria-pressed="true"] { background: rgba(255,255,255,.28); }
.save-state { font-size: 13px; opacity: .9; margin: 0 8px; white-space: nowrap; } .save-state.dirty { opacity: 1; } .save-state.err { color: #ffd2cf; font-weight: 600; }
.menu { position: relative; } .menu > summary { list-style: none; } .menu > summary::-webkit-details-marker { display: none; }
.menu-body { position: absolute; right: 0; top: 46px; min-width: 230px; background: #fff; color: var(--ink); border-radius: 12px; box-shadow: 0 12px 36px rgba(0,0,0,.25); padding: 8px; z-index: 40; display: grid; gap: 2px; }
.menu-body button { display: flex; align-items: center; gap: 8px; font: inherit; text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: inherit; } .menu-body button:hover { background: #f1f3f6; } .menu-body .danger { color: var(--danger); }
.menu-title { font-size: 12px; color: var(--muted); padding: 4px 10px; } .menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; } .menu-body hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.options { flex: none; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 7px 12px; background: #fff; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.options .sep { background: var(--line); }
.colors, .widths { display: flex; gap: 8px; align-items: center; }
.color { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px #c7ccd2; cursor: pointer; padding: 0; flex: none; } .color.active { box-shadow: 0 0 0 3px var(--blue); }
.color-custom { display: grid; place-items: center; width: 28px; height: 28px; margin: 0; } .color-custom input { width: 28px; height: 28px; padding: 0; border: 0; background: none; cursor: pointer; }
.width { display: grid; place-items: center; width: 34px; height: 34px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; flex: none; } .width:hover { background: #f1f3f6; } .width.active { background: var(--blue-soft); }
.width span { display: block; border-radius: 50%; background: #333; }
.body { position: relative; flex: 1; min-height: 0; display: flex; }
.sidebar { width: 210px; flex: none; background: #f6f7f9; border-right: 1px solid var(--line); overflow-y: auto; padding: 14px 12px 80px; transition: margin .18s; }
.sidebar.hidden { margin-left: -210px; }
.pages { display: grid; gap: 14px; justify-items: center; }
.page-item { display: grid; gap: 4px; justify-items: center; text-decoration: none; color: var(--muted); font-size: 13px; width: 100%; }
.page-thumb { display: block; width: 100%; aspect-ratio: 1000 / 1414; background-color: #fff; border: 2px solid transparent; outline: 1px solid #d2d6dc; border-radius: 3px; overflow: hidden; }
.page-thumb img { width: 100%; height: 100%; display: block; object-fit: cover; }
.page-item.current .page-thumb { border-color: var(--blue); } .page-item.current .page-num { color: var(--blue); font-weight: 600; }
.page-add { display: grid; place-items: center; align-content: center; gap: 4px; width: 100%; aspect-ratio: 1000 / 1414; background: #eceef2; border: 0; border-radius: 6px; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; } .page-add:hover { background: #e2e5ea; }
.stage { position: relative; flex: 1; min-width: 0; overflow: auto; -webkit-overflow-scrolling: touch; padding: 16px; overscroll-behavior: contain; }
.sheet { position: relative; margin: 0 auto; background: #fff; box-shadow: 0 3px 16px rgba(0,0,0,.22); }
.layer { position: absolute; left: 0; top: 0; }
#live { touch-action: none; cursor: crosshair; }
#live.eraser { cursor: cell; }
.pager { position: absolute; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 2px; background: rgba(28,32,40,.86); color: #fff; padding: 4px 8px; border-radius: 999px; z-index: 15; font-size: 14px; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.3); }
.pager .icon-btn { width: 36px; height: 36px; } .pager .sep { background: rgba(255,255,255,.3); } #pager-text { min-width: 64px; text-align: center; }
.backdrop { display: none; }

@media (max-width: 820px) {
  .nb-name { display: none; } .save-state { display: none; }
  .sidebar { position: absolute; z-index: 30; left: 0; top: 0; bottom: 0; width: min(78vw, 240px); margin-left: 0; box-shadow: 4px 0 24px rgba(0,0,0,.25); transform: translateX(0); transition: transform .18s; }
  .sidebar.hidden { margin-left: 0; transform: translateX(-105%); box-shadow: none; }
  .backdrop.show { display: block; position: absolute; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .stage { padding: 8px; } .options { justify-content: flex-start; }
  .library { padding-top: 16px; } .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
}
@media (pointer: coarse) { .tool { width: 44px; height: 40px; } .icon-btn { width: 44px; height: 44px; } }

.size-choice { margin: 0 !important; cursor: pointer; display: inline-flex !important; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; }
.size-choice input { position: absolute; opacity: 0; } .size-choice em { font-style: normal; color: var(--ink); }
.size-sample { display: block; border: 1px solid #aeb5bd; border-radius: 3px; background: #fff; width: 40px; height: 56px; }
.size-a4l { width: 56px; height: 40px; } .size-letter { width: 44px; height: 57px; } .size-square { width: 48px; height: 48px; } .size-wide { width: 64px; height: 36px; } .size-tall { width: 30px; height: 64px; }
.size-choice input:checked + .size-sample { box-shadow: 0 0 0 3px var(--blue); }
.size-custom { display: flex; align-items: center; gap: 6px; padding: 6px 10px 4px; } .size-custom input { width: 74px; padding: 7px 8px; } .size-custom .btn { padding: 7px 12px; }
.zoom-level { min-width: 52px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: #fff; font: inherit; font-size: 13px; cursor: pointer; font-variant-numeric: tabular-nums; } .zoom-level:hover { background: rgba(255,255,255,.16); }
