@font-face {
  font-family: Hannari;
  src: url("fonts/HannariMincho-Regular.otf") format("opentype");
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #173e3a;
  --bg: #e5f7f2;
  --panel: #b9ede3;
  --accent: #116e65;
  --paper: #fffaf1;
  font-family: Hannari, "Hiragino Mincho ProN", "Yu Mincho", serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; padding: 30px 18px 46px; }
button, input, select, textarea { font: inherit; color: inherit; border-radius: 0; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #854300; outline-offset: 3px; }
.masthead { text-align: center; margin: 0 auto 24px; }
h1 {
  display: inline-block;
  margin: 0;
  padding: 13px 22px;
  font-size: clamp(1.15rem, 4.8vw, 2rem);
  letter-spacing: .05em;
  font-weight: normal;
  border: 2px solid var(--ink);
  background: var(--accent);
  color: var(--paper);
  outline: 1px solid var(--paper);
  outline-offset: -7px;
  box-shadow: 5px 5px var(--ink);
}
.masthead p { margin: 16px 0 0; }
.desk {
  max-width: 950px;
  margin: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: start;
  gap: 24px;
}
.controls { display: grid; gap: 18px; min-width: 0; }
.panel {
  min-width: 0;
  border: 2px solid var(--ink);
  padding: 15px;
  background: var(--panel);
  box-shadow: 5px 5px var(--ink);
}
h2 { margin: 0 0 12px; font-size: 1.2rem; border-bottom: 1px solid var(--ink); padding-bottom: 6px; }
label { display: block; margin: 10px 0 5px; }
input:not([type="checkbox"], [type="range"]), select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--ink);
  padding: 8px;
  background: var(--paper);
}
textarea { resize: vertical; }
input[type="range"] { width: 100%; margin: 0; }
input[type="range"], input[type="checkbox"] { accent-color: var(--accent); }
input[type="file"]::file-selector-button { font: inherit; }
.actions { display: flex; gap: 8px; }
.actions { flex-wrap: wrap; margin-top: 10px; }
button {
  background: var(--paper);
  border: 1px solid var(--ink);
  padding: 7px 10px;
  box-shadow: 2px 2px var(--ink);
}
button:hover { background: #e5f7f2; }
button:active { transform: translate(2px, 2px); box-shadow: none; }
.primary {
  width: 100%;
  margin-top: 12px;
  padding: 11px;
  border-width: 2px;
  outline: 1px solid var(--paper);
  outline-offset: -5px;
  color: var(--paper);
  background: var(--accent);
}
.primary:hover { background: #095951; }
.primary:focus-visible { outline: 3px solid #854300; outline-offset: 3px; }
.status { margin: 7px 0 0; font-size: .875rem; overflow-wrap: anywhere; }
.check { display: flex; align-items: center; gap: 4px; }
.preview { position: sticky; top: 16px; }
.book {
  --cover-hue: 166;
  --cover-saturation: 53%;
  --cover-dark: hsl(var(--cover-hue) var(--cover-saturation) 11%);
  --cover-ink: hsl(var(--cover-hue) var(--cover-saturation) 21%);
  --cover-light: hsl(var(--cover-hue) var(--cover-saturation) 94%);
  --cover-accent: hsl(calc(var(--cover-hue) - 28) var(--cover-saturation) 83%);
  --cover-gold: hsl(calc(var(--cover-hue) - 44) var(--cover-saturation) 80%);
  position: relative;
  isolation: isolate;
  overflow: hidden;
  container-type: inline-size;
  aspect-ratio: 2 / 3;
  border: 1px solid var(--cover-dark);
  background: var(--cover-ink) url("covers/default.png") center / cover;
}
.book::after {
  position: absolute;
  z-index: -1;
  inset: 0;
  content: "";
  background: linear-gradient(90deg, hsl(var(--cover-hue) 46% 12% / .9), transparent 50%, hsl(var(--cover-hue) 46% 12% / .82)),
    linear-gradient(0deg, hsl(var(--cover-hue) 46% 10% / .9), transparent 48%);
  pointer-events: none;
}
.book:not(:has(#cover-image:not([hidden])))::after {
  background:
    radial-gradient(ellipse at 50% 45%, transparent 21%, hsl(var(--cover-hue) 57% 11% / .35) 57%, var(--cover-dark)),
    linear-gradient(150deg, hsl(var(--cover-hue) 48% 22% / .74), hsl(var(--cover-hue) 38% 27% / .12) 55%, var(--cover-dark));
}
#cover-image, .book-frame { position: absolute; pointer-events: none; }
#cover-image {
  z-index: -2;
  inset: var(--image-top, 0) auto auto var(--image-left, 0);
  width: var(--image-width, 100%);
  height: var(--image-height, 100%);
}
.book-frame {
  inset: 2.3%;
  border: 1px solid hsl(var(--cover-hue) 42% 88% / .52);
  outline: 1px solid hsl(var(--cover-hue) 56% 15% / .67);
}
.book-title {
  position: absolute;
  inset: 4.5% 4% 5%;
  display: flex;
  flex-direction: row-reverse;
  justify-content: space-between;
  align-items: flex-start;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", Hannari, serif;
  font-weight: 800;
  color: var(--cover-light);
}
.title-bank { display: flex; flex-direction: row-reverse; gap: .9cqw; }
.title-bank:nth-child(2) { margin-top: 7cqw; }
.title-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: calc(var(--title-unit) * var(--column-width));
}
.glyph {
  position: relative;
  display: grid;
  place-items: center;
  writing-mode: vertical-rl;
  line-height: 1;
  inline-size: 1em;
  block-size: 1em;
  font-size: calc(var(--title-unit) * var(--glyph-size));
  paint-order: stroke fill;
  -webkit-text-stroke: .11em var(--cover-dark);
  text-shadow: .055em .075em 0 var(--cover-ink), 0 0 .3em var(--cover-dark);
}
.glyph-accent { color: var(--cover-accent); }
.glyph-name {
  color: var(--cover-light);
  -webkit-text-stroke-color: var(--cover-ink);
  text-shadow: .045em .08em 0 var(--cover-dark), 0 0 .32em var(--cover-dark);
}
.glyph-impact {
  color: var(--cover-gold);
  -webkit-text-stroke: .13em var(--cover-ink);
  text-shadow: .045em .09em 0 var(--cover-dark), 0 0 .3em var(--cover-dark);
}
.book-band {
  position: absolute;
  z-index: 2;
  inset: auto 0 0;
  display: grid;
  align-items: center;
  height: 19.5%;
  overflow: hidden;
  border-top: 1px solid var(--cover-gold);
  box-shadow: 0 -1cqw 2cqw #0005;
  color: #fff9ee;
  background: var(--cover-dark);
}
.band-photo, .band-shade { position: absolute; inset-block: 0; height: 100%; pointer-events: none; }
.band-photo { inset-inline-start: 0; width: 100%; overflow: hidden; }
.band-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--band-x, 50%) var(--band-y, 50%);
  transform-origin: var(--band-x, 50%) var(--band-y, 50%);
  transform: scale(var(--band-zoom, 1));
}
.band-crop { position: relative; aspect-ratio: 3.42; background: #000; margin-block: 10px; }
.band-shade { inset-inline: 0; }
[data-layout="full"] > .band-shade { background: linear-gradient(0deg, #000a, #0003 58%, #0007); }
.book-band[data-layout="right"], .book-band[data-layout="left"] { background: #000; }
[data-layout="right"] > .band-photo { inset-inline: auto 0; width: 62%; }
[data-layout="left"] > .band-photo { width: 62%; }
[data-layout="right"] > .band-shade { background: linear-gradient(90deg, #000 38%, #000d 48%, #0002 76%, transparent 92%); }
[data-layout="left"] > .band-shade { background: linear-gradient(270deg, #000 38%, #000d 48%, #0002 76%, transparent 92%); }
.band-text {
  position: relative;
  width: 94%;
  margin: 0 auto;
  text-align: center;
  font-weight: bold;
  font-size: var(--band-font, 5cqw);
  line-height: calc(var(--band-font, 5cqw) * 1.42);
}
.book-band[data-layout="right"] .band-text { width: 59%; margin-inline: 2% auto; }
.book-band[data-layout="left"] .band-text { width: 59%; margin-inline: auto 2%; }
.band-row { display: flex; align-items: center; justify-content: center; }
.band-glyph {
  flex-shrink: 0;
  min-width: .56em;
  white-space: pre;
  paint-order: stroke fill;
  -webkit-text-stroke: .045em #150c0b;
  text-shadow: 0 .08em .1em #0009;
}
.band-kanji { font-size: 1.23em; }
.band-accent { color: var(--cover-gold); }
#remove-band-image { margin-top: 10px; }
.revealing .book-band { opacity: 0; }
.show-result { background: var(--bg); color: var(--ink); }
.show-result .masthead { display: none; }
.result {
  width: min(100%, 440px);
  margin: auto;
  display: grid;
  gap: 12px;
  text-align: center;
}
.result h1 { font-size: 1.2rem; justify-self: center; box-shadow: none; }
.result-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; color: var(--ink); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
@media (max-width: 700px) {
  .desk { grid-template-columns: minmax(0, 1fr); max-width: 480px; }
  .preview { position: static; }
  .show-result { padding: 14px 9px 24px; }
  
}
.image-crop {
  width: min(100%, 270px);
  margin: 12px auto;
  aspect-ratio: 2 / 3;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--ink);
  background: var(--ink);
}
#crop-image, #cover-image {
  position: absolute;
  left: var(--image-left, 0);
  top: var(--image-top, 0);
  width: var(--image-width, 100%);
  height: var(--image-height, 100%);
  transform: rotate(var(--image-angle, 0deg));
}
.desk { max-width: 560px; grid-template-columns: minmax(0, 1fr); }
.book-title[data-layout="cascade"] .title-bank:nth-child(2) { margin-top: 13cqw; }
.book-title:is([data-layout="horizontal"], [data-layout="diagonal"]) { flex-direction: column; justify-content: space-between; }
:is([data-layout="horizontal"], [data-layout="diagonal"]) .title-bank { flex-direction: column; gap: 0; align-self: flex-start; }
:is([data-layout="horizontal"], [data-layout="diagonal"]) .title-bank:nth-child(2) { align-self: flex-end; margin-top: 0; }
:is([data-layout="horizontal"], [data-layout="diagonal"]) .title-column {
  flex-direction: row;
  justify-content: flex-start;
  width: auto;
  height: calc(var(--title-unit) * var(--column-width));
}
:is([data-layout="horizontal"], [data-layout="diagonal"]) .title-bank:nth-child(2) .title-column { justify-content: flex-end; }
:is([data-layout="horizontal"], [data-layout="diagonal"]) .glyph { writing-mode: horizontal-tb; }
.result-details { text-align: left; background: var(--panel); border: 2px solid var(--ink); padding: 15px; box-shadow: 4px 4px var(--ink); }
#result-title { overflow-wrap: anywhere; }
#save-cover { margin-top: 0; }
#save-photo { width: min(100%, 360px); height: auto; margin-inline: auto; }

.book:has(.book-band:not([hidden])) .book-title { bottom: 20%; }
.book-title[data-layout="full"] .title-bank:nth-child(2) { align-self: flex-end; margin-top: 0; }
[data-layout="diagonal"] .title-bank:first-child { align-self: flex-end; }
[data-layout="diagonal"] .title-bank:first-child .title-column { justify-content: flex-end; }
[data-layout="diagonal"] .title-bank:nth-child(2) { align-self: flex-start; }
[data-layout="diagonal"] .title-bank:nth-child(2) .title-column { justify-content: flex-start; }
#result-book { width: min(100%, 62svh); justify-self: center; box-shadow: 5px 5px var(--ink); }
.show-reveal { overflow: hidden; padding: 0; }
.reveal-stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  isolation: isolate;
  background: radial-gradient(ellipse at 50% 45%, #213a3b 0, #111e22 50%, #080e12 88%);
}
.reveal-stage:focus { outline: none; }
.reveal-camera {
  --depth: clamp(16px, 5vw, 28px);
  --half-depth: calc(var(--depth) / 2);
  position: relative;
  width: min(74vw, 43svh, 410px);
  aspect-ratio: 2 / 3;
  perspective: 1050px;
  will-change: transform;
}
.reveal-object { position: absolute; inset: 0; transform-style: preserve-3d; }
.reveal-front, .reveal-back, .reveal-edge, .reveal-spine, .reveal-top, .reveal-bottom {
  position: absolute;
  backface-visibility: hidden;
}
.reveal-front, .reveal-back { inset: 0; }
.reveal-front { transform: translateZ(var(--half-depth)); }
.reveal-front .book { box-shadow: 0 16px 52px #0008; }
.reveal-back {
  transform: rotateY(180deg) translateZ(var(--half-depth));
  background: radial-gradient(ellipse, #2b524c, #142c2b);
  border: 2px solid #476456;
  outline: 1px solid #acc1a3;
  outline-offset: -12px;
}
.reveal-spine, .reveal-edge { width: var(--depth); height: 100%; top: 0; }
.reveal-spine {
  left: calc(-1 * var(--half-depth));
  transform: rotateY(-90deg);
  background: linear-gradient(90deg, #101c1b, #427267 52%, #1b3530);
}
.reveal-edge, .reveal-top, .reveal-bottom {
  background: repeating-linear-gradient(90deg, #a59a81 0 1px, #e8dec3 1px 3px);
}
.reveal-edge { right: calc(-1 * var(--half-depth)); transform: rotateY(90deg); }
.reveal-top, .reveal-bottom { width: 100%; height: var(--depth); left: 0; }
.reveal-top { top: calc(-1 * var(--half-depth)); transform: rotateX(90deg); }
.reveal-bottom { bottom: calc(-1 * var(--half-depth)); transform: rotateX(-90deg); }
.reveal-glint {
  position: absolute;
  inset: 0;
  transform: translateZ(calc(var(--half-depth) + 1px));
  opacity: 0;
  pointer-events: none;
  background: linear-gradient(113deg, transparent 33%, #fff4c741 43%, #fffde5da 49%, #efffe72e 53%, transparent 61%);
  background-size: 245% 100%;
  mix-blend-mode: screen;
}
.reveal-stars { position: absolute; inset: -6%; pointer-events: none; }
.reveal-stars i {
  position: absolute;
  width: clamp(13px, 4vw, 27px);
  aspect-ratio: 1;
  background: #ffffdc;
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
  opacity: 0;
}
.reveal-stars i:nth-child(1) { top: 10%; left: 1%; }
.reveal-stars i:nth-child(2) { top: 25%; right: 0; --delay: 130ms; }
.reveal-stars i:nth-child(3) { bottom: 19%; right: -3%; --delay: 230ms; }
.reveal-stars i:nth-child(4) { bottom: 9%; left: 9%; --delay: 140ms; }
.reveal-stars i:nth-child(5) { top: 0; right: 16%; --delay: 300ms; }
.reveal-finished .reveal-stars i { animation: cover-star 490ms var(--delay, 0ms) both ease-out; }
@keyframes cover-star {
  0% { opacity: 0; transform: scale(.15) rotate(-24deg); }
  35% { opacity: 1; transform: scale(1.18) rotate(8deg); }
  100% { opacity: 0; transform: scale(.35) rotate(27deg); }
}
.reveal-skip {
  position: absolute;
  right: 1rem;
  bottom: max(1rem, env(safe-area-inset-bottom));
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  color: #d6e9e2;
  background: #132327;
  border: 1px solid #5b7675;
  box-shadow: none;
  font-size: 1.4rem;
}
.reveal-skip:hover { background: #284447; }

#name-form label { margin-top: 0; font-size: 1.15rem; }
#hero-name { padding: 12px; font-size: 1.1rem; }
#generate { font-size: 1.14rem; }
details.panel summary { cursor: pointer; padding-block: 2px; }
details.panel[open] summary { border-bottom: 1px solid var(--ink); padding-bottom: 8px; margin-bottom: 8px; }
button:disabled { opacity: .65; cursor: wait; }

:root {
  color-scheme: dark;
  --ink: #f0e6ff;
  --bg: #0c0918;
  --panel: #171127ee;
  --accent: #ba9be9;
  --paper: #f5e8ff;
  --line: #9b7ac66b;
}
body {
  min-height: 100svh;
  padding-block: clamp(52px, 11svh, 132px) 48px;
  background: radial-gradient(ellipse at 50% 39%, #301d51, #18102b 47%, var(--bg) 81%) fixed;
}
#vortex { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.masthead, .desk, .result { position: relative; }
.masthead { margin-bottom: clamp(28px, 5svh, 52px); }
.masthead h1, .result h1 {
  padding: 0;
  border: 0;
  outline: 0;
  box-shadow: none;
  background: none;
  color: #fff1ff;
  text-shadow: 0 0 26px #ba82f590;
}
.masthead h1 { font-size: clamp(1.25rem, 5.9vw, 2.8rem); }
.masthead p { color: #d8c6ee; font-size: .9rem; }
.desk { max-width: 440px; gap: 12px; }
.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(8px, 3vw, 22px);
  color: #c2acce;
  font-size: .88rem;
}
.steps li + li::before { content: "◇"; margin-inline-end: clamp(8px, 3vw, 22px); color: #b88fe0; }
.steps [aria-current] { color: #fff0c9; text-shadow: 0 0 12px #edb65e8c; }
.panel, .result-details {
  padding: clamp(18px, 5vw, 34px);
  border: 1px solid var(--line);
  border-radius: 0;
  box-shadow: 5px 5px #090510b0, inset 0 0 0 3px #171127, inset 0 0 0 4px #af8cc72c;
}
.step { animation: page-enter 430ms ease-out both; }
@keyframes page-enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.step h2 { border: 0; padding: 0; margin-bottom: 18px; font-size: 1.35rem; font-weight: normal; }
.step h2:focus, .result h1:focus { outline: none; }
input:not([type="checkbox"], [type="range"]), select, textarea {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #0e0a1c;
  border-radius: 0;
  font-size: max(1rem, 16px);
}
input[type="file"]::file-selector-button { color: var(--ink); background: #35254c; border: 1px solid var(--line); padding: 5px 8px; }
button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #251939;
  box-shadow: none;
}
button:hover { background: #382451; }
button:active { transform: translateY(1px); }
.primary {
  margin-top: 20px;
  border: 1px solid #cbb0ed;
  outline: 1px solid #e4c9ef88;
  outline-offset: -5px;
  background: linear-gradient(110deg, #473067, #674788, #473067);
  box-shadow: inset 0 0 14px #ecd2ff23, 0 3px 22px #ac7edf28;
}
.primary:hover { background: #724d98; }
:focus-visible, .primary:focus-visible { outline: 2px solid #f3d99e; outline-offset: 3px; }
.step-back { display: block; margin: 6px auto 0; border-color: transparent; background: transparent; }
.image-crop { width: min(100%, 195px); border-color: var(--line); }
.show-result { background: radial-gradient(ellipse at 50% 39%, #301d51, #18102b 47%, var(--bg) 81%) fixed; }
#result-book { box-shadow: 0 14px 45px #05030cb3, 0 0 29px #b88fe038; }
.reveal-stage { background: radial-gradient(ellipse at 50% 45%, #25173d25, #080512c9 88%); }
.site-footer {
  position: relative;
  text-align: center;
  width: min(100%, 440px);
  margin: 0 auto;
  padding-top: 15px;
  border-top: 1px solid var(--line);
  font-size: .875rem;
}
.site-footer a { color: inherit; text-underline-offset: 3px; }
.site-footer a + a { margin-inline-start: 1.25rem; }
body { display: flex; flex-direction: column; gap: 32px; }
.masthead { margin-bottom: 0; }
.desk { width: min(100%, 440px); margin-block: 0 auto; }
.show-reveal .site-footer { display: none; }
.show-finished {
  background: radial-gradient(ellipse at 50% 36%, #fff7cb 0%, #eec8ff 27%, #9974d2 64%, #45366d 100%) fixed;
}
.show-finished .result h1 {
  color: #35194c;
  text-shadow: 0 0 14px #fff;
}
.show-finished .result-actions button { color: var(--ink); }
.show-finished #save-status { color: #321845; background: #f7e8ffde; }
.show-finished .site-footer { color: #fdf0ff; background: #291a48b0; padding: 10px; }
.show-finished #result-book {
  box-shadow: 0 0 24px #fff8da, 0 0 65px #fff1bcbb, 0 16px 38px #3c245f77;
}
.reveal-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(ellipse at center, #fffad9 0%, #f7cdf577 40%, transparent 72%),
    repeating-conic-gradient(from 15deg at center, #ffefc86b 0deg, transparent 8deg 30deg),
    radial-gradient(ellipse at center, #edb4f988, #b090e952 65%, #57317b6b);
}
.reveal-bright::before { animation: reveal-light 1.2s ease-out both; }
@keyframes reveal-light {
  from { opacity: 0; transform: scale(.5); }
  46% { opacity: 1; }
  to { opacity: .93; transform: scale(1.2); }
}
.reveal-finished .reveal-stars i {
  background: #fffdf0;
  filter: drop-shadow(0 0 7px #ffdc7f);
  animation-duration: 550ms;
}
@media (prefers-reduced-motion: reduce) {
  .step { animation: none; }
}
