/*
 * noted — User's guide: the styles of the booklet in manual.js.
 *
 * Link this next to the module (fonts/ sits beside it) and give the page an
 * empty <dialog id="manual">: manual.js builds everything else into it.
 *
 * Every rule sits under #manual, every class is bk-prefixed, and nothing here
 * styles html or body: the page's own rules can't be reached by the booklet's
 * names, and these can't reach the page. Whatever the page sets on its
 * elements (a global button, :focus-visible and ::selection rules, a
 * 16px/24px body with kerning off) is answered below, under #manual, by an
 * explicit value for each property the booklet depends on. What the page
 * leaves to the host (html.manual-open { overflow: hidden }, the dialog's
 * opener) is not done here.
 *
 * State classes, on the dialog: bk-clean (the interface hidden), bk-flat (no
 * WebGL: plain images), bk-wood (the table's wood is in: the canvas shows),
 * bk-ready (the book is on the table), bk-inline (the book lies in the page:
 * see the end of this file).
 */

@font-face {
  font-family: "Barlow Semi Condensed";
  src: url("./fonts/BarlowSemiCondensed-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Barlow Semi Condensed";
  src: url("./fonts/BarlowSemiCondensed-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

/* ---------------------------------------------------------------- the dialog */

#manual {
  --bk-label: #dccdb8;
  --bk-quiet: #bcab94;
  --bk-active: #fbf3e8;
  --bk-ring: rgba(251, 243, 232, .3);
  --bk-font: "Barlow Semi Condensed", "Barlow", "Arial Narrow", system-ui, sans-serif;
  --bk-ease: cubic-bezier(.2, .8, .2, 1);

  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
  background: #1c0e08;
  color: var(--bk-active);
  color-scheme: dark;

  /* The text of the booklet, whatever the page's body says. */
  font: 500 15px/20px var(--bk-font);
  font-kerning: auto;
  font-synthesis: weight style;
  font-variant: normal;
  text-rendering: auto;
  text-align: left;
  text-indent: 0;
  text-transform: none;
  text-shadow: none;
  letter-spacing: normal;
  word-spacing: normal;
  white-space: normal;
  cursor: default;
  outline: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
#manual::backdrop { background: #120904; }

#manual[open] {
  animation: bk-in 240ms var(--bk-ease) both;
  transform-origin: var(--ox, 50%) var(--oy, 50%);
}
@keyframes bk-in { from { opacity: 0; transform: scale(.96); } }

#manual,
#manual *,
#manual *::before,
#manual *::after { box-sizing: border-box; }
/* Whatever colour the page gives the dialog itself, the booklet's parts start from their own. */
#manual > * { color: var(--bk-active); }
#manual [hidden] { display: none !important; }
#manual ::selection { background: rgba(251, 243, 232, .22); color: inherit; text-shadow: none; }
#manual svg { display: block; max-width: none; margin: 0; padding: 0; border: 0; vertical-align: baseline; overflow: visible; }
#manual .bk-icon svg { width: 20px; height: 20px; }
#manual .bk-round svg { width: 18px; height: 18px; }
#manual img,
#manual canvas { image-rendering: auto; }

/* Without WebGL the table is the wood itself: a pool of lamp light, the
   room's falloff and a faint film grain over it. */
#manual.bk-flat {
  background-color: #1a100a;
  background-image:
    radial-gradient(ellipse 60% 55% at 68% 6%, rgba(255, 176, 96, .24), rgba(255, 176, 96, 0) 70%),
    radial-gradient(ellipse farthest-corner at 50% 46%, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, .66) 100%),
    linear-gradient(rgba(0, 0, 0, .4), rgba(0, 0, 0, .4)),
    url("./desk.jpg");
  background-size: cover;
  background-position: center;
}
#manual.bk-flat::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='220' height='220' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------------------------------------------------------------- the stage */

#manual .bk-stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  display: block;
  touch-action: none;
  -webkit-touch-callout: none;
  /* The table fades in out of the dark once its wood is in. */
  opacity: 0;
  transition: opacity 360ms ease;
}
#manual.bk-wood .bk-stage { opacity: 1; }

#manual .bk-captions { position: absolute; inset: 0; margin: 0; pointer-events: none; }

#manual .bk-cap {
  position: absolute;
  left: 0;
  top: 0;
  margin: 0;
  font: 500 20px/24px var(--bk-font);
  letter-spacing: .005em;
  color: var(--bk-label);
  text-shadow: 0 1px 3px rgba(0, 0, 0, .55);
  white-space: nowrap;
  opacity: 0;
  will-change: transform, opacity;
}

/* Shown only if the book takes a moment, and gone as it appears. */
#manual .bk-opening {
  position: absolute;
  left: 50%;
  top: 50%;
  margin: 0;
  transform: translate(-50%, -50%);
  font: 500 15px/20px var(--bk-font);
  letter-spacing: .02em;
  color: var(--bk-quiet);
  opacity: 0;
  pointer-events: none;
  animation: bk-opening-in 400ms ease 300ms forwards;
}
@keyframes bk-opening-in { to { opacity: .85; } }
#manual.bk-ready .bk-opening { display: none; }

/* ---------------------------------------------------------------- top bar */

#manual .bk-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  margin: 0;
  padding: 0 max(28px, env(safe-area-inset-right)) 0 max(28px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  /* Clicks pass through to the stage (which takes the keyboard); only the
     buttons catch them. */
  pointer-events: none;
}

#manual .bk-title {
  margin: 0;
  padding: 0;
  font: 500 15px/20px var(--bk-font);
  letter-spacing: .02em;
  color: var(--bk-label);
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
#manual .bk-brand { font-weight: 600; color: #f1e6d6; letter-spacing: .04em; }

#manual .bk-tools {
  display: flex;
  flex: none;
  align-items: center;
  gap: 2px;
  margin: 0 -12px 0 0;
  padding: 0;
  pointer-events: none;
}
#manual .bk-exit {
  display: flex;
  align-items: center;
  gap: 2px;
  transition: opacity 320ms ease;
  pointer-events: none;
}
#manual .bk-sep {
  display: block;
  width: 1px;
  height: 18px;
  margin: 0 8px;
  background: rgba(251, 243, 232, .2);
}

#manual .bk-icon {
  -webkit-appearance: none;
  appearance: none;
  width: 44px;
  height: 44px;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: none;
  box-shadow: none;
  color: var(--bk-quiet);
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
  text-shadow: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  pointer-events: auto;
  transition: color 160ms ease, background-color 160ms ease, opacity 320ms ease;
}
#manual .bk-icon:hover { color: var(--bk-active); background-color: rgba(255, 255, 255, .05); }
#manual .bk-icon:active { background-color: rgba(255, 255, 255, .09); }
#manual .bk-sound[aria-pressed="true"] .bk-mute,
#manual .bk-sound[aria-pressed="false"] .bk-wave,
#manual .bk-eye[aria-pressed="true"] .bk-slash { display: none; }

/* ---------------------------------------------------------------- pager */

#manual .bk-pager {
  position: absolute;
  left: 50%;
  bottom: max(28px, env(safe-area-inset-bottom));
  margin: 0;
  padding: 0;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 18px;
  pointer-events: none;
}

#manual .bk-round {
  -webkit-appearance: none;
  appearance: none;
  width: 44px;
  height: 44px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  border: 1.5px solid var(--bk-ring);
  background: transparent;
  box-shadow: none;
  color: #eee2d1;
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
  text-shadow: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  pointer-events: auto;
  transition: border-color 160ms ease, color 160ms ease, background-color 160ms ease, opacity 200ms ease;
}
#manual .bk-round:hover { border-color: rgba(251, 243, 232, .6); color: #fff; background-color: rgba(255, 255, 255, .05); }
#manual .bk-round:active { background-color: rgba(255, 255, 255, .08); }
#manual .bk-round[aria-disabled="true"] { opacity: .32; cursor: default; }
#manual .bk-round[aria-disabled="true"]:hover { border-color: var(--bk-ring); color: #eee2d1; background-color: transparent; }

#manual .bk-dots { display: flex; align-items: center; gap: 2px; margin: 0; padding: 0; pointer-events: none; }
#manual .bk-dot {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  min-width: 0;
  min-height: 0;
  padding: 0;
  margin: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  box-shadow: none;
  color: inherit;
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
  text-shadow: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  pointer-events: auto;
}
#manual .bk-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--bk-ring);
  transition: background-color 200ms ease, transform 200ms ease;
}
#manual .bk-dot:hover::before { background: rgba(251, 243, 232, .6); }
#manual .bk-dot[aria-current="step"]::before { background: var(--bk-active); transform: scale(1.1); }
@media (pointer: coarse) {
  #manual .bk-dot { width: 30px; height: 44px; border-radius: 12px; }
}

/* The stage and the flat view are the keyboard's; a ring on the whole window would say nothing. */
#manual:focus-visible,
#manual .bk-stage:focus,
#manual .bk-flatview:focus { outline: none; }
#manual :focus-visible { outline: 2px solid var(--bk-active); outline-offset: 3px; }
#manual .bk-dot:focus-visible { outline-offset: 0; }
#manual .bk-icon:focus-visible { outline-offset: -4px; border-radius: 12px; }
#manual .bk-stage:focus-visible,
#manual .bk-flatview:focus-visible { outline: none; }

/* ---------------------------------------------------------------- no-WebGL fallback */

#manual .bk-flatview {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
#manual .bk-spread {
  position: absolute;
  display: flex;
  margin: 0;
  padding: 0;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .35);
}
#manual .bk-fig { position: relative; margin: 0; padding: 0; }
#manual .bk-fig img {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
  object-fit: cover;
  -webkit-user-drag: none;
}
#manual .bk-fig + .bk-fig::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 7%;
  background: linear-gradient(90deg, rgba(0, 0, 0, .16), rgba(0, 0, 0, 0));
  pointer-events: none;
}
#manual .bk-fig.bk-left::after {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: 7%;
  background: linear-gradient(270deg, rgba(0, 0, 0, .16), rgba(0, 0, 0, 0));
  pointer-events: none;
}
#manual .bk-label {
  position: absolute;
  left: 50%;
  top: 100%;
  margin: 0;
  padding: 0;
  transform: translate(-50%, 14px);
  font: 500 20px/24px var(--bk-font);
  letter-spacing: .005em;
  color: var(--bk-label);
  white-space: nowrap;
}

#manual .bk-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- clean view */
/* Everything but the book can be hidden: H, or the eye button. The eye and
   the × stay, quietly: the way back, and the way out. */

#manual .bk-pager,
#manual .bk-captions,
#manual .bk-label,
#manual .bk-title,
#manual .bk-sound { transition: opacity 320ms ease, visibility 0s linear 0s; }
#manual.bk-clean .bk-pager,
#manual.bk-clean .bk-captions,
#manual.bk-clean .bk-label,
#manual.bk-clean .bk-title,
#manual.bk-clean .bk-sound {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 320ms ease, visibility 0s linear 320ms;
}
#manual.bk-clean .bk-eye,
#manual.bk-clean .bk-exit { opacity: .5; }
#manual.bk-clean .bk-eye:hover,
#manual.bk-clean .bk-exit:hover,
#manual.bk-clean .bk-eye:focus-visible,
#manual.bk-clean .bk-exit:focus-within { opacity: 1; }

#manual .bk-toast {
  position: absolute;
  left: 50%;
  bottom: max(34px, env(safe-area-inset-bottom));
  margin: 0;
  padding: 9px 16px 10px;
  border-radius: 999px;
  background: rgba(26, 14, 8, .88);
  border: 1px solid rgba(251, 243, 232, .16);
  color: #efe4d4;
  font: 500 15px/20px var(--bk-font);
  letter-spacing: .02em;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity 260ms ease, transform 320ms var(--bk-ease);
}
#manual:not(.bk-clean) .bk-toast { bottom: calc(max(28px, env(safe-area-inset-bottom)) + 58px); }
#manual .bk-toast.bk-show { opacity: 1; transform: translate(-50%, 0); }
#manual .bk-key {
  display: inline-block;
  min-width: 20px;
  margin: 0 3px;
  padding: 1px 5px 2px;
  border: 1px solid rgba(251, 243, 232, .32);
  border-radius: 4px;
  font: 600 13px/16px var(--bk-font);
  letter-spacing: normal;
  color: var(--bk-active);
  text-align: center;
}

@media (max-width: 560px) {
  #manual .bk-top { padding: 0 16px; gap: 12px; }
  #manual .bk-title { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  #manual[open] { animation: none; }
  #manual .bk-stage { transition-duration: 1ms; }
  #manual .bk-toast { transform: translate(-50%, 0); transition: opacity 120ms ease; }
  #manual .bk-opening { animation-duration: 1ms; }
}

/* ---------------------------------------------------------------- inline */
/* The same book, in the page's flow instead of a dialog: no desk, no chrome,
   just the book on a transparent canvas. The page sizes the host (an
   aspect-ratio here, which it may override) and gives it its place; the
   booklet's text rules above still hold for the toast and the fallback.
   Where the page leaves empty room above the host, --bk-bleed lets the
   canvas reach up into it: the book lies in the host, and a page rising as
   it turns may use that room, so the book can be framed larger. */

#manual.bk-inline {
  position: relative;
  inset: auto;
  z-index: auto;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  background: none;
  overflow: visible;
  animation: none;
}
#manual.bk-inline.bk-flat { background: none; }
#manual.bk-inline.bk-flat::before { display: none; }
#manual.bk-inline .bk-top,
#manual.bk-inline .bk-captions,
#manual.bk-inline .bk-pager,
#manual.bk-inline .bk-opening,
#manual.bk-inline .bk-label { display: none; }
/* A page scrolls past the book: only a sideways drag turns it. */
#manual.bk-inline .bk-stage { top: calc(-1 * var(--bk-bleed, 0px)); height: auto; touch-action: pan-y; transition-duration: 480ms; }
#manual.bk-inline.bk-ready .bk-stage { opacity: 1; }
#manual.bk-inline .bk-toast { bottom: 8px; }
/* The book is the focus: no ring round the whole canvas. */
#manual.bk-inline .bk-stage:focus-visible,
#manual.bk-inline .bk-flatview:focus-visible { outline: none; }

