:root {
  --paper: #eadfc9;
  --paper-deep: #d9c8aa;
  --ink: #40312b;
  --muted: #706157;
  --story: #9f4039;
  --story-deep: #7c302d;
  --story-soft: #dec1b6;
  --character: #277380;
  --character-soft: #bcd3d5;
  --world: #9b7540;
  --world-soft: #dfcfaa;
  --essay: #6f6844;
  --essay-soft: #d8d1ae;
  --gold: #ab8442;
  --gold-light: #d1b36d;
  --blush: #d9bbb3;
  --beige: #c7b08f;
  --white: #f2e8d5;
  --shadow: 0 24px 60px rgba(87, 58, 42, 0.13);
  --serif: "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", Georgia, serif;
  --sans: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.8;
}

button, input { font: inherit; }
button { color: inherit; }

.page-texture {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0.52;
  background:
    radial-gradient(circle at 16% 10%, rgba(159, 64, 57, 0.08), transparent 27rem),
    radial-gradient(circle at 84% 38%, rgba(111, 136, 117, 0.07), transparent 30rem),
    radial-gradient(circle at 52% 92%, rgba(169, 124, 66, 0.06), transparent 24rem),
    repeating-linear-gradient(0deg, rgba(91, 64, 48, 0.025) 0, rgba(91, 64, 48, 0.025) 1px, transparent 1px, transparent 5px);
}

.masthead {
  position: relative;
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 42px 0 74px;
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr) 168px;
  gap: 62px;
  align-items: start;
  border-bottom: 1px solid rgba(75, 56, 47, 0.22);
}
.masthead::after {
  content: "✦";
  position: absolute;
  right: 4px;
  bottom: -13px;
  padding: 0 10px;
  background: var(--paper);
  color: var(--gold);
  font-size: 18px;
}

.brand { color: inherit; text-decoration: none; display: inline-flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.brand-mark {
  display: block;
  width: 118px;
  height: 118px;
  object-fit: contain;
}
.brand-caption { font-size: 9px; letter-spacing: 0.18em; color: var(--muted); }

.eyebrow, .section-number {
  margin: 0 0 14px;
  color: var(--story);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.eyebrow span { display: inline-block; width: 28px; height: 1px; margin: 0 10px 3px 0; background: currentColor; }

.hero-copy h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(40px, 5.3vw, 70px);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.28;
}
.hero-copy h1 em { color: var(--story); font-style: normal; background: linear-gradient(transparent 72%, rgba(171, 132, 66, 0.22) 0); }
.lede { margin: 24px 0 0; color: var(--muted); font-family: var(--serif); font-size: 15px; line-height: 2; }

.combination-stamp {
  width: 150px;
  height: 150px;
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  font-size: 11px;
  letter-spacing: 0.08em;
  transform: rotate(5deg);
  color: var(--story-deep);
  box-shadow: inset 0 0 0 5px var(--paper), inset 0 0 0 6px rgba(171, 132, 66, 0.45);
}
.combination-stamp strong { margin: -1px 0 -4px; font-family: var(--serif); font-size: 28px; font-weight: 500; letter-spacing: -0.05em; }

main { width: min(1180px, calc(100% - 48px)); margin: 0 auto; }

.draw-panel {
  padding: 54px 0 32px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 30px;
}
.panel-copy h2, .brief-heading-wrap h2, .how-to h2 { margin: 0; font-family: var(--serif); font-size: clamp(28px, 3vw, 40px); font-weight: 500; line-height: 1.35; }
.panel-copy > p:last-child, .brief-heading-wrap > p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 13px; }

.draw-actions { display: grid; gap: 12px; justify-items: end; }
.mode-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(132px, 1fr));
  gap: 5px;
  margin: 0;
  padding: 5px;
  border: 1px solid rgba(171, 132, 66, 0.55);
  border-radius: 13px;
  background: rgba(255, 250, 241, 0.48);
}
.mode-picker label { position: relative; cursor: pointer; }
.mode-picker input { position: absolute; opacity: 0; pointer-events: none; }
.mode-picker label > span {
  min-height: 50px;
  padding: 7px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: var(--muted);
  line-height: 1.35;
  transition: background .2s ease, color .2s ease, box-shadow .2s ease;
}
.mode-picker strong { font-family: var(--serif); font-size: 13px; }
.mode-picker small { font-size: 9px; }
.mode-picker input:checked + span { background: var(--story); color: var(--white); box-shadow: 0 5px 13px rgba(83,47,37,.16); }
.mode-picker input:focus-visible + span { outline: 3px solid rgba(171,132,66,.4); outline-offset: 2px; }
.is-essay-mode .mode-picker input:checked + span { background: var(--essay); }
.draw-controls { display: flex; gap: 14px; align-items: center; }
.world-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 8px 14px 8px 18px;
  border: 1px solid rgba(171, 132, 66, 0.55);
  border-radius: 12px;
  background: rgba(255, 250, 241, 0.68);
  cursor: pointer;
}
.world-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-copy { display: flex; flex-direction: column; line-height: 1.35; }
.toggle-copy strong { font-size: 12px; }
.toggle-copy small { color: var(--muted); font-size: 10px; }
.toggle-track { width: 42px; height: 24px; padding: 3px; border-radius: 99px; background: #b8afa5; transition: background .2s ease; }
.toggle-track span { display: block; width: 18px; height: 18px; border-radius: 50%; background: white; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s ease; }
.world-toggle input:checked + .toggle-track { background: var(--world); }
.is-essay-mode .world-toggle input:checked + .toggle-track { background: var(--essay); }
.world-toggle input:checked + .toggle-track span { transform: translateX(18px); }
.world-toggle:focus-within { outline: 3px solid rgba(181, 129, 53, .25); outline-offset: 3px; }

.draw-all, .copy-brief, .save-image {
  min-height: 62px;
  border: 0;
  border-radius: 10px;
  background: var(--story);
  color: var(--white);
  padding: 0 24px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .05em;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(83, 47, 37, 0.18), inset 0 0 0 1px rgba(209, 179, 109, .65);
  transition: transform .2s ease, background .2s ease;
}
.draw-all:hover, .copy-brief:hover, .save-image:hover { background: var(--story-deep); transform: translateY(-2px); }
.draw-all:active, .copy-brief:active, .save-image:active { transform: translateY(0); }
.draw-all:focus-visible, .copy-brief:focus-visible, .save-image:focus-visible, .reroll:focus-visible { outline: 3px solid rgba(171, 132, 66, .4); outline-offset: 3px; }
.button-spark, .save-image span { margin-right: 7px; color: var(--gold-light); }

.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; align-items: stretch; }
.prompt-card {
  position: relative;
  min-height: 410px;
  padding: 20px 22px 18px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 8px solid currentColor;
  border-radius: 16px;
  background: var(--white);
  box-shadow: var(--shadow), 0 5px 0 rgba(64, 49, 43, 0.08);
  transition: transform .24s ease, opacity .24s ease, filter .24s ease;
}
.prompt-card::after {
  content: "";
  position: absolute;
  right: -34px;
  bottom: -34px;
  width: 116px;
  height: 116px;
  border: 1px solid currentColor;
  border-radius: 50%;
  opacity: .12;
}
.story-card { color: var(--story); background: linear-gradient(145deg, var(--white), #dfc6ba); }
.character-card { color: var(--character); background: linear-gradient(145deg, var(--white), var(--character-soft)); }
.world-card { color: var(--world); background: linear-gradient(145deg, var(--white), #e3d5b4); }
.is-essay-mode .story-card { color: var(--essay); background: linear-gradient(145deg, var(--white), #ded8b9); }
.is-essay-mode .character-card { color: #8c604f; background: linear-gradient(145deg, var(--white), #ddc6bb); }
.is-essay-mode .world-card { color: #777b58; background: linear-gradient(145deg, var(--white), #d7d5b8); }
.prompt-card.is-shuffling { transform: translateY(-8px) rotate(-1deg); opacity: .58; }

.card-topline, .card-footer { position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; }
.card-topline { padding-bottom: 14px; border-bottom: 1px solid currentColor; }
.card-kind { font-size: 11px; font-weight: 700; letter-spacing: .14em; }
.reroll { width: 34px; height: 34px; border: 1px solid currentColor; border-radius: 50%; background: transparent; cursor: pointer; font-size: 19px; line-height: 1; transition: transform .25s ease, background .2s ease; }
.reroll:hover:not(:disabled) { transform: rotate(80deg); background: rgba(255,255,255,.65); }
.reroll:disabled { opacity: .32; cursor: not-allowed; }
.card-index { margin: 0 0 12px; font-size: 10px; font-weight: 700; letter-spacing: .14em; opacity: .68; }
.prompt-card h3 { margin: 0; font-family: var(--serif); font-weight: 600; color: var(--ink); }
.story-body { flex: 1; padding: 34px 5px 22px; }
.story-body h3 { font-size: 27px; }
.story-lines { margin-top: 28px; color: var(--ink); font-family: var(--serif); font-size: clamp(16px, 1.55vw, 19px); line-height: 2.1; }
.story-lines p { margin: 0 0 8px; }
.character-body, .world-body { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 28px 0 18px; text-align: center; }
.portrait-frame {
  width: 104px;
  height: 132px;
  margin: 4px 0 22px;
  display: grid;
  place-items: center;
  border: 1px solid currentColor;
  border-radius: 50% 50% 45% 45%;
  background: rgba(255,255,255,.42);
  box-shadow: inset 0 0 0 7px rgba(255,255,255,.38);
}
.portrait-frame span { font-family: var(--serif); font-size: 42px; font-weight: 400; opacity: .48; }
.character-body h3, .world-body h3 { font-size: 23px; line-height: 1.55; }
.character-note, .world-body > p:last-child { margin: 14px 5px 0; color: var(--ink); font-size: 12px; line-height: 1.8; opacity: .72; }
.world-orbit { position: relative; width: 116px; height: 116px; margin: 12px 0 22px; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 50%; }
.world-orbit::before, .world-orbit::after { content: ""; position: absolute; inset: 19px -10px; border: 1px solid currentColor; border-radius: 50%; transform: rotate(28deg); opacity: .55; }
.world-orbit::after { transform: rotate(-28deg); }
.world-orbit span { font-size: 28px; }
.card-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid currentColor; font-size: 10px; letter-spacing: .08em; }
.card-symbol { font-size: 14px; }
.world-card.is-inactive { filter: grayscale(.75); opacity: .66; background: repeating-linear-gradient(135deg, #f5efe3 0, #f5efe3 12px, #ede3d3 12px, #ede3d3 13px); }

.brief-section {
  margin-top: 92px;
  padding: 72px 0;
  display: grid;
  grid-template-columns: .72fr 1.28fr;
  gap: 70px;
  align-items: start;
  border-top: 1px solid rgba(51,46,42,.2);
}
.brief-paper {
  position: relative;
  padding: 46px 50px 42px;
  background: #f8f1e5;
  border: 1px solid var(--gold);
  box-shadow: 0 28px 70px rgba(74,57,42,.15);
  transform: rotate(.5deg);
}
.brief-paper::before { content: ""; position: absolute; inset: 12px; border: 1px solid rgba(171,132,66,.48); pointer-events: none; }
.brief-paper::after {
  content: "";
  position: absolute;
  top: -10px;
  right: 46px;
  width: 72px;
  height: 25px;
  background: rgba(243, 201, 197, 0.72);
  transform: rotate(3deg);
  box-shadow: 0 1px 2px rgba(75,56,47,.08);
}
.paper-pin { position: absolute; top: 18px; left: 50%; width: 10px; height: 10px; border-radius: 50%; background: var(--story); box-shadow: 1px 3px 5px rgba(0,0,0,.25); }
.brief-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; letter-spacing: .13em; }
.brief-rule { height: 3px; margin: 20px 0 29px; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
.brief-label { margin: 22px 0 5px; color: var(--story); font-size: 10px; font-weight: 700; letter-spacing: .18em; }
.brief-character { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 600; }
blockquote { margin: 0; color: var(--ink); font-family: var(--serif); font-size: 18px; line-height: 2; }
blockquote p { margin: 0; }
.brief-world { padding: 1px 0 20px; }
.brief-world > p:last-child { margin: 0; font-size: 13px; line-height: 1.8; }
.brief-actions { display: grid; grid-template-columns: 1.12fr .88fr; gap: 10px; margin-top: 8px; }
.copy-brief, .save-image { width: 100%; min-height: 52px; margin: 0; padding: 0 16px; }
.copy-brief { background: transparent; color: var(--story-deep); border: 1px solid var(--gold); box-shadow: none; }
.copy-brief:hover { color: var(--white); }

.novel-section {
  padding: 76px 0;
  border-top: 1px solid rgba(51,46,42,.2);
}
.novel-heading-wrap { max-width: 650px; margin-bottom: 34px; }
.novel-heading-wrap h2 { margin: 0; font-family: var(--serif); font-size: clamp(28px, 3vw, 40px); font-weight: 500; line-height: 1.35; }
.novel-heading-wrap > p:last-child { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.novel-maker { display: grid; grid-template-columns: .78fr 1.22fr; gap: 44px; align-items: start; }
.novel-controls { display: grid; gap: 16px; }
.image-picker, .novel-copy {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 18px;
  border: 2px solid var(--gold);
  border-radius: 14px;
  background: rgba(248,241,229,.72);
}
.image-picker { cursor: pointer; text-align: center; }
.image-picker > span, .novel-copy > span { color: var(--story-deep); font-family: var(--serif); font-weight: 700; }
.image-picker small, .novel-copy small { color: var(--muted); font-size: 10px; }
.image-picker input { margin-top: 8px; width: 100%; font-size: 12px; }
.multiply-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 15px;
  border: 1px solid rgba(171,132,66,.55);
  border-radius: 12px;
  background: rgba(248,241,229,.72);
  cursor: pointer;
}
.multiply-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.multiply-check {
  display: grid;
  place-items: center;
  flex: 0 0 25px;
  width: 25px;
  height: 25px;
  border: 2px solid var(--gold);
  border-radius: 6px;
  color: transparent;
  font-weight: 800;
}
.multiply-toggle input:checked + .multiply-check { background: var(--story); border-color: var(--story); color: var(--white); }
.multiply-toggle > span:last-child { display: flex; flex-direction: column; line-height: 1.45; }
.multiply-toggle strong { color: var(--story-deep); font-size: 12px; }
.multiply-toggle small { color: var(--muted); font-size: 10px; }
.multiply-toggle:focus-within { outline: 3px solid rgba(171,132,66,.4); outline-offset: 3px; }
.novel-tip { margin: -7px 4px 0; color: var(--muted); font-size: 11px; line-height: 1.7; }
.novel-copy textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  border: 1px solid rgba(64,49,43,.25);
  border-radius: 8px;
  padding: 12px;
  background: var(--white);
  color: var(--ink);
  font-family: var(--serif);
  line-height: 1.8;
}
.novel-copy small { text-align: right; }
.make-novel, .save-novel {
  min-height: 54px;
  border: 0;
  border-radius: 10px;
  padding: 0 22px;
  background: var(--story);
  color: var(--white);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 9px 20px rgba(83,47,37,.18), inset 0 0 0 1px rgba(209,179,109,.65);
}
.make-novel:hover, .save-novel:hover:not(:disabled) { background: var(--story-deep); transform: translateY(-2px); }
.make-novel:focus-visible, .save-novel:focus-visible, .image-picker:focus-within { outline: 3px solid rgba(171,132,66,.4); outline-offset: 3px; }
.novel-result { display: grid; justify-items: center; gap: 16px; }
.novel-page {
  position: relative;
  width: min(100%, 620px);
  aspect-ratio: 8 / 11;
  overflow: hidden;
  display: grid;
  grid-template-columns: 48% 1fr;
  gap: 6%;
  padding: 7% 6% 8%;
  background: #f8f1e5;
  border: 2px solid var(--gold);
  box-shadow: 0 24px 55px rgba(74,57,42,.18);
}
.novel-page.is-short {
  grid-template-columns: 56% 30%;
  gap: 4%;
  padding-left: 11%;
  padding-right: 5%;
}
.novel-page::before { content: ""; position: absolute; inset: 2.2%; border: 1px solid rgba(171,132,66,.48); pointer-events: none; }
.novel-illustration {
  position: relative;
  min-width: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  align-self: stretch;
}
.novel-illustration img { width: 100%; height: 100%; object-fit: contain; }
.novel-illustration img.is-multiply { mix-blend-mode: multiply; }
.novel-illustration span { color: var(--muted); font-family: var(--serif); font-size: 12px; text-align: center; }
.novel-vertical-text {
  margin: 0;
  min-width: 0;
  max-width: 100%;
  width: 100%;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  justify-self: stretch;
  contain: layout paint;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.85;
  letter-spacing: 0;
}
.novel-page-number { position: absolute; right: 7%; bottom: 3.2%; color: var(--muted); font-family: var(--serif); font-size: 10px; }
.save-novel { width: min(100%, 620px); }
.save-novel:disabled { opacity: .45; cursor: not-allowed; }
.save-novel span { margin-right: 7px; color: var(--gold-light); }
.novel-status { min-height: 1.8em; margin: 0; color: var(--story-deep); font-size: 12px; text-align: center; }

.how-to { padding: 72px 0 88px; display: grid; grid-template-columns: .72fr 1.28fr; gap: 70px; border-top: 1px solid rgba(51,46,42,.2); }
.how-to ol { margin: 0; padding: 0; list-style: none; }
.how-to li { display: grid; grid-template-columns: 44px 1fr; gap: 18px; padding: 20px 0; border-bottom: 1px solid rgba(51,46,42,.18); }
.how-to li:first-child { padding-top: 0; }
.how-to li > span { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--story); border-radius: 50%; color: var(--story); font-family: var(--serif); }
.how-to strong { font-family: var(--serif); font-size: 17px; }
.how-to li p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

footer { padding: 32px max(24px, calc((100vw - 1180px) / 2)); display: flex; justify-content: space-between; gap: 20px; background: var(--ink); color: var(--paper); border-top: 4px solid var(--story); }
.footer-copy > span { font-family: var(--serif); font-size: 17px; }
.footer-copy p { margin: 3px 0 0; color: rgba(244,236,222,.65); font-size: 11px; }
.footer-links { display: flex; align-items: center; gap: 9px; }
.footer-links a { padding: 8px 14px; border: 1px solid rgba(209,179,109,.58); border-radius: 999px; color: var(--paper); font-size: 11px; letter-spacing: .05em; text-decoration: none; transition: color .2s ease, border-color .2s ease, transform .2s ease; }
.footer-links a:hover { color: var(--gold-light); border-color: var(--gold-light); transform: translateY(-2px); }
.footer-links a:focus-visible { outline: 3px solid rgba(209,179,109,.42); outline-offset: 3px; }
.footer-links a span { margin-left: 3px; font-size: 10px; }

.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: 900px) {
  .masthead { grid-template-columns: 128px 1fr; gap: 30px; }
  .combination-stamp { display: none; }
  .brand-mark { width: 100px; height: 100px; }
  .draw-panel { align-items: stretch; flex-direction: column; }
  .draw-actions { justify-items: stretch; }
  .draw-controls { justify-content: space-between; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .story-card { grid-column: auto; min-height: 410px; }
  .brief-section, .novel-maker, .how-to { grid-template-columns: 1fr; gap: 36px; }
}

@media (max-width: 620px) {
  .masthead, main { width: min(100% - 28px, 1180px); }
  .masthead { padding: 24px 0 48px; grid-template-columns: 1fr; }
  .brand { flex-direction: row; align-items: center; }
  .brand-mark { width: 76px; height: 76px; }
  .brand-caption { max-width: 100px; }
  .hero-copy h1 { font-size: 34px; }
  .lede br { display: none; }
  .draw-controls { flex-direction: column; align-items: stretch; }
  .mode-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .world-toggle { justify-content: space-between; }
  .cards { grid-template-columns: 1fr; }
  .story-card { grid-column: auto; }
  .prompt-card { min-height: 360px; }
  .brief-section { margin-top: 60px; padding: 54px 0; }
  .novel-section { padding: 54px 0; }
  .brief-paper { padding: 40px 28px 30px; }
  .brief-meta { flex-direction: column; gap: 3px; }
  .brief-actions { grid-template-columns: 1fr; }
  .novel-page { width: 100%; }
  .novel-vertical-text { line-height: 1.65; }
  footer { flex-direction: column; }
  .footer-links { align-self: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
