:root {
  color-scheme: light;
  --ink: #241609;
  --muted: #755f3d;
  --paper: #ead6a6;
  --paper-light: #f7e8bd;
  --line: rgba(88, 54, 18, 0.24);
  --gold: #b47a24;
  --green: #316d58;
  --red: #9d2c32;
  --blue: #315e83;
  --violet: #5a438f;
  --shadow: 0 34px 90px rgba(20, 10, 2, 0.46);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 18% 14%, rgba(180, 122, 36, 0.36), transparent 24%),
    radial-gradient(circle at 78% 10%, rgba(90, 67, 143, 0.28), transparent 26%),
    linear-gradient(145deg, #080604 0%, #20130a 45%, #34200f 72%, #0a0704 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, transparent 34%, rgba(0, 0, 0, 0.56) 100%),
    repeating-linear-gradient(90deg, rgba(255, 240, 190, 0.03) 0 1px, transparent 1px 42px);
}

button {
  font: inherit;
}

.grimoire-shell {
  position: relative;
  width: min(1080px, calc(100% - 28px));
  margin: 0 auto;
  padding: 38px 0 56px;
}

.grimoire-page {
  position: relative;
  min-height: calc(100vh - 76px);
  padding: clamp(28px, 5vw, 68px);
  border: 11px solid #1f1207;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background:
    linear-gradient(var(--line) 1px, transparent 1px) 0 184px / 100% 38px,
    radial-gradient(circle at 18% 8%, rgba(255, 244, 190, 0.75), transparent 30%),
    radial-gradient(circle at 90% 92%, rgba(94, 47, 16, 0.17), transparent 34%),
    linear-gradient(90deg, rgba(70, 39, 10, 0.16), transparent 7%, transparent 93%, rgba(70, 39, 10, 0.18)),
    var(--paper);
}

.grimoire-page::before {
  content: "LIBER TEXTUS · MENSURA · FRACTURA · FIGURA · MOTUS";
  position: absolute;
  inset: 22px auto 22px 22px;
  width: 20px;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  display: grid;
  place-items: center;
  color: rgba(96, 51, 14, 0.46);
  font-family: Cinzel, serif;
  font-size: 11px;
  letter-spacing: 0.18em;
}

.grimoire-page::after {
  content: "";
  position: absolute;
  inset: 18px;
  pointer-events: none;
  border: 1px solid rgba(117, 77, 25, 0.36);
  border-radius: 8px;
  box-shadow: inset 0 0 42px rgba(76, 39, 10, 0.18);
}

.book-header,
.spell-column {
  position: relative;
  z-index: 1;
}

.book-header {
  max-width: 820px;
  margin: 0 auto 36px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--red);
  font-family: Cinzel, serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: "Noto Serif SC", serif;
  font-size: clamp(34px, 6vw, 70px);
  line-height: 1.04;
  letter-spacing: 0;
}

.poem-line {
  margin: 22px auto 8px;
  max-width: 820px;
  color: #321d0b;
  font-family: "Noto Serif SC", serif;
  font-size: clamp(22px, 3vw, 34px);
  font-weight: 700;
  line-height: 1.55;
}

.poem-credit {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.spell-column {
  display: grid;
  gap: 18px;
  max-width: 860px;
  margin: 0 auto;
}

.spell-block {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 18px;
  min-height: 260px;
  padding: 20px;
  border: 1px solid rgba(87, 52, 15, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 248, 220, 0.72), rgba(238, 210, 154, 0.56)),
    rgba(255, 244, 204, 0.72);
  box-shadow: 0 14px 36px rgba(75, 41, 11, 0.11);
}

.spell-index {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-family: Cinzel, serif;
  font-weight: 700;
  color: var(--gold);
  background: rgba(255, 249, 222, 0.56);
}

.spell-block[data-tone="green"] .spell-index,
.spell-block[data-tone="green"] .spell-type {
  color: var(--green);
}

.spell-block[data-tone="red"] .spell-index,
.spell-block[data-tone="red"] .spell-type {
  color: var(--red);
}

.spell-block[data-tone="blue"] .spell-index,
.spell-block[data-tone="blue"] .spell-type {
  color: var(--blue);
}

.spell-block[data-tone="violet"] .spell-index,
.spell-block[data-tone="violet"] .spell-type {
  color: var(--violet);
}

.spell-block[data-tone="ink"] .spell-index,
.spell-block[data-tone="ink"] .spell-type {
  color: #362313;
}

.spell-content {
  min-width: 0;
}

.spell-type {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h2 {
  margin: 0;
  font-size: clamp(21px, 3vw, 30px);
  line-height: 1.15;
  letter-spacing: 0;
}

.spell-desc {
  margin: 9px 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.measurement-plate {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 12px;
  align-items: stretch;
}

#measureCanvas,
.wide-canvas,
.glyph-scroll {
  display: block;
  width: 100%;
  height: 156px;
  border: 1px solid rgba(91, 55, 18, 0.25);
  border-radius: 8px;
  background: rgba(255, 252, 239, 0.78);
}

.measure-stats {
  display: grid;
  gap: 10px;
}

.measure-stats span {
  display: grid;
  place-items: center;
  border: 1px solid rgba(91, 55, 18, 0.25);
  border-radius: 8px;
  color: #4b2b0e;
  background: rgba(242, 224, 179, 0.8);
  font-size: 13px;
  font-weight: 760;
}

.line-break-demo {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid rgba(91, 55, 18, 0.25);
  border-radius: 8px;
  background: rgba(255, 252, 239, 0.78);
}

.line-break-demo span {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 8px 10px;
  border-left: 3px solid var(--red);
  background: rgba(157, 44, 50, 0.08);
  font-family: "Noto Serif SC", serif;
  font-size: 16px;
}

.glyph-scroll {
  height: 190px;
}

.sdf-stage {
  display: grid;
  place-items: center;
  height: 156px;
  border: 1px solid rgba(91, 55, 18, 0.25);
  border-radius: 8px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, rgba(110, 91, 194, 0.36), transparent 33%),
    linear-gradient(135deg, #11131a, #262134 55%, #11131a);
}

.sdf-stage span {
  color: #fff5c8;
  font-size: clamp(30px, 5vw, 58px);
  font-weight: 760;
  letter-spacing: 0;
  text-shadow:
    0 0 5px rgba(255, 255, 255, 0.9),
    0 0 18px rgba(111, 176, 255, 0.78),
    0 0 42px rgba(124, 94, 255, 0.68);
  animation: floatText 4s ease-in-out infinite;
}

.spell-button {
  border: 1px solid rgba(72, 41, 12, 0.24);
  border-radius: 999px;
  padding: 9px 14px;
  color: #fff8e0;
  background: #6f2a25;
  cursor: pointer;
  font-weight: 650;
}

.motion-text {
  min-height: 92px;
  margin: 14px 0 0;
  padding: 16px;
  border: 1px solid rgba(91, 55, 18, 0.25);
  border-radius: 8px;
  background: rgba(255, 252, 239, 0.78);
  font-family: "Noto Serif SC", serif;
  font-size: clamp(20px, 3vw, 28px);
  line-height: 1.55;
}

.motion-text span {
  display: inline-block;
  opacity: 0;
  transform: translateY(12px);
  filter: blur(4px);
  animation: inkAppear 720ms ease forwards;
}

@keyframes inkAppear {
  to {
    opacity: 1;
    transform: translateY(0);
    filter: blur(0);
  }
}

@keyframes floatText {
  50% {
    transform: translateY(-8px) scale(1.02);
  }
}

@media (max-width: 720px) {
  .grimoire-page {
    padding: 28px 18px;
  }

  .grimoire-page::before {
    display: none;
  }

  .spell-block {
    grid-template-columns: 1fr;
  }

  .measurement-plate {
    grid-template-columns: 1fr;
  }

  .measure-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}
