:root {
  --effect-surface: #1a1d32;
  --effect-border: #3b3854;
  --effect-text: #e9e3fc;
  --effect-muted: #a5a2ba;
  --effect-accent: #c7afff;
  --mascot-width: clamp(122px, 12.8vw, 190px);
  --sky-base: #100a1d;
  --sky-nebula-near: #542d85a1;
  --sky-nebula-far: #38225dad;
  --sky-nebula-rose: #723f934b;
  --sky-band: #44276849;
  --sky-star: #f3e6ff;
  --sky-star-dim: #bca1f3c5;
  --sky-star-glow: #ce9cff8c;
  --sky-star-opacity: .76;
  --sky-star-twinkle: .93;
}

:root[data-theme="light"] {
  --effect-surface: #fffaff;
  --effect-border: #d9d0ed;
  --effect-text: #392857;
  --effect-muted: #685d7d;
  --effect-accent: #633eac;
  --sky-base: #f5effc;
  --sky-nebula-near: #b99ae9a6;
  --sky-nebula-far: #cfb7f1c7;
  --sky-nebula-rose: #e6bcee88;
  --sky-band: #d7bff499;
  --sky-star: #714bb7;
  --sky-star-dim: #815daf9e;
  --sky-star-glow: #a676cf48;
  --sky-star-opacity: .49;
  --sky-star-twinkle: .64;
}

html {
  background-color: var(--sky-base);
  scrollbar-color: var(--effect-accent) var(--sky-base);
}
.note-reading-page { scroll-behavior: auto; }
body { position: relative; isolation: isolate; background: var(--sky-base); }
body::before, body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}
body::before {
  background:
    radial-gradient(ellipse at 8% 29%, var(--sky-nebula-near), transparent 56%),
    radial-gradient(ellipse at 92% 61%, var(--sky-nebula-far), transparent 58%),
    radial-gradient(ellipse at 62% 14%, var(--sky-nebula-rose), transparent 44%),
    linear-gradient(126deg, transparent 14%, var(--sky-band) 49%, transparent 78%);
  background-size: 135% 135%, 130% 130%, 115% 132%, 100% 100%;
  background-position: 0% 25%, 100% 68%, 52% 0%, 0 0;
  background-repeat: no-repeat;
}
body::after {
  background:
    radial-gradient(circle at 24px 31px, var(--sky-star-dim) .55px, transparent 1.3px) 0 0 / 89px 73px,
    radial-gradient(circle at 71px 48px, var(--sky-star-dim) .7px, transparent 1.45px) 0 0 / 137px 103px,
    radial-gradient(circle at 42px 64px, var(--sky-star) 1px, var(--sky-star-glow) 1.6px, transparent 4px) 0 0 / 239px 191px,
    radial-gradient(circle at 178px 104px, var(--sky-star) 1.3px, var(--sky-star-glow) 2px, transparent 5px) 0 0 / 373px 287px;
  opacity: var(--sky-star-opacity);
}
@media (prefers-reduced-motion: no-preference) {
  :root[data-effects="on"] :is(.home-page, .archive-page, .article-page, .html-note-reader)::after {
    /* Leave room for the drift while the browser composites the star layer. */
    inset: -16px;
    animation: night-stars-drift 14s ease-in-out infinite alternate;
  }
}
@keyframes night-stars-drift {
  from { transform: translate(-12px, 10px); }
  to { transform: translate(12px, -10px); opacity: var(--sky-star-twinkle); }
}

.chapter-fade {
  position: absolute;
  z-index: 2;
  inset: 0 0 auto;
  block-size: min(50%, 18rem);
  background: linear-gradient(var(--surface) 18%, transparent);
  opacity: 0;
  pointer-events: none;
}
.article-page > .chapter-fade {
  position: fixed;
  block-size: min(42dvh, 18rem);
}
.chapter-landing {
  position: absolute;
  z-index: 2;
  inset: 0 auto auto 0;
  border: 1px solid color-mix(in srgb, var(--effect-accent) 52%, transparent);
  border-inline-start: 5px solid var(--effect-accent);
  border-radius: 7px;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--effect-accent) 27%, transparent),
    color-mix(in srgb, var(--effect-accent) 16%, transparent));
  contain: strict;
  opacity: 0;
  pointer-events: none;
}
.article-page > .chapter-landing { position: fixed; }

:is(.note-toc nav a, .html-note-toc button)[aria-current="location"] {
  color: var(--text);
  background-color: color-mix(in srgb, var(--effect-accent) 22%, var(--surface));
  box-shadow: inset 3px 0 var(--effect-accent),
    inset 0 0 0 1px color-mix(in srgb, var(--effect-accent) 40%, transparent);
}

:is(.note-toc nav, .html-note-toc ol).resizable-outline-list {
  max-height: min(52dvh, 28rem);
  contain: layout paint;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
@media (max-width: 900px) {
  [data-enhanced-outline] {
    position: fixed;
    z-index: 13;
    inset-block-start: max(12px, env(safe-area-inset-top));
    inset-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right));
    max-width: 30rem;
    margin-inline: auto;
    box-shadow: 0 12px 42px rgb(8 6 21 / 30%);
  }
  .note-toc[data-enhanced-outline]:not(:has(details[open])),
  .html-note-toc[data-enhanced-outline]:not([open]) { display: none; }
}
.outline-resize {
  display: grid;
  place-items: center;
  height: 27px;
  border-top: 1px solid var(--line);
  border-radius: 0 0 12px 12px;
  color: var(--muted);
  cursor: ns-resize;
  touch-action: none;
  user-select: none;
}
.outline-resize::before {
  content: "";
  width: 24px;
  height: 5px;
  border-block: 1px solid currentColor;
}
.outline-resize:is(:hover, :focus-visible, [data-dragging]) {
  color: var(--accent-text);
  background: var(--accent-wash);
}
.outline-resize:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }

.reading-tools {
  position: fixed;
  z-index: 14;
  inset-inline-start: max(12px, env(safe-area-inset-left));
  inset-block-end: max(12px, env(safe-area-inset-bottom));
  display: grid;
  gap: 6px;
}
.reading-tools button {
  min-width: 42px;
  min-height: 36px;
  padding: 4px 6px;
  border: 1px solid var(--effect-border);
  border-radius: 9px;
  background: var(--effect-surface);
  color: var(--effect-text);
  box-shadow: 0 4px 16px rgb(8 6 21 / 18%);
  font-size: 12px;
}
.reading-tools button:hover { border-color: var(--effect-accent); }
.reading-tools .back-to-top {
  display: grid;
  place-items: center;
  gap: 1px;
  min-height: 46px;
  background:
    linear-gradient(var(--effect-accent), var(--effect-accent)) left bottom / var(--scroll-progress, 0%) 2px no-repeat,
    var(--effect-surface);
}
.back-to-top span { font-size: 19px; line-height: 1; }
.back-to-top small { color: var(--effect-muted); font: 650 9px/1.2 var(--mono); }
@media (max-width: 900px) {
  .reading-tools button { min-inline-size: 44px; min-block-size: 44px; }
  .reading-tools .reading-directory { padding-inline: 9px; }
  .reading-directory[aria-expanded="true"] {
    border-color: var(--effect-accent);
    color: var(--effect-text);
    background: color-mix(in srgb, var(--effect-accent) 18%, var(--effect-surface));
  }
  :is(.note-toc nav a, .html-note-toc button) { min-block-size: 40px; padding-block: .55rem; }
  .outline-resize { block-size: 34px; }
}
@media (prefers-reduced-motion: no-preference) {
  :root[data-effects="on"] .back-to-top:not([hidden]) {
    animation: notebook-enter .28s ease-out both;
  }
}

.corner-tools {
  position: fixed;
  z-index: 12;
  inset-inline-end: max(14px, env(safe-area-inset-right));
  inset-block-end: max(14px, env(safe-area-inset-bottom));
  display: grid;
  justify-items: end;
  width: max-content;
  pointer-events: none;
}

.mascot-dock[hidden] { display: none; }
.mascot-dock {
  position: relative;
  width: var(--mascot-width);
  user-select: none;
  margin-inline-end: 3px;
}
.mascot-dock::before {
  content: "";
  position: absolute;
  inset: 29% 5% 0 8%;
  background: radial-gradient(ellipse at 55% 80%, rgb(126 91 206 / 29%), transparent 72%);
  filter: blur(11px);
}
.mascot-frame { position: relative; }
.mascot-frame img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 7px 9px rgb(7 6 22 / 44%));
}
.mascot-eye {
  position: absolute;
  top: 38.55%;
  width: 9.83%;
  height: 9.42%;
}
.mascot-dock:not([data-mascot-ready]) .mascot-eye { visibility: hidden; }
/* The masks follow the painted eyelids so the iris can sit behind them. */
.mascot-eye-left {
  left: 35.40%;
  clip-path: polygon(
    34% 2%, 52% 0, 67% 5%, 80% 14%, 91% 24%, 97% 38%, 100% 51%,
    98% 65%, 94% 78%, 87% 89%, 75% 97%, 60% 100%, 44% 99%, 30% 95%,
    17% 86%, 9% 75%, 3% 63%, 0 46%, 4% 29%, 12% 16%, 22% 8%
  );
}
.mascot-eye-right {
  left: 54.72%;
  clip-path: polygon(
    34% 3%, 49% 0, 66% 1%, 80% 9%, 89% 17%, 96% 30%, 100% 44%,
    97% 58%, 92% 72%, 84% 85%, 72% 94%, 56% 100%, 39% 99%, 23% 94%,
    12% 84%, 5% 72%, 0 56%, 1% 42%, 5% 29%, 12% 18%, 22% 9%
  );
}
.mascot-pupil {
  position: absolute;
  inset: 48% auto auto 50%;
  width: 74%;
  height: 94%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 23%, #fffaff 0 12%, #f7eeff 13%, transparent 17%),
    radial-gradient(circle at 69% 41%, #f8f4ff 0 5%, transparent 9%),
    radial-gradient(circle at 64% 73%, #f0e5ff 0 4%, transparent 8%),
    radial-gradient(ellipse at 50% 42%, #21182f 0 29%, #34244c 30%, transparent 35%),
    radial-gradient(ellipse at 53% 89%, #c7afe3 0 17%, #9573b7 37%, transparent 66%),
    linear-gradient(180deg, #34244c 7%, #4c3c6c 49%, #7c54a4 81%, #b59bcf 98%);
  box-shadow: inset 0 0 0 .65px #34244c;
  transform: translate(-50%, -50%) translate(var(--pupil-x, 0px), var(--pupil-y, 0px));
}

.corner-controls {
  display: flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--effect-border);
  border-radius: 10px;
  background: var(--effect-surface);
  color: var(--effect-text);
  pointer-events: auto;
  box-shadow: 0 6px 25px rgb(8 6 21 / 20%);
}
.corner-controls button {
  min-height: 28px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--effect-muted);
  padding: 1px 7px;
  font-size: 11px;
  line-height: 1.2;
}
.corner-controls button:hover { border-color: var(--effect-border); }
.corner-controls button[aria-pressed="true"] {
  background: color-mix(in srgb, var(--effect-accent) 13%, var(--effect-surface));
  color: var(--effect-text);
}
.corner-controls button span { color: var(--effect-accent); }
.corner-controls button:focus-visible {
  outline: 2px solid var(--effect-accent);
  outline-offset: 2px;
}

.hero-starlight {
  position: absolute;
  z-index: -1;
  inset: 0;
  pointer-events: none;
}
.hero-starlight span {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #e6d6ff;
  box-shadow: 0 0 8px #c09cff;
  opacity: .47;
}
.hero-starlight span:nth-child(1) { top: 20%; left: 13%; }
.hero-starlight span:nth-child(2) { top: 19%; left: 38%; width: 3px; height: 3px; }
.hero-starlight span:nth-child(3) { top: 72%; left: 44%; width: 4px; height: 4px; }

@keyframes notebook-enter {
  from { opacity: .38; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes notebook-twinkle {
  0%, 100% { transform: scale(.73); opacity: .32; }
  50% { transform: scale(1.3); opacity: .82; }
}
@keyframes notebook-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

:root[data-effects="on"] :is(.hero-content, .archive-heading, .article-nav) {
  animation: notebook-enter .48s cubic-bezier(.2, .7, .3, 1) both;
}
:root[data-effects="on"] .archive-heading { animation-delay: 45ms; }

@media (any-hover: hover) and (any-pointer: fine) {
  :root[data-effects="on"], :root[data-effects="on"] body {
    cursor: url("./assets/cursor-night-refined.png") 4 3, auto;
  }
  :root[data-effects="on"] :is(a, button:not(:disabled), select:not(:disabled), label[for], [role="button"]) {
    cursor: url("./assets/cursor-night-refined-action.png") 9 3, pointer;
  }
  :root[data-effects="on"] :is(input:not([type]), input[type="text"], input[type="search"], textarea, [contenteditable="true"], pre, code) {
    cursor: text;
  }
  :root[data-effects="on"] :is(button:disabled, select:disabled, input:disabled, textarea:disabled, [aria-disabled="true"]) {
    cursor: not-allowed;
  }

  :root[data-effects="on"] .hero-image {
    transform: translate3d(var(--hero-x, 0px), var(--hero-y, 0px), 0) scale(1.032);
    transition: transform 240ms ease-out;
  }
  :root[data-effects="on"] .hero-starlight span {
    animation: notebook-twinkle 4.4s var(--starlight-delay, 0s) ease-in-out infinite;
  }
  :root[data-effects="on"] .hero-starlight span:nth-child(2) { --starlight-delay: -1.1s; }
  :root[data-effects="on"] .hero-starlight span:nth-child(3) { --starlight-delay: -2.6s; }
  :root[data-effects="on"] .mascot-frame { animation: notebook-float 5.1s ease-in-out infinite; }

  :root[data-effects="on"] :is(.note-link, .folder-button, .collection-button, .manage-link, .hero-button) {
    transition: background-color 155ms, border-color 155ms, box-shadow 155ms, transform 155ms ease-out;
  }
  :root[data-effects="on"] :is(.folder-button, .hero-button, .manage-link):hover { transform: translateY(-2px); }
  :root[data-effects="on"] .note-arrow { transition: transform 155ms ease-out, color 155ms; }
  :root[data-effects="on"] .note-link:hover .note-arrow { transform: translate(2px, -2px); color: var(--effect-accent); }
}

.click-spark-layer {
  position: fixed;
  z-index: 30;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.click-spark-burst { position: absolute; left: var(--burst-x); top: var(--burst-y); }
.click-spark-burst::before, .click-spark-burst::after {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 56px;
  aspect-ratio: 1;
  border: 2px solid #c9b9ff;
  border-radius: 50%;
  box-shadow: 0 0 11px rgb(144 108 246 / 80%);
  animation: notebook-ripple .62s ease-out both;
}
.click-spark-burst::after { border-color: #a5eadc; animation-delay: .09s; }
@keyframes notebook-ripple {
  from { opacity: .95; transform: translate(-50%, -50%) scale(.17); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(1.5); }
}
.click-spark {
  position: absolute;
  width: var(--spark-size);
  height: var(--spark-size);
  border-radius: 50%;
  background: var(--spark-color);
  box-shadow: 0 0 5px var(--spark-color);
  animation: notebook-spark var(--spark-duration) var(--spark-delay) ease-out both;
}
.click-spark[data-shape="star"] {
  border-radius: 0;
  clip-path: polygon(50% 0, 61% 38%, 100% 50%, 61% 62%, 50% 100%, 39% 62%, 0 50%, 39% 38%);
}
@keyframes notebook-spark {
  from { opacity: 1; transform: translate(-50%, -50%) scale(.75); }
  to {
    opacity: 0;
    transform: translate(calc(-50% + var(--spark-x)), calc(-50% + var(--spark-y))) rotate(var(--spark-rotation)) scale(.2);
  }
}

@media (min-width: 55rem) {
  :is(.home-page, .archive-page) :is(.site-header, .site-main, .site-footer) {
    --mascot-gutter: calc(var(--mascot-width) + 8px);
    width: min(1160px, calc(100% - 32px - var(--mascot-gutter)));
    margin-inline-start: max(32px, min(calc((100% - 1160px) / 2), calc(100% - 1160px - var(--mascot-gutter))));
    margin-inline-end: auto;
  }
}

@media (max-width: 44rem) {
  .corner-tools {
    inset-inline-end: max(8px, env(safe-area-inset-right));
    inset-block-end: max(8px, env(safe-area-inset-bottom));
  }
  .mascot-dock { width: 108px; }
  .corner-controls button { min-height: 29px; padding-inline: 6px; }
  .site-footer { padding-bottom: 43px; }
}
