:root {
  color-scheme: light;
  --ink: #3c2b35;
  --muted: #76656e;
  --line: #cfb995;
  --paper: #fcf8f0;
  --serif: "Iowan Old Style", "Palatino Linotype", "Songti SC", "STSong", "Noto Serif CJK SC", SimSun, Georgia, serif;
  font-family: var(--serif);
  color: var(--ink);
  background: #e9e2e6;
}
* { box-sizing: border-box; }
.model-name { display: block; font: 500 .72em/1.1 Georgia, serif; letter-spacing: .02em; }
html, body { width: 100%; height: 100%; margin: 0; overflow: clip; }
button { font: inherit; cursor: pointer; color: inherit; }
button:focus-visible { outline: 2px solid #705783; outline-offset: 3px; }
#landscape-hint { display: none; }
@media (orientation: portrait) {
  body { display: flex; flex-direction: column; height: 100dvh; }
  #landscape-hint:not([hidden]) {
    display: flex; flex: none; align-items: center; justify-content: center; gap: 12px;
    padding: max(4px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 4px max(12px, env(safe-area-inset-left));
    color: var(--ink); background: #fcf7ed; border-bottom: 1px solid var(--line); font-size: 15px;
  }
  #landscape-hint button {
    flex: none; min-height: 44px; padding: 0 10px; border: 0; background: transparent;
    font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
  }
  #landscape-hint:not([hidden]) + .viewport { flex: 1; min-height: 0; }
}
#pool-load-notice {
  position: fixed; z-index: 10; inset-inline: 12px;
  bottom: max(14px, env(safe-area-inset-bottom)); margin-inline: auto;
  width: fit-content; max-width: calc(100% - 24px); padding: 8px 14px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 12px;
  color: var(--ink); background: #fff9ef; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 3px 16px #3c2b3533; font-size: 15px;
}
#pool-load-notice[hidden] { display: none; }
#pool-load-notice button {
  min-height: 34px; padding: 3px 10px; border: 1px solid var(--line);
  border-radius: 5px; background: #f5ecdf;
}
.viewport {
  width: 100%; height: 100%; height: 100dvh; position: relative; overflow: clip;
  background-color: #efe9ea;
  isolation: isolate;
}
.viewport::before {
  content: ""; position: absolute; inset: -35px; z-index: -1; background: var(--ambient-art, none) center / cover;
  filter: blur(28px) saturate(.52); opacity: .72;
}
#stage {
  position: absolute; top: 50%; left: 50%; width: 1376px; height: 768px;
  transform: translate(-50%, -50%) scale(var(--stage-scale, 1)); transform-origin: center;
  background-color: var(--paper); overflow: clip; isolation: isolate;
  box-shadow: 0 0 60px #42374c1f;
}
.scene, .orbit-ring { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.scene { object-fit: cover; }
.orbit-ring { background-position: center; background-size: 100% 100%; background-repeat: no-repeat; }
.departing-scene { opacity: 0; }
.orbit-ring { opacity: 0; transition: opacity .55s ease-out; }
#stage[data-pool="gemini"][data-initial-art="true"] .orbit-ring { opacity: 1; background-image: url("../assets/chrome/orbit.webp"); }
.rail-paper {
  position: absolute; inset: 0 auto 0 0; width: 164px; pointer-events: none;
  background: linear-gradient(to right, #e8e0ee82, #f9f7f926 96%, #b9a99036);
  box-shadow: inset -1px 0 #e2d6bd55;
}
.bottom-wash {
  position: absolute; inset: auto 0 0; height: 210px; pointer-events: none;
  background: linear-gradient(0deg, #dccfe4be, #e8ddeb78 45%, transparent);
}
.rail-star { position: absolute; pointer-events: none; left: 70px; top: 707px; width: 33px; }
.vertical-ornament { position: absolute; pointer-events: none; left: 202px; top: 349px; width: 23px; height: 285px; }
.back-button {
  position: absolute; left: 32px; top: 12px; width: 69px; height: 68px;
  display: grid; place-content: center; z-index: 2;
  appearance: none; background: transparent; border: 0; padding: 0; border-radius: 50%;
}
.back-button img { width: 59px; height: 58px; transition: transform .18s; }
#sound-toggle {
  position: absolute; z-index: 9; top: 23px; left: 108px; min-height: 38px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 4px 13px; border: 1px solid #b39b73; border-radius: 30px;
  background: #fff9edf2; color: #6c523d; box-shadow: inset 0 0 0 2px #fffdf6bd, 0 1px 5px #735e4b33;
  font: 600 15px/1.1 var(--serif);
}
#sound-toggle[aria-pressed="true"] { background: #f9edcb; color: #674620; border-color: #a17b44; }
.sound-note { position: relative; display: inline-block; font: 20px/1 Georgia, serif; }
#sound-toggle[aria-pressed="false"] .sound-note::after {
  content: ""; position: absolute; top: 44%; left: -12%; width: 125%; height: 1.5px;
  background: currentColor; transform: rotate(-47deg); box-shadow: 0 -1px #fff9ed;
}
#stage.portrait > #sound-toggle { left: 13px; top: auto; bottom: 314px; min-height: 43px; }
#stage.portrait.is-performing > #sound-toggle { top: 11px; left: 12px; bottom: auto; }
#stage.portrait:has(#draw-flow[data-view="results"]) > #sound-toggle {
  left: 47px; top: 4px; width: 44px; padding: 0;
}
#stage.portrait:has(#draw-flow[data-view="results"]) > #sound-toggle .sound-label { display: none; }
#panel > #sound-toggle { left: auto; right: 18px; top: 13px; }
#panel.illustrated > #sound-toggle { right: auto; left: 13px; top: 12px; }
#panel.portrait.illustrated > #sound-toggle { left: 8px; top: 7px; width: 44px; min-height: 44px; padding: 0; }
#panel.portrait.illustrated > #sound-toggle .sound-label { display: none; }
@media (hover: hover) { .back-button:hover img { transform: translateX(-3px); } }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

#panel {
  width: min(520px, calc(100vw - 32px)); max-height: min(90dvh, 850px);
  margin: auto; padding: 6px; color: var(--ink); font-family: var(--serif);
  border: 1px solid #b7a078; border-radius: 12px;
  background: #faf6ee; box-shadow: 0 18px 85px #2d203860, inset 0 0 0 2px #fffdf8;
  overflow-y: auto; overscroll-behavior: contain; scrollbar-color: #cebdd0 #f6f0ed;
}
#panel::backdrop { background: #30253569; backdrop-filter: blur(5px); }
#panel[open] { animation: show-panel 200ms ease-out; }
#panel.illustrated {
  position: fixed; inset: 50% auto auto 50%; margin: 0; padding: 0;
  width: var(--panel-width); height: var(--panel-height); max-width: none; max-height: none;
  transform: translate(-50%, -50%) scale(var(--panel-scale, 1)); transform-origin: center;
  border: none; border-radius: 0; box-shadow: none; background: transparent; overflow: clip;
}
#panel.illustrated[open] { animation: none; }
#panel.illustrated::backdrop { background: rgba(59, 42, 47, .29); backdrop-filter: blur(2.5px); }
#panel.illustrated[data-kind="history"]::backdrop { background: rgba(47, 36, 44, .55); }
#panel.illustrated #panel-content {
  position: relative; width: 100%; height: 100%; padding: 0; border: none; border-radius: 0;
}
#panel.illustrated h2:focus { outline: none; }
#panel-content { border: 1px solid #d9caaa; border-radius: 8px; padding: clamp(16px, 3vw, 34px); }
#panel[data-kind="results"], #panel[data-kind="overview"] { width: min(870px, calc(100vw - 30px)); }
#panel[data-kind="results"]:has(.is-single) { width: min(430px, calc(100vw - 30px)); }
.panel-heading { display: flex; gap: 10px; align-items: center; margin: 0 0 18px; }
.panel-heading img { width: 29px; height: 31px; object-fit: contain; }
.panel-heading h2 { font-family: var(--serif); font-size: clamp(25px, 4vw, 36px); line-height: 1.2; font-weight: 600; letter-spacing: .065em; margin: 0; }
.panel-heading h2:focus { outline: none; }
.panel-prose, .empty-history { font-size: 16px; line-height: 1.85; }
.panel-prose p, .empty-history { margin: 0 0 12px; }
.panel-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 20px 0 0; }
.dialog-button {
  padding: 9px 21px; border-radius: 30px; border: 1px solid #b49364;
  background: #f4e6c3; box-shadow: inset 0 0 0 2px #fffae5; line-height: 1.4;
  font-weight: 600; font-size: 15px; min-height: 42px;
}
.dialog-button.secondary { background: #f3edf3; border-color: #bcaebf; box-shadow: inset 0 0 0 2px #fcf9fb; }
.dialog-button:hover { filter: brightness(1.04); }
.resource-value { font-family: Georgia, var(--serif); color: #856245; text-align: center; font-size: 58px; margin: .2em 0 .35em; }
.resource-value small { font-family: var(--serif); font-size: 17px; padding-left: 7px; }
.rules-table { margin: 1em 0; }
.rules-table div { display: grid; grid-template-columns: 76px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid #e3d8c5; }
.rules-table dt { font-weight: 600; color: #705738; }
.rules-table dd { margin: 0; }
.fine-note, .result-note, .history-count { color: var(--muted); font-size: 14px; }
.history-count { margin: -3px 0 15px; }
.history-list { padding: 0; margin: 0; list-style: none; max-height: 44dvh; overflow: auto; }
.history-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid #dfd3c4; padding: 11px 5px; }
.history-list b, .history-list small { display: block; }
.history-list small { margin-top: 4px; color: var(--muted); font-size: 12px; }
.history-rarity { font-size: 14px; }
.history-rarity.rarity-5, .history-rarity.legacy-rarity-6 { color: #886021; }
.history-rarity.rarity-4, .history-rarity.legacy-rarity-5 { color: #79608e; }
.history-rarity.rarity-3, .history-rarity.legacy-rarity-4 { color: #635e68; }
.pool-overview, .result-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 9px; padding: 0; margin: 0; list-style: none; }
.pool-overview button { position: relative; overflow: hidden; border: 1px solid var(--line); padding: 0; border-radius: 6px; background: #fff9eb; }
.pool-overview img { width: 100%; display: block; aspect-ratio: 2/3; object-fit: cover; }
.pool-overview strong { display: block; padding: 7px 2px; font-size: 15px; }
.result-grid.is-single { display: block; max-width: min(210px, 29vh); margin: 0 auto; }
.reveal-card {
  position: relative; overflow: hidden; aspect-ratio: 2/2.8; color: #fffdf4; border: 2px solid #ad9eaa;
  border-radius: 5px; background: #d6c7d7; box-shadow: 0 3px 10px #33243c22;
  animation: reveal 380ms both; animation-delay: calc(var(--index)*35ms);
}
.reveal-card.rarity-5 { border-color: #c6a05b; }
.reveal-card.rarity-4 { border-color: #a187b3; }
.reveal-card img { width: 100%; height: 100%; object-fit: cover; }
.card-caption { position: absolute; inset: auto 0 0; padding: 17% 9% 8%; background: linear-gradient(transparent,#342536d9); text-shadow: 0 1px 2px #342532; }
.card-caption span, .card-caption strong { display: block; }
.card-grade { font-size: clamp(10px, 1.2vw, 13px); }
.card-caption strong { font: 600 clamp(14px, 2vw, 23px)/1.3 var(--serif); }
.rarity-5 .card-grade { color: #ffe6a8; }
.result-note { text-align: center; margin: 15px 0 0; }
@keyframes show-panel { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes reveal { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

#stage.portrait .scene, #stage.portrait .orbit-ring { inset: 65px 0 auto; width: 100%; height: calc(100% - 200px); object-fit: cover; object-position: 69% 50%; background-size: cover; background-position: 69% 50%; }
#stage.portrait .rail-paper, #stage.portrait .rail-star, #stage.portrait .vertical-ornament { display: none; }
#stage.portrait .bottom-wash { height: 50%; background: linear-gradient(0deg,#e8dfea 2%,#f0e7ec 35%,#f5ececd9 53%,transparent 95%); }
#stage.portrait .back-button { top: 7px; left: 8px; width: 45px; height: 42px; }
#stage.portrait .back-button img { width: 44px; height: 43px; }
#stage.portrait .summon-controls .summon-crystals { left: 92px; top: 9px; width: 118px; height: 34px; }
#stage.portrait .summon-controls .summon-tickets { left: 223px; top: 9px; width: 124px; height: 34px; }
#stage.portrait .summon-controls .summon-balance { top: 2px; left: 25px; width: 64px; height: 29px; font-size: 17px; }
#stage.portrait .summon-controls .summon-tickets .summon-balance { left: 30px; }
#stage.portrait .summon-controls .summon-history, #stage.portrait .summon-controls .summon-rules { top: 51px; width: 104px; height: 33px; font-size: 16px; }
#stage.portrait .summon-controls .summon-history { left: 187px; }
#stage.portrait .summon-controls .summon-rules { left: 300px; }
#stage.portrait .summon-controls .summon-history span, #stage.portrait .summon-controls .summon-rules span { left: 32px; top: 2px; width: 67px; height: 28px; }
#stage.portrait .summon-heading { left: 8px; top: 60px; transform: scale(.48); transform-origin: top left; }
#stage.portrait .summon-feature { left: 18px; top: auto; bottom: 233px; transform: scale(.76); transform-origin: bottom left; }
#stage.portrait .summon-controls .summon-single, #stage.portrait .summon-controls .summon-ten { top: auto; bottom: 39px; width: 199px; height: 81px; }
#stage.portrait .summon-controls .summon-single { left: 7px; }
#stage.portrait .summon-controls .summon-ten { left: 214px; }
#stage.portrait .summon-pity { left: 13px; top: auto; bottom: 5px; transform: scale(.74); transform-origin: left bottom; }
@media(max-width:600px) {
  #panel-content { padding: 17px 12px; }
  #panel[data-kind="results"] .result-grid:not(.is-single) { grid-template-columns: repeat(5,minmax(0,1fr)); gap: 4px; }
  .reveal-card { border-width: 1px; aspect-ratio: 2 / 3.5; }
  .card-caption { padding: 24px 3px 6px; }
  .card-caption strong { font-size: 13px; }
  .is-single .card-caption { padding: 25px 10px 12px; }
  .is-single .card-caption strong { font-size: 23px; }
  .pool-overview { gap: 5px; grid-template-columns: repeat(3,minmax(0,1fr)); }
}
@media(max-height:525px) and (orientation:landscape) {
  #panel-content { padding: 12px 18px; }
  .panel-heading { margin-bottom: 10px; }
  .panel-heading h2 { font-size: 23px; }
  .result-grid:not(.is-single) { width: min(100%, 80vh); margin: auto; }
  .result-grid.is-single { max-width: 23vh; }
  .result-note, .panel-actions { margin-top: 7px; }
  .reveal-card .card-grade { font-size: 9px; }
  .reveal-card .card-caption strong { font-size: 13px; }
}
@media(prefers-reduced-motion:reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition-duration: 0s !important; }
}
#stage.portrait .summon-rail {
  left: 11px; right: 11px; top: auto; bottom: 128px; width: auto; height: 101px;
  display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); grid-auto-rows: 48px; gap: 5px;
}
#stage.portrait .summon-rail__tab, #stage.portrait .summon-rail__tab[aria-pressed="true"] {
  position: relative; inset: auto; height: 48px; width: 100%; border-radius: 6px;
}
#stage.portrait .summon-rail__silver { inset: 0; clip-path: inset(0 round 6px); }
#stage.portrait .summon-rail__portrait { inset: 1px; width: auto; border-radius: 6px; }
#stage.portrait .summon-rail__rim {
  inset: 0; width: 100%; height: 100%; border: 1px solid #bd9957; border-radius: 6px;
  box-shadow: inset 0 0 0 2px #ffeeccbc, 0 0 7px #ebd198; background: none;
}

#stage.portrait .summon-heading::before {
  content: ""; position: absolute; z-index: -1; inset: -10px -22px -17px -18px; pointer-events: none;
  background: radial-gradient(ellipse at 24% 58%, #faf6eef5 15%, #fbf7efd9 49%, #fbf7ef78 66%, transparent 81%);
}
#stage.portrait .summon-heading__subtitle { font-size: 22px; line-height: 24px; }
#stage.portrait .scene, #stage.portrait .orbit-ring {
  mask-image: linear-gradient(to bottom, transparent 0%, #000 8%, #000 88%, transparent 100%);
}


.gallery-dock {
  position: absolute; left: 231px; top: 583px; z-index: 2;
  display: flex; align-items: center; gap: 1px; max-width: 362px;
  border: 1px solid #c7b99a9c; border-radius: 22px;
  background: #fffaf1cf; box-shadow: inset 0 0 0 2px #fffdf78c, 0 1px 5px #75566519;
  backdrop-filter: blur(4px); color: #5e4a3d;
}
.gallery-caption { display: flex; gap: 9px; align-items: baseline; min-width: 0; }
.gallery-count { flex: none; font: 12px/1 Georgia, serif; color: #846d4c; font-variant-numeric: tabular-nums; }
.gallery-title { font: 600 14px/1.3 var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery-arrow, .gallery-toggle {
  flex: none; appearance: none; border: 0; background: transparent; line-height: 1;
}
.gallery-arrow { width: 31px; height: 31px; padding: 2px; border-radius: 50%; display: grid; place-content: center; }
.gallery-arrow img { width: 24px; height: 24px; }
.gallery-arrow.next img { transform: scaleX(-1); }
.gallery-toggle { padding: 4px 12px 4px 9px; border-left: 1px solid #d9cdb3; font: 13px/1 var(--serif); }
.gallery-dock button:hover { color: #8b5b22; background-color: #f2e4c950; }
#stage.portrait .gallery-dock { left: auto; right: 15px; top: auto; bottom: 314px; max-width: 322px; }
#stage.portrait .gallery-arrow { width: 35px; height: 35px; }
#stage.portrait .gallery-toggle { align-self: stretch; margin: 0; padding-inline: 10px; }


/* A three-pose sheet needs its full width on tall screens. */
#stage.portrait .scene.group-scene {
  inset: 45% auto auto -45%; width: 145%; height: auto; aspect-ratio: 1376 / 768;
  object-fit: contain; transform: translateY(-50%);
  mask-image: linear-gradient(to bottom, transparent, #000 14%, #000 86%, transparent);
}
