:root {
  color-scheme: light;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  color: #4b3a65;
  background: #ede6fa;
  font-synthesis: none;
  --ink: #4b3a65;
  --violet: #7451b1;
  --line: #e3d2f3;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; height: 100dvh; margin: 0; min-width: 280px; }
#main { height: 100%; overflow: clip; }
body:is([data-page="chapter"], [data-page="studio"]) {
  min-height: 100dvh;
  background: #e6dcfa url('/assets/starlight-sky.png') center / cover no-repeat;
}
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
.title-image {
  width: auto;
  height: var(--title-height, 1.65rem);
  object-fit: contain;
}
h1, h2, p { margin: 0; }
:focus-visible { outline: 3px solid #633bb3; outline-offset: 4px; }
main:focus { outline: none; }

.sr-only, .skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link:focus {
  position: fixed;
  z-index: 5;
  top: .75rem;
  left: .75rem;
  border-radius: .5rem;
  padding: .65rem 1rem;
  background: white;
}

.offline-status {
  position: fixed;
  right: max(.7rem, env(safe-area-inset-right));
  bottom: max(.55rem, env(safe-area-inset-bottom));
  z-index: 3;
  padding: .43rem .68rem;
  border: 1px solid var(--line);
  border-radius: .75rem;
  color: var(--ink);
  background: #fffaf4;
  font-size: .8rem;
}
.offline-status[hidden] { display: none; }
.offline-status a, .offline-status button { padding: 0 .25rem; color: inherit; text-decoration: underline; }
.offline-status button { border: 0; background: transparent; }
body[data-page="studio"] .offline-status { position: static; width: fit-content; margin: .5rem .7rem .5rem auto; }

.lock {
  position: absolute;
  right: 8%;
  top: 13%;
  display: grid;
  place-items: center;
  width: clamp(16px, 2.45vw, 30px);
  aspect-ratio: 1;
  transform: rotate(6deg);
  border: 2px solid #fff;
  border-radius: 48%;
  background: #574b69e8;
  color: #fff6df;
  box-shadow: 0 2px 7px #2f233d66;
}
.lock::before {
  content: "";
  width: 47%;
  height: 35%;
  border-radius: 2px;
  background: currentColor;
  transform: translateY(18%);
}
.lock::after {
  content: "";
  position: absolute;
  top: 25%;
  width: 29%;
  height: 32%;
  border: 1.5px solid currentColor;
  border-radius: 50% 50% 0 0;
}

.chapter-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  padding-bottom: .35rem;
}
.chapter-banner {
  position: relative;
  width: 100%;
  max-width: 1440px;
  max-height: 24dvh;
  margin: auto;
  aspect-ratio: 1536 / 171;
  overflow: hidden;
  background: #b19af0;
}
.chapter-banner > img { width: 100%; height: auto; }
.back-icon { flex: none; width: 1.9rem; height: auto; }
.chapter-back {
  position: absolute;
  top: 15%;
  left: 1%;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid #f1d9a8;
  background: #fffaf1;
}
.chapter-back:focus-visible { outline-offset: -3px; }
.chapter-back .back-icon { width: 2.6rem; }
.chapter-back:hover { background: #fff0cf; }
.chapter-content { max-width: 1332px; margin: 0 auto; padding: 1.25rem 1.5rem; }

.difficulty-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: clamp(.7rem, 3vw, 1.5rem);
  overflow: auto;
  overscroll-behavior: contain;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.difficulty-dialog[open] {
  display: grid;
  align-items: safe center;
  justify-items: center;
}
.difficulty-panel {
  width: min(100%, 65rem);
  padding: clamp(.8rem, 2.8vw, 2rem);
  border: 2px solid #eee4ff;
  border-radius: clamp(1.15rem, 3vw, 1.75rem);
  background:
    radial-gradient(circle at 14% 9%, #fff6cd 2px, transparent 4px),
    radial-gradient(circle at 36% 5%, #fff9eb 1px, transparent 3px),
    radial-gradient(circle at 86% 10%, #fff6cd 2px, transparent 4px),
    radial-gradient(circle at 25% 94%, #fff9eb 1.5px, transparent 3px),
    radial-gradient(circle at 75% 94%, #fff6cd 2px, transparent 4px),
    radial-gradient(ellipse at 50% -15%, #f9e2e9, transparent 64%),
    linear-gradient(145deg, #bea8ec, #e1cdf7 55%, #b49ae5);
  box-shadow: 0 18px 60px #31204b66, inset 0 0 0 3px #f8efffa0;
  animation: card-enter .2s ease-out both;
}
.difficulty-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(.35rem, 1.65vw, 1.2rem);
}
.easy { --accent: #a685d9; --pale: #f1e8ff; }
.medium { --accent: #8b7bc9; --pale: #ebe8ff; }
.hard { --accent: #af76d0; --pale: #f6e7fb; }
.difficulty-card {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: clamp(.3rem, 1vw, .6rem);
  padding: clamp(.25rem, 1.35vw, .85rem);
  text-align: center;
  border: 3px solid var(--accent);
  border-radius: clamp(.85rem, 2vw, 1.65rem);
  background: linear-gradient(165deg, var(--pale), #fff 80%);
  box-shadow: 0 7px 14px #58388624, inset 0 0 0 2px #fff9;
  transition: transform .18s ease, box-shadow .18s ease;
}
a.difficulty-card:hover { transform: translateY(-3px); box-shadow: 0 10px 21px #58388642; }
a.difficulty-card[data-selected] {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 60%, transparent), 0 9px 24px #58388642;
  animation: difficulty-card-select .23s ease-out both;
}
.difficulty-card[data-selected] .difficulty-stars {
  animation: difficulty-stars-select .23s ease-out both;
}
@keyframes difficulty-card-select {
  0% { transform: scale(.975); }
  65%, 100% { transform: translateY(-2px) scale(1.01); }
}
@keyframes difficulty-stars-select {
  0% { transform: scale(.95); }
  60% { transform: translateY(-4px) scale(1.14); filter: drop-shadow(0 0 8px #f3bc38); }
  100% { transform: none; filter: drop-shadow(0 0 4px #f3bc38); }
}
.difficulty-stars {
  display: inline-flex;
  justify-content: center;
  gap: .06em;
  vertical-align: -.14em;
}
.difficulty-star {
  /* The 64 px crop starts at (503, 10) on the 1536 × 1024 chapter banner. */
  flex: none;
  width: 1em;
  aspect-ratio: 1;
  background: url('/assets/starlight-reference.png') 34.1712% 1.041667% / 2400% auto no-repeat;
  clip-path: polygon(
    49% 6%, 56% 8%, 62% 17%, 68% 27%, 86% 30%, 93% 34%, 95% 42%,
    91% 50%, 81% 61%, 83% 76%, 82% 84%, 76% 89%, 68% 89%, 50% 81%,
    31% 89%, 24% 90%, 19% 86%, 18% 78%, 21% 62%, 9% 49%, 4% 43%,
    4% 38%, 8% 32%, 30% 28%, 40% 13%
  );
}
.difficulty-card .difficulty-stars { font-size: clamp(1.2rem, 3.8vw, 2.65rem); line-height: 1; }
.studio-level { flex: none; font-size: clamp(.8rem, 1.6vw, 1.2rem); }
.difficulty-card img {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: contain;
  border: 2px solid var(--accent);
  border-radius: .85rem;
  background: #fff;
}
.chapter-content.gallery {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 0;
  padding-block: .35rem .65rem;
  container-type: size;
}
.episode-slides {
  --slide-width: 76%;
  --card-gutter: clamp(.3rem, 1.1vw, .75rem);
  --lock-pull: clamp(1.25rem, 4.6vw, 3.6rem);
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--slide-width);
  width: min(100%, 78rem, max(0px, calc((100cqh - 4.6rem) * 1.95)));
  overflow-x: auto;
  overscroll-behavior-x: none;
  touch-action: pan-x pinch-zoom;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  list-style: none;
  margin: 0 auto;
  padding: 0;
  user-select: none;
}
.episode-slides::-webkit-scrollbar { display: none; }
.episode-slides[data-has-locked] {
  --edge-width: calc((100% - var(--slide-width)) / 2 + var(--lock-pull));
  grid-template-columns: var(--edge-width) repeat(var(--open-count), var(--slide-width)) var(--edge-width);
}
.episode-slides[data-returning] { scroll-snap-type: none; }
.episode-slides[data-dragging] { scroll-snap-type: none; cursor: grabbing; }
.episode-slides[data-dragging] .episode-card { pointer-events: none; }
.episode-slides > li {
  min-width: 0;
  padding: .6rem var(--card-gutter) .7rem;
  scroll-snap-align: center;
  scroll-snap-stop: always;
}
.episode-slides:not([data-dragging]) > li[data-episode-index]:not([data-current]) { cursor: pointer; }
.episode-slides > li[aria-hidden="true"] .episode-card { pointer-events: none; }
.episode-slides > li:not([data-current]) .episode-card {
  transform: scale(.94);
  opacity: .78;
}
.episode-slides > .episode-locked-edge {
  position: relative;
  overflow: clip;
  padding: 0;
  scroll-snap-align: none;
}
.locked-peek {
  position: absolute;
  inset: 1.4rem 0 1.6rem;
  overflow: hidden;
  border: 2px solid #bba6d4;
  border-radius: 1.1rem;
  background: #e6d8f7;
}
[data-locked-edge="left"] .locked-peek { right: var(--card-gutter); }
[data-locked-edge="right"] .locked-peek { left: var(--card-gutter); }
.locked-peek img {
  position: absolute;
  height: 100%;
  width: auto;
  max-width: none;
  opacity: .25;
  filter: grayscale(1) blur(1.25px);
}
[data-locked-edge="left"] .locked-peek img { right: 0; }
[data-locked-edge="right"] .locked-peek img { left: 0; }
.locked-peek .locked-label {
  top: 50%;
  right: auto;
  width: clamp(1.7rem, 4vw, 3.5rem);
  transform: translate(-50%, -50%);
  background: #624880;
}
[data-locked-edge="left"] .locked-label { left: calc(50% + var(--lock-pull) / 2); }
[data-locked-edge="right"] .locked-label { left: calc(50% - var(--lock-pull) / 2); }
.episode-card {
  position: relative;
  display: grid;
  height: 100%;
  grid-template-rows: auto 1fr;
  border: 2px solid #ac81e5;
  border-radius: 1.1rem;
  padding: .4rem;
  color: #4e2677;
  background: #fbf6ff;
  box-shadow: 0 4px 8px #58388627;
  transition: transform .18s ease, opacity .18s ease, box-shadow .18s ease;
}
.episode-slides > li[data-current] > a.episode-card:hover { box-shadow: 0 8px 17px #58388642; }
.episode-card > img {
  background: #fff;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: contain;
  border-radius: .75rem;
}
.episode-card strong {
  --title-height: clamp(1.45rem, 3vw, 2rem);
  align-self: center;
  min-width: 0;
  padding: .45rem .3rem .25rem;
}
.episode-card strong .title-image { margin-inline: auto; }
.episode-number {
  position: absolute;
  left: clamp(1rem, 2vw, 1.6rem);
  top: clamp(.85rem, 1.7vw, 1.45rem);
  width: clamp(2.95rem, 5.8vw, 4.7rem);
  aspect-ratio: 1;
  background: url('/assets/episode-star.png') center / contain no-repeat;
}
/* The sheet has one square tile for each of the ten stage numerals. */
.episode-number::after {
  position: absolute;
  inset: 0;
  background: url('/assets/episode-digits.png') calc(var(--episode-digit) * 100% / 9) center / 1000% 100% no-repeat;
  content: "";
}
.complete-label {
  position: absolute;
  top: .55rem;
  right: .55rem;
  display: grid;
  width: clamp(1.85rem, 4vw, 2.5rem);
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px #5838862b;
  background: #d8f1bf;
  color: #2c5e3c;
  font-weight: 800;
}

.studio-page { --progress-height: 1rem; max-width: 1440px; margin: 0 auto; padding: .55rem .85rem 1.2rem; }
.studio-page[data-coloring]:not([data-coloring="coloring"]) { --progress-height: 0px; }
.studio-heading {
  --navigation-button-width: clamp(2.95rem, 4.8vw, 3.7rem);
  --navigation-gap: .34rem;
  --navigation-width: calc(2 * var(--navigation-button-width) + var(--navigation-gap));
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: var(--navigation-width) minmax(0, 1fr) minmax(var(--navigation-width), max-content);
  grid-template-areas: "navigation title actions";
  align-items: center;
  gap: .45rem;
  min-height: 42px;
  margin-bottom: .52rem;
}
.studio-heading:has(.zoom-controls) {
  grid-template-columns: var(--navigation-width) minmax(0, 1fr) max-content minmax(var(--navigation-width), max-content);
  grid-template-areas: "navigation title zoom actions";
}
.studio-title {
  grid-area: title;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  min-width: 0;
}
.studio-heading h1 {
  --title-height: clamp(1.55rem, 3.25vw, 2.55rem);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .3rem;
  min-width: 0;
}
.studio-heading h1 .title-image { min-width: 0; }
.button.studio-continue {
  flex: none;
  min-height: 44px;
  padding-inline: .65rem;
  font-size: .85rem;
  white-space: nowrap;
}
.studio-continue[hidden] { display: none; }
.studio-continue-next .back-icon { transform: scaleX(-1); }
.studio-heading-actions { grid-area: actions; display: flex; justify-content: end; align-items: center; gap: var(--navigation-gap); }
.studio-navigation { grid-area: navigation; display: flex; align-items: center; gap: var(--navigation-gap); }
.button.studio-icon {
  width: 38px;
  min-width: 0;
  min-height: 38px;
  padding: 0;
  font-size: 1.42rem;
  line-height: 1;
}
.studio-navigation .studio-icon, .studio-settings-open, .studio-actions .studio-icon, .zoom-controls .studio-icon {
  border: 1px solid #dfceef;
  background: #fffaff;
}
.studio-navigation .button.studio-icon, .studio-heading-actions .button.studio-icon, .zoom-controls .button.studio-icon {
  width: var(--navigation-button-width);
  min-height: 46px;
  padding-inline: .25rem;
  font-size: 1.65rem;
}
.studio-navigation .studio-symbol { scale: 1.12; }
.studio-actions .button-primary { background: var(--violet); color: #fff; }
.studio-symbol { position: relative; display: inline-block; width: 1.25rem; height: 1.25rem; }
.studio-symbol::before, .studio-symbol::after { position: absolute; content: ""; }
.symbol-book::before {
  inset: 3px 1px 3px;
  border: 2px solid currentColor;
  border-radius: 3px;
}
.symbol-book::after { inset: 4px auto 4px 9px; border-left: 2px solid currentColor; }
.studio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(144px, 164px);
  gap: .68rem;
  align-items: start;
}
.artwork { min-width: 0; }
.scene-story {
  position: fixed;
  bottom: max(1rem, calc(env(safe-area-inset-bottom) + .5rem));
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 2rem), 480px);
  max-height: min(48dvh, 20rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: .42rem;
  padding: .72rem clamp(.85rem, 2vw, 1.2rem) .9rem;
  border: 1px solid #e8d7a8;
  border-radius: 1rem;
  background: #fffaf0;
  color: #574434;
  box-shadow: 0 8px 22px #59427232;
}
.scene-story[hidden] { display: none; }
.story-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  min-height: 1.9rem;
}
.story-header h2 { min-width: 0; }
.story-controls { display: flex; flex: none; align-items: center; gap: .4rem; }
.story-close.button { width: 33px; min-height: 33px; }
.story-skip {
  min-height: 1.85rem;
  padding: .23rem .65rem;
  border: 1px solid #e3d5ed;
  border-radius: 999px;
  background: #fff;
  color: #624388;
  font-size: .83rem;
  font-weight: 750;
  white-space: nowrap;
}
.story-skip:hover { background: #f4e8ff; }
.story-line { position: relative; display: grid; font-size: 1rem; line-height: 1.58; }
.story-line > span { grid-area: 1 / 1; }
.story-full { opacity: 0; pointer-events: none; user-select: none; }
.story-prompt { color: #673d88; font-weight: 800; }
.story-ending:not([hidden]) {
  display: grid;
  justify-items: start;
  gap: .38rem;
  margin-top: .3rem;
  padding: .68rem .8rem;
  border: 1px solid #e9d8f5;
  border-radius: .72rem;
  background: #f4eaff;
  color: #573480;
  animation: card-enter .3s ease-out;
}
.story-ending h3 { --title-height: 1.5rem; margin: 0; max-width: 100%; }
.story-ending p { font-size: 1rem; line-height: 1.5; font-weight: 700; }
.story-ending .button { margin-top: .22rem; }
.story-text.is-typing::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: .9em;
  margin-inline-start: .12em;
  vertical-align: -.1em;
  border-radius: 2px;
  background: #9251c7;
  animation: story-caret .7s step-end infinite;
}
.drawing-board { min-width: 0; width: 100%; }
.sheet {
  position: relative;
  width: 100%;
  aspect-ratio: var(--drawing-ratio, 1.5);
  overflow: hidden;
  overscroll-behavior-x: none;
  border: 6px solid white;
  border-radius: 1.1rem;
  background: #fff;
  box-shadow: 0 9px 25px #4c2d6926;
  isolation: isolate;
  touch-action: none;
  user-select: none;
}
.sheet:has(canvas:focus-visible) { outline: 3px solid var(--violet); outline-offset: 3px; }
.sheet[data-pinching] { box-shadow: 0 0 0 3px #ad81e5, 0 9px 25px #4c2d6926; }
.pinch-feedback {
  position: absolute;
  z-index: 2;
  display: grid;
  width: 3.4rem;
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid #fff4c9;
  border-radius: 50%;
  background: #7451b1;
  color: #fff4bf;
  font-size: 2rem;
  line-height: 1;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: pinch-ready .7s ease-out both;
}
.pinch-feedback[hidden] { display: none; }
.pinch-feedback > span { transform: rotate(-45deg); }
@keyframes pinch-ready {
  from { opacity: 0; transform: translate(-50%, -50%) scale(.62); }
  28%, 62% { opacity: 1; transform: translate(-50%, -50%) scale(1.07); }
  to { opacity: 0; transform: translate(-50%, -50%) scale(1.24); }
}
.page-surface { position: absolute; inset: 0; transform-origin: 50% 0; }
.canvas-frame {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}
.sheet canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: default; outline: none; }
.sheet:not(.is-panning):has(.paint-pointer:not([hidden])) canvas { cursor: none; }
.sheet.is-panning canvas { cursor: grab; }
.sheet.is-panning canvas:active { cursor: grabbing; }
.paint-pointer {
  --pointer-angle: -38deg;
  position: absolute;
  z-index: 1;
  width: 0;
  height: 0;
  pointer-events: none;
}
.paint-pointer:is(.pointer-left, .pointer-below) { --pointer-angle: 38deg; }
.paint-pointer.pointer-left.pointer-below { --pointer-angle: -38deg; }
.paint-pointer-glyph {
  position: absolute;
  top: 0;
  left: 0;
  width: 36px;
  height: 24px;
  transform: translateY(-50%) rotate(var(--pointer-angle));
  transform-origin: left center;
  filter: drop-shadow(0 1px 1px #43295c66);
}
.paint-pointer-tool { width: 100%; height: 100%; object-fit: contain; }
.paint-pointer.pointer-left .paint-pointer-glyph { left: auto; right: 0; transform-origin: right center; }
.paint-pointer.pointer-left .paint-pointer-tool { transform: scaleX(-1); }
.zoom-controls {
  grid-area: zoom;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: var(--navigation-gap);
}
.zoom-controls output {
  min-width: 3.2rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.tools, .paint-tools, .primary-tools, .additional-tools {
  display: grid;
  gap: .52rem;
}
.tools {
  height: var(--board-height, auto);
  container: coloring-tools / size;
  grid-template-rows: minmax(0, 1fr) auto;
  padding: .56rem;
  border: 2px solid var(--line);
  border-radius: 1.1rem;
  background: #fffaff;
}
.paint-tools {
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  align-items: start;
  padding: 3px;
  margin: -3px;
}
.studio-page[data-coloring="scratch"] .tools { height: auto; container-type: normal; }
.studio-page[data-coloring="scratch"] .paint-tools { grid-template-columns: minmax(0, 1fr); }
.swatches { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; }
.swatch {
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid white;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 1px #d5c4e2;
}
.swatch:hover, .swatch[aria-pressed="true"] { box-shadow: 0 0 0 2.5px #7449b4; }
.swatch[data-editing] { box-shadow: 0 0 0 2.5px #7449b4, 0 0 0 5px #dfc8f5; }
.swatch[data-preset] { touch-action: manipulation; user-select: none; -webkit-touch-callout: none; }
.swatch[data-preset]:not([data-editing]) {
  background-image: var(--swatch-texture, none);
  background-size: var(--swatch-texture-size, auto);
}
.swatches[data-paint-tool="crayon"] {
  --swatch-texture: radial-gradient(circle at 18% 25%, #fff9 0 .55px, transparent 1px),
    radial-gradient(circle at 68% 76%, #47264259 0 .4px, transparent .9px),
    radial-gradient(ellipse at 80% 30%, #ffffff70 0 .65px, transparent 1.2px);
  --swatch-texture-size: 4px 5px, 5px 7px, 7px 4px;
}
.swatches[data-paint-tool="pen"] {
  --swatch-texture: linear-gradient(150deg, #fff5, transparent 47%, #3b1d451a);
}
.swatches[data-paint-tool="highlighter"] {
  --swatch-texture: linear-gradient(145deg, #fff7 39%, #fff2 40% 69%, #fff5 70%);
}
.swatches[data-paint-tool="pattern"] {
  --swatch-texture: repeating-linear-gradient(135deg, #fff9 0 2.5px, transparent 2.5px 6px);
}
.swatches[data-paint-tool="fill"] {
  --swatch-texture: linear-gradient(0deg, #2f15382d, transparent 58%),
    linear-gradient(0deg, transparent 65%, #ffffff70 66%, #ffffff15 85%, transparent 86%);
}
.swatches[data-paint-tool="erase"] {
  --swatch-texture: linear-gradient(136deg, transparent 56%, #fff9 57%, #fffef5 82%);
}
.palette-next {
  position: relative;
  isolation: isolate;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 40% 24%, #fffcff 8%, #f7effc 59%, #eadbf7 100%);
}
.palette-cycle-arrow {
  grid-area: 1 / 1;
  display: block;
  width: min(78%, 39px);
  height: auto;
  transform: rotate(var(--palette-turn, 0turn));
  transition: transform .3s cubic-bezier(.2,.72,.25,1);
  filter: drop-shadow(0 1px 1px #56347732);
  pointer-events: none;
}
.palette-next::after {
  grid-area: 1 / 1;
  z-index: 1;
  width: min(24%, 12px);
  aspect-ratio: 1;
  border: 1px solid #fffaff;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #fffd 0, transparent 65%), var(--palette-color, white);
  box-shadow: 0 0 0 1px #9975ba;
  pointer-events: none;
  content: "";
}
.palette-editor {
  position: fixed;
  inset: 0 auto auto 0;
  width: min(18rem, calc(100vw - 20px));
  max-width: none;
  max-height: calc(100dvh - 20px);
  margin: 0;
  padding: .65rem;
  border: 2px solid #c7a4e6;
  border-radius: 1rem;
  background: #fff8ff;
  color: #58397d;
  box-shadow: 0 12px 34px #46286148;
}
.palette-editor::backdrop { background: transparent; }
.palette-field {
  position: relative;
  height: min(10.25rem, 44dvh);
  border-radius: .52rem;
  outline: 1px solid #a182b2;
  touch-action: none;
  cursor: crosshair;
}
.palette-field:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }
.palette-spectrum { display: block; width: 100%; height: 100%; border-radius: inherit; }
.palette-spectrum-point {
  position: absolute;
  top: var(--point-y);
  left: var(--point-x);
  width: 16px;
  aspect-ratio: 1;
  border: 2px solid white;
  border-radius: 50%;
  background: var(--editor-color);
  box-shadow: 0 0 0 1px #2e153e, 0 1px 5px #220d3e6b;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  min-height: 38px;
  border: 0;
  border-radius: .63rem;
  padding: .46rem .63rem;
  background: #f0e5fb;
  color: #5d4184;
  font-size: .9rem;
  font-weight: 760;
}
.button:not(:disabled):hover { background: #e5d5f6; }
.button:disabled { opacity: .5; }
.button[aria-pressed="true"], .button-primary { background: var(--violet); color: #fff; }
.button[aria-pressed="true"]:not(:disabled):hover, .button-primary:not(:disabled):hover { background: #5f3d98; }
.studio-tool-toggle::after {
  width: .47rem;
  height: .47rem;
  border-block-start: 2px solid currentColor;
  border-inline-end: 2px solid currentColor;
  transform: rotate(45deg);
  content: "";
}
.studio-tool-picker {
  --tool-art-width: 116px;
  --tool-join-border: #c4a4e0;
  display: grid;
  min-width: 0;
}
.button.studio-tool-toggle {
  position: relative;
  width: 100%;
  height: 56px;
  padding: .1rem 1.3rem .1rem .4rem;
  border: 1px solid #d9c4eb;
  background: linear-gradient(#fffafd, #f1e4fb);
}
.studio-tool-toggle::after {
  position: absolute;
  right: .55rem;
  top: 50%;
  transform: translateY(-72%) rotate(135deg);
}
.studio-tool-toggle[aria-expanded="true"]::after { transform: translateY(-27%) rotate(-45deg); }
.button.studio-tool-toggle[aria-expanded="true"] {
  border-color: var(--tool-join-border);
  background: #f5eafb;
}
.paint-tool-art {
  width: var(--tool-art-width);
  min-width: 0;
  max-width: 100%;
  height: auto;
}
.studio-tool-options {
  position: fixed;
  inset: 0 auto auto 0;
  width: min(max(264px, calc(2 * var(--tool-art-width) + 58px)), calc(100vw - 16px));
  height: fit-content;
  max-width: none;
  max-height: calc(100dvh - 16px);
  margin: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .85rem .65rem;
  padding: .75rem .65rem;
  border: 1px solid var(--tool-join-border);
  border-radius: .85rem;
  background: #faf2ff;
  box-shadow: 0 8px 24px #51306c3d;
}
.studio-tool-options[open] { display: grid; }
.studio-tool-options::backdrop { background: transparent; }
.studio-tool-picker[data-tool-placement] .studio-tool-options[open] {
  transform-origin: var(--tool-anchor-x) 0;
  animation: studio-tool-open .18s cubic-bezier(.16, 1, .3, 1) both;
}
.studio-tool-picker[data-tool-placement="below"] .studio-tool-toggle { border-end-end-radius: 0; }
.studio-tool-picker[data-tool-placement="below"] .studio-tool-options { border-start-end-radius: 0; }
.studio-tool-picker[data-tool-placement="above"] .studio-tool-toggle { border-start-end-radius: 0; }
.studio-tool-picker[data-tool-placement="above"] .studio-tool-options {
  border-end-end-radius: 0;
  transform-origin: var(--tool-anchor-x) 100%;
}
.studio-tool-picker[data-tool-placement="left"] .studio-tool-options { transform-origin: 100% var(--tool-anchor-y); }
@keyframes studio-tool-open {
  from { opacity: .35; transform: scale(.88, .72); }
  to { opacity: 1; transform: scale(1); }
}
.button.studio-tool-option {
  min-width: 0;
  min-height: 60px;
  padding: .24rem .25rem;
  border: 1px solid #e6d6f3;
  border-radius: .46rem;
  background: #fffbff;
}
.button.studio-tool-option[aria-pressed="true"] {
  border-color: #9b70c3;
  background: #eedff8;
}
.button.studio-tool-option:not(:disabled):hover { background: #e8d6f7; }
.studio-actions {
  display: grid;
  gap: .35rem;
  padding-top: .55rem;
  border-top: 1px solid var(--line);
}
.studio-actions .studio-icon { width: 100%; min-height: 42px; }
.studio-heading-actions .studio-capture {
  position: relative;
  border: 1px solid #d1afe9;
  background: linear-gradient(#fff9fe, #eedbfa);
}
.capture-icon { width: clamp(1.9rem, 3.4vw, 2.35rem); height: auto; }
.brush-settings { display: grid; gap: .4rem; font-size: .86rem; }
.brush-size-control {
  --grip-size: 30px;
  --gutter: .38rem;
  --ink-color: var(--sample-color, #754cb1);
  position: relative;
  display: grid;
  padding-inline: var(--gutter);
  border: 1px solid #e1cfef;
  border-radius: 999px;
  background: linear-gradient(#fdfaff, #f4e8fa);
}
.brush-size-control::before {
  position: absolute;
  inset-inline: calc(var(--gutter) + var(--grip-size) / 2);
  top: 50%;
  height: 10px;
  transform: translateY(-50%);
  clip-path: polygon(0 39%, 97% 0, 100% 16%, 100% 84%, 97% 100%, 0 61%);
  background: linear-gradient(#fff5, transparent 58%, #47245e20),
    linear-gradient(90deg, color-mix(in srgb, var(--ink-color) 85%, #997db5) var(--size-value, 50%), #ddc8ef 0);
  pointer-events: none;
  content: "";
}
.brush-size-control:has(input:disabled) { opacity: .54; }
.brush-size-control input {
  --thumb-radius: calc(var(--sample-diameter, 10px) / 2);
  --thumb-ink: radial-gradient(circle at 43% 41%, #ffffff7a, transparent calc(var(--thumb-radius) * .75)),
    radial-gradient(circle, var(--ink-color) calc(var(--thumb-radius) - .3px),
    #fffef9 0 calc(var(--thumb-radius) + 1.1px), #9472b2 0 calc(var(--thumb-radius) + 1.9px),
    transparent calc(var(--thumb-radius) + 2.4px));
  appearance: none;
  position: relative;
  width: 100%;
  min-height: 36px;
  margin: 0;
  background: transparent;
  border-radius: inherit;
  cursor: ew-resize;
}
.brush-size-control input::-webkit-slider-thumb {
  appearance: none;
  width: var(--grip-size);
  height: var(--grip-size);
  border: 0;
  background: var(--thumb-ink);
  filter: drop-shadow(0 1px 1px #5e3d754d);
}
.brush-size-control input::-moz-range-track { background: transparent; }
.brush-size-control input::-moz-range-thumb {
  width: var(--grip-size);
  height: var(--grip-size);
  border: 0;
  background: var(--thumb-ink);
  filter: drop-shadow(0 1px 1px #5e3d754d);
}
.brush-size-control input:disabled { cursor: default; }
.finish-progress {
  position: relative;
  height: var(--progress-height);
  padding-top: .35rem;
}
.progress-track { height: .52rem; overflow: hidden; border-radius: 999px; background: #d9cae9; }
.progress-fill {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  clip-path: inset(0 calc(100% - var(--painted-percent, 0%)) 0 0);
}
.finish-progress[data-live-progress] .progress-fill { transition: clip-path .22s cubic-bezier(.22,.67,.32,1); }
.studio-status:not(.sr-only) {
  min-height: 2.5em;
  border-radius: .55rem;
  padding: .46rem .52rem;
  background: #fff3ce;
  color: #5e4e33;
  font-size: .76rem;
  line-height: 1.4;
}

dialog {
  max-width: min(90vw, 390px);
  border: 2px solid var(--line);
  border-radius: 1rem;
  padding: 1.3rem;
  background: #fffaff;
  color: var(--ink);
}
dialog::backdrop { background: #31204b66; }
.stage-finale {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: clip;
  border: 0;
  border-radius: 0;
  background: #000;
  color: #fff;
}
.stage-finale::backdrop { background: #000; }
.stage-finale video { display: block; width: 100%; height: 100%; object-fit: contain; }
.stage-finale .stage-finale-back {
  position: absolute;
  top: max(.9rem, env(safe-area-inset-top));
  right: max(.9rem, env(safe-area-inset-right));
  background: #2e2141e8;
  color: #fff;
}
.stage-finale .stage-finale-back:hover { background: #513c70; }
.stage-finale-play, .stage-finale-error {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.stage-finale [hidden] { display: none; }
dialog h2 { font-size: 1.15rem; }
dialog p { margin: .57rem 0 1rem; font-size: .92rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .48rem; }

.entering { animation: page-enter .28s ease-out backwards; }
.studio-page.entering { animation-name: studio-enter; }
.entering .drawing { animation: card-enter .34s cubic-bezier(.2, .75, .3, 1.2) backwards; }

@keyframes page-enter {
  from { opacity: .2; transform: translateY(7px); }
  to { opacity: 1; transform: none; }
}
@keyframes studio-enter {
  from { opacity: .2; }
}
@keyframes card-enter {
  from { opacity: 0; transform: translateY(14px) scale(.965); }
  to { opacity: 1; transform: none; }
}
@keyframes story-caret {
  50% { opacity: 0; }
}

@media (min-width: 721px) and (max-height: 960px) {
  .studio-page {
    --studio-gap: 80px;
    max-width: min(1440px, max(700px, calc((100dvh - var(--studio-gap) - var(--progress-height)) * 1.5 + 184px)));
  }
}
@media (max-width: 720px) {
  .chapter-banner { min-height: 56px; }
  .chapter-back { top: 50%; transform: translateY(-50%); }
  .chapter-content { padding-inline: .85rem; }
  .studio-page { padding-inline: .62rem; }
  .studio-layout { grid-template-columns: minmax(0, 1fr); }
  .tools {
    height: auto;
    margin-top: 0;
    container-type: normal;
  }
  .paint-tools { grid-template-columns: minmax(0, 1fr) minmax(116px, .52fr); }
  .swatches { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .swatch { max-width: 46px; justify-self: center; }
}
@media (max-width: 680px) {
  .studio-heading {
    grid-template-columns: minmax(0, 1fr) max-content;
    grid-template-areas: "navigation actions" "title title";
  }
}
@media (max-width: 740px) {
  .studio-heading:has(.zoom-controls) {
    grid-template-columns: minmax(0, 1fr) max-content;
    grid-template-areas: "navigation actions" "zoom zoom" "title title";
  }
  .zoom-controls { justify-self: center; }
}
@media (max-width: 460px) {
  .swatches { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (orientation: landscape) and (max-height: 520px) and (min-width: 560px) {
  .studio-page {
    --studio-gap: 72px;
    max-width: min(100%, max(560px, calc((100dvh - var(--studio-gap) - var(--progress-height)) * 1.5 + 184px)));
  }
  .studio-layout { grid-template-columns: minmax(0, 1fr) minmax(144px, 164px); }
  .tools {
    height: var(--board-height, auto);
    container-type: size;
  }
  .paint-tools { grid-template-columns: minmax(0, 1fr); }
}
@container coloring-tools (max-height: 570px) {
  .swatches { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@container coloring-tools (max-height: 290px) {
  .swatches { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .28rem; }
  .studio-tool-picker { --tool-art-width: 76px; }
  .button.studio-tool-toggle { height: 39px; }
  .button.studio-tool-option { min-height: 54px; }
  .brush-size-control input { min-height: 30px; }
  .studio-actions .studio-icon { min-height: 38px; }
}

.studio-page {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding-block: .55rem;
}
.studio-layout {
  flex: 1;
  min-height: 0;
  align-items: stretch;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr) minmax(152px, clamp(164px, 17vw, 194px));
}
.studio-layout .artwork {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.studio-layout .drawing {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.studio-layout .drawing-space {
  display: grid;
  container-type: size;
  flex: 1;
  min-height: 0;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: start center;
}
.studio-layout .drawing-board {
  width: min(100%, max(0px, calc((100cqh - var(--progress-height)) * var(--drawing-ratio, 1.5))));
}
.studio-layout .sheet { overscroll-behavior: none; }
.studio-layout .tools {
  align-self: start;
  min-height: 0;
  max-height: 100%;
}
@media (max-width: 900px) and (orientation: portrait), (max-width: 559px) {
  .studio-layout { grid-template: minmax(0, 1fr) auto / minmax(0, 1fr); }
  .studio-layout .drawing-space { place-items: center; }
  .studio-layout .tools {
    height: auto;
    max-height: min(48dvh, 22rem);
    margin-top: 0;
    container-type: normal;
  }
  .studio-layout .paint-tools { grid-template-columns: minmax(0, 1fr) minmax(116px, .52fr); }
}
@media (min-width: 600px) and (max-width: 900px) and (orientation: portrait) {
  .studio-layout .paint-tools { grid-template-columns: minmax(0, 1fr) 142px; }
  .studio-layout .swatches { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .studio-layout .swatch { max-width: 46px; justify-self: center; }
}

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