:root {
  --room: #0b0a0b;
  --ink: #2a2420;
  --paper: #efe6d3;
  --paper-edge: #d9ccb2;
  --glow: #e9dcc4;
  --glow-dim: rgba(233, 220, 196, 0.62);
  --glow-faint: rgba(233, 220, 196, 0.32);
  --accent: #c8a15a;
  --font: "IM Fell English", "Iowan Old Style", Georgia, serif;
  --font-sc: "IM Fell English SC", "IM Fell English", Georgia, serif;
  color-scheme: dark;
}
/* Folio is a dark room with a lamp in it whatever the system theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --room: #0b0a0b; }
}
:root[data-theme="dark"] { --room: #0b0a0b; }

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--room);
  color: var(--glow);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
  overscroll-behavior: none;
}
canvas#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}
canvas#view.turning { cursor: grabbing; }
canvas#view.page { cursor: pointer; }
canvas#view.lamp { cursor: crosshair; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.mast {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  pointer-events: none;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.8);
}
.mast h1 {
  margin: 0;
  font-weight: 400;
  font-size: 30px;
  letter-spacing: 0.02em;
  color: var(--glow);
}
.mast .sub {
  margin: 2px 0 0;
  font-style: italic;
  font-size: 15px;
  color: var(--glow-dim);
}
.mast .where {
  margin: 10px 0 0;
  font-family: var(--font-sc);
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--glow-faint);
}

.tools {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  display: flex;
  gap: 6px;
}
.tool {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px 0 10px;
  border: 1px solid rgba(233, 220, 196, 0.16);
  border-radius: 19px;
  background: rgba(20, 17, 16, 0.55);
  color: var(--glow-dim);
  font: 15px var(--font);
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.tool:hover, .tool:focus-visible { color: var(--glow); border-color: rgba(233, 220, 196, 0.4); outline: none; }
.tool[aria-pressed="true"]#lampBtn { color: #f3d28c; border-color: rgba(243, 210, 140, 0.55); background: rgba(60, 44, 20, 0.6); }
.tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#soundBtn[aria-pressed="false"] .wave { opacity: 0.15; }

.turn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 72px;
  border: 0;
  background: transparent;
  color: var(--glow-faint);
  font: 48px/1 var(--font);
  cursor: pointer;
  transition: color 0.2s, opacity 0.3s;
}
.turn:hover, .turn:focus-visible { color: var(--glow); outline: none; }
.turn.prev { left: max(6px, env(safe-area-inset-left)); }
.turn.next { right: max(6px, env(safe-area-inset-right)); }
.turn[disabled] { opacity: 0; pointer-events: none; }

.hint {
  position: fixed;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  margin: 0;
  font-style: italic;
  font-size: 19px;
  color: var(--glow-dim);
  text-shadow: 0 1px 14px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  transition: opacity 0.8s;
  white-space: nowrap;
}
.hint.gone { opacity: 0; }

.slip {
  position: fixed;
  left: 50%;
  bottom: max(48px, calc(env(safe-area-inset-bottom) + 40px));
  transform: translateX(-50%) rotate(-0.4deg);
  width: min(640px, calc(100vw - 32px));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px 7px 18px;
  background:
    radial-gradient(120% 140% at 10% 0%, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 60%),
    linear-gradient(180deg, #f1e8d5, #e6dbc4);
  border-radius: 3px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset, 0 12px 30px rgba(0, 0, 0, 0.55), 0 2px 4px rgba(0, 0, 0, 0.4);
  transition: opacity 0.5s, transform 0.5s;
}
.slip::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 3px;
  background-image: repeating-linear-gradient(90deg, rgba(120, 100, 70, 0.025) 0 1px, transparent 1px 3px);
  pointer-events: none;
}
.slip.away { opacity: 0; transform: translateX(-50%) translateY(16px) rotate(-0.4deg); pointer-events: none; }
.slip input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 21px/1.3 var(--font);
  padding: 6px 0;
  outline: none;
}
.slip input::placeholder { color: rgba(42, 36, 32, 0.45); font-style: italic; }
.nib {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px 0 12px;
  border: 0;
  border-radius: 2px;
  background: #2b3a44;
  color: #efe6d3;
  font: 17px var(--font);
  cursor: pointer;
  transition: background 0.2s;
}
.nib:hover, .nib:focus-visible { background: #3b4f5c; outline: none; }
.nib svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; }

.knows {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(640px, calc(100vw - 32px));
  margin: 0;
  text-align: center;
  font-size: 15px;
  font-style: italic;
  color: var(--glow-faint);
  min-height: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.knows b { font-weight: 400; font-style: normal; color: var(--glow-dim); }
.knows i { color: #d9b878; }

.about {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  top: 64px;
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 180px);
  overflow: auto;
  padding: 18px 22px 16px;
  background: linear-gradient(180deg, #f1e8d5, #e4d8bf);
  color: var(--ink);
  border-radius: 3px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  font-size: 16px;
  line-height: 1.45;
}
.about h2 { margin: 0 0 8px; font-weight: 400; font-size: 22px; }
.about p { margin: 0 0 10px; }
.about .keys { font-size: 14px; color: rgba(42, 36, 32, 0.75); }
.about .close {
  border: 1px solid rgba(42, 36, 32, 0.3);
  background: transparent;
  color: var(--ink);
  font: 15px var(--font);
  padding: 5px 14px;
  border-radius: 2px;
  cursor: pointer;
}

.about .row { display: flex; gap: 8px; margin: 4px 0 0; }
.flying {
  position: fixed;
  z-index: 5;
  font: 21px/1.3 var(--font);
  color: #f1e8d5;
  text-shadow: 0 0 18px rgba(255, 220, 150, 0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  transition: transform 1.4s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 1.4s ease-in, filter 1.4s;
}
.flying.go { transform: translateY(-34vh) scale(0.8); opacity: 0; filter: blur(2px); }
.toast {
  position: fixed;
  left: 50%;
  top: 76px;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 16px;
  background: rgba(20, 17, 16, 0.82);
  border: 1px solid rgba(233, 220, 196, 0.18);
  border-radius: 18px;
  font-size: 15px;
  color: var(--glow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
.toast.show { opacity: 1; }
.nojs { position: fixed; inset: 40% 0 auto; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .flying { display: none; }
  .slip, .hint, .toast { transition: none; }
}
body.shot .mast, body.shot .tools, body.shot .turn, body.shot .hint, body.shot .slip, body.shot .knows { display: none; }

@media (max-width: 640px) {
  .mast h1 { font-size: 24px; }
  .mast .sub { display: none; }
  .tool .label { display: none; }
  .tool { padding: 0 10px; width: 38px; justify-content: center; }
  .turn { width: 36px; font-size: 40px; }
  .slip input { font-size: 18px; }
  .nib span { display: none; }
  .hint { font-size: 17px; }
}
