/* The ebook page with the sentence you highlight with a finger: one page of a reading app on warm paper, lit by a
   window. The highlight sits on its own layer under the words (.hl), one bar per line: the outer bar is placed by the
   script, the inner ink is what GSAP scales; the menu (.pop) is moved by GSAP, its face (.pop__face) is styled here. */
:root {
  --page: #ebe5dc;          /* the table under the page */
  --page-light: #f8f4ed;    /* the window light on it */
  --paper: #fcf9f4;         /* the paper */
  --ink: #2a2520;           /* the words */
  --muted: #8f857a;         /* the small words */
  --select: rgba(70, 118, 245, 0.2); /* the selection while the finger drags */
  --handle: #3d6ef0;        /* the two handles */
  --amber: #ffd06e;         /* marker one */
  --sage: #bfe0a6;          /* marker two */
  --rose: #ffbcc6;          /* marker three */
  --sky: #b7dbff;           /* marker four */
  --menu: #1e1c1a;          /* the menu */
  --cover: #234d4b;         /* the book's cover */
  --mark: var(--amber);     /* the marker in use */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background:
    radial-gradient(90% 70% at 12% 4%, var(--page-light) 0%, rgba(248, 244, 237, 0) 62%),
    linear-gradient(165deg, var(--page) 0%, #e1d9cd 100%);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* a very fine grain over everything */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.22;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .35  0 0 0 0 .28  0 0 0 0 .2  0 0 0 .55 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.stage {
  position: relative;
  isolation: isolate;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: hidden;
}

/* the soft shadow of a window frame falling across the table */
.stage__window {
  position: absolute;
  inset: -20%;
  z-index: -1;
  pointer-events: none;
  transform: rotate(-24deg);
}

.stage__window span {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent 0 38%, rgba(90, 70, 45, 0.07) 40% 43%, transparent 46% 60%, rgba(90, 70, 45, 0.055) 62% 64.5%, transparent 67%);
  filter: blur(14px);
}

/* the reader */
.rd {
  position: relative;
  width: min(90vw, 372px);
  border-radius: 22px;
  background:
    linear-gradient(90deg, rgba(120, 90, 60, 0.05), rgba(120, 90, 60, 0) 7%, rgba(120, 90, 60, 0) 92%, rgba(120, 90, 60, 0.06)),
    var(--paper);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 0 0 1px rgba(70, 50, 30, 0.07),
    0 2px 3px rgba(70, 50, 30, 0.05),
    0 12px 24px -10px rgba(70, 50, 30, 0.14),
    0 42px 70px -30px rgba(70, 50, 30, 0.32);
  padding: clamp(12px, 3.2vh, 22px) clamp(16px, 5vw, 24px) clamp(10px, 2.8vh, 18px);
}

/* the pages underneath */
.book {
  position: relative;
  opacity: 0;
}

.book__page {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -5px;
  height: 40px;
  border-radius: 0 0 20px 20px;
  background: #f4efe7;
  box-shadow: 0 0 0 1px rgba(70, 50, 30, 0.06), 0 6px 10px -6px rgba(70, 50, 30, 0.22);
}

.book__page--2 {
  left: 22px;
  right: 22px;
  bottom: -10px;
  background: #ece6dc;
}

/* the light on the paper, following the pointer */
.rd__sheen {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(260px 200px at var(--mx, 30%) var(--my, 20%), rgba(255, 255, 255, 0.85), rgba(255, 255, 255, 0) 70%);
  opacity: 0.9;
}

.rd__head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  padding-bottom: clamp(8px, 2.2vh, 14px);
  border-bottom: 1px solid rgba(70, 50, 30, 0.08);
}

/* the little cover */
.rd__cover {
  position: relative;
  flex: none;
  width: 28px;
  height: 40px;
  border-radius: 3px 4px 4px 3px;
  overflow: hidden;
  background: linear-gradient(160deg, #2f6461, var(--cover) 55%, #163230);
  box-shadow: inset 2px 0 0 rgba(255, 255, 255, 0.12), inset 3px 0 0 rgba(0, 0, 0, 0.18), 0 1px 2px rgba(30, 20, 10, 0.25), 0 4px 8px -3px rgba(30, 20, 10, 0.3);
}

.rd__cover::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 45%);
}

.rd__cover-title {
  position: absolute;
  left: 7px;
  right: 5px;
  top: 7px;
  height: 2px;
  border-radius: 1px;
  background: rgba(244, 226, 190, 0.85);
  box-shadow: 0 4px 0 rgba(244, 226, 190, 0.5);
}

.rd__cover-line {
  position: absolute;
  left: 4px;
  right: 0;
  bottom: 12px;
  height: 1px;
  background: rgba(244, 226, 190, 0.45);
}

.rd__cover-sun {
  position: absolute;
  right: 6px;
  bottom: 14px;
  width: 8px;
  height: 4px;
  border-radius: 8px 8px 0 0;
  background: #e8a35a;
}

.rd__book {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.rd__title {
  font-family: 'Newsreader Variable', Georgia, serif;
  font-size: 15px;
  font-weight: 560;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rd__author {
  font-size: 11.5px;
  font-variation-settings: 'wdth' 92;
  color: var(--muted);
  white-space: nowrap;
}

/* the highlights button with its count */
.rd__marks {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 11px 0 9px;
  border: 0;
  border-radius: 17px;
  background: rgba(70, 50, 30, 0.05);
  box-shadow: inset 0 0 0 1px rgba(70, 50, 30, 0.07), inset 0 1px 0 rgba(255, 255, 255, 0.7);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 0.2s;
}

.rd__marks:focus-visible {
  outline: 2px solid var(--handle);
  outline-offset: 2px;
}

@media (hover: hover) {
  .rd__marks:hover {
    background: rgba(70, 50, 30, 0.09);
  }
}

.rd__marks svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  overflow: visible;
}

.rd__marker-tip {
  fill: var(--mark);
}

.rd__count {
  position: relative;
  display: inline-block;
  height: 16px;
  min-width: 2ch;
  overflow: hidden;
  line-height: 16px;
}

.rd__count span {
  position: absolute;
  left: 0;
  top: 0;
}

.rd__count span + span {
  transform: translateY(110%);
}

.rd__body {
  position: relative;
  padding-top: clamp(10px, 2.6vh, 18px);
}

.rd__chapter {
  margin: 0 0 clamp(5px, 1.4vh, 9px);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.rd__text {
  position: relative;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: text;
}

.rd__para {
  position: relative;
  z-index: 1;
  margin: 0;
  font-family: 'Newsreader Variable', Georgia, serif;
  font-size: clamp(13px, min(4.3vw, 3.6vh), 17.5px);
  line-height: 1.55;
  font-weight: 400;
  color: var(--ink);
  font-optical-sizing: auto;
  text-wrap: pretty;
}

.rd__para span {
  transition: color 0.3s;
}

.rd__para .is-marked {
  color: #1b1713;
}

/* the highlight layer, under the words */
.hl {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.hl__bar {
  position: absolute;
  left: 0;
  top: 0;
  height: 0;
}

.hl__ink {
  position: absolute;
  inset: 0;
  transform-origin: 0 50%;
}

.hl__bar--sel .hl__ink {
  border-radius: 3px;
  background: var(--select);
}

/* a marker stroke: uneven ends, a lighter top where the felt lifts, multiplied into the paper */
.hl__bar--mark .hl__ink {
  border-radius: 3px 7px 4px 8px / 6px 4px 7px 3px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 30%, rgba(0, 0, 0, 0) 80%, rgba(120, 80, 20, 0.06)),
    var(--c, var(--amber));
  mix-blend-mode: multiply;
}

/* the two selection handles: a thin bar with a cap, no knobs */
.handle {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  width: 2px;
  height: 22px;
  border-radius: 1px;
  background: var(--handle);
  pointer-events: none;
  opacity: 0;
}

.handle::before {
  content: '';
  position: absolute;
  left: -3px;
  width: 8px;
  height: 2.5px;
  border-radius: 2px;
  background: var(--handle);
}

.handle--a::before {
  top: -1px;
}

.handle--b::before {
  bottom: -1px;
}

.rd__foot {
  position: relative;
  margin-top: clamp(10px, 2.8vh, 20px);
}

.rd__rail {
  display: block;
  height: 2px;
  border-radius: 2px;
  background: rgba(70, 50, 30, 0.1);
  overflow: hidden;
}

.rd__fill {
  display: block;
  width: 64%;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(42, 37, 32, 0.5), var(--ink));
}

.rd__meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 9px;
  font-size: 11.5px;
  font-variation-settings: 'wdth' 92;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.rd__status {
  position: relative;
  display: grid;
}

.rd__line {
  grid-area: 1 / 1;
  white-space: nowrap;
}

.rd__line--saved {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--ink);
  font-weight: 560;
  opacity: 0;
}

.rd__line--saved svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: #3f8a4a;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rd__left {
  white-space: nowrap;
}

/* the menu over the selection */
.pop {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  opacity: 0;
  visibility: hidden;
  transform-origin: var(--ox, 50%) 100%;
}

.pop__face {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-radius: 15px;
  background: linear-gradient(180deg, #2a2724, var(--menu));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    0 1px 2px rgba(20, 12, 4, 0.2),
    0 10px 22px -8px rgba(20, 12, 4, 0.45),
    0 24px 40px -22px rgba(20, 12, 4, 0.5);
}

.pop__notch {
  position: absolute;
  left: var(--ox, 50%);
  bottom: -5px;
  width: 11px;
  height: 11px;
  margin-left: -5.5px;
  border-radius: 0 0 3px 0;
  background: var(--menu);
  transform: rotate(45deg);
}

.pop--below {
  transform-origin: var(--ox, 50%) 0;
}

.pop--below .pop__notch {
  bottom: auto;
  top: -5px;
  border-radius: 3px 0 0 0;
  background: #2a2724;
}

.pop button {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.82);
}

.pop button:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 0;
}

/* a swatch: the colour, a ring when chosen */
.pop__sw span {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: var(--c);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), inset 0 -1px 0 rgba(0, 0, 0, 0.12), 0 0 0 0 rgba(255, 255, 255, 0);
  transition: box-shadow 0.25s;
}

.pop__sw.is-on span {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), inset 0 -1px 0 rgba(0, 0, 0, 0.12), 0 0 0 2px var(--menu), 0 0 0 3.5px rgba(255, 255, 255, 0.85);
}

.pop__sw[data-sw='0'] { --c: var(--amber); }
.pop__sw[data-sw='1'] { --c: var(--sage); }
.pop__sw[data-sw='2'] { --c: var(--rose); }
.pop__sw[data-sw='3'] { --c: var(--sky); }

.pop__rule {
  width: 1px;
  height: 20px;
  margin: 0 3px;
  background: rgba(255, 255, 255, 0.14);
}

.pop__act svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (hover: hover) {
  .pop button:hover {
    background: rgba(255, 255, 255, 0.08);
  }
}
