:root {
  --ink: #fff4e5;
  --muted: #c8b7c9;
  --coal: #060407;
  --black: #010102;
  --wine: #461020;
  --wine-bright: #8d1f45;
  --violet: #8b3cff;
  --purple: #321348;
  --gold: #d7aa4a;
  --ember: #ff85ea;
  --paper: #190b12;
  --shadow: rgba(0, 0, 0, 0.62);
  color: var(--ink);
  font: 16px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: var(--coal);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100svh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(4, 0, 0, 0.14), rgba(4, 0, 0, 0.36)),
    radial-gradient(circle at 58% 18%, rgba(255, 32, 22, 0.12), transparent 23%),
    linear-gradient(135deg, rgba(6, 0, 0, 0.18), rgba(40, 2, 4, 0.38)),
    url("./assets/blood-moon-forest.png"),
    url("./assets/blood-moon-forest.svg"),
    #060407;
  background-attachment: fixed;
  background-position: center;
  background-size: cover;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid rgba(215, 170, 74, 0.42);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(9, 4, 9, 0.28);
  cursor: pointer;
  backdrop-filter: blur(6px);
}

button:hover,
button:focus-visible {
  border-color: rgba(255, 218, 147, 0.9);
  background: rgba(70, 16, 32, 0.46);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid #ffb6f2;
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.app-shell {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 410px);
  gap: 18px;
  padding: clamp(14px, 3vw, 28px);
}

.ritual-panel,
.grimoire-panel {
  min-width: 0;
}

.ritual-panel {
  display: grid;
  grid-template-rows: auto auto auto auto auto;
  gap: 14px;
  padding: clamp(14px, 2vw, 20px);
  border: 1px solid rgba(215, 170, 74, 0.26);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(22, 2, 3, 0.24), rgba(2, 0, 0, 0.34)),
    rgba(6, 4, 7, 0.18);
  backdrop-filter: blur(3px);
  box-shadow: 0 26px 80px var(--shadow);
  overflow: hidden;
}

.hero-bar,
.section-heading,
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #e7c675;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 820px;
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(32px, 4.2vw, 58px);
  line-height: 0.98;
}

h2 {
  margin-bottom: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  line-height: 1.05;
}

.spell-count {
  width: 108px;
  min-height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(215, 170, 74, 0.48);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(70, 16, 32, 0.28), rgba(6, 4, 7, 0.34)),
    rgba(9, 4, 9, 0.2);
  backdrop-filter: blur(6px);
}

.spell-count span {
  display: block;
  color: #ffd98e;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.spell-count small {
  color: #d6c9d8;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.spell-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.spell-tab {
  min-width: 0;
  padding: 0 8px;
  white-space: nowrap;
}

.spell-tab.is-active {
  color: #140710;
  background: linear-gradient(180deg, rgba(255, 224, 164, 0.76), rgba(199, 131, 53, 0.66));
  border-color: #fff0bd;
  font-weight: 900;
}

.spell-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px 12px;
  padding: 12px;
  border: 1px solid rgba(215, 170, 74, 0.26);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(70, 16, 32, 0.18), rgba(8, 3, 9, 0.28)),
    rgba(10, 5, 10, 0.16);
  backdrop-filter: blur(5px);
}

.field,
.element-field {
  display: grid;
  gap: 6px;
}

.field-wide,
.element-field,
.focus-check,
.terms-note {
  grid-column: 1 / -1;
}

.field label,
.element-field legend,
.focus-check {
  color: #ffe0a4;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.1;
}

.field input,
.field select,
.field textarea,
.journal-box textarea {
  width: 100%;
  border: 1px solid rgba(215, 170, 74, 0.34);
  border-radius: 6px;
  color: var(--ink);
  background: rgba(2, 1, 2, 0.24);
  backdrop-filter: blur(6px);
}

.field input,
.field select {
  min-height: 42px;
  padding: 0 12px;
}

.field textarea,
.journal-box textarea {
  resize: vertical;
  padding: 10px 12px;
}

.field textarea::placeholder,
.journal-box textarea::placeholder,
.field input::placeholder {
  color: rgba(200, 183, 201, 0.72);
}

.element-field {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 10px;
  border: 1px solid rgba(215, 170, 74, 0.24);
  border-radius: 6px;
}

.element-field legend {
  padding: 0 6px;
}

.element-field label {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid rgba(215, 170, 74, 0.28);
  border-radius: 999px;
  background: rgba(1, 1, 2, 0.18);
  backdrop-filter: blur(6px);
  color: var(--muted);
  font-weight: 800;
}

.element-field input {
  accent-color: var(--ember);
}

.focus-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid rgba(215, 170, 74, 0.22);
  border-radius: 6px;
  background: rgba(2, 1, 2, 0.18);
  backdrop-filter: blur(6px);
  cursor: pointer;
}

.focus-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--ember);
}

.terms-note {
  color: rgba(200, 183, 201, 0.7);
  font-size: 12px;
}

.terms-note summary {
  width: max-content;
  color: rgba(255, 224, 164, 0.78);
  cursor: pointer;
}

.terms-note p {
  max-width: 720px;
  margin: 6px 0 0;
}

.ritual-top {
  display: grid;
  grid-template-columns: minmax(210px, 0.8fr) auto minmax(210px, 0.8fr);
  align-items: center;
  gap: 16px;
}

.recital-prayer {
  grid-column: 1;
  width: 100%;
  max-width: 320px;
  justify-self: end;
  padding: 14px;
  border: 1px solid rgba(215, 170, 74, 0.36);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(58, 5, 9, 0.24), rgba(7, 0, 3, 0.42)),
    rgba(9, 0, 5, 0.28);
  backdrop-filter: blur(6px);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.38);
}

.recital-prayer[hidden] {
  display: none;
}

.recital-prayer p:last-child {
  margin: 0;
  color: #fff2dd;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.35;
}

.ritual-table {
  position: relative;
  grid-column: 2;
  min-height: 0;
  aspect-ratio: 1 / 1;
  max-height: 320px;
  width: min(52vw, 320px);
  justify-self: center;
  display: grid;
  place-items: center;
  border: 1px solid rgba(215, 170, 74, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(6, 0, 0, 0.04), rgba(1, 0, 0, 0.14)),
    url("./assets/witch-caster.png");
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  overflow: hidden;
}

.sigil-art {
  display: none;
}

.orb-button {
  position: absolute;
  left: 50%;
  top: 63%;
  z-index: 3;
  width: clamp(72px, 27%, 98px);
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  transform: translate(-50%, -50%) scale(1);
}

.orb-button::before {
  content: "";
  position: absolute;
  inset: -10%;
  border-radius: inherit;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 236, 204, 0.72) 0 5%, rgba(255, 32, 20, 0.3) 6% 17%, transparent 18% 58%),
    radial-gradient(circle, transparent 0 46%, rgba(255, 28, 14, 0.48) 47% 55%, transparent 64%);
  box-shadow:
    0 0 10px rgba(255, 38, 18, 0.94),
    0 0 24px rgba(255, 38, 18, 0.68),
    inset 0 0 18px rgba(255, 26, 14, 0.62);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.92);
  transition: opacity 160ms ease, transform 160ms ease, box-shadow 160ms ease;
  mix-blend-mode: screen;
}

.orb-button img {
  display: none;
}

.orb-button:hover::before,
.orb-button:focus-visible::before {
  opacity: 0.98;
  transform: scale(1);
  animation: orb-hover-glow 1.05s ease-in-out infinite alternate;
}

.orb-button:focus-visible {
  outline: 1px solid rgba(255, 204, 139, 0.78);
  outline-offset: 8px;
}

.orb-button.is-casting {
  animation: pulse-orb 760ms ease-in-out 3;
}

.orb-button.is-casting::before {
  animation: orb-cast-glow 760ms ease-in-out 3;
}

@keyframes pulse-orb {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    transform: translate(-50%, -50%) scale(1.08);
  }
}

@keyframes orb-hover-glow {
  from {
    box-shadow:
      0 0 10px rgba(255, 38, 18, 0.94),
      0 0 24px rgba(255, 38, 18, 0.68),
      inset 0 0 18px rgba(255, 26, 14, 0.62);
  }
  to {
    box-shadow:
      0 0 14px rgba(255, 76, 45, 1),
      0 0 34px rgba(255, 28, 14, 0.86),
      inset 0 0 22px rgba(255, 48, 22, 0.76);
  }
}

@keyframes orb-cast-glow {
  0%,
  100% {
    opacity: 0;
    transform: scale(0.92);
  }
  50% {
    opacity: 1;
    transform: scale(1.04);
  }
}

.candle {
  display: none;
}

.candle-left {
  left: clamp(18px, 8vw, 96px);
}

.candle-right {
  right: clamp(18px, 8vw, 96px);
}

.candle span {
  position: absolute;
  left: 50%;
  top: -40px;
  width: 18px;
  height: 46px;
  border-radius: 50% 50% 48% 48%;
  background:
    radial-gradient(circle at 50% 72%, #fff7c8 0 18%, transparent 19%),
    linear-gradient(180deg, #ffb0ff, #8b3cff 55%, transparent);
  transform: translateX(-50%);
  filter: drop-shadow(0 0 18px rgba(255, 92, 239, 0.78));
  animation: flame 1.45s infinite ease-in-out alternate;
}

@keyframes flame {
  from {
    transform: translateX(-50%) scaleX(0.92) translateY(1px);
  }
  to {
    transform: translateX(-50%) scaleX(1.08) translateY(-2px);
  }
}

.spark-field {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.spark {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #ffb6f2;
  box-shadow: 0 0 16px #ffb6f2;
  animation: rise-spark 1.3s ease-out forwards;
}

@keyframes rise-spark {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.7);
  }
  20% {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translateY(-120px) scale(0.2);
  }
}

.controls {
  justify-content: flex-start;
}

.controls button {
  min-width: 130px;
  padding: 0 18px;
  font-weight: 900;
}

.primary-action {
  color: #140710;
  background: linear-gradient(180deg, #ffe0a4, #c78335);
  border-color: #fff0bd;
}

.primary-action:hover,
.primary-action:focus-visible {
  background: linear-gradient(180deg, #fff2c2, #d99b48);
}

.grimoire-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.reader-note,
.payment-box,
.spell-card,
.journal-box {
  padding: 16px;
  border: 1px solid rgba(215, 170, 74, 0.26);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(24, 2, 4, 0.24), rgba(3, 0, 0, 0.34)),
    rgba(5, 3, 5, 0.18);
  backdrop-filter: blur(5px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
}

.section-heading h2 {
  margin-bottom: 0;
}

.section-heading span,
.section-heading button {
  flex: 0 0 auto;
}

.section-heading span {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(215, 170, 74, 0.34);
  border-radius: 999px;
  padding: 0 10px;
  color: #ffe0a4;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.payment-box p,
.reader-note p,
.spell-details,
.save-status {
  color: var(--muted);
}

.spell-details {
  display: grid;
  gap: 10px;
}

.spell-details h3 {
  margin: 0;
  color: #fff4e5;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 26px;
  line-height: 1.05;
}

.spell-details dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.spell-details dt {
  color: #e7c675;
  font-weight: 900;
  text-transform: uppercase;
  font-size: 12px;
}

.spell-details dd {
  margin: 0 0 2px;
}

.spell-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.spell-chip {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid rgba(215, 170, 74, 0.3);
  border-radius: 999px;
  color: #ffe0a4;
  background: rgba(70, 16, 32, 0.28);
  backdrop-filter: blur(6px);
  font-size: 12px;
  font-weight: 900;
}

.empty-state {
  margin: 0;
}

.journal-box textarea {
  min-height: 126px;
}

.save-status {
  min-height: 20px;
  margin: 8px 0 0;
  font-size: 13px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .ritual-top {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .recital-prayer,
  .ritual-table {
    grid-column: auto;
  }

  .recital-prayer {
    max-width: 520px;
    justify-self: center;
  }

  .spell-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .hero-bar,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .spell-count {
    width: 100%;
  }

  .spell-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .ritual-table {
    width: min(78vw, 300px);
    max-height: 300px;
  }

  .candle {
    width: 42px;
    height: 102px;
  }
}
