/*
 * Notepad. The artwork (wood desk, paper, spiral binding, heading flourish) is adapted from
 * https://codepen.io/alvaromontoro/pen/mdggGbg
 *
 * Two custom properties size everything:
 *
 *   --u     one scale unit: 1% of the window's smaller side, capped so a big monitor doesn't get giant
 *           handwriting and narrowed so the pad always fits the window's width.
 *   --line  the row pitch, in whole pixels. Text rows and the ruled lines both use it, which is what keeps the
 *           handwriting on the rules. Anything in the flow of the pad must be a whole number of lines tall, so
 *           row buttons sit in an absolutely positioned gutter and never add height.
 */

@font-face {
  font-family: 'Indie Flower';
  src: url('fonts/indie-flower-latin-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --u: min(1vmin, 8.5px, 0.84vw);
  --line: calc(6.6 * var(--u));
  --paper: #eee;
  --ink: #222;
  --rule: #99f;
  --pen: #1a3fb5;
  --pencil: #0009; /* small or secondary writing: 5.5:1 on the paper */
  --faint: #0008;  /* a placeholder, a number not yet used */
  --highlighter: #fff27a99;
  color-scheme: light;
}

/* A fractional row pitch made rows alternate 28 / 29 px and drift off the rules: round it where CSS can. */
@supports (width: round(nearest, 1.5px, 1px)) {
  :root { --line: round(nearest, calc(6.6 * var(--u)), 1px); }
}

*, *::before, *::after { box-sizing: border-box; }

/* Author display rules would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

html {
  background: #f0a274;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--ink);
}

/* The desk is a fixed layer: on the scrolling page its percentage-sized grain would stretch with the list. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    /* grain */
    radial-gradient(70% 1% at 30% 5%, #c632 80%, #0000 0) 50% 50% / 100% 10%,
    radial-gradient(60% 1.3% at 30% 5%, #c631 80%, #0000 0) 30% 50% / 70% 7.5%,
    radial-gradient(50% 0.7% at 30% 5%, #c631 80%, #0000 0) 30% 50% / 50% 17.5%,
    radial-gradient(60% 1% at 30% 5%, #c631 80%, #0000 0) 0% 10% / 60% 9%,
    radial-gradient(80% 1.3% at 30% 5%, #a411 80%, #0000 0) 70% 20% / 66% 7.5%,
    radial-gradient(100% 1.1% at 30% 5%, #c631 80%, #0000 0) 0% 17% / 70% 12.5%,
    radial-gradient(60% 3% at 50% 0, #c631 80%, #0000 0) 0% 10% / 70% 7.5% repeat-y,
    radial-gradient(40% 4% at 70% 5%, #b521 80%, #0000 0) 100% 2% / 70% 5%,
    /* stains */
    radial-gradient(80% 50% at 20% 20%, #c0824334 10%, #0000 25%),
    radial-gradient(140% 50% at 90% 45%, #c0824324 10%, #0000 15%),
    radial-gradient(100% 50% at 70% 50%, #c0824324 10%, #0000 15%),
    /* base */
    linear-gradient(to top right, #0001, #ffc5),
    #f0a274;
}

/* The page scrolls down; the pad's tilt may poke out sideways, and only that is clipped. It is clipped here
   and not on body: on body a 390 px phone still measured a 411 px wide document. */
.desk {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(13 * var(--u)) 0 calc(16 * var(--u));
  overflow-x: clip;
}

/* ---------- the pad ---------- */

.pad {
  /* The tilt eases off as the list grows: at a fixed 3deg a 2,000 px page would swing 105 px sideways. */
  --tilt: calc(3deg * 14 / max(14, var(--rows, 0)));
  --margin: 2.35em;                   /* the pink margin line, from the left edge */
  --gutter: 2.8em;                    /* where the item numbers start */
  --num: 1.2em;                       /* the number column */
  --tool: 1.05em;                     /* one row button */
  --tools: calc(var(--tool) * 2 + 0.1em);
  --head: calc(var(--line) * 2);      /* blank strip above the heading */
  --nudge: calc(var(--line) * 0.27);  /* how far above a row's bottom edge its rule is drawn */

  position: relative;
  flex: none;
  width: calc(110 * var(--u));
  min-height: calc(130 * var(--u));
  padding: var(--head) 1em calc(var(--line) * 1.5) var(--gutter);
  counter-reset: item;
  font-family: 'Indie Flower', 'Patrick Hand SC', 'Comic Neue', 'Comic Sans', 'Comic Sans MS', Helvetica, Arial, sans-serif;
  font-size: calc(5 * var(--u));
  line-height: var(--line);
  background:
    /* punched holes for the rings */
    radial-gradient(circle at 0.4em 50%, #000 0.125em, #0000 0.135em) 0 0 / 100% calc(3 * var(--u)) repeat-y,
    /* margin line */
    linear-gradient(90deg, #0000 var(--margin), #fbb 0 calc(var(--margin) + 0.05em), #0000 0),
    /* blank strips at the top and bottom of the ruled area */
    linear-gradient(var(--paper), var(--paper)) 100% 0 / calc(100% - var(--margin) - 0.05em) var(--head) no-repeat,
    linear-gradient(var(--paper), var(--paper)) 100% 100% / calc(100% - var(--margin) - 0.05em) calc(var(--line) * 0.9) no-repeat,
    /* ruled lines: one tile per row, the rule on its last pixel */
    linear-gradient(#0000 calc(100% - 1px), var(--rule) 0) 100% calc(var(--head) - var(--nudge)) / calc(100% - var(--margin)) var(--line) repeat-y,
    var(--paper);
  border-radius: 0.05em;
  /* The page edges and the cover, then two soft shadows on the desk. The soft ones used to be a
     filter: drop-shadow() on the whole pad, which made the browser re-raster the pad through the filter on
     every hover and scroll: about 100 times the work of these two layers (measured), for the same picture. */
  box-shadow:
    0.1em 0.1em #ddd,
    0.065em 0.05em #fff,
    0.15em 0.15em #bbb,
    0.125em 0 0 0.15em #333,
    0.25em 0.125em 0 0.15em #000,
    calc(0.25em - 0.25 * var(--u)) 0.225em calc(0.35 * var(--u)) 0.15em #0002,
    calc(0.25em + var(--u)) 0.125em var(--u) 0.15em #0003;
  transform: rotate(var(--tilt));
  transform-origin: calc(11 * var(--u)) calc(13 * var(--u));
}

/* spiral binding: the rings… */
.pad::before {
  content: "";
  position: absolute;
  top: 0;
  left: -1em;
  width: 1.5em;
  height: 100%;
  pointer-events: none;
  background:
    linear-gradient(#0000 0.225em, #999 0 0.375em, #0000 0) 80% 0 / 68% calc(3 * var(--u)) repeat-y,
    linear-gradient(25deg, #0000 0.225em, #666 0 0.35em, #0000 0) 44% 0.1% / 40% calc(3 * var(--u)) repeat-y,
    radial-gradient(circle at 0.4em 50%, #999 0.075em, #0000 0.085em) 0 0 / 100% calc(3 * var(--u)) repeat-y,
    radial-gradient(circle at 1.4em 50%, #999 0.075em, #0000 0.085em) 0 0 / 100% calc(3 * var(--u)) repeat-y;
}

/* …and the light catching them */
.pad::after {
  content: "";
  position: absolute;
  top: 0;
  left: -1em;
  width: 1.5em;
  height: 100%;
  pointer-events: none;
  background:
    linear-gradient(#0000 0.225em, #fff7 0 0.375em, #0000 0) 80% 0 / 68% calc(3 * var(--u)) repeat-y;
  -webkit-mask:
    linear-gradient(90deg, #0000 0.4em, #000 0.6em, #0000 1.2em),
    linear-gradient(#0000 0.225em, #fff7 0.28em 0.3em, #0000 0.375em) 80% 0 / 68% calc(3 * var(--u)) repeat-y;
  -webkit-mask-composite: source-in;
  mask:
    linear-gradient(90deg, #0000 0.4em, #000 0.6em, #0000 1.2em),
    linear-gradient(#0000 0.225em, #fff7 0.28em 0.3em, #0000 0.375em) 80% 0 / 68% calc(3 * var(--u)) repeat-y;
  mask-composite: intersect;
}

/* ---------- controls shared by the whole pad ---------- */

/* :where() keeps this reset at zero specificity, so every rule below it wins without !important. */
:where(.pad, .note, .picker) :where(button, input, textarea) {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: inherit;
  font: inherit;
  line-height: inherit;
  -webkit-appearance: none;
  appearance: none;
}

:where(.pad, .note, .picker) button { cursor: pointer; }

:where(.pad, .note, .picker) :focus-visible {
  outline: max(2px, 0.06em) dashed var(--pen);
  outline-offset: 0.08em;
}

/* ---------- heading ---------- */

/* One line tall per line of text, then one blank row that the flourish hangs into. */
.title {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 var(--line);
  font-size: 1.3em;
  font-weight: bold;
  line-height: var(--line);
}

.title.is-editing { width: 100%; }

.title-text {
  display: block;
  text-align: left;
  overflow-wrap: anywhere;
  cursor: text;
}

/* hand-drawn underline, anchored to the last line so a wrapped heading keeps it underneath */
.title::after {
  content: "";
  position: absolute;
  left: -1%;
  right: -4%;
  bottom: -0.62em;
  height: 1.46em;
  pointer-events: none;
  background: radial-gradient(175% 100% at 50% 100%, #0000 50%, #000 51% 55%, #0000 56%);
  transform: rotate(0.25deg);
}

/* ---------- items ---------- */

.items {
  margin: 0;
  padding: 0;
  list-style: none;
}

.item,
.add-row {
  position: relative;
  display: grid;
  grid-template-columns: var(--num) minmax(0, 1fr);
  column-gap: 0.35em;
  min-height: var(--line);
  padding-right: var(--tools);
  counter-increment: item;
}

/* The item's number is its drag handle. */
.grip,
.add-num {
  display: flex;
  justify-content: flex-end; /* a long number grows to the left, into the margin */
  height: var(--line);
  white-space: nowrap;
}

/* No touch-action here: under a finger the number lifts only after a short hold (makeSortable in script.js),
   so a scroll that happens to start on a number still scrolls the page. */
.grip {
  position: relative;
  cursor: grab;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.grip::before,
.add-num::before { content: counter(item) "."; }

/* six dots in the margin: "this row can be dragged" */
.grip::after {
  content: "";
  position: absolute;
  left: -1.35em;
  top: calc(50% - 0.36em);
  width: 0.44em;
  height: 0.66em;
  background: radial-gradient(circle, currentColor 34%, #0000 40%) 0 0 / 50% 33.34%;
  opacity: 0;
  transition: opacity 0.12s;
}

.item:hover .grip::after,
.grip:focus-visible::after,
.item.is-dragging .grip::after { opacity: 0.4; }

/* The item's text fills its line: clicking anywhere on the line edits it in place.
   - text-decoration is written as longhands: Safari before 26.2 drops the shorthand when it carries a colour,
     and a crossed-off item would show no line at all.
   - touch-action: a finger moving sideways reaches the page (the swipe that crosses a line off), while one
     moving up or down still scrolls. */
.text {
  position: relative;
  min-width: 0;
  overflow-wrap: anywhere;
  cursor: text;
  touch-action: pan-y pinch-zoom;
  text-decoration-line: line-through;
  text-decoration-color: transparent;
  transition: text-decoration-color 0.15s, color 0.15s;
}

/* crossed off: the red line, and the ink fades so what is still open stands out */
.is-done .text {
  color: var(--pencil);
  text-decoration-color: #f00;
}

/* written, not saved yet (the connection is slow or gone): pencil until the server has it */
.is-pending .text { color: var(--pencil); }

/* the red line following a finger that is crossing the item off (script.js sets the three properties) */
.is-striking .text::after {
  content: "";
  position: absolute;
  left: var(--strike-from, 0);
  top: calc((var(--strike-line, 0) + 0.56) * var(--line));
  width: var(--strike-length, 0);
  height: max(2px, 0.08em);
  border-radius: 1px;
  background: #f00;
  pointer-events: none;
}

/* the cross-off button shows the state too */
.is-done .tool.done { color: #d00; }

/* the in-place editor for an item or the heading, and the "next blank line" input */
.editor,
#newItem {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: var(--line);
  outline: 0;
  resize: none;
  overflow: hidden;
}

.editor { grid-column: 2; }

#newItem { height: var(--line); }

.editor,
#newItem:focus {
  /* a stroke of highlighter instead of a boxy focus ring */
  background: linear-gradient(var(--highlighter), var(--highlighter)) 0 62% / 100% 58% repeat-y;
}

#newItem::placeholder {
  color: var(--faint);
  opacity: 1;
}

.add-num { color: var(--faint); }

/* ---------- row buttons ---------- */

.tools {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 0.1em;
  height: var(--line);
}

.tool {
  display: grid;
  place-items: center;
  width: var(--tool);
  height: var(--tool);
  border-radius: 50%;
  color: #445;
  opacity: 0;
  transition: opacity 0.12s, background-color 0.12s;
}

.tool svg {
  width: 0.6em;
  height: 0.6em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (hover: hover) {
  .tool:hover { background: #0001; color: #000; }
}

.item:hover .tool,
.item:focus-within .tool,
.item.is-editing .tool,
#newItem:not(:placeholder-shown) ~ .tools .tool { opacity: 1; }

/* The Add button is only there once something is typed. While it is not, it must not take the focus either
   (opacity alone would leave an invisible Tab stop). */
@media (hover: hover) {
  #newItem:placeholder-shown ~ .tools .add { visibility: hidden; }
}

/* ---------- dragging ---------- */

.item.is-dragging {
  z-index: 2;
  background: #fffdf2;
  box-shadow: 0 0.08em 0.35em #0004;
}

.is-sorting .item:not(.is-dragging) { transition: transform 0.16s ease; }

body.is-sorting,
body.is-sorting .grip { cursor: grabbing !important; }

body.is-sorting {
  -webkit-user-select: none;
  user-select: none;
}

body.is-sorting .tool { opacity: 0 !important; }

/* ---------- foot ---------- */

/* One line: "clear crossed-off" and "un-cross all" on the left, "tear out this page" on the right. When they
   wrap (three of them do on a phone), each link is a line tall, so the foot still ends on a rule. */
.foot {
  display: flex;
  flex-wrap: wrap;
  column-gap: 1.2em;
  min-height: var(--line);
  margin: var(--line) 0 0;
}

.foot-link {
  height: var(--line);
  font-size: 0.6em;
  color: var(--pencil);
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-underline-offset: 0.15em;
  white-space: nowrap;
}

/* Red under the pointer. Only where there is one: a touch screen keeps the last thing tapped "hovered", and the
   link that happened to be under an Undo tap stayed red. */
@media (hover: hover) {
  .foot-link:hover { color: #b00; }
}

.tear,
.empty { margin-left: auto; }

/* only there while something on the page is crossed off */
.clear,
.uncross { display: none; }

.pad:has(.item.is-done) .clear,
.pad:has(.item.is-done) .uncross { display: block; }

/* a plain line of writing: the "can't reach the database" page, "The trash is empty." */
.plain { margin: 0; }

.plain a { color: var(--pen); }

/* ---------- the Trash, as a page of the pad ---------- */

/* its foot: how long things stay, and the way to empty it */
.foot-note {
  font-size: 0.6em;
  color: var(--pencil);
}

.empty { color: #b00; }

/* how long ago, where an item's number would be */
.age {
  display: flex;
  justify-content: flex-end;
  height: var(--line);
  padding-top: 0.16em; /* small writing sits high in a full-height line: bring it down to the baseline */
  font-size: 0.6em;
  color: var(--pencil);
  white-space: nowrap;
}

/* what is in the trash is written a little fainter than what is on a page */
.gone .text {
  cursor: default;
  color: #000a;
}

@media (hover: hover) {
  .forever:hover { color: #b00; }
}

/* line-height 0: smaller writing on the same line would otherwise make the line a few pixels taller than
   --line, and every row below would slide off the rules */
.gone small {
  font-size: 0.6em;
  line-height: 0;
  color: var(--pencil);
}

/* Restore is the only thing to do here, so it does not wait for a hover */
.gone .tool { opacity: 1; }

/* "from <page>" above that page's deleted items */
.from {
  height: var(--line);
  padding-left: 2.6em; /* the text column, in this smaller writing */
  overflow: hidden;
  font-size: 0.6em;
  color: var(--pencil);
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- index tabs along the top edge ---------- */

.tabs {
  position: absolute;
  left: calc(var(--margin) + 0.3em);
  right: 0.7em;
  bottom: 100%;
  display: flex;
  align-items: flex-end;
  gap: 0.25em;
  padding: 0.4em 0.2em 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  font-size: 0.5em;
  line-height: 1.9;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: none;
  max-width: 11em;
  padding: 0 0.8em;
  overflow: hidden;
  border-radius: 0.45em 0.45em 0 0;
  background: var(--tab, #ffe08a);
  box-shadow: inset 0 -0.3em 0.3em -0.3em #0006;
  color: #333;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A page's colour comes from its id (notepad_render_tab), so it keeps it wherever its tab is dragged to.
   The same classes colour the pages in the "Move to…" picker. */
.tab-c1 { --tab: #ffe08a; }
.tab-c2 { --tab: #bfe6cb; }
.tab-c3 { --tab: #f9c4c4; }
.tab-c0 { --tab: #c2dcf6; }

/* the open page's tab is paper-coloured, stands a little taller and keeps a stripe of its colour */
.tab[aria-current] {
  padding-top: 0.3em;
  background: var(--paper);
  box-shadow: inset 0 0.22em 0 var(--tab, #0000);
  color: #000;
}

/* Tabs are links that can also be dragged: no text selection, no long-press link preview. */
.tab {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.tab.is-dragging {
  position: relative;
  z-index: 2;
  box-shadow: 0 0.1em 0.5em #0007;
}

.is-sorting .tab:not(.is-dragging) { transition: transform 0.16s ease; }

/* the way into the Trash, where the window has no desk to stand the wastebasket on */
.tab.tab-bin {
  --tab: #dcd6cc;
  display: flex;
  align-items: center;
  height: 1lh;
  padding: 0 0.6em;
}

.tab-bin svg {
  width: 1.05em;
  height: 1.05em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* How many things are in it, in drawn digits (lib.php, notepad_digits(), says why they are not written in the
   handwriting font). They take the icon's pen from the rule above; each is as wide as its own box. */
.tab-count {
  display: flex;
  margin-left: 0.3em;
}

.tab-count svg { width: auto; }

.tab-count:empty { display: none; }

/* ---------- the wastebasket on the desk ---------- */

/* The trash has two ways in and one shows at a time. A wide window has bare desk to the right of the pad, and
   the wastebasket stands there: fixed, like the desk itself, so it stays put while the pad scrolls. Where
   there is no such room, the bin tab above stands in for it. */
.desk-bin { display: none; }

@media (min-width: 1300px) {
  .tab.tab-bin { display: none; }

  .desk-bin {
    position: fixed;
    right: calc(25vw - 35 * var(--u)); /* centred in the strip of desk beside the pad */
    bottom: calc(5 * var(--u));
    z-index: 1;
    display: grid;
    justify-items: center;
    width: calc(15 * var(--u));
    color: #333;
    font-family: 'Indie Flower', 'Comic Sans MS', Helvetica, Arial, sans-serif;
    font-size: calc(2.7 * var(--u));
    line-height: 1.35;
    text-decoration: none;
    transition: transform 0.15s;
    -webkit-tap-highlight-color: transparent;
  }
}

.desk-bin:hover { transform: scale(1.04); }

.desk-bin:focus-visible {
  outline: 3px dashed var(--pen);
  outline-offset: 6px;
  border-radius: 8px;
}

.bin-art {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(calc(0.5 * var(--u)) calc(0.9 * var(--u)) calc(0.8 * var(--u)) #0007);
}

/* Up to three balls of crumpled paper; data-pile says how many. They pop in when something is thrown away
   and shrink out when the trash is emptied. */
.ball {
  opacity: 0;
  transform: scale(0.4);
  transform-box: fill-box;
  transform-origin: center;
  transition: opacity 0.2s, transform 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
}

.desk-bin[data-pile="1"] .ball-1,
.desk-bin[data-pile="2"] .ball-1,
.desk-bin[data-pile="2"] .ball-2,
.desk-bin[data-pile="3"] .ball {
  opacity: 1;
  transform: none;
}

/* A line that was just thrown away, on its way to the wastebasket as a ball of paper (script.js, toss()).
   Outside the pad, so the pad's tilt does not become its frame of reference. */
.toss {
  position: fixed;
  z-index: 5;
  pointer-events: none;
}

.toss svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
  filter: drop-shadow(0 0.35em 0.3em #0005);
}

/* its name, on a strip of masking tape */
.bin-label {
  margin-top: 0.55em;
  padding: 0 0.7em;
  background: #f6edc8e6;
  box-shadow: 0 1px 2px #0005;
  white-space: nowrap;
  rotate: -2deg;
}

.desk-bin[aria-current] .bin-label { box-shadow: 0 1px 2px #0005, inset 0 -0.14em 0 #b00a; } /* open now */

.tab.tab-add,
.tab.tab-help {
  --tab: #fff9;
  padding: 0 0.7em;
}

.tab:hover:not([aria-current]) { filter: brightness(1.06); }

.tab:focus-visible { outline-offset: -0.2em; }

/* ---------- sticky notes: an item's note, "how this pad works", and the question before a delete for good ---------- */

.picker {
  width: min(88vw, 24rem);
  max-height: 80vh;
  padding: 0.9em 1.1em 0.8em;
  overflow-y: auto;
  border: 0;
  background: #fff59d;
  box-shadow: 0 0.3em 1.2em #0008;
  color: #222;
  font-family: 'Indie Flower', 'Comic Sans MS', Helvetica, Arial, sans-serif;
  font-size: clamp(19px, calc(3.2 * var(--u)), 26px);
  line-height: 1.35;
  rotate: -1deg;
}

.picker::backdrop { background: #3a1e0a66; }

.picker h2 {
  margin: 0 0 0.45em;
  font-size: 1em;
  overflow-wrap: anywhere;
}

.picker p { margin: 0; }

.picker-pages { display: grid; }

.pick {
  display: flex;
  align-items: baseline;
  gap: 0.55em;
  min-height: 40px;
  padding: 0.2em 0.35em;
  border-radius: 0.2em;
  text-align: left;
  overflow-wrap: anywhere;
}

/* the page's tab colour */
.pick::before {
  content: "";
  flex: none;
  width: 0.7em;
  height: 0.7em;
  border-radius: 0.12em;
  background: var(--tab, #ffe08a);
  box-shadow: inset 0 0 0 1px #0003;
}

.pick:hover,
.pick:focus-visible { background: #0001; }

/* what can be done with the line itself: no colour chip, a pencilled dash */
.pick.act::before {
  width: 0.7em;
  height: 0.08em;
  align-self: center;
  border-radius: 0;
  background: #0007;
  box-shadow: none;
}

.pick[hidden] + .pick { margin-top: 0; }

/* "move to", above the pages */
.picker-label,
.picker-none,
.picker-hint {
  font-size: 0.8em;
  color: #0009;
}

.picker .picker-label { margin: 0.45em 0 0.1em; }

.picker .picker-hint { margin-top: 0.5em; }

.picker-cancel {
  margin-top: 0.6em;
  font-size: 0.8em;
  color: #0009;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-underline-offset: 0.15em;
}

/* Words that depend on how the pad is being used: a mouse, or a finger. */
.by-touch { display: none; }

@media (hover: none) {
  .by-touch { display: revert; }
  .by-mouse { display: none; }
}

/* "how this pad works": a reference, so smaller writing than the other notes, and two columns of it (what a
   mouse does, what the keys do) where there is room for both */
.help {
  width: min(94vw, 24rem);
  font-size: clamp(16px, calc(2.4 * var(--u)), 20px);
}

.help h2 { font-size: 1.25em; }

.help dl { margin: 0; }

.help dl > div {
  display: grid;
  grid-template-columns: 7.4em 1fr;
  gap: 0 0.9em;
  padding: 0.14em 0;
}

.help dt { font-weight: bold; }

.help dd { margin: 0; }

.help-keys { margin-top: 0.7em; }

.help dl.help-keys > div { grid-template-columns: 6.3em 1fr; }

.help-keys dt { font-weight: normal; }

.help kbd {
  padding: 0 0.3em;
  border: 1px solid #0005;
  border-radius: 0.2em;
  background: #fff8;
  font: inherit;
  white-space: nowrap;
}

@media (hover: hover) and (min-width: 760px) {
  .help { width: min(94vw, 50rem); }

  .help-cols {
    display: grid;
    grid-template-columns: 1.25fr 1fr;
    gap: 0 2.4em;
    align-items: start;
  }

  .help-keys { margin-top: 0; }
}

/* The same note asks before something that cannot be undone (the Trash): cancel on the left, where the focus
   starts, and the deed on the right, ringed in red pen. */
.confirm-actions {
  display: flex;
  flex-wrap: wrap; /* on a narrow note the deed drops below "cancel" rather than breaking in two */
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5em 1em;
  margin-top: 0.9em;
}

.confirm-actions .picker-cancel { margin-top: 0; }

.confirm-yes {
  padding: 0.1em 0.7em 0.05em;
  border: 0.09em solid #b00;
  border-radius: 0.5em 1.1em 0.6em 1.2em / 1.1em 0.5em 1.2em 0.6em;
  color: #b00;
  font-weight: bold;
  white-space: nowrap;
}

.confirm-yes:hover { background: #b0000016; }

/* ---------- the note at the bottom (Undo, errors) ---------- */

/* --keyboard is how much of the window an on-screen keyboard covers (script.js, visualViewport): the note and
   the saving label stay above it. */
.note {
  position: fixed;
  left: 50%;
  bottom: calc(max(1rem, env(safe-area-inset-bottom)) + var(--keyboard, 0px));
  z-index: 10;
  display: flex;
  align-items: baseline;
  gap: 0.9em;
  max-width: min(92vw, 36rem);
  padding: 0.5em 1em 0.45em;
  background: #fff59d;
  box-shadow: 0 0.15em 0.5em #0006;
  color: #222;
  font-family: 'Indie Flower', 'Comic Sans MS', Helvetica, Arial, sans-serif;
  font-size: clamp(18px, calc(3 * var(--u)), 24px);
  line-height: 1.3;
  translate: -50% 0;
  rotate: -1.2deg;
  animation: note-in 0.18s ease-out;
}

.note.is-error { background: #ffc9c9; }

.note button,
.note a {
  flex: none;
  color: var(--pen);
  text-decoration: underline;
}

/* an error stays until it is dismissed */
.note .note-close {
  color: #0009;
  text-decoration: none;
  font-size: 1.2em;
  line-height: 0.8;
}

/* ---------- "saving…": a strip of tape, bottom left, only when saving is slow or not getting through ---------- */

.sync {
  position: fixed;
  left: max(0.8rem, env(safe-area-inset-left));
  bottom: calc(max(0.8rem, env(safe-area-inset-bottom)) + var(--keyboard, 0px));
  z-index: 9;
  display: flex;
  align-items: baseline;
  gap: 0.6em;
  padding: 0.05em 0.8em;
  background: #f6edc8f0;
  box-shadow: 0 1px 2px #0005;
  color: #333;
  font-family: 'Indie Flower', 'Comic Sans MS', Helvetica, Arial, sans-serif;
  font-size: clamp(16px, calc(2.6 * var(--u)), 21px);
  line-height: 1.5;
  rotate: 1.5deg;
}

.sync.is-stuck { background: #ffd9a8f5; }

.sync button,
.sync a {
  padding: 0;
  border: 0;
  background: none;
  color: var(--pen);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

@keyframes note-in {
  from { translate: -50% 1em; opacity: 0; }
}

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

/* ---------- touch screens: buttons are always there, one per row ---------- */

@media (hover: none) {
  /* A touch screen never gets rows shorter than its buttons, however small the window: a phone on its side
     (844 × 390) used to get 26 px rows under 40 px buttons, so a tap on one row's edge ticked the next. */
  :root {
    --u: max(4.4px, min(1vmin, 8.5px, 0.84vw));
    --line: max(40px, calc(6.6 * var(--u)));
  }

  @supports (width: round(nearest, 1.5px, 1px)) {
    :root { --line: max(40px, round(nearest, calc(6.6 * var(--u)), 1px)); }
  }

  .pad {
    --tool: max(1.05em, 40px);
    --tools: calc(var(--tool) + 0.1em);
  }

  .tool { opacity: 0.75; }

  .grip::after { opacity: 0.25; }

  .tabs {
    font-size: max(0.5em, 16px);
    line-height: 2.2;
  }

  /* a row in the Trash keeps both its buttons: put back, and delete for good */
  .pad[data-view="trash"] { --tools: calc(var(--tool) * 2 + 0.1em); }

  /* One button per row, and it never changes under the thumb: the tick. Throwing a line away is in the note
     that opens from its number. */
  .item .del { display: none; }
}

/* ---------- phones: the pad fills the screen ---------- */

@media (max-width: 640px) {
  :root {
    --u: 1.14vw;
    --line: max(40px, calc(8.6 * var(--u)));
  }

  @supports (width: round(nearest, 1.5px, 1px)) {
    :root { --line: max(40px, round(nearest, calc(8.6 * var(--u)), 1px)); }
  }

  .desk {
    justify-content: flex-start;
    padding: calc(15 * var(--u)) 0 calc(12 * var(--u));
  }

  .pad {
    --tilt: calc(0.5deg * 14 / max(14, var(--rows, 0)));
    --margin: 1.7em;
    --gutter: 2.05em;
    width: calc(100vw - 1em - 14px);
    min-height: calc(100vh - 27 * var(--u));
    min-height: calc(100dvh - 27 * var(--u));
    margin-left: calc(1em + 4px); /* room for the binding, which hangs 1em off the left edge */
    padding-right: 0.5em;
  }

  .tabs {
    font-size: 0.74em;
    line-height: 2.2;
  }
}

/* ---------- motion ---------- */

@media (prefers-reduced-motion: no-preference) {
  /* Opening another page turns the sheet over the spiral, in browsers that can animate from one document to
     the next. The script in index.php's <head> says which way: "forward" lifts the sheet that was on top and
     the new page is under it; "back" brings the earlier sheet down onto the one being left. With neither (the
     same place in the strip, or no way to tell) the pad cross-fades; elsewhere the page simply changes. */
  @view-transition { navigation: auto; }

  .pad { view-transition-name: pad; }

  /* The new page is already there under the moving picture: a click during the turn goes to it. (Chromium.
     Safari holds clicks until the turn is over whatever is said here; measured in WebKit.) */
  ::view-transition { pointer-events: none; }

  html:active-view-transition-type(forward)::view-transition-group(pad),
  html:active-view-transition-type(back)::view-transition-group(pad) { animation-duration: 0.42s; }

  html:active-view-transition-type(forward)::view-transition-old(pad),
  html:active-view-transition-type(forward)::view-transition-new(pad),
  html:active-view-transition-type(back)::view-transition-old(pad),
  html:active-view-transition-type(back)::view-transition-new(pad) {
    mix-blend-mode: normal; /* one sheet lies on the other: nothing is blended */
    transform-origin: 0 50%;
    animation: none;
  }

  /* Only the paper turns: the cover, the rings and the tabs are cut off the moving picture (they are all
     outside the pad's own box), and the ones of the page underneath show in their place. */
  html:active-view-transition-type(forward)::view-transition-old(pad) {
    z-index: 1;
    clip-path: inset(0);
    animation: 0.42s cubic-bezier(0.45, 0, 0.9, 0.55) both turn-over;
  }

  /* the same turn played backwards, so it slows as the sheet lands */
  html:active-view-transition-type(back)::view-transition-new(pad) {
    clip-path: inset(0);
    animation: 0.42s cubic-bezier(0.45, 0, 0.9, 0.55) reverse both turn-over;
  }
}

/* The sheet swings on its left edge, the spiral, until it is edge-on to the desk; it darkens a little as it
   turns away from the light. */
@keyframes turn-over {
  to {
    transform: perspective(260vmin) rotateY(-88deg);
    filter: brightness(0.82);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
