/* READING A TALE (A2 renewal, 2026-11). Boards: Tale.dc.html TAL-1…3 (reading, a balloon opened, the
   last leaf) and Rooms.dc.html RMS-7 (the end of a tale: E-1 read again / the next tale, E-2 the last
   tale, E-3 a guest's free tale). Page: templates/comics/reader.html (standalone: the page IS the
   comic, no corner chrome). Behaviour: static/js/comics_reader.js (the book, the staff editor) and
   static/js/a2/tale.js (the strand, the forward pearl, the lens, the end). Flat
   (tests/test_stylesheets_are_flat.py). Prefix .tl-.

   NOT here: how a box is lettered. The boxes' type and layout are static/css/comics_lettering.css and
   static/js/comics_lettering.js (shared with the shelf's covers, tuned and pinned): this file places
   the page around them and never sets a property the lettering measures.

   The geometry is the board's at 1440x900: the bar 10px from the top, the page 1216x684 at y 76 (112px
   either side), the page-bead strand 46px under it, 94px under that. Fluid: the page takes the room
   the window gives it (--side, --top, --below), at the comic's own aspect (--arw/--arh, from its first
   page). */

/* ---- the dark page ------------------------------------------------------------------------- */
body.tl-body{margin:0;background:#14151A;overflow:hidden;overscroll-behavior:none}
.a2.tl{--c:226,84,108;--side:112px;--top:76px;--below:140px;--fw:60px;--W:100vw;--H:100vh;position:relative;height:100vh;height:100dvh;overflow:hidden;isolation:isolate;background:#14151A;color:#F4EFE6}
.tl :focus-visible{outline-color:#F4EFE6}

/* ---- the bar: the way back to the tales, the tale's name, the language it is lettered in ---- */
.tl-bar{position:absolute;z-index:8;left:58px;right:64px;top:10px;height:56px;display:flex;align-items:center;gap:22px}
.tl-bar .gb{flex:none;color:rgba(244,239,230,.66)}
.tl-bar .gb:hover{color:#fff}
.tl-bar h1{min-width:0;margin:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:800 21px/1.3 var(--fd);letter-spacing:-.01em;color:#F4EFE6}
/* TAL-1: the page is lettered in one language, chosen once and kept; no picking before the story. */
.tl-lg{flex:none;margin-left:auto;display:flex;align-items:center;gap:24px}
.tl-lg .qa{height:40px;font-size:16.5px;color:rgba(244,239,230,.6);background-image:linear-gradient(#F4EFE6,#F4EFE6)}
.tl-lg .qa:hover{color:#fff}
.tl-lg .qa[aria-pressed="true"]{color:#fff;background-size:100% 2px}
.tl-lg .qa[lang="fa"]{font-family:Vazirmatn,sans-serif;font-size:17.5px}
/* staff only: the editor's own words (Edit, Outline, View), quieter than the languages */
.tl-lg .qa.tl-tool{font-size:14px;letter-spacing:.04em;color:rgba(244,239,230,.5)}
.tl-lg .qa.tl-tool[aria-pressed="true"]{color:#F5C469}

/* ---- the book: the page, its strand under it -------------------------------------------------- */
.tl-bk{position:absolute;left:0;right:0;top:var(--top);bottom:0;display:flex;flex-direction:column;align-items:center;justify-content:center;transition:transform .7s cubic-bezier(.3,.9,.3,1)}
.tl-col{position:relative;flex:none;width:min(calc(var(--W) - 2 * var(--side)), calc((var(--H) - var(--top) - var(--below)) * var(--arw) / var(--arh)));padding-bottom:calc(var(--below) - 46px)}
@supports (height:100dvh){.a2.tl{--H:100dvh}}
.tl-st{position:relative;width:100%;aspect-ratio:var(--arw) / var(--arh);border-radius:6px;background:#1c1a17;box-shadow:0 30px 60px -30px rgba(0,0,0,.9);overflow:hidden;touch-action:pan-y pinch-zoom}
/* The stage keeps the comic's own type around the boxes (comics_lettering.css resets the rest):
   the page shell's Baloo 2 never reaches them. */
.tl-st.comic-lettering{font:400 16px/normal Inter,system-ui,sans-serif;letter-spacing:normal;color:#F4EFE6}

/* one leaf per page, and the closing leaf: the shown one in place, the others a step aside */
.tl-pg{position:absolute;inset:0;transition:transform .5s cubic-bezier(.3,.9,.3,1),opacity .35s,visibility 0s}
.tl-pg.tl-nx{transform:translateX(5%);opacity:0;visibility:hidden;pointer-events:none;transition:transform .5s cubic-bezier(.3,.9,.3,1),opacity .35s,visibility 0s .5s}
.tl-pg.tl-pv{transform:translateX(-5%);opacity:0;visibility:hidden;pointer-events:none;transition:transform .5s cubic-bezier(.3,.9,.3,1),opacity .35s,visibility 0s .5s}
.tl-pg.tl-still{transition:none}
.tl-pg .sheet{position:absolute;inset:0;overflow:hidden}
.tl-pg .stage{position:absolute;left:0;top:0;transform-origin:0 0}
.tl-pg .stage img{position:absolute;left:0;top:0;max-width:none;user-select:none;-webkit-user-drag:none}

/* TAL-2: press any balloon and it is read to you in all three. The story stays where it is. The
   box is the lettering's own (sized in page pixels: --k is the stage's scale). */
.tl:not(.editing) .tl-st .box{cursor:pointer;border-radius:calc(8px / var(--k, 1));transition:background-color .2s}
.tl:not(.editing) .tl-st .box:hover{background-color:rgba(196,48,74,.1)}
.tl:not(.editing) .tl-st .box[aria-expanded="true"]{background-color:rgba(196,48,74,.16)}
.tl .tl-st .box:focus-visible{outline:calc(3px / var(--k, 1)) solid #1C39BB;outline-offset:calc(2px / var(--k, 1))}

.tl-ln{position:absolute;z-index:6;left:0;top:0;width:380px;max-width:calc(100% - 24px);margin:0;padding:14px 18px 15px;border-radius:16px;background:rgba(16,18,26,.95);color:#fff;box-shadow:0 20px 40px -20px rgba(0,0,0,.7);animation:a2-pop .22s cubic-bezier(.3,1.4,.5,1)}
.tl-ln[hidden]{display:none}
.tl-ln:focus{outline:none}
.tl-ln:focus-visible{outline:2px solid #F4EFE6;outline-offset:2px}
.tl-ln b{display:block;font:700 19px/1.3 var(--fd)}
.tl-ln span{display:block;margin-top:7px;font:500 16.5px/1.4 var(--fb);color:rgba(255,255,255,.76)}
.tl-ln i{display:block;margin-top:8px;font:500 19px/1.6 Vazirmatn,sans-serif;font-style:normal;direction:rtl;text-align:right;color:#F5C469}
.tl-ln.tl-asks i{padding-right:52px}
.tl-ask{position:absolute;right:12px;bottom:12px;display:grid;place-items:center;width:40px;height:40px;border-radius:50%;background:#1C39BB;color:#fff;transition:transform .2s cubic-bezier(.3,1.6,.5,1)}
.tl-ask:hover{transform:scale(1.08)}
.tl-ask svg{width:20px;height:20px}

/* ---- the tale's own strand: a bead for each page; the pearl that turns the page is your place --- */
.tl-sd{position:relative;height:0;margin-top:46px}
.tl-th{position:absolute;left:0;right:0;top:0;height:2px;margin-top:-1px;background:rgba(226,84,108,.4)}
.tl-rl{position:absolute;left:0;top:0;width:calc(var(--at, 0) / max(1, var(--n1)) * 100%);height:2px;margin-top:-1px;background:rgb(var(--c));transition:width .6s cubic-bezier(.333,.667,.667,1)}
.tl-dots{position:absolute;left:0;right:0;top:0;height:0}
.tl-bd{position:absolute;top:0;left:calc(var(--i) / max(1, var(--n1)) * 100%);width:28px;height:28px;margin:-14px 0 0 -14px;display:grid;place-items:center;border-radius:50%}
.tl-bd i{display:block;width:12px;height:12px;border-radius:50%;background:#14151A;box-shadow:inset 0 0 0 2px rgb(var(--c));transition:background-color .3s,transform .3s cubic-bezier(.3,1.6,.5,1)}
.tl-bd.tl-read i{background:rgb(var(--c))}
.tl-bd:hover i{transform:scale(1.35)}
.tl-fw{position:absolute;z-index:4;top:0;left:calc(var(--at, 0) / max(1, var(--n1)) * 100%);width:0;height:0;transition:left .6s cubic-bezier(.333,.667,.667,1),opacity .3s}
.tl-fw.tl-back{transition:left .9s cubic-bezier(.333,.667,.667,1),opacity .3s}
.tl-fw button{position:absolute;left:calc(var(--fw) / -2);top:calc(var(--fw) / -2);width:var(--fw);height:var(--fw);border-radius:50%;display:block}
.tl-fw canvas{display:block;width:var(--fw);height:var(--fw);border-radius:50%;filter:drop-shadow(0 8px 8px rgba(20,42,140,.4));transition:transform .2s}
.tl-fw button:active canvas{transform:scale(.92)}
.tl-fw button::after{content:"";position:absolute;left:calc(var(--fw) * .35);top:calc(var(--fw) * .383);width:11px;height:11px;border-top:3.5px solid #fff;border-right:3.5px solid #fff;border-radius:2px;transform:rotate(45deg);pointer-events:none}
.tl-fw.tl-gone{opacity:0;pointer-events:none}
/* RMS-7: "Read again" under the first bead, where its result appears; it rolls the pearl back there */
.tl-again{position:absolute;left:-16px;top:26px;height:40px;font-size:17px;color:rgba(244,239,230,.75);background-image:linear-gradient(#F4EFE6,#F4EFE6)}
.tl-again:hover{color:#fff}
.tl-again[hidden]{display:none}
.tl-turn{display:none;margin:0;font:600 14px/1.3 var(--fb);color:rgba(244,239,230,.55);text-align:center}

/* ---- TAL-3 / RMS-7: the last leaf. The thread goes on to the next tale. --------------------- */
.tl-end{display:flex;flex-direction:column;align-items:center;justify-content:center;background:#14151A;color:#F4EFE6;font:500 18px/1.4 var(--fb)}
.tl-end h2{margin:0;font:800 96px/1 var(--fd);letter-spacing:-.02em;color:rgb(var(--c));text-align:center}
.tl-end h2 small{display:block;margin-top:10px;text-align:center;font:700 13px/1 var(--fd);letter-spacing:.3em;text-transform:uppercase;color:rgba(244,239,230,.6)}
.tl-nx{position:relative;margin-top:64px;display:flex;align-items:center;gap:26px}
.tl-nx::before{content:"";position:absolute;left:-400px;right:-400px;top:50%;height:2px;margin-top:-1px;background:rgba(196,48,74,.4)}
.tl-nx > canvas{position:relative;flex:none;display:block;width:132px;height:132px;border-radius:50%;filter:drop-shadow(0 9px 9px rgba(10,14,40,.28))}
.tl-nx.tl-done > canvas{box-shadow:0 0 0 4px #14151A,0 0 0 8px #E8A21A}
.tl-nx p{position:relative;margin:0;max-width:330px;padding:10px 14px;background:#14151A;font:500 17.5px/1.4 var(--fb);color:rgba(244,239,230,.8)}
.tl-nx p i{display:block;font:700 11px/14px var(--fd);font-style:normal;letter-spacing:.16em;text-transform:uppercase;color:rgb(var(--c))}
.tl-nx p b{display:block;margin:3px 0 4px;font:800 24px/1.1 var(--fd);color:#fff}
/* Screen QC 2026-11-21 (owner: "put read again right below the line and center it"): on the end leaf the button sits in the note, under its line. */
.tl-nx p .tl-again{position:static;display:block;margin:6px auto 0}
.tl-nx p .tl-again[hidden]{display:none}
.tl-nx .go{position:relative;flex:none;background:#14151A;padding-left:8px;color:#F4EFE6}
.tl-nx .go.won{--ch:#2A1B00;color:#F5C469}

/* ---- the tutor's page over the dark page (static/css/a2/tutor.css): the tale makes room ------ */
html.tu-open .tl-bk{transform:translateX(calc(-1 * min(232px, 16vw)))}

/* ---- the staff editor (the office's comics editor, unchanged in what it does) ---------------- */
.tl.editing .txt{cursor:text;caret-color:#c0392b}
.tl.editing .box::after{content:"";position:absolute;inset:calc(-4px / var(--k, 1));border:calc(2px / var(--k, 1)) dashed rgba(40,73,138,0);border-radius:calc(8px / var(--k, 1));pointer-events:none}
.tl.editing.outlined .box::after,.tl.editing .box:hover::after,.tl.editing .box.selected::after{border-color:rgba(40,73,138,.85)}
.tl.editing .box.edited::after{border-color:rgba(198,120,20,.9)}
.tl .box.over::after{border-color:#ff8a73 !important}
/* The text box's grips sit just OUTSIDE its edges, so they never cover the first or last letter of a
   full-width line; sizes are divided by the stage's scale (--k) so a grip is the same size on screen
   at any zoom. */
.tl .grip{display:none;position:absolute;z-index:4;width:calc(14px / var(--k, 1));height:calc(14px / var(--k, 1));border-radius:50%;background:#28498a;border:calc(2px / var(--k, 1)) solid #fff;touch-action:none}
.tl.editing .box.selected .grip{display:block}
.tl .grip[data-edge*="w"]{left:calc(-13px / var(--k, 1))}
.tl .grip[data-edge*="e"]{left:calc(100% - 1px / var(--k, 1))}
.tl .grip[data-edge="n"],.tl .grip[data-edge="s"]{left:calc(50% - 7px / var(--k, 1))}
.tl .grip[data-edge*="n"]{top:calc(-13px / var(--k, 1))}
.tl .grip[data-edge*="s"]{top:calc(100% - 1px / var(--k, 1))}
.tl .grip[data-edge="w"],.tl .grip[data-edge="e"]{top:calc(50% - 7px / var(--k, 1))}
.tl .grip[data-edge="nw"],.tl .grip[data-edge="se"]{cursor:nwse-resize}
.tl .grip[data-edge="ne"],.tl .grip[data-edge="sw"]{cursor:nesw-resize}
.tl .grip[data-edge="n"],.tl .grip[data-edge="s"]{cursor:ns-resize}
.tl .grip[data-edge="e"],.tl .grip[data-edge="w"]{cursor:ew-resize}
.tl-boxbar{position:fixed;z-index:50;display:none;gap:6px;align-items:center;background:#fff;color:#16181d;border-radius:10px;padding:6px 8px;box-shadow:0 8px 28px rgba(0,0,0,.45);font:600 12px/1 var(--fb)}
.tl-boxbar.open{display:flex}
.tl-boxbar .ref{color:#5a6070;font-weight:500;font-family:ui-monospace,Menlo,monospace}
.tl-boxbar button{border:1px solid #d6dae2;background:#fff;color:#16181d;border-radius:7px;padding:6px 9px;font:inherit;cursor:pointer}
.tl-boxbar button:hover{border-color:#28498a;color:#28498a}
.tl-boxbar button[hidden]{display:none}
.tl-toast{position:fixed;z-index:60;bottom:28px;left:50%;transform:translateX(-50%);margin:0;padding:9px 18px;border-radius:999px;background:rgba(16,18,26,.95);color:#F4EFE6;font:600 14px/1.2 var(--fb);opacity:0;transition:opacity .2s;pointer-events:none}
.tl-toast.show{opacity:1}
.tl-toast.bad{color:#ff8a73;box-shadow:inset 0 0 0 1px #ff8a73}

/* ---- between 700 and 1100 px: the structure stays, the margins narrow ------------------------ */
@media (max-width:1100px){
  .a2.tl{--side:40px}
  .tl-bar{left:28px;right:32px;gap:16px}
  .tl-lg{gap:18px}
  .tl-end h2{font-size:72px}
  .tl-nx{margin-top:40px;gap:18px}
  .tl-nx > canvas{width:112px;height:112px}
}

/* ---- a short window (a phone on its side): the bar narrows, the page takes the height ------- */
@media (max-height:560px){
  .a2.tl{--top:50px;--below:58px;--fw:48px;--side:56px}
  .tl-bar{top:2px;height:46px}
  .tl-bar h1{font-size:17px}
  .tl-lg .qa{height:36px;font-size:15px}
  .tl-sd{margin-top:26px}
  .tl-col{padding-bottom:calc(var(--below) - 26px)}
  .tl-again{top:auto;bottom:12px;left:-6px;height:32px;font-size:15px}
  .tl-end h2{font-size:48px}
  .tl-end h2 small{margin-top:6px;font-size:11px}
  .tl-nx{margin-top:20px;gap:14px}
  .tl-nx > canvas{width:88px;height:88px}
  .tl-nx p{padding:6px 10px;font-size:15px}
  .tl-nx p b{font-size:19px}
}

/* ---- below 700 px: one column. The bar takes two rows; the page runs the width; the end leaf
   grows to hold its next step; the lens opens under the page ---------------------------------- */
@media (max-width:699px),(orientation:portrait) and (max-width:1199px){
  .a2.tl{--side:12px;--top:112px;--below:132px;--fw:52px}
  .tl-bar{left:8px;right:12px;top:6px;height:auto;display:grid;grid-template-columns:auto 1fr;grid-template-rows:44px auto;column-gap:8px;row-gap:2px}
  .tl-bar .gb{grid-column:1;grid-row:1;height:44px}
  .tl-lg{grid-column:2;grid-row:1;justify-self:end;gap:14px}
  .tl-lg .qa{height:44px;font-size:15px}
  .tl-lg .qa[lang="fa"]{font-size:16px}
  .tl-lg .qa.tl-tool{display:none}
  .tl-bar h1{grid-column:1 / -1;grid-row:2;padding:0 6px;font-size:22px;white-space:normal;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
  .tl-bk{justify-content:flex-start;padding:16px 0 24px}
  .tl-sd{margin:40px 26px 0}
  .tl-col{padding-bottom:calc(var(--below) - 40px)}
  .tl-bd{width:24px;height:24px;margin:-12px 0 0 -12px}
  .tl-bd i{width:10px;height:10px}
  .tl-again{top:24px;left:-8px;height:44px}
  .tl-turn{display:block;position:absolute;left:0;right:0;bottom:calc(env(safe-area-inset-bottom, 0px) + 14px)}
  .tl.tl-at-end .tl-turn{display:none}
  /* the end leaf takes the room it needs, its next tale's pearl over its line, the GO under it */
  .tl.tl-at-end .tl-st{aspect-ratio:auto;height:min(470px, calc(100dvh - var(--top) - var(--below)))}
  .tl-end h2{font-size:56px}
  .tl-end h2 small{margin-top:8px;font-size:11px}
  .tl-nx{margin-top:22px;flex-direction:column;gap:6px;text-align:center}
  .tl-nx::before{top:48px}
  .tl-nx > canvas{width:96px;height:96px}
  .tl-nx p{max-width:300px;padding:8px 12px;font-size:16px}
  .tl-nx p b{font-size:21px}
  .tl-nx .go{padding-left:0}
  .tl-nx .go.won{white-space:normal;max-width:300px;font-size:20px;line-height:1.1;text-align:right}
  /* the lens opens in the room under the page, over the strand, the width of the page */
  .tl-ln{width:auto;max-width:none}
  .tl-ask{width:44px;height:44px}
  html.tu-open .tl-bk{transform:none}
}

@media (pointer:coarse){
  .tl-ask{width:44px;height:44px}
}
@media (prefers-reduced-motion:reduce){
  .tl-bk,.tl-pg,.tl-rl,.tl-fw{transition:none}
}

/* ---- A DEVICE HELD UPRIGHT: the comic turned (owner, 2026-11-17: "for comic reader also the comic should be full
   screen meaning they should rotate their screen. this is only for vertical aspect ratio screens of course"). A touch
   screen taller than wide draws the whole reader a quarter turn clockwise, its top along the screen's right edge, so
   the reader turns the phone or tablet onto its side to read it (with the rotation lock on, the page reads upright
   then; with it off the browser turns too and the page is laid out on its side, unturned, as wide as before). The
   frame's two lengths swap (--W, --H). --lt-turned tells the scripts that a box's place on the screen is turned
   (static/js/comics_lettering.js measures the text across it, comics_reader.js reads a swipe down the screen,
   static/js/a2/tale.js places the lens in the page's own frame). ------------------------------------------------- */
@media (orientation:portrait) and (pointer:coarse){
  html:has(> body.tl-body){overflow:hidden;background:#14151A}
  body.tl-body{position:fixed;left:100vw;top:0;width:100vh;height:100vw;transform:rotate(90deg);transform-origin:0 0}
  .a2.tl{--lt-turned:1;--W:100vh;--H:100vw;height:100%}
  .tl-st{touch-action:none}
  .tl-turn{display:none}
}
@supports (height:100dvh){
  @media (orientation:portrait) and (pointer:coarse){
    body.tl-body{width:100dvh}
    .a2.tl{--W:100dvh}
  }
}

/* ---- FULL SCREEN on a phone, on its side or turned: the page takes the screen; the bar lies over its top and the
   strand over its foot, each on a fade of the night, and both step aside once a page turns (.tl-calm, tale.js; a
   press on the page where no balloon is brings them back). Undoes the phone column's bar and strand (below 700 px)
   where the screen is a phone held upright and the reader is turned. ---------------------------------------- */
@media (pointer:coarse) and (orientation:landscape) and (max-height:560px),(pointer:coarse) and (orientation:portrait) and (max-width:560px){
  .a2.tl{--top:0px;--below:0px;--side:0px;--fw:48px}
  .tl-bk{top:0;padding:0;justify-content:center}
  html.tu-open .tl-bk{transform:none}
  .tl-col{padding-bottom:0}
  .tl-st{border-radius:0;box-shadow:none}
  .tl-bar{left:0;right:0;top:0;height:auto;display:flex;align-items:center;gap:16px;padding:2px max(20px, env(safe-area-inset-right)) 26px max(20px, env(safe-area-inset-left));background:linear-gradient(rgba(20,21,26,.92) 50%,rgba(20,21,26,0));transition:opacity .3s}
  .tl-bar .gb{height:40px}
  .tl-bar h1{min-width:0;padding:0;font-size:17px;white-space:nowrap;display:block;-webkit-line-clamp:none}
  .tl-lg{margin-left:auto;gap:18px}
  .tl-lg .qa{height:36px;font-size:15px}
  .tl-lg .qa[lang="fa"]{font-size:16px}
  .tl-sd{position:absolute;z-index:5;left:12%;right:12%;bottom:30px;margin:0;transition:opacity .3s}
  .tl-sd::before{content:"";position:absolute;left:-19%;right:-19%;top:-44px;height:74px;background:linear-gradient(rgba(20,21,26,0),rgba(20,21,26,.85));pointer-events:none}
  .tl-again{top:auto;bottom:-24px;left:-6px;height:32px;font-size:15px}
  .tl-turn{display:none}
  .tl.tl-calm .tl-bar,.tl.tl-calm .tl-sd{opacity:0;pointer-events:none}
  /* the end leaf, at the page's own size */
  .tl.tl-at-end .tl-st{aspect-ratio:var(--arw) / var(--arh);height:auto}
  .tl-end h2{font-size:44px}
  .tl-end h2 small{margin-top:6px;font-size:11px}
  .tl-nx{margin-top:18px;flex-direction:row;gap:14px;text-align:left}
  .tl-nx > canvas{width:80px;height:80px}
  .tl-nx p{max-width:300px;padding:6px 10px;font-size:15px}
  .tl-nx p b{font-size:19px}
  .tl-nx .go.won{max-width:none;font-size:18px;text-align:left}
  .tl-ln{width:340px;max-width:calc(100% - 24px)}
}
