/* Ištraukos reader — the book on a quiet stage, one floating tool strip below it */
:root{
  --stage:transparent; --ink:#24201c; --muted:#6f685e; --line:#e4e0da;
  --accent:#7a2e2a; --fs-bg:#2b2826;
  --tool-bg:rgba(255,255,255,.94); --tool-ink:#3a3530; --tool-hover:rgba(36,32,28,.07); --tool-on:rgba(122,46,42,.11);
  --pop-bg:#fffefc; --frame:#e1ddd7;
  --ui:"Work Sans",system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;
}
*{box-sizing:border-box}
[hidden]{display:none!important}
html,body{height:100%;margin:0}
body{background:transparent;color:var(--ink);font:14px/1.3 var(--ui);overflow:hidden}
#app{position:relative;height:100%;display:flex;flex-direction:column;background:var(--stage);overflow:hidden}
#app > *{position:relative;z-index:1}

/* background picture (Skaitytuvas → Fonas) */
#app > #bgPic{position:absolute;inset:0;z-index:0;background-position:center;background-size:cover;background-repeat:no-repeat;pointer-events:none}

/* thin light grey frame, only when the reader sits inside another page */
.in-frame #app.frame{border:1px solid var(--frame);border-radius:10px;overflow:hidden}
.fs #app.frame{border:0;border-radius:0}

/* fullscreen: dark room unless the book has its own background */
.fs:not(.has-bg-page) #app{background:var(--fs-bg)}

#hiddenNote{margin:0;padding:6px 12px;background:#fff3cf;color:#5f4a00;font-size:13px;text-align:center}

#app > #stageWrap{flex:1;min-height:0;position:relative;overflow:hidden}
/* #stage scrolls when zoomed in, so the side arrows, logo and pop-ups stay put */
#stage{position:absolute;inset:0;overflow:hidden;display:flex;padding:12px 8px}
#stageWrap.zoomed #stage{overflow:auto;padding:24px;cursor:grab;-webkit-user-select:none;user-select:none}
#stageWrap.zoomed #stage.panning,#stageWrap.zoomed #stage.panning .plink{cursor:grabbing}
#bookHolder{transition:transform .45s ease;flex:none;position:relative;margin:auto}
.shadow #bookHolder{filter:drop-shadow(0 6px 14px rgba(0,0,0,.22))}
.rounded .pg{border-radius:7px}
/* stack of pages beside the book */
.edge{position:absolute;top:3px;bottom:3px;pointer-events:none;
  background:repeating-linear-gradient(to right,#fdfcf9 0 1px,#d6d0c5 1px 2px)}
#edgeL{border-radius:3px 0 0 3px;box-shadow:inset -2px 0 3px rgba(0,0,0,.12)}
#edgeR{border-radius:0 3px 3px 0;box-shadow:inset 2px 0 3px rgba(0,0,0,.12)}
.rounded #edgeL{border-radius:7px 0 0 7px}.rounded #edgeR{border-radius:0 7px 7px 0}

/* clickable areas on pages: blue with a white ring, so they show on light and dark pages alike */
.plink{position:absolute;z-index:2;border-radius:3px;cursor:pointer;background:rgba(31,111,235,0);transition:background .15s,box-shadow .15s,transform .15s}
.linkhint .plink{background:rgba(31,111,235,.1);box-shadow:0 0 0 1px rgba(255,255,255,.85),0 0 0 2.5px rgba(31,111,235,.7);animation:lp 1.1s ease-in-out .5s 2}
.plink:hover,.plink:focus-visible{background:rgba(31,111,235,.2);box-shadow:0 0 0 1.5px #fff,0 0 0 3.5px #1f6feb;outline:none}
@keyframes lp{50%{background:rgba(31,111,235,.28);box-shadow:0 0 0 1.5px #fff,0 0 0 5px rgba(31,111,235,.85)}}
/* a link with its own picture (e.g. a "buy" button): the picture is the hint */
.plink.pic,.linkhint .plink.pic{background:none;box-shadow:none;animation:none;border-radius:0}
.plink.pic img{width:100%;height:100%;object-fit:contain;display:block;pointer-events:none;-webkit-user-drag:none}
.plink.pic:hover,.plink.pic:focus-visible{background:none;box-shadow:none;transform:scale(1.04);filter:brightness(1.06)}
.plink.pic:focus-visible{outline:2px solid #1f6feb;outline-offset:2px}
.hit{position:absolute;z-index:1;background:rgba(255,214,0,.45);mix-blend-mode:multiply;border-radius:2px;pointer-events:none}

/* corners: the logo and the buy button (stacked when they share a corner) */
.corner{position:absolute;z-index:3;display:flex;flex-direction:column;gap:8px;max-width:calc(50% - 24px)}
.corner.tl{top:10px;left:10px;align-items:flex-start}.corner.tr{top:10px;right:10px;align-items:flex-end}
.corner.bl{bottom:10px;left:10px;align-items:flex-start;flex-direction:column-reverse}.corner.br{bottom:10px;right:10px;align-items:flex-end;flex-direction:column-reverse}
.logo{display:block;opacity:.92;line-height:0}
.logo img{height:100%;width:auto;display:block}
.logo.s{height:26px}.logo.m{height:40px}.logo.l{height:60px}
a.logo:hover{opacity:1}
/* buy button: a pill with a cart, or the uploaded picture */
.buy{display:inline-flex;align-items:center;gap:7px;max-width:100%;padding:0 14px;border-radius:999px;background:var(--accent);color:#fff;text-decoration:none;
  font:600 13px/1 var(--ui);white-space:nowrap;box-shadow:0 2px 10px rgba(0,0,0,.18);transition:transform .15s,box-shadow .15s,filter .15s}
.buy span{overflow:hidden;text-overflow:ellipsis}
.buy .i{width:18px;height:18px;stroke-width:1.9}
.buy.s{height:30px;font-size:12px;padding:0 11px}.buy.m{height:38px}.buy.l{height:46px;font-size:15px;padding:0 18px}
.buy:hover,.buy:focus-visible{transform:translateY(-1px);box-shadow:0 4px 16px rgba(0,0,0,.24);filter:brightness(1.08)}
.buy.pic{padding:0;background:none;border-radius:0;box-shadow:none;line-height:0}
.buy.pic img{height:100%;width:auto;display:block}
.buy.pic:hover{box-shadow:none}

/* pages */
.pg{background:#fff;overflow:hidden;position:relative}
.pg canvas{display:block;width:100%;height:100%}
.pg.blank{background:#fff}
.pg:not(.done)::before{content:"";position:absolute;left:50%;top:50%;width:22px;height:22px;margin:-11px;border:2px solid #ddd;border-top-color:#999;border-radius:50%;animation:sp 1s linear infinite}
/* binding: soft shadow along the spine side of each page */
.pg::after{content:"";position:absolute;top:0;bottom:0;width:7%;pointer-events:none}
.pg.--left::after{right:0;background:linear-gradient(to left,rgba(0,0,0,.16),rgba(0,0,0,0))}
.pg.--right::after{left:0;background:linear-gradient(to right,rgba(0,0,0,.16),rgba(0,0,0,0))}
.single .pg::after{width:3%;background:linear-gradient(to right,rgba(0,0,0,.12),rgba(0,0,0,0));left:0;right:auto}

/* icons */
.i{width:20px;height:20px;fill:none;stroke:currentColor;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round;display:block;flex:none}

/* round arrows beside the book */
.side{position:absolute;top:50%;transform:translateY(-50%);z-index:3;width:44px;height:44px;border:0;border-radius:50%;padding:0;
  display:grid;place-items:center;background:var(--tool-bg);color:var(--tool-ink);cursor:pointer;
  box-shadow:0 1px 2px rgba(0,0,0,.08),0 4px 14px rgba(0,0,0,.12);opacity:.88;transition:opacity .15s,transform .15s}
.side .i{width:22px;height:22px;stroke-width:2}
.side:hover{opacity:1;transform:translateY(-50%) scale(1.06)}
#prevSide{left:12px} #nextSide{right:12px}
.side:disabled{opacity:0;pointer-events:none}

#loading{pointer-events:none;position:absolute;inset:0;display:flex;align-items:center;justify-content:center;gap:10px;color:var(--muted);z-index:4}
.spin{width:20px;height:20px;border:2px solid var(--line);border-top-color:var(--accent);border-radius:50%;animation:sp 1s linear infinite}
@keyframes sp{to{transform:rotate(360deg)}}

/* page thumbnails */
#thumbs{display:flex;gap:8px;overflow-x:auto;padding:10px 12px 2px;justify-content:safe center;scrollbar-width:thin}
#thumbs .th{flex:none;width:54px;border:2px solid transparent;border-radius:5px;padding:0;background:#fff;cursor:pointer;position:relative;
  box-shadow:0 1px 3px rgba(0,0,0,.2);overflow:hidden;transition:transform .12s}
#thumbs .th:hover{transform:translateY(-2px)}
#thumbs .th canvas{display:block;width:100%;height:auto}
#thumbs .th span{position:absolute;bottom:2px;right:3px;font-size:10px;color:#666;background:rgba(255,255,255,.85);padding:0 3px;border-radius:3px}
#thumbs .th.on{border-color:var(--accent)}

/* the tool strip */
#bar{flex:none;display:flex;justify-content:center;padding:8px 8px calc(10px + env(safe-area-inset-bottom,0px))}
.tools{display:flex;align-items:center;gap:2px;padding:4px;border-radius:14px;background:var(--tool-bg);
  box-shadow:0 1px 2px rgba(0,0,0,.06),0 4px 18px rgba(0,0,0,.10);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);max-width:100%}
.tb{position:relative;width:38px;height:38px;flex:none;display:grid;place-items:center;padding:0;border:0;border-radius:10px;
  background:transparent;color:var(--tool-ink);cursor:pointer;transition:background .12s,color .12s}
.tb:hover{background:var(--tool-hover)}
.tb[aria-pressed="true"]{background:var(--tool-on);color:var(--accent)}
.tb:disabled{opacity:.3;cursor:default;background:transparent}
.sep{width:1px;height:22px;background:rgba(0,0,0,.1);margin:0 5px;flex:none}
#counter{height:38px;min-width:72px;padding:0 10px;border:0;border-radius:10px;background:transparent;color:var(--tool-ink);cursor:pointer;
  font:500 13px var(--ui);font-variant-numeric:tabular-nums;white-space:nowrap;position:relative}
#counter:hover{background:var(--tool-hover)}
#gotoForm{display:flex}
#gotoInput{width:72px;height:32px;margin:3px 0;border:1px solid var(--line);border-radius:8px;text-align:center;font:500 14px var(--ui);color:var(--ink);background:#fff;-moz-appearance:textfield}
#gotoInput::-webkit-outer-spin-button,#gotoInput::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}
button:focus-visible,a:focus-visible,input:focus-visible{outline:2px solid var(--accent);outline-offset:2px}

/* small labels above the tools */
@media (hover:hover){
  [data-tip]::after{content:attr(data-tip);position:absolute;left:50%;bottom:calc(100% + 9px);transform:translate(-50%,3px);
    background:#24201c;color:#fff;font:500 12px/1 var(--ui);padding:6px 8px;border-radius:6px;white-space:nowrap;
    opacity:0;pointer-events:none;transition:opacity .12s,transform .12s;z-index:10}
  [data-tip]:hover::after,[data-tip]:focus-visible::after{opacity:1;transform:translate(-50%,0)}
  .pop [data-tip]::after{bottom:auto;top:calc(100% + 8px)}
  #shareBtn[aria-pressed="true"]::after,#searchBtn[aria-pressed="true"]::after{display:none}
}

/* pop-ups: search and share */
.pop{position:absolute;z-index:6;background:var(--pop-bg);border-radius:14px;padding:12px;
  box-shadow:0 1px 3px rgba(0,0,0,.08),0 14px 40px rgba(0,0,0,.18);color:var(--ink)}
#searchBox{top:10px;right:10px;width:min(340px,calc(100% - 20px));max-height:calc(100% - 20px);display:flex;flex-direction:column}
#searchForm{display:flex;gap:4px;align-items:center}
#searchQ{flex:1;min-width:0;font:15px var(--ui);color:var(--ink);background:#fff;border:1px solid var(--line);border-radius:9px;padding:8px 10px}
#searchInfo{margin:8px 2px 4px;font-size:12px;color:var(--muted)}
#searchInfo:empty{display:none}
#searchResults{list-style:none;margin:0;padding:0;overflow:auto;min-height:0}
#searchResults button{display:block;width:100%;text-align:left;border:0;border-bottom:1px solid var(--line);background:none;color:var(--ink);padding:8px 4px;font:13px/1.35 var(--ui);cursor:pointer}
#searchResults button:hover{background:rgba(0,0,0,.035)}
#searchResults strong{color:var(--accent);margin-right:4px}
#searchResults mark{background:rgba(255,214,0,.55);color:inherit}
#searchResults .more{color:var(--muted);font-size:12px}

#shareBox{left:50%;bottom:10px;transform:translateX(-50%);width:min(460px,calc(100% - 20px));max-height:calc(100% - 20px);overflow:auto}
.pop-head{display:flex;align-items:center;justify-content:space-between;margin:-2px -2px 8px 2px}
.pop-head strong{font:600 15px var(--ui)}
.share-body{display:flex;gap:14px;align-items:flex-start}
.qr{flex:none;width:132px;height:132px;padding:6px;background:#fff;border:1px solid var(--line);border-radius:10px}
.qr canvas,.qr img{width:100%!important;height:100%!important;display:block}
.share-side{flex:1;min-width:0;display:flex;flex-direction:column;gap:10px}
.share-link{display:flex;align-items:center;gap:4px;border:1px solid var(--line);border-radius:10px;padding:2px 2px 2px 10px;background:#fff}
.share-link input{flex:1;min-width:0;border:0;background:none;font:13px var(--ui);color:var(--ink);padding:6px 0;outline:none}
.share-link .tb{width:34px;height:34px}
.share-ways{display:flex;flex-wrap:wrap;gap:6px}
.way{display:inline-flex;align-items:center;gap:6px;padding:7px 10px;border:0;border-radius:9px;background:rgba(36,32,28,.05);color:var(--ink);
  font:500 13px var(--ui);text-decoration:none;cursor:pointer}
.way:hover{background:rgba(36,32,28,.1)}
.way .i{width:18px;height:18px}
.share-side .muted{margin:0;font-size:12px;color:var(--muted)}
.copied{color:#1f6b3b!important}

/* fullscreen without a background of its own: dark tools */
.fs:not(.has-bg-page){--tool-bg:rgba(48,45,42,.92);--tool-ink:#eee8df;--tool-hover:rgba(255,255,255,.08);--tool-on:rgba(255,255,255,.14);--accent:#e3a49b}
.fs:not(.has-bg-page) #counter{color:#d9d2c8}

@media (max-width:640px){
  .side{display:none}
  #first,#last,#layoutBtn{display:none}
  .tb{width:36px;height:36px}
  #counter{min-width:58px;padding:0 6px}
  .sep{margin:0 3px}
  .logo.m{height:30px}.logo.l{height:40px}
  .buy.m,.buy.l{height:34px;font-size:12px;padding:0 12px}.buy.pic.m,.buy.pic.l{padding:0}
}
@media (max-width:440px){
  .share-body{flex-direction:column;align-items:center}
  .share-side{width:100%}
}
@media (prefers-reduced-motion:reduce){#bookHolder{transition:none}.spin,.pg::before,.linkhint .plink{animation:none}.side,.tb,[data-tip]::after{transition:none}}
