:root {
  color-scheme: light;
  --ink: #211725;
  --paper: #fff9e8;
  --page: #eee5f9;
  --yellow: #ffd941;
  --purple: #ad8cf2;
  --pink: #ffc0da;
  --green: #d6f880;
  --muted: #4c3d52;
  font: 16px/1.49 system-ui, "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: var(--page);
  background-image: radial-gradient(#42215723 .8px, transparent .9px);
  background-size: 8px 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
a { color: inherit; }
h1, h2, p, figure, blockquote { margin: 0; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: progress; }
:focus-visible { outline: 3px solid #6943aa; outline-offset: 4px; }
.sheet { width: min(100% - 2.3rem, 69rem); margin-inline: auto; padding-bottom: 3rem; }
.head { display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid var(--ink); min-height: 3.75rem; }
.wordmark { font-size: 1rem; font-weight: 1000; letter-spacing: .16em; }
.head a, .link { font-size: .9rem; font-weight: 720; text-underline-offset: .23em; }
.head a { display: flex; min-height: 44px; align-items: center; }

.opening { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .94fr); gap: clamp(1.5rem, 4vw, 3rem); align-items: center; padding: clamp(1.8rem, 4vw, 3.1rem) 0 2.1rem; }
.opening-copy { min-width: 0; }
h1 { font-size: clamp(2.35rem, 5.1vw, 4.55rem); font-weight: 1000; line-height: 1.08; letter-spacing: -.078em; overflow-wrap: break-word; }
h1 em { font-style: normal; background: linear-gradient(transparent 70%, var(--purple) 70% 98%, transparent 98%); }
.bubble {
  position: relative; width: fit-content; max-width: 100%; margin: 1.25rem 0 1.5rem;
  background: var(--paper); border: 2px solid var(--ink); border-radius: .75rem;
  box-shadow: 3px 3px 0 var(--ink); padding: .68rem .9rem;
}
.bubble::after {
  content: ""; position: absolute; bottom: -.49rem; left: 1rem; width: .8rem; height: .8rem;
  transform: rotate(45deg); background: var(--paper); border-bottom: 2px solid var(--ink); border-right: 2px solid var(--ink);
}
.bubble strong { display: block; font-weight: 900; }
#prompt { color: var(--muted); font-size: .9rem; margin-top: .2rem; }
.opening-art { border: 3px solid var(--ink); box-shadow: 7px 7px 0 var(--ink); background: var(--yellow); overflow: hidden; }
.opening-art img { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; }
#draw, .share {
  display: inline-flex; text-decoration: none; align-items: center; justify-content: center; min-height: 3rem; text-align: center;
  background: var(--yellow); color: var(--ink); padding: .64rem 1.2rem; border: 2px solid var(--ink);
  border-radius: .35rem; box-shadow: 4px 4px 0 var(--ink); font-weight: 920; transition: box-shadow .12s, translate .12s;
}
#draw:hover:not(:disabled), .share:hover { box-shadow: 2px 2px 0 var(--ink); translate: 2px 2px; }
#draw:disabled { background: var(--paper); }
#message:not(:empty) { margin-top: .6rem; color: var(--muted); font-weight: 650; }

.slots { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: clamp(.55rem, 2.4vw, 1rem); list-style: none; padding: 0; margin: 0 0 1.35rem; }
.slot { min-height: 10rem; padding: .8rem .95rem; background: var(--paper); border: 2px solid var(--ink); border-top-width: 7px; box-shadow: 4px 4px 0 var(--ink); overflow-wrap: anywhere; }
.slot:nth-child(2) { border-top-color: #7750bc; }
.slot:nth-child(3) { border-top-color: #ae3268; }
.slot-meta { color: var(--muted); font-size: .74rem; font-weight: 870; text-transform: uppercase; letter-spacing: .055em; margin-bottom: .28rem; }
.slot h2 { font-size: clamp(1.14rem, 2.3vw, 1.65rem); font-weight: 940; line-height: 1.18; letter-spacing: -.043em; }
.context { color: var(--muted); font-size: .81rem; font-weight: 620; margin: .38rem 0 .46rem; }
.fact { font-size: .87rem; }
.profile { margin-top: .52rem; color: var(--muted); font-size: .76rem; }
.profile summary, .ranks summary { cursor: pointer; }
.empty { display: grid; place-items: center; min-height: 7.45rem; background: var(--purple); font-size: 2rem; font-weight: 980; font-variant-numeric: tabular-nums; color: var(--ink); }
.empty:nth-child(2) { background: var(--yellow); }
.empty:nth-child(3) { background: var(--pink); }
.opening:has(#draw:disabled) + .slots .empty { animation: slot-pulse .36s ease-in-out alternate infinite; }
.result { background: var(--paper); border: 3px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); padding: clamp(.95rem, 3vw, 1.6rem); }
.result-head { display: flex; gap: .7rem; align-items: center; justify-content: space-between; margin-bottom: .68rem; }
.result h2 { font-size: clamp(1.35rem, 3vw, 2rem); line-height: 1.15; font-weight: 950; letter-spacing: -.046em; }
#rank { margin-top: .2rem; color: var(--muted); font-size: .83rem; }
.stamp { border: 3px double var(--ink); background: var(--yellow); padding: .22rem .56rem; text-align: center; white-space: nowrap; font-weight: 920; }
#upper { font-size: .78rem; line-height: 1.2; }
#score { font-size: clamp(1.35rem, 4vw, 1.94rem); line-height: 1.14; font-variant-numeric: tabular-nums; }
#reason { font-size: .9rem; }
.boss-result {
  color: var(--ink); margin-top: .9rem; border: 2px solid var(--ink); padding: .66rem .8rem; background: var(--pink);
  background-image: repeating-linear-gradient(135deg, transparent 0 6px, #21172509 6px 7px);
}
.boss-result[data-outcome="close"] { background-color: var(--purple); }
.boss-result[data-outcome="victory"] { background-color: var(--green); }
.boss-title { font-size: .7rem; font-weight: 870; letter-spacing: .09em; text-transform: uppercase; }
.verdict { font-size: clamp(1.35rem, 3.8vw, 2.35rem); line-height: 1.14; letter-spacing: -.055em; font-weight: 1000; margin: .16rem 0; }
.boss-detail { font-size: .76rem; color: var(--muted); font-weight: 700; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; margin-top: 1rem; }
.share { min-height: 44px; background: var(--ink); color: var(--paper); }
.link { min-height: 44px; background: none; border: 0; padding: .2rem .5rem; text-decoration: underline; }
.challenge { font-weight: 860; margin-top: .8rem; }
#copy-status:not(:empty), #copy-fallback:not([hidden]) { margin-top: .65rem; }
#copy-fallback { width: 100%; }
.ranks { padding-top: .9rem; margin-top: 1.5rem; border-top: 2px solid var(--ink); font-weight: 700; }
.ranks li { margin: .32rem 0; }
#method { margin-top: .75rem; color: var(--muted); font-size: .82rem; font-weight: 500; }
footer { margin-top: 1.55rem; color: var(--muted); font-size: .77rem; }

@media (max-width: 44rem) {
  .sheet { width: min(100% - 1.45rem, 69rem); }
  .head { min-height: 3rem; }
  .opening { grid-template-columns: 1fr; gap: 1rem; padding: 1.25rem 0 1.1rem; }
  h1 { font-size: clamp(2.18rem, 8.4vw, 3.4rem); }
  .opening-art { box-shadow: 4px 4px 0 var(--ink); }
  .opening-art img { aspect-ratio: 2 / 1; object-position: center 39%; }
  .bubble { margin: .8rem 0 1rem; }
  .slots { grid-template-columns: 1fr; gap: .48rem; }
  .slot { min-height: 0; border-top-width: 4px; padding: .62rem .75rem; }
  .slots:not(:has(.revealed)) { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .slot.empty { min-height: 2.6rem; font-size: 1.1rem; }
  .sheet[data-result] .opening-art { display: none; }
  .sheet[data-result] .opening h1 { font-size: clamp(1.65rem, 6vw, 2.4rem); }
  .sheet[data-result] .bubble { display: none; }
  .sheet[data-result] #draw { margin-top: .7rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .slot.revealed { animation: reveal .24s ease-out; }
  .boss-result { animation: reveal .28s cubic-bezier(.2,.8,.35,1.15) both; }
  @keyframes reveal { from { opacity: .42; transform: translateY(5px) scale(.98); } }
  @keyframes slot-pulse { to { filter: brightness(1.12); } }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; transition-duration: 0s !important; }
}
