:root {
  --page-bg: #ffffff;
  --page-text: #111111;
  --link: #31588e;
  --reader-ink: #31588e;
  --panel-bg: rgba(255, 255, 255, 0.97);
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--page-bg);
  color: var(--page-text);
}

body {
  min-height: 100vh;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.68;
}

button,
input,
textarea { font: inherit; }

a {
  color: var(--link);
  text-underline-offset: 0.15em;
}

.site-shell {
  position: relative;
  z-index: 2;
  width: min(760px, calc(100% - 3rem));
  margin: 0 auto;
  padding: 12vh 0 18vh;
}

.site-shell.narrow { width: min(620px, calc(100% - 3rem)); }

.story-entry p {
  margin: 0 0 1.45rem;
  font-size: clamp(1.08rem, 0.7vw + 0.92rem, 1.28rem);
}

.page-number {
  position: absolute;
  top: 1rem;
  left: 1rem;
  z-index: 20;
  display: block;
  min-width: 1rem;
  color: #ffffff;
  background: #ffffff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1rem;
  line-height: 1.4;
  user-select: text;
}

.page-number::selection {
  color: #000000;
  background: #bcd7ff;
}

.long-drop { min-height: 300vh; }

.password-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 2rem;
}

.password-card {
  width: min(420px, 100%);
  text-align: center;
}

.password-card form {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 0.5rem;
}

.password-card input {
  width: 100%;
  padding: 0.75rem 0.4rem;
  border: 0;
  border-bottom: 1px solid var(--page-text);
  outline: none;
  background: transparent;
  color: var(--page-text);
  text-align: center;
}

.password-card button {
  padding: 0.65rem 0.75rem;
  border: 0;
  background: transparent;
  color: var(--page-text);
  cursor: pointer;
}

.password-card .start-link {
  display: inline-block;
  margin-top: 3.75rem;
}

.password-error { animation: password-error 180ms linear 2; }

@keyframes password-error {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(0.35rem); }
}

#freehand-canvas,
#margin-layer {
  position: absolute;
  top: 0;
  left: 0;
}

#freehand-canvas {
  z-index: 10;
  pointer-events: none;
}

#freehand-canvas.is-drawing {
  pointer-events: auto;
  cursor: crosshair;
  touch-action: none;
}

#margin-layer {
  z-index: 11;
  pointer-events: none;
}

.margin-note {
  position: absolute;
  right: max(1rem, calc((100vw - min(760px, calc(100vw - 3rem))) / 2 - 12rem));
  width: min(11rem, 24vw);
  padding-left: 0.7rem;
  border-left: 2px solid var(--note-color, var(--reader-ink));
  color: var(--note-color, var(--reader-ink));
  font-family: "Bradley Hand", "Comic Sans MS", cursive;
  font-size: clamp(0.76rem, 0.35vw + 0.68rem, 0.92rem);
  line-height: 1.3;
  overflow-wrap: anywhere;
  transform: rotate(var(--note-rotation, 0deg));
}

.pen-toggle {
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 40;
  display: grid;
  width: 3rem;
  height: 3rem;
  place-items: center;
  border: 1px solid rgba(17, 17, 17, 0.4);
  border-radius: 999px;
  background: var(--panel-bg);
  color: var(--reader-ink);
  cursor: pointer;
}

.pen-toggle svg {
  width: 1.3rem;
  height: 1.3rem;
}

.pen-panel {
  position: fixed;
  left: 1rem;
  bottom: 4.6rem;
  z-index: 39;
  display: grid;
  gap: 0.45rem;
  width: min(190px, calc(100vw - 2rem));
  padding: 0.7rem;
  border: 1px solid rgba(17, 17, 17, 0.2);
  background: var(--panel-bg);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.12);
}

.pen-panel[hidden] { display: none; }

.pen-panel button,
.note-dialog button {
  padding: 0.48rem 0.6rem;
  border: 1px solid rgba(17, 17, 17, 0.25);
  background: transparent;
  color: var(--page-text);
  cursor: pointer;
}

.pen-panel button[aria-pressed="true"] {
  border-color: var(--reader-ink);
  color: var(--reader-ink);
  box-shadow: inset 0 0 0 1px var(--reader-ink);
}

body.margin-note-active .margin-note-anchor { cursor: text; }

body.margin-note-active .margin-note-anchor:hover {
  outline: 1px dashed var(--reader-ink);
  outline-offset: 0.25rem;
}

.note-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.22);
}

.note-dialog {
  width: min(430px, 100%);
  padding: 1rem;
  border: 1px solid rgba(17, 17, 17, 0.25);
  background: #ffffff;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.16);
}

.note-dialog textarea {
  width: 100%;
  min-height: 7rem;
  padding: 0.65rem;
  border: 1px solid rgba(17, 17, 17, 0.25);
  background: #ffffff;
  color: var(--page-text);
  resize: vertical;
}

.note-dialog footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

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

@media (max-width: 1040px) {
  .site-shell,
  .site-shell.narrow {
    width: min(680px, calc(100% - 4rem));
    margin-left: 2rem;
  }

  .margin-note {
    right: 0.7rem;
    width: min(9rem, 28vw);
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--note-color, var(--reader-ink));
    background: rgba(255, 255, 255, 0.94);
  }
}

@media (max-width: 680px) {
  .site-shell,
  .site-shell.narrow {
    width: calc(100% - 2rem);
    margin: 0 auto;
    padding-top: 10vh;
  }

  .margin-note {
    right: 0.45rem;
    width: min(8rem, 38vw);
    font-size: 0.74rem;
  }
}
