/* ==========================================================================
   Reader: webtoon (continuous) + paged modes, docked controls, page grid,
   zoom lens, the end-of-chapter hanko. The chrome is always ink (.ink-dark);
   the page ground follows the reader's background setting.
   ========================================================================== */

.reader {
  --reader-bg: #0B0A09;
  --reader-w: 820px;
  --reader-gap: 0px;
  --reader-bright: 1;
  --r-fg: #F2EDE4;       /* type set directly on the page ground (end card, placeholders) */
  --r-muted: #8D867B;
  display: flow-root; /* the end card's margin stays inside: no paper showing below the last page */
  min-height: 100dvh; background: var(--reader-bg); color: var(--text);
  transition: background-color .6s var(--ease);
}
body.is-reader::before { background: #0B0A09; }
.reader:focus { outline: none; }
.reader[data-bg="gray"] { --reader-bg: #252422; }
.reader[data-bg="paper"] { --reader-bg: #EDE8DE; --r-fg: #121110; --r-muted: #6F695F; }
.reader[data-bg="white"] { --reader-bg: #FFFFFF; --r-fg: #121110; --r-muted: #6F695F; }

/* ---------------------------------------------------------------- docked bars (they float over art) */
.rbar {
  position: fixed; left: 0; right: 0; z-index: 40; display: flex; align-items: center; gap: 6px;
  padding-inline: max(12px, calc((100% - 1200px) / 2));
  color: var(--text); background: var(--bar);
  -webkit-backdrop-filter: blur(16px) saturate(1.1); backdrop-filter: blur(16px) saturate(1.1);
  transition: transform var(--t-slow) var(--ease), opacity .5s var(--ease);
}
.rbar--top { top: 0; height: calc(62px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top); }
.rbar--bottom { bottom: 0; height: calc(68px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); gap: 16px; }
.rbar--top::after { bottom: -3px; }
.rbar--bottom::before { top: -3px; -webkit-mask-image: var(--edge-h2); mask-image: var(--edge-h2); }
.reader.ui-hidden .rbar--top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.reader.ui-hidden .rbar--bottom { transform: translateY(100%); opacity: 0; pointer-events: none; }
.rbar .icon-btn[aria-pressed="true"] { color: var(--text); }
.rbar .icon-btn[aria-pressed="true"]::before { --v: 107%; opacity: 1; background: var(--accent); }
.rbar__title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; padding-left: 6px; }
.rbar__title a { position: relative; isolation: isolate; align-self: flex-start; max-width: 100%; font: 750 var(--fs-base)/1.3 var(--f-sans); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbar__title a:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.rbar__title span { font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rbar__sep { width: 4px; height: 24px; background: var(--line-2); margin-inline: 5px; -webkit-mask: var(--edge-v1) 0 0 / 100% 100% no-repeat; mask: var(--edge-v1) 0 0 / 100% 100% no-repeat; }
.ch-picker {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px 0 15px; border-radius: var(--r-pill);
  background: var(--hover); font: 650 var(--fs-xs)/1 var(--f-sans); color: var(--text-2);
  transition: background-color var(--t-fast), color var(--t-fast);
}
.ch-picker:hover { background: color-mix(in srgb, var(--text) 12%, transparent); color: var(--text); }
.ch-picker .ico { width: 16px; height: 16px; }
.ch-picker b { font: 850 19px/1 var(--f-sans); font-stretch: 62.5%; color: var(--text); }
.rprogress { flex: 1; display: flex; align-items: center; gap: 16px; min-width: 0; max-width: 760px; margin-inline: auto; }
.rprogress__count { display: inline-flex; align-items: baseline; justify-content: center; gap: 5px; min-width: 76px; font: 850 24px/1 var(--f-sans); font-stretch: 62.5%; white-space: nowrap; }
.rprogress__count small { font-size: .66em; color: var(--muted); }
.rprogress .range { flex: 1; min-width: 0; }
/* the reading line: a thin vermilion thread across the very top */
.reader-line { position: fixed; left: 0; top: 0; height: 3px; z-index: 41; background: var(--accent); width: 0; transition: width .2s linear; pointer-events: none; }
@media (max-width: 640px) {
  .rbar .hide-sm { display: none; }
  .rbar__sep { display: none; }
  .rbar--bottom { gap: 8px; }
  .rbar--bottom .btn span { display: none; }
  .rbar--bottom .btn--ghost { width: 40px; padding: 0; }
  .rprogress { gap: 10px; }
  .rprogress__count { min-width: 58px; font-size: 20px; }
}

/* ---------------------------------------------------------------- pages (shared) */
.rpage { position: relative; margin-inline: auto; background: color-mix(in srgb, var(--r-fg) 4%, transparent); }
.rpage img { width: 100%; height: auto; display: block; filter: brightness(var(--reader-bright)); opacity: 0; transition: opacity .5s var(--ease); user-select: none; -webkit-user-drag: none; }
.rpage img.is-loaded { opacity: 1; }
.rpage.is-loaded { background: transparent; }
.rpage__state {
  position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 16px;
  color: color-mix(in srgb, var(--r-fg) 20%, transparent); font: 850 clamp(48px, 6vw, 76px)/1 var(--f-sans); font-stretch: 62.5%; pointer-events: none;
}
.rpage.is-loaded .rpage__state { display: none; }
.rpage.is-error .rpage__state { pointer-events: auto; font: 600 var(--fs-sm)/1.5 var(--f-sans); color: var(--r-muted); }
.rpage.is-error .rpage__state .btn { --btn-fg: var(--r-fg); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--r-fg) 25%, transparent); }
.rpage.is-error .rpage__state .btn:hover { box-shadow: inset 0 0 0 1.5px var(--r-fg); }

/* ---------------------------------------------------------------- webtoon mode */
.strip { width: min(100%, var(--reader-w)); margin: 0 auto; padding-top: 62px; display: flex; flex-direction: column; gap: var(--reader-gap); }
.strip .rpage { width: 100%; min-height: 260px; }
.strip .rpage[style*="aspect-ratio"] { min-height: 0; }
.reader[data-fit="original"] .strip { width: auto; max-width: 100%; }
.reader[data-fit="original"] .strip .rpage img { width: auto; max-width: 100%; margin: 0 auto; }

/* ---------------------------------------------------------------- paged mode */
.stage { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: pan-y pinch-zoom; }
.stage .rpage { display: none; background: transparent; }
.stage .rpage.is-current { display: block; }
.reader[data-fit="height"] .stage .rpage img { height: 100dvh; width: auto; max-width: 100vw; object-fit: contain; }
.reader[data-fit="width"] .stage { overflow-y: auto; align-items: flex-start; }
.reader[data-fit="width"] .stage .rpage { width: min(100vw, var(--reader-w)); }
.reader[data-fit="original"] .stage { overflow: auto; align-items: flex-start; }
.reader[data-fit="original"] .stage .rpage img { width: auto; max-width: none; }
/* a page turn: the next sheet slides a little and settles, like paper */
.stage .rpage.is-current img.is-loaded { animation: turn .42s var(--ease); }
.stage[data-dir="back"] .rpage.is-current img.is-loaded { animation-name: turn-back; }
@keyframes turn { from { opacity: .35; transform: translateX(-14px); } }
@keyframes turn-back { from { opacity: .35; transform: translateX(14px); } }
.reader[data-dir="ltr"] .stage .rpage.is-current img.is-loaded { animation-name: turn-back; }
.reader[data-dir="ltr"] .stage[data-dir="back"] .rpage.is-current img.is-loaded { animation-name: turn; }

/* zoom lens: the page scales up and follows the pointer */
.rpage.is-zoomed { overflow: hidden; cursor: zoom-out; }
.rpage.is-zoomed img { transform: scale(var(--zoom, 2.2)); transform-origin: var(--zx, 50%) var(--zy, 50%); animation: none !important; transition: transform-origin .08s linear; }
.reader.is-zoomed .tapzones { display: none; }

.tapzones { position: fixed; inset: 0; z-index: 5; display: grid; grid-template-columns: 1fr 1.1fr 1fr; }
.tapzones > div { cursor: pointer; }
.tapzones > div:first-child { cursor: w-resize; }
.tapzones > div:last-child { cursor: e-resize; }

/* ---------------------------------------------------------------- end of chapter */
.endcard {
  --text: var(--r-fg); --text-2: var(--r-fg); --muted: var(--r-muted);
  --line: color-mix(in srgb, var(--r-fg) 10%, transparent); --line-2: color-mix(in srgb, var(--r-fg) 22%, transparent);
  --hover: color-mix(in srgb, var(--r-fg) 6%, transparent); --on-text: var(--reader-bg);
  position: relative; width: min(100% - 32px, 600px); margin: 140px auto 170px; text-align: center; color: var(--r-fg);
}
/* the hanko. 完 stays a round chop; つづく is a tall brush column, stamped a little off-square */
.endseal {
  display: inline-grid; place-items: center; position: relative; isolation: isolate;
  margin: 0 auto 34px; font: 400 36px/1 var(--f-kana); color: #F6EFE4; background: transparent;
}
.endseal--tbc {
  writing-mode: vertical-rl; text-orientation: mixed;
  min-height: 176px; padding: 30px 18px 34px; letter-spacing: .28em; font-size: 30px;
  text-shadow: 0 1px 0 rgba(90, 18, 10, .35);
}
.endseal--tbc::before {
  content: ""; position: absolute; z-index: -1; inset: -8px -14px -12px -12px;
  background: linear-gradient(100deg, #8E2418 0%, #E24B34 34%, #C23522 68%, #9A281C 100%);
  -webkit-mask: var(--brush-vstroke) center / 100% 100% no-repeat;
  mask: var(--brush-vstroke) center / 100% 100% no-repeat;
}
.endseal--tbc::after {
  content: ""; position: absolute; inset: 9px 8px; pointer-events: none;
  border: 1px solid rgba(246, 239, 228, .5);
  -webkit-mask: var(--brush-vstroke) center / 130% 112% no-repeat;
  mask: var(--brush-vstroke) center / 130% 112% no-repeat;
}
.endseal--end { width: 112px; height: 112px; font-size: 54px; text-shadow: 0 1px 0 rgba(90, 18, 10, .35); }
.endseal--end::before {
  content: ""; position: absolute; z-index: -1; inset: -12px;
  background: linear-gradient(140deg, #8E2418 0%, #E24B34 38%, #C23522 70%, #9A281C 100%);
  -webkit-mask:
    radial-gradient(closest-side, #000 64%, transparent 76%) center / 82% 82% no-repeat,
    var(--brush-enso) center / 100% 100% no-repeat;
  -webkit-mask-composite: source-over;
  mask:
    radial-gradient(closest-side, #000 64%, transparent 76%) center / 82% 82% no-repeat,
    var(--brush-enso) center / 100% 100% no-repeat;
  mask-composite: add;
}
.endseal--end::after {
  content: ""; position: absolute; inset: 16px; pointer-events: none; border-radius: 50%;
  border: 1.5px solid rgba(246, 239, 228, .55);
}
.endcard.is-in .endseal--end { animation: stamp .7s cubic-bezier(.2, .9, .25, 1) both; }
.endcard.is-in .endseal--tbc { animation: stamp-tbc .7s cubic-bezier(.2, .9, .25, 1) both; }
@keyframes stamp { from { opacity: 0; transform: scale(1.45) rotate(-14deg); } 58% { opacity: 1; transform: scale(.94) rotate(2deg); } to { transform: scale(1) rotate(-3deg); } }
@keyframes stamp-tbc { from { opacity: 0; transform: scale(1.4) rotate(-16deg); } 58% { opacity: 1; transform: scale(.96) rotate(-1deg); } to { transform: scale(1) rotate(-4deg); } }
.endcard h2 { font: 400 clamp(2.4rem, 1.6rem + 2.8vw, 3.4rem)/1.05 var(--f-brush); -webkit-text-stroke: .034em currentColor; paint-order: stroke fill; }
.endcard > p { color: var(--r-muted); margin: 14px auto 0; max-width: 42ch; }
/* next chapter: its banner waits in grey; point at it and the colour splashes in */
.endcard__next {
  position: relative; isolation: isolate; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 16px; text-align: left;
  margin-top: 46px; padding: 32px 28px; border-radius: var(--r-lg); overflow: hidden;
  background: color-mix(in srgb, var(--r-fg) 7%, transparent); color: var(--r-fg);
}
.endcard__next:has(img) { color: #F2EDE4; background: #0B0A09; box-shadow: 0 30px 50px -28px rgba(0, 0, 0, .7); }
.endcard__next img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -2; }
.endcard__next .bloom-color { filter: brightness(.78); }
.endcard__next::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(90deg, rgba(8, 7, 6, .82), rgba(8, 7, 6, .2)); opacity: 0; }
.endcard__next:has(img)::after { opacity: 1; }
.endcard__next small { display: block; font-size: var(--fs-xs); opacity: .75; }
.endcard__next b { display: block; font: 800 var(--fs-xl)/1.25 var(--f-ui); margin-top: 5px; }
.endcard__next .ico { width: 24px; height: 24px; transition: transform var(--t-slow) var(--ease); }
.endcard__next:hover .ico { transform: translateX(5px); }
.endcard__actions { display: flex; justify-content: center; gap: 10px; margin-top: 24px; flex-wrap: wrap; }
.stage-end { position: fixed; inset: 0; display: grid; place-items: center; z-index: 6; overflow-y: auto; background: var(--reader-bg); }
.stage-end .endcard { margin: 110px auto; }

/* ---------------------------------------------------------------- chapter list sheet
   The numbers share one column (subgrid) as wide as the widest; the chapter you are
   reading is marked in red. */
.chlist { display: grid; grid-template-columns: max-content minmax(0, 1fr) auto; column-gap: 14px; }
.chlist a {
  position: relative; grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; align-items: center;
  padding: 12px 12px 12px 10px; border-radius: var(--r); color: var(--text-2);
  transition: color var(--t-fast), background-color var(--t-fast);
}
@supports not (grid-template-columns: subgrid) { .chlist a { grid-template-columns: minmax(4.5rem, max-content) minmax(0, 1fr) auto; column-gap: 14px; } }
.chlist a:hover { color: var(--text); background: var(--hover); }
.chlist a[aria-current="true"] { color: var(--text); background: var(--hover); box-shadow: inset 3px 0 0 var(--accent); }
.chlist a[aria-current="true"] > .num:first-child { color: var(--accent); }
.chlist a.is-read { color: var(--muted); }
.chlist .num { min-width: 1.4em; font-size: 1.3rem; text-align: right; white-space: nowrap; }
.chlist span:nth-child(2) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.chlist small { color: inherit; opacity: .7; }
.chlist small.num { font-size: 13px; font-weight: 400; }

/* ---------------------------------------------------------------- page grid sheet */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(108px, 1fr)); gap: 18px 14px; padding-top: 10px; }
.pthumb {
  position: relative; display: block; aspect-ratio: 2 / 3; border-radius: var(--r); overflow: hidden; background: var(--surface-2);
  outline: 2px solid transparent; outline-offset: 3px; transition: outline-color var(--t-fast), transform var(--t) var(--ease);
}
.pthumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; opacity: 0; transition: opacity .5s var(--ease); }
.pthumb img.is-loaded { opacity: 1; }
.pthumb:hover { outline-color: var(--line-2); transform: translateY(-3px); }
.pthumb[aria-current="true"] { outline-color: var(--accent); }
.pthumb span { position: absolute; left: 6px; bottom: 6px; min-width: 28px; padding: 5px 7px 4px; border-radius: var(--r-pill); background: rgba(11, 10, 9, .82); color: #F2EDE4; font: 850 14px/1 var(--f-sans); font-stretch: 62.5%; text-align: center; }
.pthumb[aria-current="true"] span { background: var(--accent); color: var(--on-accent); }

/* ---------------------------------------------------------------- resume hint */
.resume-hint {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 45;
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 20px; border-radius: var(--r-pill);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-panel), 0 0 0 1px var(--line);
  font-size: var(--fs-sm); font-weight: 600; animation: toast-in .5s var(--ease); white-space: nowrap;
}
.resume-hint .btn { height: 36px; }
@media (max-width: 480px) { .resume-hint { white-space: normal; width: calc(100% - 24px); border-radius: var(--r-lg); } }

.reader-loading { position: fixed; inset: 0; display: grid; place-items: center; background: var(--reader-bg); }
