:root {
  color-scheme: dark;
  --ink: #17182b;
  --paper: #fff3df;
  --gold: #efc780;
  --line: #cbad7560;
  --serif: Georgia, "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-family: "Hiragino Sans", system-ui, sans-serif;
  color: var(--paper);
  background: #141528;
}
* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
body {
  margin: 0;
}
button,
input,
select {
  font: inherit;
}
button,
a,
input,
select {
  touch-action: manipulation;
}
button,
.button {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #25273b;
  color: var(--paper);
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
button:hover,
.button:hover {
  border-color: var(--gold);
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
button:focus-visible,
a:focus-visible {
  outline: 3px solid #87e0f4;
  outline-offset: 2px;
}
.home {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  position: relative;
  isolation: isolate;
  background: linear-gradient(165deg,#19182f,#3f3a55 54%,#19182a 84%);

}
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(16px, env(safe-area-inset-top))
    max(6vw, env(safe-area-inset-right)) 0;
  gap: 12px;
}
.bar button {
  background: #141629ab;
  backdrop-filter: blur(10px);
  border-color: #f3d19a66;
  font-size: 0.82rem;
}
.emblem {
  color: var(--gold);
  letter-spacing: 0.2em;
  font-family: var(--serif);
}
.hero {
  margin: auto auto 0;
  width: min(1120px, 100%);
  padding: clamp(165px, 36svh, 430px) 6vw 1rem;
}
.hero h1 {
  margin: 0;
  line-height: 1.15;
  font-size: clamp(50px, 8.5vw, 100px);
  font-family: var(--serif);
  letter-spacing: 0.08em;
  text-shadow: 0 3px 16px #151323;
}
.hero p {
  line-height: 1.8;
  max-width: 38ch;
  margin: 10px 0 22px;
  text-shadow: 0 1px 6px #000;
}
.homeactions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.homeactions input {
  max-width: 240px;
  flex: 1;
  min-width: 140px;
}
.primary {
  color: #211c30;
  font-weight: 750;
  background: linear-gradient(115deg, #ffe5ab, #deaa64);
  border-color: #fff0c1;
  box-shadow: 0 2px 0 #886642;
  padding: 12px 23px;
}
.primary::after {
  content: "›";
  font-size: 1.25em;
}
.foot {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 0 6vw max(20px, env(safe-area-inset-bottom));
}
.foot button,
.foot a {
  background: #202033cc;
  font-size: 0.86rem;
}
.x-share {
  background: #111 !important;
  color: white !important;
}
input,
select {
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 11px;
  color: var(--paper);
  background: #121625;
}
.page {
  min-height: 100svh;
  background: radial-gradient(ellipse at 74% 0%, #494159, #252239 46%, #151526);
  padding: max(16px, env(safe-area-inset-top))
    max(4vw, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom));
}
.frame {
  max-width: 820px;
  margin: auto;
}
.pagehead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
}
.pagehead h2,
.panel h2 {
  font: 700 clamp(25px, 5vw, 40px) / 1.15 var(--serif);
  margin: 0;
}
.pagehead button {
  background: transparent;
}
.paper {
  color: #332a32;
  background: radial-gradient(
    ellipse at 85% 0,
    #fff7dc 5%,
    #f2ddba 80%,
    #e1c29c
  );
  padding: clamp(18px, 4vw, 36px);
  border: 3px double #a08a66;
  border-radius: 7px;
  box-shadow: 0 12px 50px #0004;
}
.paper button {
  background: #fff6dc;
  color: #423347;
  border-color: #b59c78;
}
.paper .primary {
  background: #373853;
  color: white;
}
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  border-block: 1px solid currentColor;
  padding: 10px 0;
  margin: 12px 0;
}
.stats small,
.stats b {
  display: block;
}
.stats small {
  font-size: 0.73rem;
  opacity: 0.8;
}
.stats b {
  font: 700 clamp(15px, 4vw, 24px) var(--serif);
}
.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
  gap: 6px;
}
.shelf button:disabled {
  flex-wrap: wrap;
  opacity: 0.8;
}
.shelf button {
  display: flex;
  justify-content: space-between;
  text-align: left;
  font-size: 0.86rem;
}
.shelf button.selected {
  background: #d6c5a8;
}
.shelf small {
  opacity: 0.8;
}
.lines {
  padding: 0;
  list-style: none;
}
.lines li {
  display: flex;
  align-items: center;
  gap: 3px;
  border-bottom: 1px solid #aa947744;
}
.lines .verse-text {
  flex: 1;
  font-family: var(--serif);
  font-weight: bold;
}
.lines button {
  padding: 4px;
  min-width: 44px;
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.panel {
  max-width: 620px;
  margin: auto;
  padding: 24px;
  background: #202238f2;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.panel p,
.paper p {
  line-height: 1.65;
}
.panel label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
}
.panel input[type="checkbox"] {
  width: 21px;
  height: 21px;
  accent-color: #dab67f;
}
.bookline {
  font: 700 clamp(18px, 4vw, 28px) / 1.5 var(--serif);
  margin: 0;
}
.seal .bookline {
  animation: seal-verse .65s both;
}
.badge {
  color: var(--gold);
}
.preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
}
/* The mage and the footprint share a 12 px per metre scale. */
.scale {
  width: 148px; min-height: 112px; flex: none; position: relative;
  display: grid; grid-template-columns: 26px 1fr; align-items: center; justify-items: center;
  border: 1px solid #af976d; border-radius: 6px;
  background: repeating-linear-gradient(90deg,transparent 0 11px,#b49e7844 11px 12px);
}
.scale-person {
  width: 12px; height: 20px; background: #ffe6bc;
  clip-path: polygon(48% 0,68% 3%,72% 18%,100% 27%,79% 34%,94% 65%,76% 68%,82% 100%,58% 100%,52% 71%,39% 100%,15% 100%,24% 68%,8% 66%,23% 35%,0 31%,32% 21%);
}
.impact-disc {
  width: var(--d); height: var(--d); border: 2px solid #a3e8f5;
  background: radial-gradient(circle,#8fdfff80,#74a8dc28); border-radius: 50%;
}
.preview { flex-wrap: wrap; }
.preview small { display: block; margin-top: .25em; }
.note {
  font-size: 0.85rem;
  opacity: 0.83;
}
.rules {
  font: 400 1.08rem/1.7 var(--serif);
}
table {
  width: 100%;
  border-collapse: collapse;
}
td {
  padding: 7px;
  border-bottom: 1px solid var(--line);
}
.langs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
#arena {
  height: 100svh;
  position: fixed;
  inset: 0;
  background: linear-gradient(#37365c, #ae8191 48%, #e8ac8e 67%, #596482);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}
#world {
  display: block;
  width: 100%;
  height: 100%;
}
.hud {
  position: absolute;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  top: max(10px, env(safe-area-inset-top));
  pointer-events: none;
}
.hudtop {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #16182be8;
  border: 1px solid var(--line);
  padding-left: 12px;
  border-radius: 5px;
  font-size: 0.85rem;
}
.hudtop b {
  color: #ffda92;
  letter-spacing: 0.07em;
}
.hudtop button {
  margin-left: auto;
  pointer-events: auto;
}
.healthline,
#clock > div {
  height: 4px;
  background: #29283b;
  overflow: hidden;
}
.healthline i,
#progress {
  height: 100%;
  display: block;
  background: #8bd8c7;
}
#boss {
  color: #fff0c9;
  text-shadow: 0 1px 3px #151528;
  padding: 0.4rem;
  text-align: center;
  font-weight: 700;
}
#boss-layer {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
}
.boss-hp {
  position: absolute; width: 70px; box-sizing: border-box; transform: translate(-50%, -100%);
  text-align: center; color: #fff3d9; background: #2b2036;
  border: 1px solid #dbb384; border-radius: 4px; overflow: hidden;
  font: bold 12px/15px system-ui, sans-serif; font-variant-numeric: tabular-nums;
}
.boss-hp i { display: block; height: 3px; background: #ffa877; }
#pad {
  position: absolute;
  inset: 30% 0 0;
  touch-action: none;
}
#stick {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 86px;
  height: 86px;
  border: 2px solid #fff9;
  border-radius: 50%;
  background: #20233d66;
  display: grid;
  place-items: center;
  pointer-events: none;
}
#stick i {
  width: 38px;
  height: 38px;
  border: 2px solid #eee;
  border-radius: 50%;
  background: #a2aac999;
}
#clock {
  min-width: 85px;
  background: #191b31ed;
  border: 1px solid #d7bd82;
  border-radius: 6px 6px 12px 6px;
  padding: 3px 9px 6px;
  box-shadow: 0 2px 8px #17172966;
  text-align: center;
}
.hud {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  z-index: 3;
}
.vitals { flex: 1; min-width: 0; }
.hudtop { gap: 6px; justify-content: space-between; padding-left: 7px; font-size: clamp(10px, 3.1vw, 14px); }
.hudtop button { margin-left: 0; flex: none; }
#boss:empty { display: none; }
#clock strong {
  font: 700 clamp(28px, 7vw, 42px)/1.1 Georgia, serif;
  font-variant-numeric: tabular-nums;
  color: #ffde9c;
  white-space: nowrap;
}
#progress { background: #9fe5ff; }
#speech-layer, #hit-layer {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden;
}
#hit-layer { z-index: 2; }
#speech-layer { z-index: 1; }
.spell-speech {
  position: absolute; top: 0; left: 0;
  width: max-content; max-width: min(48%, 9.7em); min-width: 42px;
  padding: 5px 13px 6px;
  border: 1px solid #80603d; border-radius: 10px 14px 11px 5px;
  color: #32263e; background: linear-gradient(125deg, #fffbee, #f7e4c6);
  box-shadow: inset 0 0 0 2px #fff4d8, inset 0 0 0 3px #ccab75, 0 2px 5px #1b193c80;
  font: 700 clamp(15px, 3.8vw, 19px)/1.55 "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  letter-spacing: .035em; overflow-wrap: break-word;
}
.spell-speech::after {
  content: ""; position: absolute; bottom: -6px; left: var(--tail, 15px);
  width: 9px; height: 9px;
  background: #f8e8cc; border-bottom: 1px solid #80603d; border-right: 1px solid #80603d;
  transform: translateX(-50%) rotate(45deg);
}
.damage {
  position: absolute; transform: translate(-50%, -100%);
  font: bold clamp(23px, 5.6vw, 30px)/1 Georgia, serif;
  font-variant-numeric: tabular-nums;
  color: #ffe69d; -webkit-text-stroke: 3px #39253c;
  paint-order: stroke fill; text-shadow: 0 2px 4px #181225;
}
.damage.taken { color: #ff9e99; -webkit-text-stroke-color: #451628; }
@media (max-height: 470px) {
  #clock strong { font-size: 29px; }
  .spell-speech { font-size: 14px; padding: 4px 12px; }
}
#overlay:not([open]) { display: none; }
#overlay::backdrop { background: transparent; }
#overlay {
  width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; border: 0; color: inherit;
  z-index: 4;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #14152996;
  padding: 12px;
  overflow: auto;
}
#overlay .panel {
  width: min(460px, 100%);
}
#overlay h2 {
  color: var(--gold);
}
@keyframes appear {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}
@media (max-width: 600px) {
  .home {
    background-position:
      center,
      67% top;
    background-size:
      cover,
      auto 77svh;
  }
  .hero {
    padding-top: 40svh;
  }
  .hero p {
    font-size: 0.9rem;
  }
  .homeactions input,
  .homeactions .primary {
    max-width: none;
    width: 100%;
    flex: auto;
  }
  .foot {
    gap: 5px;
  }
  .foot button,
  .foot a {
    padding: 7px 10px;
  }
  .shelf {
    grid-template-columns: 1fr 1fr;
  }
  .panel {
    padding: 17px;
  }
  .stats {
    gap: 1px;
  }
  .emblem {
    font-size: 0.76rem;
  }
  .hero h1 {
    font-size: clamp(40px, 10vw, 68px);
  }
}
@media (max-height: 470px) and (orientation: landscape) {
  .hero {
    padding-top: 16px;
  }
  .hero h1 {
    font-size: 40px;
  }
  .hero p {
    margin: 4px 0;
  }
  .home {
    background-position:
      center,
      center 35%;
  }
  .bar {
    padding-top: 5px;
  }
  .foot {
    padding-bottom: 8px;
  }
  #stick {
    width: 64px;
    height: 64px;
  }
  #overlay .panel {
    max-height: 95svh;
    overflow: auto;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
  }
}
#arena { background: linear-gradient(#393755, #85708d 44%, #d5a997 70%, #4a526a); }

@font-face {
  font-family: "Grimoire Mincho";
  src: url("assets/incantation.woff") format("woff");
  font-weight: 700;
  font-display: swap;
}
:root { --rune: "Grimoire Mincho", "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif; }
.home {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  background: radial-gradient(ellipse at 78% 37%, #645873 0%, #35334c 39%, #1b1b2c 75%);
}
.home .bar { grid-column: 1/-1; z-index: 1; }
.home-stage { grid-column: 2; grid-row: 2 / 4; min-height: 310px; position: relative; overflow: hidden; }
.home-stage canvas, .book-stage canvas { display: block; position: absolute; width: 100%; height: 100%; }
.home .hero { grid-column: 1; grid-row: 2; align-self: center; padding: 28px 2vw 22px 6vw; margin: 0; }
.home h1 { font: 700 clamp(40px, 6.7vw, 100px)/1.15 var(--rune); color: #ffe9bb; }
.home .foot { grid-column: 1; grid-row: 3; padding-right: 0; }
.verse-text > [lang="ja"], .spell-speech { font-family: var(--rune); }
.scriptorium {
  padding: max(12px,env(safe-area-inset-top)) max(12px,env(safe-area-inset-right)) max(26px, env(safe-area-inset-bottom)) max(12px,env(safe-area-inset-left));
  background: radial-gradient(ellipse at 60% 10%, #4b445b, #292840 34%, #161827 75%);
}
.scriptorium .frame { max-width: 960px; }
.grimoire-head {
  position: relative; isolation: isolate; height: clamp(135px, 19vw, 182px); overflow: hidden;
  border-bottom: 1px solid #d2b78870; margin-bottom: 13px;
  background: radial-gradient(ellipse at 74% 61%, #ac805733, transparent 60%);
}
.grimoire-head > button { position: relative; z-index: 1; font-size: .79rem; padding: 6px 14px; min-height: 40px; background: #181826ac; }
.grimoire-head h2 {
  position: absolute; bottom: 12px; left: clamp(6px, 2vw, 20px); margin: 0;
  color: #ffeac0; font: 700 clamp(29px, 6.8vw, 52px)/1.22 var(--rune);
  letter-spacing: .065em; text-shadow: 0 2px 8px #1a142a;
}
.book-stage { position: absolute; right: 0; top: 0; bottom: 0; width: 50%; z-index: -1; }
.grimoire {
  display: grid; grid-template-columns: 1.2fr 1fr; align-items: start;
  border: 2px solid #8c7049; border-radius: 8px 13px 12px 8px;
  padding: 5px; background: #38293a;
  box-shadow: 0 3px 0 #8f7457, 0 6px 0 #332b3b, 0 12px 30px #11132380;
}
.leaf { min-width: 0; padding: clamp(13px, 2.6vw, 26px); }
.source-leaf {
  color: #3a2934; border-radius: 3px 2px 2px 5px;
  background: linear-gradient(90deg,#cbb18e 0%,#efdbba 3%,#f6e8c9 48%,#eedbb7 92%,#c8ac87 100%);
}
.leaf-heading {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 42px; gap: 10px; margin-bottom: 11px; border-bottom: 3px double #a68b66;
}
.leaf-heading h3 { margin: 0 0 5px; font: 700 clamp(19px, 4.85vw, 26px)/1.25 var(--rune); letter-spacing: .07em; }
.to-weave, .folio-count { font: 700 15px Georgia,serif; white-space: nowrap; font-variant-numeric: tabular-nums; }
.to-weave { color: #4a3340; min-height: 42px; padding: 4px 8px; background: transparent; border: 0; border-radius: 0; text-decoration: underline; text-underline-offset: 4px; }
.scriptorium .shelf { grid-template-columns: 1fr; gap: 0; }
.scriptorium .shelf button {
  display: grid; grid-template-columns: 25px 1fr auto; align-items: center; gap: 8px;
  min-height: 48px; padding: 7px 6px; color: #3c2a38; border: 0; border-bottom: 1px solid #937c5b60; border-radius: 0;
  background: transparent; font: 700 clamp(16px, 4.5vw, 20px)/1.28 var(--rune);
  transition: background-color .15s;
}
.scriptorium .shelf button:hover:enabled { background: #fff1cd; }
.scriptorium .shelf button.selected { color:#ffeec4; background: #493b51; box-shadow: inset 3px 0 #b59251; }
.scriptorium .shelf button.selected:hover { background: #52425c; }
.choice-seal {
  display: grid; place-content: center; width: 22px; height: 22px;
  border: 1px solid #9f8058; border-radius: 50%; color: #805538; font: 700 17px/1 Georgia,serif;
}
.selected .choice-seal { background: #edd3a1; color: #493449; }
.shelf .letter-count { font: italic bold 15px Georgia,serif; }
.shelf .verse-text { min-width: 0; }
.verse-text small { font: normal 12px/1.45 system-ui,sans-serif; }
.scriptorium .shelf button:disabled { background: #dfceaf; color: #62575c; }
.scriptorium .bound-leaf {
  background: radial-gradient(ellipse at 80% 0%,#504554,#302f45 75%); color: #fff0cb; align-self: stretch;
  border: 1px solid #ae8a57; border-radius: 1px 8px 7px 1px; scroll-margin-top: 10px;
}
.bound-leaf .leaf-heading { border-color:#bc9b69; }
.bound-leaf .lines { margin: .4rem 0 1.1rem; }
.bound-leaf .lines li { padding-block: 4px; }
.bound-leaf .lines .verse-text { font: 700 16px/1.5 var(--rune); }
.bound-leaf .lines button { background:#26253a; color: #f7ddb1; min-width: 38px; min-height: 44px; }
.order-no { color: #e8c187; font: italic 700 17px Georgia,serif; padding-right: 4px; }
.blank-verse { padding: .6rem 0 .9rem; font: 700 16px/1.75 var(--rune); }
.bound-leaf .stats { border-color: #aa9460; }
.bound-leaf .scale { background: repeating-linear-gradient(90deg,transparent 0 11px,#a99d8d44 12px); }
.bound-leaf .primary { width: 100%; margin-top: 8px; }
@media(width < 700px) and (orientation:portrait) {
  .home { display: flex; min-height: 100svh; }
  .home-stage { flex: 1 0 auto; min-height: 0; height: clamp(210px, 42svh, 530px); }
  .home .hero { width: 100%; padding: 2px 6vw 14px; }
  .home h1 { font-size: clamp(42px, 12vw, 69px); }
  .home .hero p { margin: 6px 0 12px; line-height: 1.45; }
  .home .foot { padding-right: 6vw; }
}
@media(width < 700px) {
  .grimoire { grid-template-columns: 1fr; }
  .grimoire-head { height: 123px; }
  .grimoire-head h2 { bottom: 11px; }
  .book-stage { width: clamp(125px, 43%, 230px); }
  .source-leaf { border-radius: 3px 9px 1px 1px; }
  .bound-leaf { margin-top: 4px; }
  .scriptorium .shelf button { min-height: 47px; }
}
@media (max-height: 470px) and (orientation:landscape) {
  .home-stage { min-height: 220px; }
  .home .hero { padding-top: 7px; padding-bottom: 6px; }
  .home h1 { font-size: clamp(32px,6vw,53px); }
  .home .hero p { line-height: 1.38; }
  .grimoire-head { height: 112px; }
  .grimoire-head h2 { font-size: clamp(28px, 4.75vw, 39px); }
}
.source-leaf { position: relative; }
.source-leaf::after {
  content: ""; position: absolute; pointer-events: none; inset: 5px;
  border: 1px solid #c0a3788c; border-radius: 1px 3px 1px 2px;
}
.choice-seal { font-family: Georgia, "Hiragino Mincho ProN", serif; }

#speed {
  display: inline-block; margin-left: 3px; padding: .13em .28em;
  border: 1px solid #92deed; border-radius: 4px; vertical-align: .32em;
  color: #d0f9ff; background: #204451; font: bold 13px/1.1 system-ui, sans-serif;
}
#wave-clear {
  position: absolute; top: 27%; left: 50%; transform: translateX(-50%);
  z-index: 3; pointer-events: none; white-space: nowrap; padding: .55em 1.15em;
  background: #282139e8; color: #ffe2a1; border-block: 1px solid #d9b56c;
  font: 700 clamp(18px,4.7vw,30px) var(--rune); letter-spacing: .08em;
}
.scriptorium .shelf button { position: relative; isolation: isolate; }
.rune-fire { position: absolute; inset: auto 0 0; height: 5px; overflow: hidden; border-radius: inherit; pointer-events: none; }
.rune-fire i {
  --ember: #127bee; --heart: #70eaff;
  position: absolute; inset: 4% auto 2% 0; width: 48%;
  background: linear-gradient(90deg,transparent, var(--ember) 40%, var(--heart) 78%, #fffce3 96%);
  clip-path: polygon(0 74%,27% 52%,9% 43%,44% 45%,30% 17%,63% 34%,52% 0,81% 22%,89% 11%,100% 55%,92% 82%,71% 99%,44% 88%,16% 100%,29% 74%);
  animation: ink-flame .56s cubic-bezier(.35,.04,.44,1) both;
}
.rune-fire i::after {
  content: ""; position: absolute; inset: 35% 8% 9% 24%;
  background: linear-gradient(90deg,transparent,var(--heart),#fffef4);
  clip-path: polygon(0 86%,28% 47%,18% 26%,59% 57%,47% 0,89% 32%,100% 68%,70% 91%,33% 100%);
}
.rune-fire.unwinding i { --ember: #159550; --heart: #9bffc0; animation-name: ink-unflame; }
@keyframes ink-flame {
  from { left: 0; transform: translateX(-100%) scaleY(.76); opacity: .4; }
  45% { opacity: .95; } 65% { transform: translateX(-45%) scaleY(1); }
  to { left: 100%; transform: translateX(0) scaleY(.78); opacity: .3; }
}
@keyframes ink-unflame {
  from { left: 100%; transform: translateX(0) scale(-1,.76); opacity: .4; }
  45% { opacity: .95; } 65% { transform: translateX(-55%) scale(-1,1); }
  to { left: 0; transform: translateX(-100%) scale(-1,.78); opacity: .3; }
}
.reading-guide { overflow: hidden; }
.tutorial[open] {
  position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none;
  padding: 0; margin: 0; overflow: hidden; border: 0; background: transparent; color: #3b2b36;
}
.tutorial::backdrop { background: transparent; }
.guide-ring {
  position: absolute; pointer-events: none; border: 2px solid #ffe4a0; border-radius: 9px;
  box-shadow: 0 0 0 100vmax #121124bc, inset 0 0 7px #edcd8f8c, 0 0 10px #f1cd81;
}
.guide-page {
  position: absolute; left: 50%; transform: translateX(-50%); width: min(91%, 420px);
  max-height: calc(100% - 24px); overflow: auto; padding: 17px 22px 14px;
  border: 1px solid #b99a60; border-radius: 4px 16px 4px 12px;
  background: linear-gradient(115deg,#f1dcb0,#fff2d2 46%,#eddbb6);
  box-shadow: inset 0 0 0 4px #f7e7c8, inset 0 0 0 5px #b59b67, 0 7px 24px #12112177;
}
.guide-page[data-placement="top"] { top: max(12px, env(safe-area-inset-top)); max-height: calc(var(--guide-vertical-space) - max(12px, env(safe-area-inset-top)) - 6px); }
.guide-page[data-placement="bottom"] { bottom: max(12px, env(safe-area-inset-bottom)); max-height: calc(var(--guide-vertical-space) - max(12px, env(safe-area-inset-bottom)) - 6px); }
.guide-page h2 { margin: 0; font: 700 clamp(20px,5vw,27px)/1.35 var(--rune); color: #49324c; }
.guide-page h2::before { content: "✧"; color: #816132; margin-right: .4em; }
.guide-page p { margin: .45em 0 .7em; font: 600 clamp(14px,3.75vw,17px)/1.6 var(--rune); }
.guide-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.guide-actions button { min-height: 44px; font: 700 14px/1.3 var(--rune); }
.skip-guide { background: transparent; color: #554453; border: 0; padding: 5px; text-decoration: underline; }
.read-guide { background: #403046; color: #ffedbc; padding: 8px 21px; border-color: #826740; }
@media (max-height: 480px) and (min-width: 550px) {
  .guide-page { width: min(48%,400px); padding: 11px 16px; }
  .guide-page[data-side="left"], .guide-page[data-side="right"] {
    max-width: calc(var(--guide-side-space) - max(12px, env(safe-area-inset-left), env(safe-area-inset-right)) - 8px);
    max-height: calc(100% - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
  }
  .guide-page[data-side="left"] { left: max(12px, env(safe-area-inset-left)); transform: none; }
  .guide-page[data-side="right"] { left: auto; right: max(12px, env(safe-area-inset-right)); transform: none; }
  .guide-page p { font-size: 14px; }
}

#hit-edge {
  position: absolute; inset: 0; pointer-events: none; z-index: 3;
  border: 4px solid #e9565f; box-shadow: inset 0 0 18px 3px #db3e506e;
  animation: edge-fade .28s ease-out both;
}
@keyframes edge-fade { from { opacity: .92; } to { opacity: 0; } }
#health { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 6px; }
#hp-number { font-size: 1.45em; color: #fff3dc; font-variant-numeric: tabular-nums; }
.healthline { height: 10px; border: 1px solid #4b3c4b; border-radius: 0 0 5px 5px; background: #3a2837; }
#hpfill { background: #efb455; }
.healthline.critical #hpfill { background: #fc666c; animation: low-pulse 2.4s ease-in-out infinite; }
.healthline.hit { animation: hp-hit .24s ease-out; }
@keyframes hp-hit { 25% { transform: translateX(-3px); } 65% { transform: translateX(3px); } }
@keyframes low-pulse { 50% { opacity: .62; } }
#clock.ready { border-color: #a7e7fe; }
#clock.ready strong { font: 700 clamp(14px,3.5vw,20px)/1.55 var(--serif); color: #c4f3ff; white-space: normal; }
.stats { grid-template-columns: repeat(auto-fit,minmax(min(76px,100%),1fr)); }
.tradeoff, #phrase-limit { font-size: .88rem; line-height: 1.5; margin: .45rem 0 .7rem; }
#phrase-limit { color: #673348; font-weight: 700; }
#phrase-limit:empty { display: none; }
.weave-dock {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 14px; background: #242335; border: 1px solid #9d8057; border-radius: 5px;
}
.dock-stats { flex: 1; display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 6px; }
.dock-stats small, .dock-stats b { display: block; }
.dock-stats small { color: #e5cfaa; font-size: .72rem; overflow-wrap: break-word; }
.dock-stats b { font: 700 1.2rem/1.3 Georgia,serif; font-variant-numeric: tabular-nums; }
.weave-dock button { margin: 0; min-height: 44px; }
.stat-changed { animation: stat-flare .55s ease-out; }
@keyframes stat-flare { from { color: #fff1a1; text-shadow: 0 0 8px #f2c26e; } }
@keyframes seal-verse {
  from { opacity: 0; color: #8b693d; text-shadow: 0 0 8px #eebe58; }
  55% { opacity: 1; color: #885b18; text-shadow: 0 0 4px #e6ab40; }
  to { opacity: 1; color: #392d39; }
}
.seal .bookline { border-bottom: 1px solid #b698694f; padding-block: .3em; }
.result-rows { margin: 0; }
.result-rows div { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.result-rows dd { margin: 0; font-variant-numeric: tabular-nums; }
.result-chant p { margin: .3em 0; font-family: var(--rune); }
.result-tip { border-left: 2px solid var(--gold); padding-left: .85em; }
.rules ul, .rules ol { padding-inline-start: 1.3em; }
.rules li + li { margin-top: .5em; }
@media (width < 700px) and (orientation: portrait) {
  .scriptorium { height: 100svh; min-height: 0; padding-block: max(5px,env(safe-area-inset-top)) max(5px,env(safe-area-inset-bottom)); }
  .scriptorium .frame { height: 100%; display: flex; flex-direction: column; }
  .edit-scroll { flex: 1; min-height: 0; overflow: auto; padding-bottom: 6px; }
  .weave-dock { flex: none; }
}
@media (orientation: landscape) and (max-height: 600px) {
  .scriptorium { height: 100svh; min-height: 0; padding-block: max(4px,env(safe-area-inset-top)) max(4px,env(safe-area-inset-bottom)); }
  .scriptorium .frame {
    display: grid; height: 100%; grid-template-columns: minmax(0,1.05fr) minmax(0,1fr);
    grid-template-rows: auto minmax(0,1fr) auto; gap: 4px;
  }
  .edit-scroll, .grimoire { display: contents; }
  .grimoire-head { display: flex; align-items: center; gap: 10px; grid-column: 1/-1; height: 47px; margin: 0; }
  .grimoire-head h2 { position: static; font-size: clamp(18px,3vw,26px); max-width: 65%; }
  .grimoire-head .book-stage { width: 15%; }
  .scriptorium .leaf { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 7px 12px; margin: 0; }
  .source-leaf { grid-column: 1; grid-row: 2 / 4; }
  .bound-leaf { grid-column: 2; grid-row: 2; }
  .weave-dock { grid-column: 2; grid-row: 3; padding: 5px 10px; }
  .to-weave { display: none; }
  .leaf-heading { min-height: 30px; margin-bottom: 4px; }
}
.soft-effects #hit-edge { animation: none; border: 2px solid #c57b80; box-shadow: none; }
.soft-effects .healthline, .soft-effects .healthline.critical #hpfill, .soft-effects .stat-changed, .soft-effects .seal .bookline { animation: none; }
@media (prefers-reduced-motion: reduce) {
  #hit-edge { border: 2px solid #c57b80; box-shadow: none; }
}

/* Keep units, controls and chant fragments together, while allowing whole
   buttons and phrases to move to the next line on smaller screens. */
.verse-part, .stats b, .dock-stats b, .result-rows dd,
#health > span, #wave, .pagehead button { white-space: nowrap; }
.verse-part { display: inline-block; }
.verse-text small { overflow-wrap: anywhere; }
.pagehead { gap: 12px; }
.pagehead h2, .hero h1 { min-width: 0; overflow-wrap: break-word; text-wrap: balance; }
.pagehead button { flex: none; }
.hero p, .panel p, .paper p, .guide-page p, .tradeoff, .result-tip { text-wrap: pretty; line-break: strict; }
:lang(ja):is(.hero p,.panel p,.paper p,.guide-page p,.tradeoff,.dock-stats small) {
  word-break: auto-phrase;
}
.hero p:lang(ja) { word-break: keep-all; overflow-wrap: break-word; }
.foot > *, .actions > * { max-width: 100%; width: max-content; text-wrap: balance; }
.hud #clock.ready strong { word-break: normal; text-wrap: balance; }
.result-panel header h2 { font-variant-numeric: tabular-nums; }
#keys button { margin: 0 4px 4px 0; }
#arena[data-pointer="mouse"] #stick { display: none; }
@media (pointer: fine) and (hover: hover) {
  #arena:not([data-pointer="touch"]) #stick { display: none; }
  #arena { cursor: crosshair; }
}
@media (min-width: 700px) and (orientation: portrait) {
  .home { grid-template: auto minmax(300px, 1fr) auto auto / 1fr; }
  .home-stage { grid-column: 1; grid-row: 2; min-height: 300px; }
  .home .hero, .home .foot { grid-column: 1; width: min(100%, 740px); margin-inline: auto; padding-inline: 5vw; }
  .home .hero { grid-row: 3; padding-block: 12px 20px; }
  .home .foot { grid-row: 4; }
}
@media (min-width: 700px) and (min-height: 601px) {
  .home, .page { min-height: 100svh; }
  .scriptorium { height: 100svh; }
  .scriptorium .frame { max-width: 1320px; height: 100%; display: flex; flex-direction: column; gap: 8px; }
  .edit-scroll { flex: 1; min-height: 0; display: flex; flex-direction: column; }
  .grimoire-head { flex: none; height: clamp(84px, 13svh, 150px); margin-bottom: 6px; }
  .grimoire { flex: 1; min-height: 0; align-items: stretch; }
  .scriptorium .leaf { overflow-y: auto; overscroll-behavior: contain; }
  .to-weave { display: none; }
  .weave-dock { flex: none; }
  .page:has(.result-panel) .frame { max-width: 1140px; }
  .result-panel { max-width: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 clamp(18px, 4vw, 60px); }
  .result-panel header, .result-ranking { grid-column: 1 / -1; }
  .hud { max-width: 850px; margin-inline: auto; }
}
@media (max-width: 460px) {
  .home .foot { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); }
  .home .foot > * { width: 100%; }
  .home-stage { height: clamp(145px, 35svh, 380px); }
  .weave-dock { flex-wrap: wrap; }
  .dock-stats { flex: 1 1 180px; }
  .bound-leaf .lines li { display: grid; grid-template-columns: auto repeat(3, minmax(38px, auto)) 1fr; }
  .bound-leaf .lines .verse-text { grid-column: 2 / -1; }
  .bound-leaf .lines button:first-of-type { grid-column: 2; }
}

.result-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(6px, 2vw, 24px);
}
.result-summary { min-width: 0; padding-block: .5rem; overflow-wrap: anywhere; }
.result-summary p, .result-summary h2 { margin: .25em 0; }
.result-wave { margin: 0; letter-spacing: .04em; overflow-wrap: break-word; }
.result-summary h2 { font-size: clamp(34px, 10vw, 82px); line-height: 1.05; }
.result-summary h2 small { font-size: .45em; }
.result-summary .result-honor { color: var(--gold); font: 700 clamp(26px, 7.2vw, 50px)/1.22 var(--rune); }
.result-summary .outcome { margin-top: .65em; }
.result-stage { position: relative; height: clamp(155px, 42vw, 268px); }
.result-stage canvas { display: block; position: absolute; inset: 0; width: 100%; height: 100%; }
