/* The ebook reader with the word that opens in the dictionary: one page of a reading app on warm paper, alone on
   white. The reader is drawn at one size (392 px wide) and .fit scales it to the window from the script, so the words
   always wrap the same way. GSAP moves the outer pieces (.w, .dict, .dict__face rows); the CSS styles their children. */
:root {
  --bg: #ffffff;            /* the page around the reader */
  --paper: #fbf7f0;         /* the paper */
  --paper-edge: #f1ebe1;    /* the pages underneath */
  --ink: #2a2520;           /* the words */
  --muted: #8d8378;         /* the small words */
  --accent: #b4432f;        /* the one accent: vermilion ink */
  --accent-soft: rgba(180, 67, 47, 0.13); /* the pill that fills behind a held word */
  --glass: rgba(255, 253, 249, 0.6);      /* the dictionary card */
  --cover: #2b2c35;         /* the book's cover */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

.stage {
  position: relative;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
}

/* centred by the script (xPercent and yPercent), so a reader wider than a small window is scaled around its middle */
.fit {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 392px;
  transform: translate(-50%, -50%);
  transform-origin: 50% 50%;
}

.book {
  position: relative;
  opacity: 0;
}

/* the edges of the pages underneath */
.book__page {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -5px;
  height: 40px;
  border-radius: 0 0 22px 22px;
  background: var(--paper-edge);
  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: 26px;
  right: 26px;
  bottom: -10px;
  background: #e9e2d6;
}

/* the reader */
.rd {
  position: relative;
  border-radius: 26px;
  padding: 22px 26px 18px 34px;
  background:
    linear-gradient(90deg, rgba(120, 90, 60, 0.06), rgba(120, 90, 60, 0) 8%, rgba(120, 90, 60, 0) 93%, rgba(120, 90, 60, 0.05)),
    var(--paper);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 0 0 1px rgba(70, 50, 30, 0.08),
    0 2px 3px rgba(70, 50, 30, 0.05),
    0 14px 26px -12px rgba(70, 50, 30, 0.16),
    0 46px 76px -30px rgba(70, 50, 30, 0.34);
}

/* the grain of the paper */
.rd::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  opacity: 0.32;
  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='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .4  0 0 0 0 .3  0 0 0 0 .2  0 0 0 .5 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

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

/* header: the cover, the book and the word list */
.rd__head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: -8px;
}

.rd__cover {
  position: relative;
  flex: none;
  width: 28px;
  height: 40px;
  border-radius: 3px 5px 5px 3px;
  background: linear-gradient(160deg, #3a3b46, var(--cover) 60%, #1d1e25);
  box-shadow: inset 2px 0 0 rgba(255, 255, 255, 0.12), inset 3px 0 2px rgba(0, 0, 0, 0.25), 0 3px 6px -2px rgba(30, 20, 10, 0.35);
  overflow: hidden;
}

.rd__cover-line {
  position: absolute;
  left: 7px;
  right: 6px;
  bottom: 11px;
  height: 1px;
  background: rgba(255, 236, 214, 0.55);
}

.rd__cover-moon {
  position: absolute;
  right: 6px;
  top: 8px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  box-shadow: inset -2.5px 1px 0 0 var(--accent);
}

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

.rd__title {
  font-family: 'Newsreader Variable', Georgia, serif;
  font-size: 15.5px;
  font-weight: 560;
  font-variation-settings: 'opsz' 24;
  letter-spacing: -0.005em;
}

.rd__author {
  font-size: 11.5px;
  color: var(--muted);
  font-variation-settings: 'wdth' 100;
  letter-spacing: 0.01em;
}

.rd__words {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: inset 0 1px 0 #fff, 0 0 0 1px rgba(70, 50, 30, 0.09), 0 2px 5px -2px rgba(70, 50, 30, 0.18);
  font-size: 12.5px;
  font-weight: 560;
  font-variation-settings: 'wdth' 96;
  transition: box-shadow 0.25s;
}

.rd__words:focus-visible,
.w:focus-visible,
.dict__add:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

@media (hover: hover) {
  .rd__words:hover {
    box-shadow: inset 0 1px 0 #fff, 0 0 0 1px rgba(70, 50, 30, 0.14), 0 6px 12px -5px rgba(70, 50, 30, 0.26);
  }
}

.rd__words-icon {
  width: 18px;
  height: 18px;
  overflow: visible;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.rd__words-ribbon {
  fill: var(--accent);
  stroke: var(--accent);
  stroke-width: 1;
}

/* a window with two figures stacked: the script slides them up */
.roll {
  position: relative;
  display: inline-grid;
  overflow: hidden;
  vertical-align: bottom;
  height: 1.25em;
  line-height: 1.25em;
}

.roll > span {
  grid-area: 1 / 1;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.rd__count {
  min-width: 1.2ch;
  color: var(--accent);
  font-weight: 640;
}

/* the page */
.rd__body {
  position: relative;
  padding-top: 20px;
}

.rd__chapter {
  margin: 0 0 12px;
  font-size: 10.5px;
  font-weight: 600;
  font-variation-settings: 'wdth' 112;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.rd__text {
  position: relative;
}

.rd__para {
  position: relative;
  margin: 0;
  font-family: 'Newsreader Variable', Georgia, serif;
  font-size: 17px;
  line-height: 1.62;
  font-weight: 400;
  font-variation-settings: 'opsz' 16;
  letter-spacing: 0.002em;
  text-wrap: pretty;
  hyphens: none;
  --dim: 0; /* the rest of the page goes quiet while the card is open: the script raises it */
  color: rgba(42, 37, 32, calc(1 - var(--dim)));
}

.rd__para .w.is-lifted .w__txt {
  color: var(--ink);
}

/* a word in the dictionary */
.w {
  position: relative;
  display: inline-block;
  font: inherit;
  line-height: 1.2;
  letter-spacing: inherit;
  cursor: pointer;
  border-radius: 6px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.w.is-lifted {
  z-index: 3;
}

.w__txt {
  position: relative;
}

.w__fill {
  position: absolute;
  inset: -1px -5px;
  border-radius: 7px;
  background: var(--accent-soft);
  transform: scaleX(0);
  opacity: 0;
}

.w__line {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 1.5px;
  background: repeating-linear-gradient(90deg, var(--accent) 0 3px, transparent 3px 5.5px);
  transform: scaleX(0);
  transform-origin: 0 50%;
}

@media (hover: hover) {
  .w:hover .w__txt {
    color: #000;
  }
}

/* the marks in the margin */
.rd__marks {
  position: absolute;
  left: -19px;
  top: 0;
  width: 6px;
  height: 100%;
  pointer-events: none;
}

.mark {
  position: absolute;
  left: 0;
  width: 3px;
  border-radius: 2px;
  background: linear-gradient(var(--accent), #d1664c);
  box-shadow: 0 1px 2px rgba(180, 67, 47, 0.3);
  transform-origin: 50% 50%;
}

/* the footer: how far you have read */
.rd__foot {
  position: relative;
  margin-top: 20px;
  display: grid;
  gap: 9px;
}

.rd__rail {
  position: relative;
  height: 3px;
  border-radius: 3px;
  background: rgba(70, 50, 30, 0.1);
}

.rd__fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  border-radius: inherit;
  background: var(--ink);
  transform-origin: 0 50%;
  transform: scaleX(0.32);
}

.rd__knob {
  position: absolute;
  top: 50%;
  left: 0;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 1.5px var(--ink), 0 2px 4px rgba(30, 20, 10, 0.25);
}

.rd__meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 11.5px;
  color: var(--muted);
  font-variation-settings: 'wdth' 100;
  font-variant-numeric: tabular-nums;
}

.rd__left {
  color: var(--ink);
  font-weight: 540;
}

.rd__sep {
  margin: 0 5px;
  color: var(--muted);
}

/* the dictionary card */
.dict {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  width: 276px;
}

.dict[hidden] {
  display: none;
}

.dict__face {
  position: relative;
  border-radius: 18px;
  padding: 12px 16px 12px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 40%),
    var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  backdrop-filter: blur(14px) saturate(1.5);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 0 0 1px rgba(255, 255, 255, 0.55),
    0 0 0 1px rgba(70, 50, 30, 0.1),
    0 2px 4px rgba(70, 50, 30, 0.06),
    0 14px 28px -10px rgba(70, 50, 30, 0.26),
    0 34px 60px -24px rgba(70, 50, 30, 0.3);
  overflow: hidden;
}

/* the light that slides over the glass as it opens */
.dict__glint {
  position: absolute;
  top: -40%;
  bottom: -40%;
  left: 0;
  width: 60px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0));
  transform: translateX(-120px) rotate(18deg);
  opacity: 0;
}

.dict__notch {
  position: absolute;
  left: var(--nx, 50%);
  width: 14px;
  height: 14px;
  margin-left: -7px;
  bottom: -6px;
  transform: rotate(45deg);
  border-radius: 3px;
  background: rgba(253, 250, 245, 0.93);
  box-shadow: 1px 1px 0 rgba(70, 50, 30, 0.1);
}

.dict.is-below .dict__notch {
  bottom: auto;
  top: -6px;
  box-shadow: -1px -1px 0 rgba(70, 50, 30, 0.1);
}

.dict__top {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 600;
  font-variation-settings: 'wdth' 110;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.dict__lang {
  letter-spacing: 0.04em;
  text-transform: none;
  font-weight: 500;
}

.dict__head {
  margin: 6px 0 0;
  line-height: 1;
}

.dict__hw {
  --hw: 560;
  display: inline-block;
  font-family: 'Newsreader Variable', Georgia, serif;
  font-size: 29px;
  font-weight: var(--hw);
  font-variation-settings: 'opsz' 60;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.dict__pos {
  margin: 4px 0 0;
  font-family: 'Newsreader Variable', Georgia, serif;
  font-style: italic;
  font-size: 13.5px;
  color: var(--accent);
}

.dict__def {
  margin: 7px 0 0;
  font-size: 13px;
  line-height: 1.45;
  font-variation-settings: 'wdth' 100;
}

.dict__ex {
  margin: 6px 0 0;
  padding-left: 10px;
  border-left: 1.5px solid rgba(70, 50, 30, 0.14);
  font-family: 'Newsreader Variable', Georgia, serif;
  font-style: italic;
  font-size: 13.5px;
  line-height: 1.4;
  color: #5b5148;
}

.dict__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid rgba(70, 50, 30, 0.1);
}

.dict__more {
  font-size: 11px;
  color: var(--muted);
}

.dict__add {
  flex: none;
  border-radius: 999px;
}

.dict__add-face {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #c24d37, var(--accent));
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  font-variation-settings: 'wdth' 100;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 0 0 1px rgba(120, 35, 20, 0.5), 0 4px 10px -4px rgba(150, 45, 25, 0.6);
  transition: box-shadow 0.25s, filter 0.25s;
}

@media (hover: hover) {
  .dict__add:hover .dict__add-face {
    filter: brightness(1.06);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 0 0 1px rgba(120, 35, 20, 0.5), 0 7px 14px -5px rgba(150, 45, 25, 0.7);
  }
}

.dict__add-icon {
  width: 13px;
  height: 13px;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.dict__check {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.dict__add-words {
  display: inline-grid;
  overflow: hidden;
  height: 16px;
  line-height: 16px;
}

.dict__add-words > span {
  grid-area: 1 / 1;
  white-space: nowrap;
}

.dict__add-words > span + span {
  transform: translateY(100%);
  opacity: 0;
}
