:root {
  color-scheme: dark;
  --magic: #aee8ff;
  --magic-bright: #e9f9ff;
  --magic-deep: #4ca7d0;
  --paper: #eef8fb;
  --paper-muted: #b9d5df;
  --panel: rgba(5, 19, 30, 0.92);
  --line: rgba(143, 218, 248, 0.28);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #030b12;
}

body {
  color: var(--paper);
  font-family: Georgia, "Times New Roman", serif;
}

.magic-background,
.magic-veil {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

.magic-background { object-fit: cover; background: #030b12; }

.magic-veil {
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(2, 11, 19, 0.95), rgba(8, 31, 48, 0.54) 48%, rgba(2, 11, 19, 0.95)),
    linear-gradient(to bottom, rgba(3, 14, 23, 0.55), rgba(2, 9, 15, 0.94)),
    radial-gradient(circle at 50% 38%, rgba(102, 202, 241, 0.22), transparent 48%);
}

.magic-header,
.spell-library {
  position: relative;
  z-index: 1;
}

.magic-header {
  height: 76px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: min(1500px, calc(100% - 48px));
  margin: 0 auto;
  border-bottom: 1px solid var(--line);
}

.magic-back {
  justify-self: start;
  color: var(--magic);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-decoration: none;
  text-transform: uppercase;
}

.magic-back:hover,
.magic-back:focus-visible { color: var(--magic-bright); }

.magic-header__title {
  display: grid;
  justify-items: center;
  gap: 4px;
}

.magic-header__title span {
  color: rgba(174, 232, 255, 0.62);
  font-size: 0.56rem;
  letter-spacing: 0.28em;
}

.magic-header__title strong { font-size: 1.05rem; font-weight: 400; letter-spacing: 0.06em; }

.magic-volume {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid rgba(174, 232, 255, 0.48);
  background: rgba(3, 15, 24, 0.78);
  color: var(--paper);
  cursor: pointer;
  font-family: inherit;
}

.magic-volume:hover,
.magic-volume:focus-visible { border-color: var(--magic-bright); outline: none; color: var(--magic-bright); }
.magic-volume span:last-child { min-width: 3ch; font-size: 0.64rem; font-weight: 700; letter-spacing: 0.12em; }

.spell-library {
  height: calc(100svh - 76px);
  display: grid;
  grid-template-columns: minmax(170px, 230px) minmax(0, 1fr);
  gap: clamp(18px, 2.5vw, 36px);
  width: min(1480px, calc(100% - 48px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.class-selector {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 9px;
  overflow-y: auto;
}

.class-tab {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: 7px;
  min-height: 112px;
  padding: 12px 7px 10px;
  border: 1px solid rgba(143, 218, 248, 0.22);
  background: rgba(4, 18, 29, 0.72);
  color: var(--paper-muted);
  cursor: pointer;
  font-family: inherit;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

.class-tab img {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  object-fit: cover;
  filter: saturate(0.72) brightness(0.9);
}

.class-tab span { overflow: hidden; font-size: 0.58rem; letter-spacing: 0.09em; text-overflow: ellipsis; text-transform: uppercase; }

.class-tab:hover,
.class-tab:focus-visible,
.class-tab.is-active {
  border-color: rgba(174, 232, 255, 0.82);
  outline: none;
  background: rgba(29, 89, 118, 0.48);
  color: var(--magic-bright);
  transform: translateY(-2px);
}

.class-tab.is-active img { filter: saturate(1.05) brightness(1.1) drop-shadow(0 0 12px rgba(125, 215, 250, 0.35)); }

.class-grimoire {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: clamp(22px, 3vw, 40px);
  border: 1px solid rgba(143, 218, 248, 0.3);
  background:
    linear-gradient(135deg, rgba(72, 166, 204, 0.09), transparent 40%),
    var(--panel);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.58), inset 0 0 55px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(8px);
}

.class-grimoire__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.class-grimoire__identity { display: flex; align-items: center; gap: 18px; }
.class-grimoire__identity img { width: 76px; height: 76px; border-radius: 50%; object-fit: cover; box-shadow: 0 0 24px rgba(106, 204, 241, 0.22); }
.class-grimoire__identity span { color: var(--magic); font-size: 0.59rem; font-weight: 700; letter-spacing: 0.24em; }
.class-grimoire h1 { margin: 5px 0 0; font-size: clamp(2rem, 4vw, 3.8rem); font-weight: 400; line-height: 0.95; }
.class-grimoire__header > p { margin: 0; color: var(--paper-muted); font-size: 0.72rem; letter-spacing: 0.1em; }

.spell-legend { display: flex; flex-wrap: wrap; gap: 12px 22px; padding: 15px 0; color: rgba(185, 213, 223, 0.72); font-size: 0.65rem; }
.spell-legend b { color: var(--magic-bright); }

.spell-groups {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 17px;
  padding: 5px 12px 10px 0;
  overflow-y: auto;
  scrollbar-color: rgba(174, 232, 255, 0.72) rgba(2, 10, 16, 0.5);
}

.spell-level-group { border: 1px solid rgba(143, 218, 248, 0.18); background: rgba(3, 14, 23, 0.62); }
.spell-level-group h2 { margin: 0; padding: 11px 14px; border-bottom: 1px solid rgba(143, 218, 248, 0.18); color: var(--magic); font-size: 0.62rem; letter-spacing: 0.2em; text-transform: uppercase; }
.spell-level-group ul { margin: 0; padding: 0; list-style: none; }

.spell-link {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 14px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(143, 218, 248, 0.11);
  color: var(--paper);
  text-decoration: none;
  transition: background 140ms ease, color 140ms ease;
}

.spell-link:hover,
.spell-link:focus-visible { outline: none; background: rgba(64, 158, 197, 0.18); color: var(--magic-bright); }
.spell-link__name { min-width: 0; font-size: 0.94rem; line-height: 1.3; }
.spell-link__original { display: block; margin-top: 4px; color: rgba(185, 213, 223, 0.56); font-size: 0.58rem; letter-spacing: 0.06em; text-transform: uppercase; }
.spell-link__school { grid-column: 1; color: rgba(174, 232, 255, 0.68); font-size: 0.62rem; }
.spell-link__special { grid-column: 2; grid-row: 1 / 3; align-self: center; color: var(--magic-bright); font-size: 0.62rem; letter-spacing: 0.1em; }
.magic-status { margin: auto; color: var(--paper-muted); font-size: 0.72rem; letter-spacing: 0.1em; }
.magic-status:empty { display: none; }

/* Detalhe da magia */
.spell-detail-page { height: calc(100svh - 76px); min-height: 0; display: grid; place-items: center; padding: 24px; overflow: hidden; }
.spell-detail {
  width: min(1120px, 100%);
  height: min(760px, calc(100svh - 124px));
  max-height: calc(100svh - 124px);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(260px, 0.72fr) minmax(420px, 1.28fr);
  overflow: hidden;
  border: 1px solid rgba(143, 218, 248, 0.32);
  background: rgba(4, 17, 27, 0.91);
  box-shadow: 0 32px 100px rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(9px);
}
.spell-detail__visual { position: relative; display: grid; place-items: center; min-height: 0; padding: 42px; overflow: hidden; background: radial-gradient(circle, rgba(99, 200, 241, 0.22), transparent 56%); }
.spell-detail__visual::after { content: ""; position: absolute; inset: 10%; border: 1px solid rgba(174, 232, 255, 0.12); border-radius: 50%; }
.spell-detail__visual img { position: relative; z-index: 1; width: min(100%, 330px); max-height: 62vh; object-fit: contain; filter: drop-shadow(0 22px 35px rgba(0, 0, 0, 0.62)); }
.spell-detail__content { min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: clamp(26px, 4vw, 52px); overflow: hidden; border-left: 1px solid var(--line); }
.spell-detail__eyebrow { color: var(--magic); font-size: 0.64rem; font-weight: 700; letter-spacing: 0.24em; }
.spell-detail h1 { margin: 9px 0 0; font-size: clamp(2.2rem, 5vw, 4.8rem); font-weight: 400; line-height: 0.94; text-wrap: balance; }
.spell-detail__original { margin: 11px 0 0; color: rgba(185, 213, 223, 0.62); font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; }
.spell-detail__summary { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 22px; }
.spell-detail__summary span { padding: 7px 10px; border: 1px solid rgba(143, 218, 248, 0.24); background: rgba(28, 77, 101, 0.2); color: var(--magic-bright); font-size: 0.66rem; }
.spell-detail__scroll {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 24px;
  padding-right: 12px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-color: rgba(174, 232, 255, 0.72) rgba(2, 10, 16, 0.5);
}
.spell-detail__metadata { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; margin: 0 0 26px; padding: 1px; background: var(--line); }
.spell-detail__metadata div { padding: 13px 14px; background: #071725; }
.spell-detail__metadata dt { color: var(--magic); font-size: 0.56rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.spell-detail__metadata dd { margin: 6px 0 0; color: var(--paper); font-size: 0.85rem; line-height: 1.45; }
.spell-detail__description p { margin: 0 0 17px; color: #dcebef; font-size: clamp(0.94rem, 1.2vw, 1.07rem); line-height: 1.7; }
.spell-detail__description strong { color: var(--magic-bright); }

@media (max-width: 850px) {
  .magic-header { width: calc(100% - 28px); grid-template-columns: 1fr auto; }
  .magic-header__title { display: none; }
  .spell-library { width: calc(100% - 24px); grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); gap: 12px; padding: 12px 0; }
  .class-selector { grid-template-columns: repeat(8, 94px); overflow-x: auto; overflow-y: hidden; }
  .class-tab { min-height: 94px; }
  .class-tab img { width: 50px; height: 50px; }
  .spell-groups { grid-template-columns: 1fr; }
  .spell-detail-page { padding: 12px; }
  .spell-detail { height: calc(100svh - 100px); max-height: calc(100svh - 100px); grid-template-columns: 1fr; grid-template-rows: minmax(180px, 34vh) minmax(0, 1fr); }
  .spell-detail__visual { padding: 20px; }
  .spell-detail__visual img { max-height: 31vh; }
  .spell-detail__content { padding: 24px 20px; border-top: 1px solid var(--line); border-left: 0; }
}

@media (max-width: 520px) {
  .magic-back { max-width: 150px; line-height: 1.35; }
  .magic-volume { width: 40px; padding: 0; justify-content: center; }
  .magic-volume span:last-child { display: none; }
  .class-grimoire { padding: 18px 14px; }
  .class-grimoire__identity img { width: 58px; height: 58px; }
  .class-grimoire__header > p { display: none; }
  .spell-detail__metadata { grid-template-columns: 1fr; }
}
