/* Lesari — standalone PDF reader. */
:root { color-scheme: light; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
[hidden] { display: none !important; }

.kl {
  --kl-accent: #2B2F36;
  --kl-on-accent: #fff;
  --kl-bg: #ECE9E4;
  --kl-ink: #1F2328;
  --kl-muted: #5F6670;
  --kl-card: #fff;
  --kl-bar-h: 56px;
  background: var(--kl-bg); color: var(--kl-ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
.kl-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- Top bar ---------- */
.kl-bar {
  flex: none; height: var(--kl-bar-h); display: flex; align-items: center; gap: 4px;
  padding: 0 max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: var(--kl-accent); color: var(--kl-on-accent);
  box-shadow: 0 1px 6px rgba(0, 0, 0, .25); z-index: 5;
}
.kl-title { flex: 1 1 auto; min-width: 0; margin: 0 8px; font-size: 1rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kl-tools { display: flex; align-items: center; gap: 2px; flex: none; }
.kl-btn {
  flex: none; width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.kl-btn:hover { background: rgba(255, 255, 255, .14); }
.kl-btn:focus-visible, .kl-nav:focus-visible, .kl-pager__in:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.kl-btn[aria-expanded="true"] { background: rgba(255, 255, 255, .22); }
.kl[data-mode="blad"] .kl-ico-blad, .kl[data-mode="skjal"] .kl-ico-skjal { display: none; }
.kl-ico-blad, .kl-ico-skjal { display: inline-flex; }
.kl-show-s { display: none; }

.kl-pager { flex: none; display: flex; align-items: center; gap: 6px; font-size: .9375rem; font-variant-numeric: tabular-nums; margin-right: 4px; }
.kl-pager__in {
  width: 3.4em; height: 34px; text-align: center; font: inherit; color: var(--kl-ink);
  background: #fff; border: 0; border-radius: 8px; padding: 0 2px; -moz-appearance: textfield; appearance: textfield;
}
.kl-pager__in::-webkit-outer-spin-button, .kl-pager__in::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.kl-pager__of { white-space: nowrap; opacity: .9; }

/* ---------- Overflow menu (small screens) ---------- */
.kl-menu {
  position: absolute; top: calc(var(--kl-bar-h) + 4px); right: 8px; z-index: 8; min-width: 180px;
  background: var(--kl-card); border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); padding: 6px; display: grid;
}
.kl-menu button { text-align: left; font: inherit; padding: 12px 14px; border: 0; background: none; border-radius: 8px; color: var(--kl-ink); cursor: pointer; }
.kl-menu button:hover { background: var(--kl-bg); }

/* ---------- Search ---------- */
.kl-search {
  position: absolute; top: calc(var(--kl-bar-h) + 4px); right: 8px; z-index: 7; width: min(380px, calc(100vw - 16px));
  max-height: calc(100% - var(--kl-bar-h) - 16px); display: flex; flex-direction: column;
  background: var(--kl-card); border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); padding: 12px;
}
.kl-search__form { display: flex; gap: 8px; }
.kl-search__form input { flex: 1; min-width: 0; height: 42px; font: inherit; padding: 0 12px; border: 1px solid #C9CDD3; border-radius: 8px; }
.kl-search__go { height: 42px; padding: 0 16px; font: inherit; font-weight: 600; border: 0; border-radius: 8px; background: var(--kl-accent); color: var(--kl-on-accent); cursor: pointer; }
.kl-search__status { margin: 10px 2px 0; font-size: .875rem; color: var(--kl-muted); }
.kl-search__status:empty { display: none; }
.kl-search__list { list-style: none; margin: 8px 0 0; padding: 0; overflow: auto; }
.kl-search__list button { width: 100%; text-align: left; font: inherit; font-size: .875rem; line-height: 1.4; padding: 8px 10px; border: 0; border-radius: 8px; background: none; color: var(--kl-ink); cursor: pointer; }
.kl-search__list button:hover { background: var(--kl-bg); }
.kl-search__list b { display: block; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--kl-muted); }
.kl-search__list mark { background: #FFE58A; color: inherit; border-radius: 2px; }

/* ---------- Loading ---------- */
.kl-progress { flex: none; height: 3px; background: transparent; }
.kl-progress span { display: block; height: 100%; width: 0; background: #F2B233; transition: width .2s; }
.kl-progress.is-done { visibility: hidden; }
.kl-status { margin: auto; padding: 24px; text-align: center; color: var(--kl-muted); max-width: 32em; }
.kl-status a { color: var(--kl-ink); font-weight: 600; }
.kl-noscript { padding: 24px; text-align: center; }

/* ---------- Main ---------- */
.kl-main { flex: 1 1 auto; min-height: 0; position: relative; overflow: auto; display: flex; flex-direction: column; outline: 0; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }

/* Scroll mode */
.kl-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 16px 10px calc(28px + env(safe-area-inset-bottom)); margin: 0 auto; min-width: min-content; }
.kl-page { position: relative; flex: none; background: var(--kl-card); box-shadow: 0 1px 4px rgba(0, 0, 0, .18); }
.kl-page canvas, .kl-leaf canvas { display: block; width: 100%; height: 100%; }
.kl-page__n { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #B5B9C0; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.kl-page.is-ready .kl-page__n { display: none; }

/* Flip mode */
.kl-stage { flex: 1 1 auto; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; overflow: auto; touch-action: pan-y pinch-zoom; }
.kl-spread { display: flex; margin: auto; padding: 12px; gap: 0; transition: opacity .12s ease, transform .16s ease; }
.kl-spread.is-out-next { opacity: 0; transform: translateX(-18px); }
.kl-spread.is-out-prev { opacity: 0; transform: translateX(18px); }
.kl-leaf { flex: none; background: var(--kl-card); box-shadow: 0 2px 14px rgba(0, 0, 0, .25); }
.kl-leaf + .kl-leaf { box-shadow: 0 2px 14px rgba(0, 0, 0, .25), inset 12px 0 14px -12px rgba(0, 0, 0, .28); }
.kl-nav {
  position: fixed; top: calc(50% + var(--kl-bar-h) / 2); transform: translateY(-50%); z-index: 3;
  width: 46px; height: 64px; border: 0; border-radius: 12px; background: rgba(31, 35, 40, .55); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; -webkit-tap-highlight-color: transparent;
}
.kl-nav:hover { background: rgba(31, 35, 40, .8); }
.kl-nav[disabled] { opacity: 0; pointer-events: none; }
.kl-nav--prev { left: max(8px, env(safe-area-inset-left)); }
.kl-nav--next { right: max(8px, env(safe-area-inset-right)); }

/* ---------- Toast ---------- */
.kl-toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 9;
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 24px);
  background: #1F2328; color: #fff; padding: 10px 14px; border-radius: 999px; font-size: .9375rem; box-shadow: 0 6px 24px rgba(0, 0, 0, .3);
}
.kl-toast button { font: inherit; font-weight: 600; color: #F2B233; background: none; border: 0; padding: 4px 2px; cursor: pointer; white-space: nowrap; }

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
  .kl { --kl-bar-h: 52px; }
  .kl-hide-s { display: none; }
  .kl-show-s { display: inline-flex; }
  .kl-title { font-size: .9375rem; margin: 0 4px; }
  .kl-pager__of { font-size: .875rem; }
  .kl-pages { padding: 10px 6px calc(24px + env(safe-area-inset-bottom)); gap: 8px; }
  .kl-spread { padding: 6px; }
  /* The page number moves to a pill at the bottom, so the title gets the top bar. */
  .kl-pager {
    position: fixed; left: 50%; bottom: calc(12px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 4; margin: 0;
    background: rgba(31, 35, 40, .88); color: #fff; padding: 5px 12px 5px 6px; border-radius: 999px; box-shadow: 0 4px 16px rgba(0, 0, 0, .3);
  }
  .kl-pager__in { height: 32px; }
  /* Flip buttons sit beside the pill instead of on top of the page. */
  .kl-nav { top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); transform: none; width: 52px; height: 42px; border-radius: 999px; background: rgba(31, 35, 40, .88); }
  .kl-nav[disabled] { opacity: .35; }
  .kl-stage { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
  .kl-pages { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .kl-toast { bottom: calc(66px + env(safe-area-inset-bottom)); }
}
.kl--embed .kl-title { margin-left: 12px; }

@media print { .kl-bar, .kl-nav, .kl-toast, .kl-search, .kl-menu, .kl-progress { display: none !important; } }
@media (prefers-reduced-motion: reduce) { .kl-spread { transition: none; } }
