/* =============================================================================
   Spellbook, classroom grimoire (kid-friendly fantasy, animated)
   ============================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Yatra+One&family=Quicksand:wght@500;600;700&display=swap');

.spellbook-overlay {
  position: fixed;
  inset: 0;
  z-index: 12100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  font-family: 'Quicksand', system-ui, sans-serif;
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}

.spellbook-overlay--visible {
  opacity: 1;
  pointer-events: auto;
}

.spellbook-backdrop {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, rgba(46, 196, 182, 0.18) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(255, 183, 77, 0.12) 0%, transparent 45%),
    rgba(12, 8, 22, 0.82);
  backdrop-filter: blur(6px);
  cursor: pointer;
}

.spellbook-stage {
  position: relative;
  z-index: 1;
  width: min(1040px, 100%);
  max-height: min(92vh, 880px);
  perspective: 1400px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.spellbook-floating-sparkles {
  position: absolute;
  inset: -20px;
  pointer-events: none;
  overflow: hidden;
  border-radius: 20px;
}

.spellbook-floating-sparkles::before,
.spellbook-floating-sparkles::after {
  content: '';
  position: absolute;
  width: 120%;
  height: 120%;
  left: -10%;
  top: -10%;
  background-image:
    radial-gradient(2px 2px at 10% 20%, rgba(255, 255, 255, 0.9), transparent),
    radial-gradient(2px 2px at 30% 70%, rgba(255, 214, 120, 0.85), transparent),
    radial-gradient(1.5px 1.5px at 55% 40%, rgba(120, 240, 220, 0.9), transparent),
    radial-gradient(2px 2px at 78% 15%, rgba(255, 255, 255, 0.7), transparent),
    radial-gradient(1.5px 1.5px at 90% 60%, rgba(255, 183, 77, 0.8), transparent);
  animation: spellbook-sparkle-drift 14s linear infinite;
  opacity: 0.55;
}

.spellbook-floating-sparkles::after {
  animation-duration: 19s;
  animation-direction: reverse;
  opacity: 0.35;
}

@keyframes spellbook-sparkle-drift {
  from {
    transform: translateY(0) translateX(0);
  }
  to {
    transform: translateY(-24px) translateX(12px);
  }
}

.spellbook-book {
  position: relative; /* target sheet positions inside */
  background: linear-gradient(145deg, #3d2914 0%, #1f140a 48%, #2a1a0e 100%);
  border-radius: 14px 18px 18px 14px;
  box-shadow:
    0 0 0 2px rgba(255, 213, 128, 0.35),
    0 24px 60px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  padding: 12px 12px 16px;
  transform: rotateX(4deg) scale(0.94);
  transform-origin: 50% 80%;
  opacity: 0;
  transition:
    transform 0.55s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.4s ease;
  flex: 0 1 auto;
  min-height: 0;
  max-height: min(92vh, 880px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.spellbook-stage:has(.spellbook-book--open) {
  perspective: none;
}

.spellbook-book--open {
  transform: none;
  opacity: 1;
}

.spellbook-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 5;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  color: #ffe9a8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background 0.2s, color 0.2s, transform 0.2s;
}

.spellbook-close:hover {
  background: rgba(255, 107, 107, 0.45);
  color: #fff;
  transform: scale(1.06);
}

.spellbook-close:focus-visible {
  outline: 2px solid #5eead4;
  outline-offset: 2px;
}

.spellbook-topper {
  position: relative;
  text-align: center;
  padding: 8px 48px 14px;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.spellbook-topper-glow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 70%;
  height: 140%;
  transform: translate(-50%, -50%);
  background: radial-gradient(ellipse, rgba(94, 234, 212, 0.2) 0%, transparent 70%);
  pointer-events: none;
}

.spellbook-title {
  font-family: 'Yatra One', serif;
  font-size: clamp(1.5rem, 4vw, 2rem);
  margin: 0;
  color: #ffe566;
  text-shadow:
    0 0 20px rgba(255, 200, 80, 0.5),
    0 2px 0 #5c3d0f;
  letter-spacing: 0.04em;
}

.spellbook-sub {
  margin: 6px 0 0;
  font-size: 0.95rem;
  color: rgba(255, 235, 190, 0.85);
  font-weight: 600;
}

.spellbook-sub-name {
  color: #a7f3d0;
}

.spellbook-spread {
  display: grid;
  grid-template-columns: 1fr 18px 1.15fr;
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
  flex: 0 1 auto;
  height: min(560px, calc(92vh - 140px));
  min-height: min(420px, 52vh);
  max-height: min(560px, calc(92vh - 140px));
  overflow: hidden;
  align-items: stretch;
}

@media (max-width: 720px) {
  .spellbook-spread {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 42vh) 12px minmax(0, 1fr);
    height: min(calc(92vh - 140px), 640px);
    max-height: min(calc(92vh - 140px), 640px);
    overflow: hidden;
  }

  .spellbook-page--left {
    max-height: none;
  }

  .spellbook-binding {
    min-height: 14px;
    flex-direction: row;
    align-items: center;
  }

  .spellbook-binding-thread {
    width: min(88%, 320px);
    height: 5px;
    margin: 0 auto;
  }
}

.spellbook-page {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.spellbook-page--left {
  background: linear-gradient(180deg, #f4e4c1 0%, #e8d5b0 40%, #dcc9a3 100%);
  box-shadow:
    inset 4px 0 12px rgba(255, 255, 255, 0.45),
    inset -2px 0 8px rgba(120, 90, 50, 0.12);
}

.spellbook-page--right {
  background: linear-gradient(180deg, #faf3e0 0%, #efe2c8 45%, #e5d6bc 100%);
  box-shadow:
    inset -4px 0 14px rgba(255, 255, 255, 0.35),
    inset 2px 0 10px rgba(80, 60, 40, 0.1);
  min-height: 0;
}

.spellbook-page-texture {
  position: absolute;
  inset: 0;
  opacity: 0.07;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='80' height='80' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
}

.spellbook-page-texture--right {
  opacity: 0.05;
}

.spellbook-chapter {
  position: relative;
  z-index: 1;
  margin: 0;
  padding: 14px 16px 10px;
  font-family: 'Yatra One', serif;
  font-size: 1.05rem;
  color: #5c3d1e;
  border-bottom: 2px dashed rgba(92, 61, 30, 0.25);
  flex-shrink: 0;
}

.spellbook-list {
  position: relative;
  z-index: 1;
  list-style: none;
  margin: 0;
  padding: 8px 8px 12px;
  overflow-x: hidden;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: thin;
  scrollbar-color: rgba(92, 61, 30, 0.4) rgba(92, 61, 30, 0.08);
}

.spellbook-overlay--visible .spellbook-list li .spellbook-row {
  animation: spellbook-row-enter 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.spellbook-overlay--visible .spellbook-list li:nth-child(1) .spellbook-row {
  animation-delay: 0.04s;
}
.spellbook-overlay--visible .spellbook-list li:nth-child(2) .spellbook-row {
  animation-delay: 0.08s;
}
.spellbook-overlay--visible .spellbook-list li:nth-child(3) .spellbook-row {
  animation-delay: 0.12s;
}
.spellbook-overlay--visible .spellbook-list li:nth-child(4) .spellbook-row {
  animation-delay: 0.16s;
}
.spellbook-overlay--visible .spellbook-list li:nth-child(5) .spellbook-row {
  animation-delay: 0.2s;
}
.spellbook-overlay--visible .spellbook-list li:nth-child(6) .spellbook-row {
  animation-delay: 0.24s;
}
.spellbook-overlay--visible .spellbook-list li:nth-child(7) .spellbook-row {
  animation-delay: 0.28s;
}
.spellbook-overlay--visible .spellbook-list li:nth-child(8) .spellbook-row {
  animation-delay: 0.32s;
}
.spellbook-overlay--visible .spellbook-list li:nth-child(n + 9) .spellbook-row {
  animation-delay: 0.36s;
}

@keyframes spellbook-row-enter {
  from {
    opacity: 0;
    transform: translateX(-12px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.spellbook-list::-webkit-scrollbar {
  width: 8px;
}

.spellbook-list::-webkit-scrollbar-track {
  background: rgba(92, 61, 30, 0.08);
  border-radius: 4px;
  margin: 4px 0;
}

.spellbook-list::-webkit-scrollbar-thumb {
  background: rgba(92, 61, 30, 0.35);
  border-radius: 4px;
}

.spellbook-list::-webkit-scrollbar-thumb:hover {
  background: rgba(92, 61, 30, 0.52);
}

.spellbook-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.35);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: #3d2914;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.spellbook-row:hover {
  background: rgba(255, 255, 255, 0.65);
  transform: translateX(4px);
  box-shadow: 0 4px 14px rgba(46, 196, 182, 0.2);
}

.spellbook-row.is-selected {
  background: linear-gradient(90deg, rgba(255, 236, 153, 0.95), rgba(255, 255, 255, 0.75));
  box-shadow:
    0 0 0 2px rgba(255, 183, 77, 0.65),
    0 6px 20px rgba(255, 160, 60, 0.25);
  transform: translateX(6px);
}

.spellbook-row--low-mp .spellbook-row-meta {
  color: #b45309;
}

.spellbook-row-icon,
.spellbook-row-icon-fallback {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.spellbook-row-icon-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #5eead4, #2dd4bf);
  color: var(--color-text);
  font-size: 1.1rem;
}

.spellbook-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.spellbook-row-name {
  font-weight: 700;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spellbook-row-meta {
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(61, 41, 20, 0.65);
}

.spellbook-row-chevron {
  color: rgba(61, 41, 20, 0.35);
  font-size: 0.75rem;
  transition: transform 0.25s ease;
}

.spellbook-row.is-selected .spellbook-row-chevron {
  transform: translateX(3px);
  color: #c2410c;
}

.spellbook-empty {
  padding: 24px 16px;
  text-align: center;
  color: rgba(61, 41, 20, 0.75);
  font-weight: 600;
  line-height: 1.45;
}

.spellbook-list-section-title {
  padding: 14px 4px 6px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(61, 41, 20, 0.55);
  list-style: none;
}

.spellbook-list-section-title:first-child {
  padding-top: 0;
}

.spellbook-binding {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  background: linear-gradient(90deg, #2a1810 0%, #4a3020 50%, #2a1810 100%);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.5);
  min-height: 0;
  height: 100%;
}

.spellbook-binding-thread {
  width: 5px;
  flex: 0 0 auto;
  margin: 10px 0;
  border-radius: 3px;
  background: repeating-linear-gradient(
    180deg,
    #8b6914 0px,
    #d4a017 3px,
    #6b4f0c 6px,
    #d4a017 9px
  );
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.4);
}

.spellbook-rune-border {
  position: absolute;
  inset: 10px;
  border: 2px solid transparent;
  border-radius: 8px;
  background:
    linear-gradient(#faf3e0, #efe2c8) padding-box,
    linear-gradient(135deg, rgba(212, 160, 23, 0.5), rgba(94, 234, 212, 0.45), rgba(212, 160, 23, 0.5)) border-box;
  pointer-events: none;
  opacity: 0.85;
  z-index: 0;
}

.spellbook-detail {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 18px 20px;
}
  min-height: 200px;
}

.spellbook-detail::-webkit-scrollbar {
  width: 8px;
}

.spellbook-detail::-webkit-scrollbar-thumb {
  background: rgba(92, 61, 30, 0.3);
  border-radius: 4px;
}

.spellbook-detail-inner {
  position: relative;
  min-height: 180px;
}

/* Inscription sweep + staggered reveal */
.spellbook-inscribe-sweep {
  position: absolute;
  left: -5%;
  top: 0;
  width: 40%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(94, 234, 212, 0.35),
    rgba(255, 236, 153, 0.5),
    transparent
  );
  filter: blur(8px);
  opacity: 0;
  pointer-events: none;
}

.spellbook-inscribe--active .spellbook-inscribe-sweep {
  animation: spellbook-sweep 0.85s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

@keyframes spellbook-sweep {
  0% {
    opacity: 0;
    transform: translateX(-20%);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateX(280%);
  }
}

.spellbook-inscribe--active [data-inscribe] {
  animation: spellbook-inscribe-pop 0.55s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.spellbook-inscribe--active [data-inscribe='0'] {
  animation-delay: 0.05s;
}
.spellbook-inscribe--active [data-inscribe='1'] {
  animation-delay: 0.12s;
}
.spellbook-inscribe--active [data-inscribe='2'] {
  animation-delay: 0.22s;
}
.spellbook-inscribe--active [data-inscribe='3'] {
  animation-delay: 0.3s;
}
.spellbook-inscribe--active [data-inscribe='4'] {
  animation-delay: 0.38s;
}
.spellbook-inscribe--active [data-inscribe='5'] {
  animation-delay: 0.42s;
}
.spellbook-inscribe--active [data-inscribe='6'] {
  animation-delay: 0.52s;
}

@keyframes spellbook-inscribe-pop {
  0% {
    opacity: 0;
    filter: blur(6px);
    transform: translateY(10px) scale(0.98);
  }
  60% {
    filter: blur(0);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.spellbook-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 16px;
  min-height: 220px;
}

.spellbook-placeholder-sigil {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  color: #0f766e;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.9), rgba(167, 243, 208, 0.5));
  box-shadow:
    0 0 0 3px rgba(212, 160, 23, 0.45),
    0 12px 28px rgba(15, 118, 110, 0.25);
  margin-bottom: 18px;
  animation: spellbook-sigil-pulse 2.8s ease-in-out infinite;
}

@keyframes spellbook-sigil-pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow:
      0 0 0 3px rgba(212, 160, 23, 0.45),
      0 12px 28px rgba(15, 118, 110, 0.25);
  }
  50% {
    transform: scale(1.04);
    box-shadow:
      0 0 0 5px rgba(94, 234, 212, 0.5),
      0 16px 36px rgba(15, 118, 110, 0.35);
  }
}

.spellbook-placeholder-text {
  max-width: 280px;
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.5;
  color: rgba(61, 41, 20, 0.82);
}

.spellbook-detail-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.spellbook-detail-icon {
  border-radius: 16px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  flex-shrink: 0;
}

.spellbook-detail-icon-fallback {
  width: 96px;
  height: 96px;
  border-radius: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  color: #134e4a;
  background: linear-gradient(145deg, #99f6e4, #5eead4);
  box-shadow: 0 6px 18px rgba(20, 184, 166, 0.35);
}

.spellbook-detail-name {
  font-family: 'Yatra One', serif;
  font-size: 1.45rem;
  margin: 0 0 8px;
  color: #422006;
  line-height: 1.2;
}

.spellbook-detail-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.spellbook-stat {
  font-size: 0.82rem;
  font-weight: 700;
  color: rgba(61, 41, 20, 0.75);
}

.spellbook-stat i {
  margin-right: 4px;
  color: #0d9488;
}

.spellbook-stat--talent-boost {
  color: #166534;
}

.spellbook-mana-was {
  text-decoration: line-through;
  opacity: 0.6;
  margin-right: 0.25rem;
}

.spellbook-talent-mods {
  margin: 0 0 14px;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  background: rgba(255, 214, 120, 0.22);
  border: 1px solid rgba(180, 120, 40, 0.35);
  font-size: 0.88rem;
}

.spellbook-talent-mods-title {
  font-family: 'Yatra One', serif;
  font-size: 0.95rem;
  color: #5c3d12;
  margin-bottom: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.spellbook-talent-mods-title i {
  color: #b8860b;
}

.spellbook-talent-mod-line {
  color: #4a3520;
  padding: 0.12rem 0;
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  font-weight: 600;
  line-height: 1.35;
}

.spellbook-talent-mod-line i {
  color: #ca8a04;
  font-size: 0.72rem;
  margin-top: 0.2rem;
}

.spellbook-effect-was {
  text-decoration: line-through;
  opacity: 0.55;
  margin-right: 0.35rem;
}

.spellbook-effect-val--boosted {
  color: #166534;
  font-weight: 800;
}

.spellbook-detail-desc {
  margin: 0 0 14px;
  font-size: 1rem;
  line-height: 1.55;
  color: #422006;
  font-weight: 600;
}

.spellbook-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
}

.spellbook-tags li {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(13, 148, 136, 0.15);
  color: #0f766e;
  border: 1px solid rgba(13, 148, 136, 0.35);
}

.spellbook-effects-block {
  margin-bottom: 18px;
}

.spellbook-effects-title {
  margin: 0 0 8px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(61, 41, 20, 0.55);
}

.spellbook-effects {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.spellbook-effects li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.45);
  color: #3d2914;
}

.spellbook-effect-name {
  flex: 1;
}

.spellbook-effect-val {
  font-variant-numeric: tabular-nums;
  color: #0f766e;
}

.spellbook-effect-more {
  justify-content: center;
  font-style: italic;
  color: rgba(61, 41, 20, 0.6);
}

.spellbook-effects-none {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: rgba(61, 41, 20, 0.65);
  line-height: 1.45;
}

.spellbook-cast-wrap {
  text-align: center;
  padding-top: 8px;
}

.spellbook-cast-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 28px;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--color-text);
  background: linear-gradient(180deg, #fde68a 0%, #fbbf24 45%, #f59e0b 100%);
  box-shadow:
    0 0 0 2px rgba(180, 83, 9, 0.35),
    0 8px 0 #b45309,
    0 12px 24px rgba(180, 83, 9, 0.35);
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    filter 0.15s ease;
}

.spellbook-cast-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  filter: brightness(1.05);
  box-shadow:
    0 0 0 2px rgba(180, 83, 9, 0.45),
    0 10px 0 #b45309,
    0 16px 28px rgba(180, 83, 9, 0.4);
}

.spellbook-cast-btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow:
    0 0 0 2px rgba(180, 83, 9, 0.35),
    0 4px 0 #b45309,
    0 8px 16px rgba(180, 83, 9, 0.3);
}

.spellbook-cast-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow:
    0 0 0 2px rgba(100, 100, 100, 0.2),
    0 6px 0 #6b7280,
    0 8px 16px rgba(0, 0, 0, 0.15);
  background: linear-gradient(180deg, #e5e7eb, #d1d5db);
}

.spellbook-cast-glow {
  position: absolute;
  inset: -6px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(253, 224, 71, 0.55) 0%, transparent 70%);
  opacity: 0;
  z-index: -1;
  animation: spellbook-cast-glow 2.2s ease-in-out infinite;
}

.spellbook-cast-btn:hover:not(:disabled) .spellbook-cast-glow {
  opacity: 1;
}

@keyframes spellbook-cast-glow {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.4;
  }
  50% {
    transform: scale(1.08);
    opacity: 0.85;
  }
}

.spellbook-cast-hint {
  margin: 10px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: #b45309;
}

/* Target picker (same-team teammates) */
.spellbook-target-sheet {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #faf3e0 0%, #e8dcc4 100%);
  border-radius: 10px;
  padding: 12px 12px 16px;
  box-shadow: inset 0 0 0 2px rgba(212, 160, 23, 0.35);
  animation: spellbook-target-enter 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes spellbook-target-enter {
  from {
    opacity: 0;
    transform: scale(0.97);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.spellbook-target-head {
  flex-shrink: 0;
  margin-bottom: 10px;
}

.spellbook-target-back {
  border: none;
  background: rgba(61, 41, 20, 0.08);
  color: #5c3d1e;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s;
}

.spellbook-target-back:hover {
  background: rgba(13, 148, 136, 0.15);
  color: #0f766e;
}

.spellbook-target-title {
  font-family: 'Yatra One', serif;
  margin: 0 0 6px;
  font-size: 1.2rem;
  color: #422006;
}

.spellbook-target-hint {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: rgba(61, 41, 20, 0.72);
  line-height: 1.4;
}

.spellbook-target-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  overflow-y: auto;
  flex: 1;
  min-height: 120px;
  max-height: min(42vh, 320px);
}

.spellbook-target-item {
  margin-bottom: 6px;
}

.spellbook-target-label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.45);
  cursor: pointer;
  transition:
    background 0.2s,
    box-shadow 0.2s;
  border: 2px solid transparent;
}

.spellbook-target-label:hover {
  background: rgba(255, 255, 255, 0.75);
}

.spellbook-target-input {
  width: 1.15rem;
  height: 1.15rem;
  flex-shrink: 0;
  accent-color: #0d9488;
}

.spellbook-target-input:focus-visible + .spellbook-target-avatar,
.spellbook-target-input:focus-visible ~ .spellbook-target-name {
  outline: 2px solid #0d9488;
  outline-offset: 2px;
}

.spellbook-target-label:has(.spellbook-target-input:checked) {
  border-color: rgba(13, 148, 136, 0.55);
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.18);
  background: rgba(167, 243, 208, 0.35);
}

.spellbook-target-avatar {
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.spellbook-target-avatar-fallback {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #99f6e4, #5eead4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #134e4a;
  flex-shrink: 0;
}

.spellbook-target-name {
  flex: 1;
  font-weight: 700;
  font-size: 0.95rem;
  color: #3d2914;
  min-width: 0;
}

.spellbook-target-you {
  font-weight: 700;
  color: #0f766e;
  font-size: 0.85rem;
}

.spellbook-target-meta {
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(61, 41, 20, 0.5);
}

.spellbook-target-actions {
  flex-shrink: 0;
  padding-top: 12px;
  text-align: center;
}

.spellbook-target-confirm:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow:
    0 0 0 2px rgba(100, 100, 100, 0.2),
    0 6px 0 #6b7280,
    0 8px 16px rgba(0, 0, 0, 0.15);
}

/* Post-cast summary (above spellbook overlay) */
.spell-cast-result-backdrop {
  position: fixed;
  inset: 0;
  z-index: 12240;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.28s ease;
}

.spell-cast-result-backdrop--show {
  opacity: 1;
}

.spell-cast-result-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -48%) scale(0.94);
  z-index: 12250;
  width: min(420px, calc(100vw - 32px));
  max-height: min(78vh, 560px);
  overflow-y: auto;
  padding: 24px 22px 20px;
  border-radius: 16px;
  background: linear-gradient(165deg, #fffef8 0%, #f3ecdc 45%, #e8dcc8 100%);
  box-shadow:
    0 0 0 3px rgba(180, 130, 40, 0.35),
    0 24px 48px rgba(0, 0, 0, 0.28);
  opacity: 0;
  transition:
    opacity 0.28s ease,
    transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  text-align: center;
}

.spell-cast-result-panel--show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.spell-cast-result-icon {
  font-size: 2.25rem;
  color: #b45309;
  margin-bottom: 8px;
  filter: drop-shadow(0 2px 4px rgba(180, 83, 9, 0.35));
}

.dungeon-spell-cast-icon .dungeon-spell-cast-icon-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgba(180, 83, 9, 0.35));
}

.dungeon-spell-cast-backdrop {
  z-index: 12290;
}

.dungeon-spell-cast-panel {
  z-index: 12300;
}

.spell-cast-result-title {
  margin: 0 0 12px;
  font-family: 'Yatra One', serif;
  font-size: 1.45rem;
  color: #422006;
}

.spell-cast-result-summary {
  margin: 0 0 16px;
  font-size: 1.02rem;
  line-height: 1.45;
  color: #3d2914;
  font-weight: 600;
}

.spell-cast-result-summary strong {
  color: #0f766e;
}

.spell-cast-result-subtitle {
  margin: 18px 0 8px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(61, 41, 20, 0.65);
  font-weight: 800;
}

.spell-cast-result-meta,
.spell-cast-result-effects {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  text-align: left;
}

.spell-cast-result-meta li,
.spell-cast-result-effects li {
  font-size: 0.92rem;
  line-height: 1.45;
  color: #3d2914;
  padding: 6px 10px;
  margin-bottom: 6px;
  background: rgba(255, 255, 255, 0.55);
  border-radius: 10px;
  border: 1px solid rgba(212, 160, 23, 0.2);
}

.spell-cast-result-muted {
  margin: 8px 0 16px;
  font-size: 0.9rem;
  color: rgba(61, 41, 20, 0.6);
  font-style: italic;
}

.spell-cast-result-cast-on {
  margin: 0 0 14px;
  font-size: 1rem;
  line-height: 1.45;
  color: #134e4a;
  font-weight: 700;
}

.spell-cast-result-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(61, 41, 20, 0.55);
  margin-bottom: 4px;
  font-weight: 800;
}

.spell-cast-result-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 16px;
  padding-top: 4px;
}

.spell-cast-result-ok {
  min-width: 160px;
  margin: 0;
}

/* Level-up after spell cast - above spellbook + cast confirmation layers */
.level-up-overlay--above-spellbook,
.level-up-group-overlay--above-spellbook {
  z-index: 12300;
}

@media (prefers-reduced-motion: reduce) {
  .spell-cast-result-backdrop,
  .spell-cast-result-panel {
    transition: none;
  }

  .spell-cast-result-panel {
    transform: translate(-50%, -50%);
  }

  .spellbook-book,
  .spellbook-overlay,
  .spellbook-row,
  .spellbook-floating-sparkles::before,
  .spellbook-floating-sparkles::after,
  .spellbook-placeholder-sigil,
  .spellbook-inscribe-sweep,
  .spellbook-inscribe--active [data-inscribe],
  .spellbook-cast-glow {
    animation: none !important;
    transition: none !important;
  }

  .spellbook-book {
    transform: none;
    opacity: 1;
  }

  .spellbook-overlay {
    opacity: 1;
  }

  .spellbook-inscribe--active [data-inscribe] {
    opacity: 1;
    filter: none;
    transform: none;
  }

  .spellbook-overlay--visible .spellbook-list li .spellbook-row {
    animation: none;
  }

  .spellbook-target-sheet {
    animation: none;
  }
}
