/* ==========================================================================
   magics.css — the Seven Energies and the schools of magic
   Load AFTER /css/site.css. Everything inside #world is sized in "world
   units" (px at zoom 1); magics.js scales the whole layer as you zoom.
   <body data-depth="0|1|2"> says how close you are, and decides how much
   text shows. The reading card (#card) lives in screen space, so its text
   is always a comfortable size.
   ========================================================================== */

.magic-page {
    --ink: #e6e3f0;
    --ink-soft: #9a96ad;
    --gold: #ffd700;
    margin: 0;
    height: 100vh;
    overflow: hidden;
    background: radial-gradient(ellipse at 50% 45%, #121026 0%, #07060f 60%, #020205 100%);
    color: var(--ink);
    user-select: none;
}

#weave {
    position: fixed; inset: 0;
    width: 100vw; height: 100vh;
    z-index: 0;
    pointer-events: none;
}
/* PixiJS layer under the weave (made by magics.js only when WebGL works): the universe's
   nebula, the edge of existence, the dark outside and black energy's stain */
#magic-pixi {
    position: fixed; inset: 0;
    width: 100vw; height: 100vh;
    z-index: 0;
    pointer-events: none;
}
#stage {
    position: fixed; inset: 0;
    z-index: 1;
    overflow: hidden;
    cursor: grab;
    touch-action: none;
}
#stage.dragging { cursor: grabbing; }
#world {
    position: absolute; left: 0; top: 0;
    width: 0; height: 0;
    transform-origin: 0 0;
}

/* --- Top bar --- */
.page-links {
    position: fixed; top: 0; left: 0; right: 0;
    z-index: 5;
    display: flex; align-items: center; gap: 22px;
    padding: 12px 16px 24px;
    font-size: 0.85rem;
    background: linear-gradient(rgba(2, 2, 5, 0.9), rgba(2, 2, 5, 0));
    pointer-events: none;
}
/* the link out is a travel plaque (site.css), in the weave's colours */
.magic-page { --travel-accent: var(--gold); --travel-ink: var(--ink); --travel-bg: #07060f; --travel-bg2: #17132e; }
.page-links > * { pointer-events: auto; }
.page-links a { color: var(--gold); text-decoration: none; }
.page-links a:hover { text-decoration: underline; }
.trail { display: flex; gap: 8px; align-items: center; font-family: var(--font-fantasy); }
.trail button {
    all: unset; cursor: pointer;
    color: var(--ink-soft);
}
.trail button:hover { color: var(--ink); }
.trail-here:not(:empty)::before { content: '\203A'; margin-right: 8px; color: var(--ink-soft); }
.trail-here { color: var(--ink); }

button:focus-visible,
[role="button"]:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

/* --- Intro, fades away once you zoom in --- */
.intro {
    position: fixed; left: 24px; top: 70px;
    z-index: 4;
    width: min(340px, calc(100vw - 48px));
    transition: opacity 0.6s ease, transform 0.6s ease;
    pointer-events: none;
}
.intro h1 {
    margin: 0 0 0.6rem;
    font-family: var(--font-fantasy);
    font-weight: 400;
    font-size: 1.8rem;
    color: var(--ink);
}
.intro p { margin: 0 0 0.8rem; font-size: 0.95rem; line-height: 1.6; color: #c9c5d8; text-shadow: 0 0 6px #000; }
.intro .hint { font-style: italic; color: var(--ink-soft); font-size: 0.88rem; }
.intro .detect-lore { font-size: 0.86rem; color: #aaa5bd; }
.reading .intro { opacity: 0; transform: translateX(-12px); }
[data-depth="1"] .intro,
[data-depth="2"] .intro { opacity: 0; transform: translateX(-12px); }

/* --- Zoom controls --- */
.zoom-controls {
    position: fixed; right: 18px; bottom: 18px;
    z-index: 5;
    display: flex; flex-direction: column; gap: 6px;
}
.zoom-controls button {
    all: unset; cursor: pointer;
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: rgba(10, 8, 20, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--ink);
    font-size: 1.1rem;
}

/* ==========================================================================
   Energies (built by magics.js). --r is the radius, --c the colour.
   ========================================================================== */
.energy {
    all: unset;
    position: absolute;
    z-index: 1;
    width: calc(var(--r) * 2px); height: calc(var(--r) * 2px);
    transform: translate(-50%, -50%);
    cursor: pointer;
    transition: opacity 0.6s ease;
}
.orb {
    /* The bubble itself is painted on the canvas underneath (magics.js); this is its clickable glass */
    position: absolute; inset: 0;
    border-radius: 50%;
    transition: box-shadow 0.4s ease;
}
.energy:hover .orb,
.energy.focus .orb { box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 70%, #fff), 0 0 calc(var(--r) * 0.6px) color-mix(in srgb, var(--c) 60%, transparent); }

/* Name and keywords under the bubble, as on the Wheel of Energies */
.e-text {
    position: absolute;
    left: 50%; top: calc(100% + 6px);
    transform: translateX(-50%);
    display: flex; flex-direction: column; align-items: center;
    text-align: center;
    white-space: nowrap;
    pointer-events: none;
}
.e-name {
    font-family: var(--font-fantasy);
    font-size: calc(var(--r) * 0.17px * var(--inv, 1));
    color: color-mix(in srgb, var(--c) 45%, #fff);
    text-shadow: 0 0 6px #000, 0 0 2px #000;
}
.e-keys {
    font-size: calc(var(--r) * 0.095px * var(--inv, 1));
    font-style: italic;
    color: #d8d2e8;
    text-shadow: 0 0 4px #000;
}
.e-yellow .e-text { top: calc(100% + 18px); }

/* ==========================================================================
   Schools of magic: bubbles on the links between energies. --r is the radius,
   --c1 and --c2 the colours of their two energies. The scene inside is painted
   on the canvas underneath (magics.js).
   ========================================================================== */
.school {
    all: unset;
    position: absolute;
    z-index: 2;
    width: calc(var(--r) * 2px); height: calc(var(--r) * 2px);
    transform: translate(-50%, -50%);
    cursor: pointer;
    transition: opacity 0.6s ease;
}
.school .orb { --c: var(--c1); }
.school:hover .orb,
.school.focus .orb { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--c1) 50%, var(--c2)), 0 0 calc(var(--r) * 0.5px) color-mix(in srgb, var(--c2) 55%, transparent); }
.s-text {
    position: absolute;
    left: 50%; top: calc(100% + 4px);
    transform: translateX(-50%);
    display: flex; flex-direction: column; align-items: center;
    text-align: center;
    white-space: nowrap;
    pointer-events: none;
}
.s-name {
    font-family: var(--font-fantasy);
    font-size: calc(max(11px, var(--r) * 0.3px) * var(--inv, 1));
    color: #fff;
    background: linear-gradient(90deg, color-mix(in srgb, var(--c1) 40%, #fff), color-mix(in srgb, var(--c2) 40%, #fff));
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 3px #000) drop-shadow(0 0 1px #000);
}
.s-spec {
    margin-top: 1px;
    font-size: calc(7px * var(--inv, 1));
    font-style: italic;
    color: #c9c5d8;
    text-shadow: 0 0 4px #000;
    opacity: 0;
    transition: opacity 0.5s ease;
}
[data-depth="1"] .s-spec,
[data-depth="2"] .s-spec { opacity: 1; }
/* Advanced and hidden schools look the part */
.school[data-type="advanced"] .s-name { font-style: italic; }
.school[data-type="hidden"] .s-name { letter-spacing: 0.06em; opacity: 0.7; }
.school[data-type="hidden"]:hover .s-name,
.school[data-type="hidden"].focus .s-name { opacity: 1; }

/* The node showing its card sits above everything else */
.energy.focus, .school.focus { z-index: 10; }

/* Labels on the energy combinations themselves */
.combo {
    position: absolute;
    transform: translate(-50%, -50%);
    font-size: 6.5px;
    font-style: italic;
    color: #c9c5d8;
    white-space: nowrap;
    text-shadow: 0 0 4px #000, 0 0 2px #000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}
[data-depth="1"] .combo,
[data-depth="2"] .combo { opacity: 0.9; }

/* ==========================================================================
   The reading card: one panel in screen space. magics.js fills it, sets
   --c / --c2 to the colours of what you are reading, and keeps it beside
   its bubble (.sheet: from the bottom on phones held upright).
   ========================================================================== */
.card {
    position: fixed; left: 0; top: 0;
    z-index: 6;
    width: 400px;
    max-height: calc(100vh - 80px);
    display: flex; flex-direction: column;
    text-align: left;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--ink);
    background: rgba(8, 7, 18, 0.94);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-top: 2px solid var(--c, var(--gold));
    border-image: linear-gradient(90deg, var(--c, var(--gold)), var(--c2, var(--gold))) 1;
    border-image-width: 2px 0 0 0;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.7), 0 0 60px -20px var(--c, transparent);
    backdrop-filter: blur(6px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0s linear 0.35s;
    cursor: auto;
    user-select: text;
}
.card.open {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.35s ease, visibility 0s;
}
.card-nav {
    position: relative; z-index: 1;
    display: flex; justify-content: flex-end; gap: 4px;
    padding: 8px 8px 0;
    flex: none;
}
.card-nav button {
    all: unset; cursor: pointer;
    width: 30px; height: 30px;
    display: grid; place-items: center;
    border-radius: 50%;
    font-size: 1.25rem; line-height: 1;
    color: var(--ink-soft);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: color 0.2s ease, border-color 0.2s ease;
}
.card-nav button:hover { color: var(--ink); border-color: var(--c, var(--gold)); }
.card-nav .card-close { margin-left: 6px; }
.card-body {
    overflow-y: auto;
    padding: 0 22px 16px;
    margin-top: -26px;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}
.lore h3 {
    margin: 0 110px 4px 0;
    font-family: var(--font-fantasy);
    font-weight: 400;
    font-size: 1.45rem;
    line-height: 1.25;
    color: var(--c, var(--gold));
}
.card[data-kind="school"] h3 {
    background: linear-gradient(90deg, color-mix(in srgb, var(--c) 70%, #fff), color-mix(in srgb, var(--c2) 70%, #fff));
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}
.lore .kind { display: block; margin: 0 0 12px; font-style: italic; color: var(--ink-soft); font-size: 0.85rem; }
.lore p { margin: 0 0 10px; }
.lore h4 {
    margin: 16px 0 6px;
    font-family: var(--font-fantasy);
    font-weight: 400;
    font-size: 1.02rem;
    color: #d8d3ea;
}
.lore ul { margin: 0 0 10px; padding: 0; list-style: none; }
.lore li { margin: 0 0 8px; padding-left: 16px; position: relative; }
.lore li::before {
    content: ''; position: absolute; left: 0; top: 0.55em;
    width: 8px; height: 8px; border-radius: 50%;
    background: linear-gradient(90deg, var(--d1, #888) 50%, var(--d2, #888) 50%);
}
.lore .to-link {
    all: unset; cursor: pointer;
    text-decoration: underline dotted rgba(255, 255, 255, 0.35);
    text-underline-offset: 3px;
}
.lore .to-link:hover { color: var(--gold); }
.lore .chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; }
.lore .chip {
    all: unset; cursor: pointer;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 0.82rem;
    border: 1px solid var(--cc);
    color: var(--cc);
    transition: background 0.2s ease;
}
.lore .chip:hover { background: color-mix(in srgb, var(--cc) 18%, transparent); }
.lore .todo { font-style: italic; color: var(--ink-soft); }
.lore a { text-decoration: none; }
.lore a:hover { text-decoration: underline; }
.lore button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ==========================================================================
   The Grimoire: an optional pane with all the text. --gw is its width;
   .strip = phones held upright, where it fills the screen below a strip
   of the weave (--strip high). The section being read has .now.
   ========================================================================== */
.grimoire-toggle {
    all: unset; cursor: pointer;
    pointer-events: auto; /* the top bar lets clicks through to the weave; its buttons take them */
    margin-left: auto;
    display: inline-flex; align-items: center; gap: 7px;
    padding: 5px 12px;
    border-radius: 999px;
    font-family: var(--font-fantasy);
    font-size: 0.85rem;
    color: var(--gold);
    border: 1px solid rgba(255, 215, 0, 0.35);
    background: rgba(10, 8, 20, 0.7);
    transition: background 0.25s ease, border-color 0.25s ease;
}
.grimoire-toggle svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; }
.grimoire-toggle:hover,
.grimoire-toggle[aria-expanded="true"] { background: rgba(255, 215, 0, 0.14); border-color: rgba(255, 215, 0, 0.7); }
.grimoire-toggle:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.grimoire {
    --gw: 440px;
    position: fixed; left: 0; top: 0; bottom: 0;
    z-index: 4;
    width: var(--gw);
    display: flex; flex-direction: column;
    padding-top: 46px;
    box-sizing: border-box;
    background:
        radial-gradient(120% 60% at 0% 0%, rgba(214, 180, 110, 0.07), transparent 60%),
        linear-gradient(90deg, rgba(9, 7, 16, 0.97), rgba(11, 9, 20, 0.94));
    border-right: 1px solid rgba(214, 180, 110, 0.35);
    box-shadow: 10px 0 50px rgba(0, 0, 0, 0.55);
    transform: translateX(-102%);
    visibility: hidden;
    transition: transform 0.55s cubic-bezier(0.3, 0.7, 0.2, 1), visibility 0s linear 0.55s;
    user-select: text;
}
.grimoire-open .grimoire {
    transform: none;
    visibility: visible;
    transition: transform 0.55s cubic-bezier(0.3, 0.7, 0.2, 1), visibility 0s;
}
.grimoire-open .intro { opacity: 0; transform: translateX(-12px); }
.grim-head {
    display: flex; align-items: center;
    padding: 6px 14px 8px 26px;
    border-bottom: 1px solid rgba(214, 180, 110, 0.22);
    flex: none;
}
.grim-title {
    flex: 1;
    font-family: var(--font-fantasy);
    font-size: 0.8rem;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: rgba(214, 180, 110, 0.85);
}
.grim-close {
    all: unset; cursor: pointer;
    width: 30px; height: 30px;
    display: grid; place-items: center;
    border-radius: 50%;
    font-size: 1.2rem;
    color: var(--ink-soft);
    border: 1px solid rgba(255, 255, 255, 0.1);
}
.grim-close:hover { color: var(--ink); border-color: var(--gold); }
.grim-close:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.grim-scroll {
    position: relative; /* the pages' offsetTop is measured from here */
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px 28px 40vh;
    font-size: 0.97rem;
    line-height: 1.7;
    color: var(--ink);
    scrollbar-width: thin;
    scrollbar-color: rgba(214, 180, 110, 0.35) transparent;
}
.g-intro h1 {
    margin: 0 0 0.7rem;
    font-family: var(--font-fantasy);
    font-weight: 400;
    font-size: 1.7rem;
    color: var(--gold);
}
.g-intro p { color: #cfcade; }
.g-intro .detect-lore { font-size: 0.9rem; color: #aaa5bd; }
.g-part {
    margin: 34px 0 6px;
    font-family: var(--font-fantasy);
    font-weight: 400;
    font-size: 0.78rem;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    text-align: center;
    color: rgba(214, 180, 110, 0.9);
}
.g-part::before, .g-part::after {
    content: ''; display: inline-block; vertical-align: middle;
    width: 48px; height: 1px; margin: 0 12px;
    background: linear-gradient(90deg, transparent, rgba(214, 180, 110, 0.7));
}
.g-part::after { background: linear-gradient(90deg, rgba(214, 180, 110, 0.7), transparent); }
.g-sec {
    position: relative;
    padding: 20px 0 8px 18px;
    border-left: 2px solid transparent;
    margin-left: -20px;
    transition: border-color 0.4s ease;
}
.g-sec + .g-sec::before {
    /* a small gold ornament between pages */
    content: '\2766';
    position: absolute; top: -6px; left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    color: rgba(214, 180, 110, 0.45);
}
.g-intro { padding-top: 4px; }
.g-sec.now { border-left-color: color-mix(in srgb, var(--c) 70%, transparent); }
.g-head {
    all: unset; cursor: pointer;
    display: flex; align-items: center; gap: 12px;
    margin: 0 0 4px;
}
.g-head h3 { margin: 0 !important; transition: text-shadow 0.3s ease; }
.g-head:hover h3, .g-sec.now .g-head h3 { text-shadow: 0 0 14px color-mix(in srgb, var(--c) 60%, transparent); }
.g-head:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
.g-orb {
    flex: none;
    width: 16px; height: 16px; border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fff 0 8%, var(--c) 45%, var(--c2) 100%);
    box-shadow: 0 0 8px color-mix(in srgb, var(--c) 60%, transparent);
    transition: box-shadow 0.4s ease, transform 0.4s ease;
}
.g-sec[data-kind="school"] .g-orb { width: 12px; height: 12px; margin: 0 2px; }
.g-sec.now .g-orb { transform: scale(1.25); box-shadow: 0 0 16px var(--c), 0 0 4px #fff; }
.grimoire h3 { color: var(--c, var(--gold)); font-family: var(--font-fantasy); font-weight: 400; font-size: 1.35rem; line-height: 1.25; }
.g-sec[data-kind="school"] h3 {
    background: linear-gradient(90deg, color-mix(in srgb, var(--c) 70%, #fff), color-mix(in srgb, var(--c2) 70%, #fff));
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}
.g-sec li { transition: background 0.3s ease; border-radius: 3px; }
.g-sec li.now { background: linear-gradient(90deg, color-mix(in srgb, var(--d2) 14%, transparent), transparent); }

/* Phones held upright: the pages fill the screen below a strip of the weave */
.grimoire.strip {
    top: var(--strip); bottom: 0;
    width: 100%;
    padding-top: 0;
    border-right: 0;
    border-top: 1px solid rgba(214, 180, 110, 0.4);
    border-radius: 14px 14px 0 0;
    transform: translateY(102%);
}
.grimoire-open .grimoire.strip { transform: none; }
.grimoire.strip .grim-scroll { padding: 14px 20px 30vh; }
.grimoire.strip .g-sec { margin-left: -14px; padding-left: 12px; }
@media (max-width: 700px) {
    .grimoire-open .zoom-controls { opacity: 0; pointer-events: none; }
    .grimoire-toggle span { display: none; }
    .grimoire-toggle { padding: 6px 9px; }
}

/* Phones held upright: the card is a sheet from the bottom, the bubble stays visible above it */
.card.sheet {
    left: 0; right: 0; top: auto; bottom: 0;
    width: auto !important;
    max-height: 56vh;
    border-radius: 14px 14px 0 0;
    transform: translateY(30px);
    transition: opacity 0.35s ease, transform 0.35s ease, visibility 0s linear 0.35s;
}
.card.sheet.open { transform: none; transition: opacity 0.35s ease, transform 0.35s ease, visibility 0s; }
.card.sheet .card-body { padding: 0 18px calc(16px + env(safe-area-inset-bottom)); }
.card.sheet h3 { font-size: 1.25rem; }

@media (max-width: 700px) {
    .intro { display: none; }
    /* the sheet covers the bottom: zoom controls move up out of its way while reading */
    .reading .zoom-controls { opacity: 0; pointer-events: none; }
}
.zoom-controls { transition: opacity 0.3s ease; }
/* Arrival through the Gateway's portal: the page opens out of its light (html.arriving, set in the <head>) */
html.arriving body { background: #07060f; }
.arrival-veil {
    position: fixed; inset: 0;
    z-index: 30;
    pointer-events: none;
    background: #07060f;
    animation: magic-arrive-fade 1.5s ease-in 0.35s forwards;
}
.arrival-veil::before {
    content: '';
    position: absolute;
    left: var(--x, 50%); top: var(--y, 50%);
    width: 40px; height: 40px; margin: -20px 0 0 -20px;
    border-radius: 50%;
    background: radial-gradient(circle, #fff 0, rgba(255, 220, 150, 0.95) 22%, rgba(180, 140, 255, 0.55) 50%, transparent 70%);
    animation: magic-arrive-bloom 1.7s cubic-bezier(0.2, 0.7, 0.2, 1) forwards;
}
@keyframes magic-arrive-bloom { from { transform: scale(0.6); opacity: 1; } 60% { opacity: 0.85; } to { transform: scale(55); opacity: 0; } }
@keyframes magic-arrive-fade { to { opacity: 0; visibility: hidden; } }

@media (prefers-reduced-motion: reduce) {
    .orb, .orb::after { animation: none !important; }
    .card, .card.sheet, .intro, .grimoire, .grimoire.strip { transition: none !important; }
}

/* ==========================================================================
   Visual quality tiers (html[data-quality], fx-quality.js)
   Light: the card does not blur the moving weave behind it (its background
   is already nearly opaque). Still: the same as the reduced-motion rules.
   ========================================================================== */
html[data-quality="light"] .card { backdrop-filter: none; -webkit-backdrop-filter: none; }
html[data-quality="still"] .orb,
html[data-quality="still"] .orb::after { animation: none !important; }
html[data-quality="still"] .card,
html[data-quality="still"] .card.sheet,
html[data-quality="still"] .intro,
html[data-quality="still"] .grimoire,
html[data-quality="still"] .grimoire.strip { transition: none !important; }
