/* ==========================================================================
   Components: nav, tab bar, footer, section heads, cards (cover, chapter,
   continue), rails, search palette, toasts, sheets, page transitions, reveals
   ========================================================================== */

/* ---------------------------------------------------------------- nav: a printed masthead */
.nav {
  position: sticky; top: 0; z-index: 50;
  height: var(--nav-h);
  background: var(--bg-tex) 0 0 / 512px 512px fixed, var(--bg);
  view-transition-name: site-nav;
}
.nav::after { bottom: -3px; --rule-c: var(--rule); }
.nav__bar { height: 100%; display: flex; align-items: center; gap: clamp(18px, 3vw, 48px); }

.brand { display: inline-flex; align-items: center; flex: none; color: var(--text); }
/* the brush lockup (drop + მელანი); black ink, recoloured on dark grounds */
.brand__logo { display: block; height: 50px; width: auto; filter: var(--mark-filter); transition: transform .5s var(--ease); }
.brand:hover .brand__logo { transform: rotate(-2deg) scale(1.03); }
/* nav: the ink drop alone, the name set beside it in the display brush */
.brand__mark { display: block; height: 40px; width: auto; filter: var(--mark-filter); transition: transform .5s var(--ease); }
.brand__name { margin-left: 10px; font: 400 1.9rem/1 var(--f-brush); -webkit-text-stroke: .03em currentColor; paint-order: stroke fill; white-space: nowrap; transform: translateY(.06em); }
.brand:hover .brand__mark { transform: rotate(-6deg) scale(1.04); }
.footer .brand__mark { filter: invert(1) sepia(.1) brightness(.95); }

.nav__links { display: flex; align-items: center; gap: clamp(8px, 1.8vw, 30px); }
/* a red brush underline paints in under the section you point at; it stays under the one you are in */
.nav__link {
  position: relative; isolation: isolate; padding: 10px 3px;
  font: 700 15px/1 var(--f-ui); color: var(--text-2); transition: color var(--t) var(--ease);
}
.nav__link::before { left: -5px; right: -8px; bottom: -1px; height: 10px; color: var(--accent); opacity: .5; }
.nav__link:hover { color: var(--text); }
.nav__link:hover::before { --p: 118%; }
.nav__link[aria-current="page"] { color: var(--text); }
.nav__link[aria-current="page"]::before { --p: 118%; opacity: 1; }
.nav__spacer { flex: 1; }
.nav__actions { display: flex; align-items: center; gap: 10px; }
.search-trigger {
  position: relative; display: inline-flex; align-items: center; gap: 10px; height: 42px; min-width: 290px; padding: 0 8px 0 14px;
  border-radius: var(--r); color: var(--muted);
  font: 600 var(--fs-sm)/1 var(--f-ui); transition: color var(--t-fast);
}
.search-trigger:hover { --frame-c: var(--text); color: var(--text); }
.search-trigger .ico { width: 18px; height: 18px; color: var(--text); }
.search-trigger span:first-of-type { flex: 1; text-align: left; }

@media (max-width: 1060px) {
  .search-trigger { min-width: 0; width: 42px; padding: 0; justify-content: center; }
  .search-trigger::after { -webkit-mask: var(--brush-enso) center / contain no-repeat; mask: var(--brush-enso) center / contain no-repeat; }
  .search-trigger span { display: none; }
}
@media (max-width: 760px) {
  .nav__links { display: none; }
  .brand__logo { height: 40px; }
  .brand__mark { height: 34px; }
  .brand__name { font-size: 1.6rem; margin-left: 8px; }
  .nav .search-trigger { display: none; }
}

/* ---------------------------------------------------------------- mobile tab bar */
.tabbar { display: none; }
@media (max-width: 760px) {
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    display: grid; grid-template-columns: repeat(4, 1fr);
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-tex) 0 0 / 512px 512px fixed, var(--bg);
    view-transition-name: tabbar;
  }
  .tabbar::before { top: -3px; --rule-c: var(--rule); }
  .tabbar a, .tabbar button {
    position: relative; isolation: isolate; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    font: 650 10.5px/1 var(--f-ui); color: var(--muted); transition: color var(--t-fast);
    -webkit-tap-highlight-color: transparent;
  }
  .tabbar .ico { width: 23px; height: 23px; }
  .tabbar a::before { left: 50%; bottom: 7px; width: 44px; height: 8px; margin-left: -22px; color: var(--accent); }
  .tabbar [aria-current="page"] { color: var(--text); }
  .tabbar [aria-current="page"]::before { --p: 118%; }
  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
}

/* ---------------------------------------------------------------- footer: the page runs into a pool of ink, the name set across its floor */
.footer {
  --text: var(--paper); --text-2: rgba(237, 230, 215, .78); --muted: rgba(237, 230, 215, .5);
  --line: rgba(237, 230, 215, .12); --accent: #DC4533;
  --mast-in: clamp(6px, 1.2vw, 22px); --foot-bg: var(--ink);
  position: relative; isolation: isolate; overflow-x: clip;
  margin-top: clamp(130px, 14vw, 220px); background: var(--foot-bg); color: var(--paper);
  padding-bottom: calc((100% - 2 * var(--mast-in)) * var(--mast-ar, .36) * .3);
}
/* the words sit over the name */
.footer__inner, .footer__bottom { position: relative; z-index: 1; }
/* the shore: brushed across, dry hairs breaking up into the paper, a spatter thrown ahead */
.footer::before {
  content: ""; position: absolute; left: 50%; bottom: calc(100% - 2px); z-index: -1;
  width: max(100%, 1300px); aspect-ratio: 1600 / 120; transform: translateX(-50%);
  background: var(--foot-bg); pointer-events: none;
  -webkit-mask: var(--brush-shore) center bottom / 100% 100% no-repeat; mask: var(--brush-shore) center bottom / 100% 100% no-repeat;
}
/* the name, across the floor: see footer.js (the span is the no-JS / pre-font fallback) */
/* at night the page is ink already: the pool goes a shade deeper so its shore still shows */
:root[data-theme="dark"] .footer { --foot-bg: #080707; }
.footer__mast {
  position: absolute; z-index: 0; left: var(--mast-in); right: var(--mast-in); bottom: 0; overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
.footer__mast > span {
  display: block; font: 400 clamp(64px, 23vw, 400px)/.9 var(--f-brush); color: #2A2622;
  letter-spacing: -.03em; white-space: nowrap; text-align: center;
}
.footer__mast svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.footer__mast svg * { transform-box: fill-box; transform-origin: center; }
.footer__mast .mast__drip path { transform-origin: 50% 0; }
/* set dark into the ink, a ground for the words rather than a word to read */
.mast__ink, .mast__falls { fill: #2A2622; }
.mast__wet { fill: #A8301F; }
:root[data-theme="dark"] .mast__ink, :root[data-theme="dark"] .mast__falls { fill: #221F1B; }
.footer__inner { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1.3fr; gap: 48px; padding-block: 64px 8px; }
.footer__brand p { color: var(--text-2); margin-top: 20px; max-width: 40ch; font-size: 1rem; line-height: 1.7; }
.footer h4 { font: 400 1.45rem/1 var(--f-brush); -webkit-text-stroke: .03em currentColor; color: var(--text); margin-bottom: 22px; }
.footer li + li { margin-top: 12px; }
.footer a:not(.brand) { position: relative; isolation: isolate; color: var(--text-2); font: 600 var(--fs-sm)/1.4 var(--f-ui); transition: color var(--t-fast); }
.footer a:not(.brand)::before { left: -3px; right: -8px; bottom: -5px; height: 8px; color: var(--accent); }
.footer a:not(.brand):hover { color: var(--text); }
.footer a:not(.brand):hover::before { --p: 118%; }
.footer__quote { align-self: start; font: 400 clamp(1.4rem, 1.1rem + .8vw, 1.9rem)/1.25 var(--f-brush); -webkit-text-stroke: .025em currentColor; color: var(--text); transform: rotate(-2deg); }
.footer__quote small { display: block; margin-top: 14px; font: 500 12px/1.4 var(--f-mono); color: var(--muted); -webkit-text-stroke: 0; transform: rotate(2deg); }
.footer__bottom {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  position: relative; padding-block: 20px 34px; color: var(--muted); font: 500 12px/1.5 var(--f-mono);
}
.footer__bottom::before { top: -2px; left: var(--gutter); right: var(--gutter); --rule-c: rgba(237, 230, 215, .2); }
@media (max-width: 960px) {
  .footer__inner { grid-template-columns: 1fr 1fr; gap: 36px 24px; }
  .footer__brand, .footer__quote { grid-column: 1 / -1; }
}
body.is-reader .footer, body.is-reader .nav, body.is-reader .tabbar { display: none; }
body.is-reader { padding-bottom: 0; }

/* ---------------------------------------------------------------- section header
   A red brush label (painted as the section scrolls in), a note, a dry brush leader
   running to "see all", and the rail arrows. */
.section { margin-top: clamp(52px, 5.6vw, 88px); }
.section__head { display: flex; align-items: center; gap: 16px 20px; margin-bottom: 24px; min-width: 0; }
.section__title {
  position: relative; isolation: isolate; flex: none; margin-left: 6px;
  padding: 11px 26px 9px 20px;
  font: 400 clamp(1.4rem, 1.05rem + .9vw, 1.95rem)/1 var(--f-brush); color: var(--on-accent);
  -webkit-text-stroke: .03em currentColor; paint-order: stroke fill;
  transition: color .3s var(--ease) .22s;
}
.section__title::before { inset: -3px -8px -2px -10px; color: var(--accent); --p: 118%; transition-duration: .7s; }
.section__title .count { margin-left: .4em; font: 800 .62em/1 var(--f-ui); font-stretch: 62.5%; -webkit-text-stroke: 0; opacity: .8; vertical-align: .12em; }
.section__sub { flex: none; font: 600 var(--fs-sm)/1.3 var(--f-ui); color: var(--text-2); }
/* the leader: a long dry stroke of thinning ink that runs out toward "see all" */
.section__leader {
  flex: 1; min-width: 24px; align-self: center; height: 8px; background: var(--muted); opacity: .75;
  -webkit-mask: var(--brush-rule) 0 0 / 100% 100% no-repeat; mask: var(--brush-rule) 0 0 / 100% 100% no-repeat;
}
.section__aside { display: flex; align-items: center; gap: 14px; flex: none; }
.section__link {
  position: relative; isolation: isolate; display: inline-flex; align-items: center; gap: 8px; padding: 6px 0;
  font: 700 var(--fs-sm)/1 var(--f-ui); color: var(--text); white-space: nowrap;
}
.section__link::before { left: -4px; right: 18px; bottom: -3px; height: 8px; color: var(--accent); }
.section__link:hover::before { --p: 118%; }
.section__link .ico { width: 18px; height: 18px; transition: transform var(--t) var(--ease); }
.section__link:hover .ico { transform: translateX(4px); }
@media (max-width: 640px) {
  .section__sub, .section__leader { display: none; }
  .section__head { justify-content: space-between; }
}

/* ---------------------------------------------------------------- cover card
   The cover is the object: it lifts and leans toward the pointer, and a sheen
   crosses its laminate once. */
.card { position: relative; display: block; min-width: 0; }
.card:focus-visible { outline: none; }
.card__cover {
  position: relative; aspect-ratio: 2 / 3; border-radius: var(--r); overflow: hidden;
  background: var(--surface-2); box-shadow: var(--shadow-card);
  transform: perspective(900px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(var(--lift, 0px));
  transition: transform .55s var(--ease), box-shadow .55s var(--ease);
}
.card__cover img { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .8s var(--ease), transform .8s var(--ease); }
.card__cover img.is-loaded { opacity: 1; }
.card__cover::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(112deg, transparent 38%, rgba(255, 252, 240, .34) 50%, transparent 62%) 160% 0 / 250% 100% no-repeat;
  mix-blend-mode: soft-light; transition: background-position 0s;
}
.card:hover .card__cover::after { background-position: -60% 0; transition: background-position 1s var(--ease); }
.card:hover .card__cover { --lift: -7px; box-shadow: var(--shadow-lift); }
.card:hover .card__cover img { transform: scale(1.04); }
.card.is-tilting .card__cover { transition: transform .12s linear, box-shadow .55s var(--ease); }
.card:focus-visible .card__cover { outline: 2px solid var(--accent); outline-offset: 4px; }
.card__progress { position: relative; height: 8px; margin-top: 12px; color: var(--text); }
.card__progress::before, .card__progress i { content: ""; position: absolute; inset: 0; background: currentColor; }
.card__progress::before { opacity: .2; -webkit-mask: var(--brush-rule) 0 0 / 100% 100% no-repeat; mask: var(--brush-rule) 0 0 / 100% 100% no-repeat; }
.card__progress i {
  color: var(--accent);
  -webkit-mask: var(--brush-rule) 0 0 / 100% 100% no-repeat, linear-gradient(90deg, #000 var(--v, 100%), transparent var(--v, 100%)) 0 0 / 100% 100% no-repeat;
  -webkit-mask-composite: source-in;
  mask: var(--brush-rule) 0 0 / 100% 100% no-repeat, linear-gradient(90deg, #000 var(--v, 100%), transparent var(--v, 100%)) 0 0 / 100% 100% no-repeat;
  mask-composite: intersect;
}
.card__body { position: relative; padding-top: 12px; }
.card__body .seal { position: absolute; z-index: 3; right: 12px; top: auto; bottom: calc(100% + 8px); transition: transform .55s var(--ease); }
.card:hover .card__body .seal { transform: translateY(-7px) rotate(var(--seal-tilt, -6deg)); }
.card__title { position: relative; font: 400 1.0625rem/1.3 var(--f-body); color: var(--text); transition: color var(--t-fast); }
.card:hover .card__title { color: var(--accent); }
.card__meta { display: flex; align-items: center; gap: 10px; margin-top: 6px; color: var(--muted); font: 500 12px/1.3 var(--f-mono); min-width: 0; }
.card__meta > span:not(.seal) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* ranked card (top 10): a huge outlined numeral that fills with ink on hover */
.rank { display: flex; align-items: flex-end; min-width: 0; }
.rank__n {
  position: relative; flex: none; z-index: 0; margin-right: -.08em; transform: translateY(-.3em);
  font: 900 clamp(120px, 11vw, 176px)/.72 var(--f-ui); font-stretch: 62.5%; letter-spacing: -.03em;
  color: transparent; -webkit-text-stroke: 2px var(--text);
}
.rank__n::after {
  /* the glyph overflows its .72 line box; grow the box (padding keeps the text in place) so the mask covers all of it */
  content: attr(data-n); position: absolute; inset: -.3em -.2em; padding: .3em .2em; color: var(--accent); -webkit-text-stroke: 0;
  -webkit-mask: linear-gradient(90deg, #000 calc(var(--p) - 18%), transparent var(--p)); mask: linear-gradient(90deg, #000 calc(var(--p) - 18%), transparent var(--p));
  --p: -20%; transition: --p .7s var(--ease);
}
.rank:hover .rank__n::after { --p: 118%; }
.rank .card { flex: 1; z-index: 1; }

/* ---------------------------------------------------------------- chapter card: a manga panel
   The chapter's own first page, inked onto the paper. Point at it and slide
   across: the pages flip under the pointer (a preview of the chapter). */
/* (it lifts with `top`, not a transform: a transform would isolate the page art from the paper it prints on) */
.chap {
  position: relative; top: 0; display: flex; flex-direction: column; min-width: 0;
  --frame-c: var(--rule); border-radius: var(--r-sm);
  transition: top .45s var(--ease), box-shadow .45s var(--ease);
}
.chap::after { z-index: 2; }
.chap:hover { top: -4px; box-shadow: var(--shadow-lift); }
.chap:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.chap__art { position: relative; aspect-ratio: 4 / 3; overflow: hidden; background: var(--hover); }
.chap__art::after { bottom: 0; z-index: 1; --rule-c: var(--rule); }
.chap__art img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 8%;
  filter: var(--art-filter); mix-blend-mode: var(--art-blend);
  opacity: 0; transition: opacity .6s var(--ease), transform .9s var(--ease);
}
.chap__art img.is-loaded { opacity: 1; }
.chap:hover .chap__art img { transform: scale(1.045); }
.chap__art.is-scrubbing img { transition: opacity .6s var(--ease); transform: none; object-position: 50% 30%; }
/* the scrub bar: one tick per page, the current one red */
.chap__ticks {
  position: absolute; left: 8px; right: 8px; bottom: 7px; height: 4px; display: flex; gap: 2px; pointer-events: none;
  opacity: 0; transition: opacity var(--t) var(--ease);
}
.chap__ticks i { flex: 1; background: rgba(20, 19, 18, .35); border-radius: 1px; }
.chap__ticks i.is-on { background: var(--accent); }
.chap__art.is-scrubbing .chap__ticks { opacity: 1; }
.chap__page {
  position: absolute; right: 8px; top: 8px; padding: 4px 6px 3px; background: var(--ink); color: var(--paper);
  font: 700 11px/1 var(--f-mono); opacity: 0; transition: opacity var(--t) var(--ease); pointer-events: none;
}
.chap__art.is-scrubbing .chap__page { opacity: 1; }
.chap__body { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 12px 14px 13px; min-width: 0; }
.chap__body .seal { position: absolute; z-index: 3; right: 12px; top: auto; bottom: calc(100% + 8px); }
.chap__title { font: 400 1.0625rem/1.25 var(--f-body); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chap__foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font: 500 12.5px/1.2 var(--f-mono); }
.chap__foot > span { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 9px; min-width: 0; }
.chap__foot b { color: var(--text); font-weight: 700; white-space: nowrap; }
.chap__when { white-space: nowrap; }
.chap__foot .ico { width: 20px; height: 20px; color: var(--text); transition: transform var(--t) var(--ease), color var(--t-fast); }
.chap:hover .chap__foot .ico { transform: translateX(4px); color: var(--accent); }
/* continue reading: the page you stopped at, and how far you got */
.chap .card__progress { margin: 0; height: 7px; }
.chap--cont .chap__art { aspect-ratio: 16 / 10; }
.chap--cont .chap__art img { object-position: 50% 30%; }
/* one or two to continue: a wide panel, the page beside the words */
.chap--wide { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); grid-template-rows: auto 1fr; }
.chap--wide .chap__art { grid-row: 1 / span 2; aspect-ratio: auto; min-height: 210px; }
.chap--wide .chap__art::after { left: auto; top: 0; bottom: 0; right: 0; width: 8px; height: auto; -webkit-mask-image: var(--edge-v1); mask-image: var(--edge-v1); }
.chap--wide .card__progress { grid-column: 2; margin: 20px 18px 0; }
.chap--wide .chap__body { grid-column: 2; justify-content: flex-end; padding: 16px 18px 18px; }
.chap--wide .chap__title { font-size: 1.35rem; white-space: normal; }
@media (max-width: 560px) { .chap--wide { display: flex; } .chap--wide .chap__art { aspect-ratio: 16 / 10; min-height: 0; } .chap--wide .chap__art::after { left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 8px; -webkit-mask-image: var(--edge-h1); mask-image: var(--edge-h1); } .chap--wide .card__progress { margin: 0; } }

/* ---------------------------------------------------------------- rail */
.rail { position: relative; }
.rail__track {
  display: grid; grid-auto-flow: column; grid-auto-columns: var(--rail-col, clamp(150px, 15vw, 210px));
  gap: clamp(14px, 1.6vw, 22px);
  overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scroll-padding-inline: var(--gutter);
  padding: 12px var(--gutter) 22px; margin-inline: calc(var(--gutter) * -1);
  scrollbar-width: none;
}
.rail__track::-webkit-scrollbar { display: none; }
.rail__track > * { scroll-snap-align: start; }
.rail__nav { display: flex; gap: 4px; }
.rail__nav .icon-btn { width: 38px; height: 38px; color: var(--text); }
.rail__nav .icon-btn .ico { width: 22px; height: 22px; }
@media (max-width: 760px) { .rail__nav { display: none; } }

/* ---------------------------------------------------------------- grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(clamp(146px, 14vw, 200px), 1fr)); gap: clamp(28px, 3vw, 44px) clamp(14px, 1.8vw, 26px); }
@media (max-width: 440px) { .grid { grid-template-columns: repeat(2, 1fr); } }

/* ---------------------------------------------------------------- scroll reveal (once)
   main.js adds .has-reveal to <html> and .is-in to [data-inview] as it scrolls in:
   the red labels are brushed on, then their words appear; rows rise. */
html.has-reveal [data-inview]:not(.is-in) .section__title::before,
html.has-reveal [data-inview]:not(.is-in).page-head h1::before { --p: -20%; }
html.has-reveal [data-inview]:not(.is-in) .section__title { color: transparent; }
.rise > * { transition: opacity .8s var(--ease), transform .8s var(--ease); }
html.has-reveal [data-inview]:not(.is-in) .rise > * { opacity: 0; transform: translateY(26px); }
.rise > :nth-child(2) { transition-delay: 60ms; }
.rise > :nth-child(3) { transition-delay: 120ms; }
.rise > :nth-child(4) { transition-delay: 180ms; }
.rise > :nth-child(5) { transition-delay: 240ms; }
.rise > :nth-child(6) { transition-delay: 300ms; }
.rise > :nth-child(7) { transition-delay: 360ms; }
.rise > :nth-child(8) { transition-delay: 420ms; }
.rise > :nth-child(n + 9) { transition-delay: 480ms; }

/* ---------------------------------------------------------------- ink bloom hover
   Grey wash at rest; point at it and the colour splashes out from the pointer.
   <a data-bloom><img class="bloom-wash"><img class="bloom-color">...</a>
   (main.js keeps --bx / --by at the pointer; keyboard focus blooms from the middle). */
@property --ms { syntax: "<length>"; inherits: true; initial-value: 0px; }
[data-bloom] { transition: --ms 1.3s var(--ease); }
[data-bloom]:hover, [data-bloom]:focus-visible { --ms: 3600px; }
.bloom-wash { filter: grayscale(1) brightness(.5) contrast(1.05); }
.bloom-color {
  -webkit-mask: var(--brush-splat) calc(var(--bx, 50%) - var(--ms) / 2) calc(var(--by, 50%) - var(--ms) / 2) / var(--ms) var(--ms) no-repeat;
  mask: var(--brush-splat) calc(var(--bx, 50%) - var(--ms) / 2) calc(var(--by, 50%) - var(--ms) / 2) / var(--ms) var(--ms) no-repeat;
}

/* ---------------------------------------------------------------- empty / boot */
.empty { display: grid; place-items: center; text-align: center; padding: 88px 20px; gap: 14px; color: var(--muted); }
.empty__art { width: 30px; height: auto; filter: var(--mark-filter); opacity: .55; }
svg.empty__art { width: 32px; height: 32px; filter: none; }
.empty h3 { color: var(--text); font: 400 var(--fs-2xl)/1.15 var(--f-brush); -webkit-text-stroke: .03em currentColor; margin-top: 6px; }
.empty p { max-width: 44ch; }
.empty .btn { margin-top: 18px; }
.boot { display: grid; place-items: center; min-height: 70vh; }

/* ---------------------------------------------------------------- search palette: a sheet of paper */
.palette-backdrop {
  position: fixed; inset: 0; z-index: 200; background: color-mix(in srgb, var(--ink) 62%, transparent);
  display: flex; justify-content: center; align-items: flex-start; padding: min(10vh, 96px) 16px 16px;
  animation: fade-in var(--t) var(--ease);
}
.palette {
  width: min(1040px, 100%); height: min(620px, 80vh); display: grid; grid-template-columns: minmax(0, 1fr) 340px;
  background: var(--bg-tex) 0 0 / 512px 512px, var(--bg); border-radius: var(--r-lg); box-shadow: var(--shadow-panel);
  overflow: hidden; animation: palette-in .5s var(--ease);
}
.palette__main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.palette__input { display: flex; align-items: center; gap: 14px; padding: 0 12px 0 24px; height: 76px; flex: none; position: relative; }
.palette__input::after { bottom: -3px; left: 10px; right: 10px; --rule-c: var(--rule); }
.palette__input > .ico { width: 22px; height: 22px; color: var(--text); }
.palette__input input {
  flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; outline: none;
  font: 400 1.6rem/1 var(--f-body); -webkit-appearance: none; appearance: none;
}
.palette__input input::placeholder { color: var(--muted); }
.palette__input input::-webkit-search-cancel-button { display: none; }
.palette__chips { display: flex; gap: 6px; padding: 14px 22px; overflow-x: auto; scrollbar-width: none; flex: none; }
.palette__chips::-webkit-scrollbar { display: none; }
.palette__body { flex: 1; overflow-y: auto; padding: 0 12px 12px; overscroll-behavior: contain; }
.palette__label { padding: 16px 14px 8px; font: 700 var(--fs-xs)/1 var(--f-ui); color: var(--muted); display: flex; justify-content: space-between; }
.palette__label .num { font-size: 14px; }
.palette__label button { color: var(--muted); }
.palette__label button:hover { color: var(--text); }
.result {
  position: relative; isolation: isolate; display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 14px;
  padding: 8px 14px; cursor: pointer; border-radius: var(--r);
}
.result[aria-selected="true"] { background: var(--hover); box-shadow: inset 3px 0 0 var(--accent); }
.result[aria-selected="true"] .result__go { opacity: 1; transform: none; }
.result__cover { width: 38px; height: 57px; border-radius: 2px; object-fit: cover; background: var(--surface-2); }
.result__title { font: 400 1.0625rem/1.25 var(--f-body); color: var(--text-2); }
.result[aria-selected="true"] .result__title { color: var(--text); }
.palette mark { background: none; color: var(--accent); }
.result__sub { font: 500 12px/1.3 var(--f-mono); color: var(--muted); margin-top: 4px; display: flex; gap: 14px; flex-wrap: wrap; }
.result__go { opacity: 0; transform: translateX(-4px); transition: opacity var(--t-fast), transform var(--t) var(--ease); color: var(--accent); }
.result__go .ico { width: 18px; height: 18px; }
.recent { position: relative; display: flex; align-items: center; gap: 12px; padding: 10px 14px; color: var(--text-2); cursor: pointer; border-radius: var(--r); font-family: var(--f-body); }
.recent[aria-selected="true"], .recent:hover { color: var(--text); background: var(--hover); }
.recent .ico { width: 16px; height: 16px; color: var(--muted); }
.palette__foot { position: relative; display: flex; gap: 18px; padding: 12px 22px; color: var(--muted); font: 500 var(--fs-xs)/1.3 var(--f-ui); flex: none; }
.palette__foot span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.palette__foot > span:last-child { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* preview pane: the art is inked in, then the cover and the facts */
.preview { position: relative; overflow: hidden; display: flex; flex-direction: column; }
.preview::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 8px; z-index: 2; pointer-events: none; background: var(--rule);
  -webkit-mask: var(--edge-v1) 0 0 / 100% 100% no-repeat; mask: var(--edge-v1) 0 0 / 100% 100% no-repeat;
}
.preview__banner {
  position: relative; height: 190px; flex: none; overflow: hidden;
  -webkit-mask: var(--brush-art) 0 0 / 100% 100% no-repeat; mask: var(--brush-art) 0 0 / 100% 100% no-repeat;
}
.preview__banner img { width: 100%; height: 100%; object-fit: cover; filter: var(--art-filter); mix-blend-mode: var(--art-blend); animation: fade-in .8s var(--ease); }
.preview__body { position: relative; padding: 0 24px 24px; margin-top: -70px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.preview__cover { width: 96px; aspect-ratio: 2 / 3; object-fit: cover; border-radius: var(--r-sm); box-shadow: var(--shadow-book); background: var(--surface-2); transform: rotate(-2deg); }
.preview__title { font: 400 1.9rem/1.05 var(--f-brush); -webkit-text-stroke: .03em currentColor; margin-top: 8px; }
.preview__orig { color: var(--muted); font: 600 12px/1.3 var(--f-mono); text-transform: uppercase; letter-spacing: .06em; margin-top: -4px; }
.preview__facts { display: flex; flex-wrap: wrap; gap: 6px; }
.preview__facts span { position: relative; padding: 5px 9px; border-radius: 2px; font: 600 var(--fs-xs)/1.2 var(--f-ui); color: var(--text-2); }
.preview__score { display: flex; align-items: center; gap: 14px; margin-top: 6px; }
.preview__score .enso { --size: 56px; }
.preview__score p { font: 500 var(--fs-xs)/1.4 var(--f-ui); color: var(--muted); max-width: 20ch; }
.preview--empty { display: grid; place-items: center; }
.preview--empty img { width: 38px; filter: var(--mark-filter); opacity: .3; }

@media (max-width: 900px) {
  .palette { grid-template-columns: 1fr; }
  .preview { display: none; }
}
@media (max-width: 760px) {
  .palette-backdrop { padding: 0; align-items: stretch; }
  .palette { height: 100%; max-height: none; border-radius: 0; }
  .palette__foot { display: none; }
}

/* ---------------------------------------------------------------- toast: a stroke of ink with words on it */
#toast-root { position: fixed; left: 50%; bottom: calc(30px + var(--tabbar-h)); transform: translateX(-50%); z-index: 400; display: grid; justify-items: center; gap: 10px; pointer-events: none; }
.toast {
  position: relative; isolation: isolate; display: flex; align-items: center; gap: 18px; min-height: 54px; padding: 0 32px;
  color: var(--on-text); font: 700 var(--fs-sm)/1.3 var(--f-ui); pointer-events: auto;
  animation: toast-in .5s var(--ease);
}
.toast::before { inset: -2px -10px; color: var(--text); animation: paint .5s var(--ease) both; }
.toast button { color: inherit; font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.toast.is-leaving { animation: toast-out var(--t) var(--ease) forwards; }

/* ---------------------------------------------------------------- sheet (reader settings, chapter list, pages) */
.sheet-backdrop { position: fixed; inset: 0; z-index: 300; background: rgba(0, 0, 0, .55); animation: fade-in var(--t) var(--ease); }
.sheet {
  position: fixed; z-index: 301; right: 0; top: 0; bottom: 0; width: min(420px, 100vw);
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-panel); animation: sheet-in .6s var(--ease); overflow: hidden;
}
.sheet--wide { width: min(760px, 100vw); }
.sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 14px 14px 26px; }
.sheet__head h3 { font: 400 1.6rem/1.1 var(--f-brush); -webkit-text-stroke: .03em currentColor; }
.sheet__body { overflow-y: auto; padding: 0 26px 26px; overscroll-behavior: contain; }
.setting { position: relative; padding: 18px 0; }
.setting + .setting::before { top: -2px; }
.setting__label { display: flex; justify-content: space-between; font: 650 var(--fs-sm)/1.3 var(--f-ui); margin-bottom: 12px; }
.setting__label span:last-child { color: var(--muted); font-weight: 600; }
.setting__label .num { font-size: 16px; }
.setting .segmented { display: flex; width: 100%; }
.setting .segmented button { flex: 1; padding: 0 8px; }
.swatches { display: flex; gap: 12px; }
.swatches button { width: 40px; height: 40px; border-radius: 50%; box-shadow: inset 0 0 0 1px var(--line-2); outline: 2px solid transparent; outline-offset: 3px; transition: outline-color var(--t-fast); }
.swatches button:hover { outline-color: var(--line-2); }
.swatches button[aria-pressed="true"] { outline-color: var(--accent); }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 10px 16px; font: 500 var(--fs-sm)/1.4 var(--f-ui); color: var(--text-2); align-items: center; }
.keys .kbd { justify-self: start; }
@media (max-width: 760px) {
  .sheet, .sheet--wide {
    left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 86vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0; animation-name: sheet-up; padding-bottom: env(safe-area-inset-bottom);
  }
  .sheet__head { position: relative; padding-top: 24px; }
  .sheet__head::before { content: ""; position: absolute; left: 50%; top: 9px; width: 36px; height: 4px; margin-left: -18px; border-radius: 4px; background: var(--line-2); }
}

@keyframes fade-in { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }
@keyframes palette-in { from { opacity: 0; transform: translateY(-10px) scale(.99); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }
@keyframes sheet-in { from { transform: translateX(40px); opacity: 0; } }
@keyframes sheet-up { from { transform: translateY(100%); } }

/* ---------------------------------------------------------------- page transitions
   The new page is brushed in over the old one (View Transitions, dry-brush
   wipe); a clicked cover flies into place on top of it. */
#app { min-height: calc(100dvh - var(--nav-h)); outline: none; }
.page-enter { animation: fade-in .45s var(--ease); }
html.vt .page-enter { animation: none; }
::view-transition-old(root) { animation: none; }
::view-transition-new(root) {
  animation: ink-wipe .8s var(--ease-in-out) both;
  -webkit-mask: var(--brush-wipe) 100% 0 / 250% 100% no-repeat;
  mask: var(--brush-wipe) 100% 0 / 250% 100% no-repeat;
}
@keyframes ink-wipe {
  from { -webkit-mask-position: 100% 0; mask-position: 100% 0; }
  to { -webkit-mask-position: 0 0; mask-position: 0 0; }
}
::view-transition-group(cover) { animation-duration: .8s; animation-timing-function: var(--ease); z-index: 100; }
::view-transition-old(cover), ::view-transition-new(cover) { animation-duration: .8s; height: 100%; object-fit: cover; border-radius: var(--r); }

.route-progress {
  position: fixed; left: 0; top: 0; height: 3px; z-index: 500; width: 0; opacity: 0;
  background: var(--accent); transition: width .6s var(--ease), opacity .3s;
}
.route-progress.is-active { opacity: 1; }
