/* The page doesn't scroll: the header and the notepad stay put, and the code point list
   fills the rest of the window and scrolls by itself. The scroller is full window width
   (wheel works anywhere below the notepad, scrollbar at the window edge); its content is
   the usual centered column. If the notepad grows taller than the window, the page
   scrolls after all, so the text is never cut off */
.layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}
.page.top {
  flex: none;
  width: 100%;
  padding-bottom: 0;
}
.list-scroll {
  flex: 1 1 0;
  min-height: 160px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* Rows scroll up to the notepad's cut edge, fading out over the last 50px */
.list-scroll::before {
  content: "";
  position: sticky;
  top: 0;
  z-index: 1;
  display: block;
  height: 50px;
  margin-bottom: -50px;
  background: linear-gradient(var(--bg), rgb(255 255 255 / 0));
  pointer-events: none;
}
/* The first glyph box starts below the fade: 46 + 4 (row padding) = 50 */
.page.code-points { padding-top: 46px; padding-bottom: 48px; isolation: isolate; }

/* Text field: a dot-grid notepad. The textarea is the top sheet, ::before and ::after are
   two sheets underneath peeking out on the right. The shadow falls on top, left and right;
   the bottom is cut off flat by clip-path */
.field {
  --dot: #a9a395;
  --dot-step: 16px;
  --ink: #0020d0;
  /* Handwriting: Shantell Sans, then Playpen Sans for Greek, math and its script-specific
     families, then the regular glyph stack (Noto, system, emoji) for everything else */
  --hand: "Shantell Sans", "Playpen Sans", "Playpen Sans Arabic", "Playpen Sans Hebrew",
    "Playpen Sans Deva", "Playpen Sans Thai", var(--glyph);
  position: relative;
  margin-top: 40px;
  isolation: isolate;
  clip-path: inset(-40px -40px 0 -40px);
}
.field::before,
.field::after {
  content: "";
  position: absolute;
  z-index: -1;
  border-radius: 0 12px 0 0;
  pointer-events: none;
}
.field::before {
  inset: 6px -5px -6px 5px;
  background: #cbc3b1;
  box-shadow: 0 0 28px rgb(51 38 13 / 0.14), 0 1px 2px rgb(0 0 0 / 0.08);
}
.field::after {
  inset: 3px -2.5px -3px 2.5px;
  background: #e4dfd3;
  box-shadow: inset 0 0 0 0.5px rgb(0 0 0 / 0.05);
}

/* Text sits on the dot grid: the line height is three dot steps, and the font size puts the
   baseline exactly on a dot row (Shantell Sans: ascent 1.02em, descent 0.32em, so at 46/48
   the baseline is 40px into the line; 48px padding + 40px = 88 = 8 + 5 × 16). Caps are
   then two dot steps tall. Fallback fonts don't change the line height, so every line lands
   on the grid

   The textarea takes input and selection; its own text, selection and caret are invisible.
   The text is drawn by .mirror on top, laid out identically, so a grapheme can be colored;
   .selection and .caret are positioned by JS, one line box tall, so they fit the grid */
.input,
.mirror {
  padding: 48px 50px;
  font: 400 46px/48px var(--hand);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  tab-size: 4;
  text-align: left;
}
.input {
  position: relative;
  display: block;
  width: 100%;
  min-height: 144px;
  margin: 0;
  border: 0;
  border-radius: 0 12px 0 0;
  /* Shade along the left edge, dots top-aligned (they stay put as lines are added) and
     centered horizontally, warm paper */
  background:
    linear-gradient(to right, rgb(107 94 69 / 0.07), transparent 16px),
    radial-gradient(circle, var(--dot) 0.5px, transparent 1px) center top / var(--dot-step) var(--dot-step),
    linear-gradient(#fbfaf6, #f4f1ea);
  box-shadow: 0 0 3px rgb(0 0 0 / 0.06), inset 0 1px 0 rgb(255 255 255 / 0.9);
  color: transparent;
  caret-color: transparent;
  resize: none;
  overflow: hidden;
  outline: none;
  field-sizing: content;
}
.input::placeholder { color: #808080; opacity: 1; }
.input::selection { color: transparent; background: transparent; }

.mirror {
  position: absolute;
  inset: 0;
  overflow: hidden;
  color: var(--ink);
  pointer-events: none;
}
::highlight(grapheme) { color: #d00000; }
.selection {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.selection > div {
  position: absolute;
  background: rgb(0 32 208 / 0.14);
}
.selection.inactive > div { background: rgb(0 0 0 / 0.07); }
.selection.mark > div { background: rgb(208 0 0 / 0.12); }
/* Positioned by JS: left edge = caret x, top and height = the line box */
.caret {
  position: absolute;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 1.5px;
  background: var(--ink);
  pointer-events: none;
  animation: blink 1.1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* scroll-margin: when hovering in the notepad scrolls a grapheme into view, it stops 100px
   from the edge (clear of the fade, with a row and a half of context), not flush with it */
.grapheme { position: relative; scroll-margin: 100px 0; }
/* No dividers: graphemes are separated by space. Code points of one grapheme are 8px apart
   (glyph box to glyph box), graphemes 24px */
.grapheme + .grapheme { margin-top: 16px; }
/* Selected in the notepad: blue; hovered (here or in the notepad): red. 12px around the glyph
   boxes, so neighbouring selected graphemes join into one band */
.grapheme.selected::before,
.grapheme.hovered::before {
  content: "";
  position: absolute;
  inset: -8px -12px;
  z-index: -1;
  background: rgb(0 32 208 / 0.14);
}
.code-points.inactive .grapheme.selected::before { background: rgb(0 0 0 / 0.07); }
.grapheme.hovered::before,
.code-points.inactive .grapheme.hovered::before { background: rgb(208 0 0 / 0.12); }
/* Hovered text turns the same red as the hovered grapheme in the notepad, muted text included */
.grapheme.hovered,
.grapheme.hovered :is(.name.label, .meta, .glyph-abbr) { color: #d00000; }

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 48px;
  padding: 4px 0;
}
/* Connects glyphs of code points that make up one grapheme */
.row:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 20px;
  top: 44px;
  width: 1px;
  height: 8px;
  background: var(--join);
}

.glyph {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: var(--tint);
  font: 400 22px/1 var(--glyph);
  overflow: hidden;
  white-space: pre;
}
/* Invisible code points: spaces, controls, format characters, variation selectors, unassigned */
.glyph.blank {
  background: transparent;
  border: 1px solid var(--join);
}
.glyph-abbr {
  color: var(--muted);
  font: 400 10px/1 var(--mono);
  letter-spacing: -0.02em;
}

.code {
  flex: none;
  width: 84px;
  font: 400 13px/17px var(--mono);
}
/* Links to unicodeplus.com: a faint underline until hovered */
a.code {
  color: inherit;
  text-decoration: underline 1px var(--join);
  text-underline-offset: 3px;
}
a.code:hover { text-decoration-color: currentColor; }

.info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 16px;
}
.name {
  flex: 1;
  min-width: 0;
}
.name.label { color: var(--muted); }
/* Category, then script when it's a real one: "Lowercase letter, Latin" */
.meta {
  flex: none;
  width: 240px;
  color: var(--muted);
  font-size: 13px;
  line-height: 16px;
}
.name, .meta {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.more {
  margin-top: 16px;
  padding: 16px 0;
  color: var(--muted);
  font: 400 12px/16px var(--mono);
}

@media (max-width: 600px) {
  /* Two dot steps per line; 23px puts the baseline 24px into the line: 32 + 24 = 56 = 8 + 3 × 16 */
  .input, .mirror { font-size: 23px; line-height: 32px; padding: 32px 28px; }
  .input { min-height: 96px; }
  .code { width: 72px; font-size: 12px; }
  .info { flex-direction: column; align-items: stretch; gap: 2px; }
  .meta { width: auto; font-size: 12px; line-height: 15px; }
}
