/* Iprix's Spells: one stylesheet for every page. Sections: base, navigation, tool pages, options dialog. */

/* ================= Base ================= */
:root {
  --night:    #140b22;  /* aubergine-black */
  --dusk:     #22123b;  /* panel violet */
  --violet:   #4b2a85;  /* deep amethyst */
  --amethyst: #8a5bd8;  /* main accent */
  --orchid:   #c9a2ff;  /* glow / links */
  --moon:     #f1e9ff;  /* text */
  --candle:   #e9c776;  /* small gold highlight */
  --nav-w: 15rem;       /* the sidebar when it is open */
  --rail-w: 3.75rem;    /* ... and retracted to a strip of icons */
}

* { box-sizing: border-box; }
html[data-nav="closed"] { --nav-w: var(--rail-w); }       /* the page makes room for the strip only; the full sidebar pops out over it */

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--moon);
  background-color: var(--night);
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff8 50%, transparent),
    radial-gradient(1px 1px at 34% 72%, #fff6 50%, transparent),
    radial-gradient(1.5px 1.5px at 61% 31%, #fff7 50%, transparent),
    radial-gradient(1px 1px at 83% 64%, #fff6 50%, transparent),
    radial-gradient(1px 1px at 92% 12%, #fff8 50%, transparent),
    radial-gradient(1px 1px at 47% 91%, #fff5 50%, transparent),
    radial-gradient(ellipse at 75% -10%, #4b2a8566, transparent 60%),
    radial-gradient(ellipse at 10% 110%, #3a1b6a55, transparent 55%);
  background-attachment: fixed;
}

a { color: var(--orchid); }
:focus-visible { outline: 2px solid var(--candle); outline-offset: 3px; }

/* ---------- Navigation ---------- */
/* #site-nav is the column the page reserves; .nav-panel is what you see. Retracted, the panel is as wide as the column. Popped
   out (.peek), it is wider and lies over the page, so nothing on the page moves. */
#site-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 100vh;
  background: linear-gradient(180deg, #2a1650f0, #170c2af0);
  border-right: 1px solid #8a5bd855;
  box-shadow: 8px 0 30px #0006;
}
.nav-panel {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--nav-w);
  display: flex;
  flex-direction: column;
  padding: 1.75rem 1.25rem;
  overflow: hidden auto;
  background: linear-gradient(180deg, #2a1650f0, #170c2af0);
  border-right: 1px solid #8a5bd855;
  transition: width .2s ease, padding .2s ease, box-shadow .2s ease;
}
.nav-panel.peek { width: 15rem; box-shadow: 14px 0 40px #000b; }

.nav-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: 2.25rem; }
.brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  min-width: 0;
  text-decoration: none;
  color: var(--moon);
}
.brand-text { white-space: nowrap; }
.nav-toggle, .nav-expand {
  flex: none;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--orchid);
  cursor: pointer;
  background: none;
  border: 1px solid #8a5bd855;
  border-radius: .4rem;
  transition: background .2s, color .2s;
}
.nav-toggle:hover, .nav-expand:hover { background: #8a5bd833; color: #fff; }
.nav-expand { display: none; margin: -1.25rem auto 1rem; }
.sigil {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  font-size: 1.5rem;
  color: var(--candle);
  border: 1px solid var(--amethyst);
  border-radius: 50%;
  box-shadow: 0 0 14px #8a5bd888 inset, 0 0 12px #8a5bd855;
}
.brand-text { font-weight: 600; font-size: 1rem; line-height: 1.2; }

#site-nav ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; }
#site-nav li a {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .55rem .75rem;
  border-radius: .4rem;
  text-decoration: none;
  color: var(--moon);
  transition: background .2s, color .2s;
}
#site-nav li a .ico { flex: none; width: 1.3rem; text-align: center; color: var(--candle); }
#site-nav li a .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#site-nav li a:hover { background: #8a5bd833; color: #fff; }
#site-nav li a[aria-current="page"] {
  background: linear-gradient(90deg, #8a5bd855, transparent);
  box-shadow: inset 3px 0 0 var(--candle);
}

.leave {
  margin-top: auto;
  padding: .5rem .75rem;
  font: inherit;
  font-size: .85rem;
  color: var(--orchid);
  background: none;
  border: 1px solid #8a5bd855;
  border-radius: .4rem;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.leave:hover { background: #8a5bd833; color: #fff; }
.leave { display: flex; align-items: center; gap: .8rem; }
.leave .ico { flex: none; width: 1.3rem; text-align: center; color: var(--candle); }
.leave .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

[hidden] { display: none !important; }

/* ---------- Page ---------- */
.page { padding: 4rem clamp(1.5rem, 5vw, 5rem) 5rem; max-width: 62rem; }

h1 {
  margin: 0 0 1rem;
  font-family: "Uncial Antiqua", serif;
  font-weight: 400;
  font-size: clamp(2.2rem, 5.5vw, 4rem);
  line-height: 1.12;
  color: var(--moon);
  text-shadow: 0 0 28px #8a5bd8aa;
  animation: glow 5s ease-in-out infinite alternate;
}

@keyframes glow {
  from { text-shadow: 0 0 14px #8a5bd855; }
  to   { text-shadow: 0 0 36px #c9a2ffcc, 0 0 6px #8a5bd8; }
}

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  body { grid-template-columns: 1fr; }
  #site-nav { position: static; height: auto; border-right: 0; box-shadow: none; }
  .nav-panel {
    position: static;
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem 1.5rem;
    padding: 1rem;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid #8a5bd855;
  }
  .nav-head { margin: 0; }
  .nav-toggle, .nav-expand { display: none !important; }              /* the top bar is always complete */
  .brand { margin: 0; }
  .leave { margin: 0 0 0 auto; }
  #site-nav ul { grid-auto-flow: column; }
}


@media (prefers-reduced-motion: reduce) {
  h1 { animation: none; }
  html { scroll-behavior: auto; }
}
/* ================= Tool pages: tabs, panels, forms, buttons, status ================= */
.page.wide { max-width: 84rem; }
h1.tool-title { font-size: clamp(1.8rem, 4vw, 2.6rem); margin-bottom: .4rem; animation: none; }
/* The description of a tool page: collapsed, the page itself starts at the controls */
.tool-about { max-width: 62rem; margin: 0; font-size: .9rem; color: #d9cbf2; }
.tool-about summary { width: max-content; cursor: pointer; color: var(--orchid); }
.tool-about p { margin: .5rem 0 0; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  margin-top: 1.75rem;
  border-bottom: 1px solid #8a5bd855;
}
.tab {
  margin-bottom: -1px;
  padding: .6rem 1rem;
  font: inherit;
  font-weight: 500;
  color: var(--moon);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: .4rem .4rem 0 0;
  cursor: pointer;
}
.tab:hover { background: #8a5bd822; }
.tab[aria-selected="true"] { background: #8a5bd833; border-bottom-color: var(--candle); }

.panel {
  padding: 1.25rem;
  background: #22123bcc;
  border: 1px solid #8a5bd855;
  border-top: 0;
  border-radius: 0 0 .6rem .6rem;
}
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; margin-bottom: .9rem; }
.fields.spaced { margin-top: 1.1rem; }
.field { display: grid; gap: .3rem; font-size: .9rem; color: #d9cbf2; }

input[type="text"], select, textarea {
  font: inherit;
  color: var(--moon);
  background: #140b22;
  border: 1px solid #8a5bd877;
  border-radius: .4rem;
  padding: .55rem .7rem;
}
input[type="text"]:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--candle); outline-offset: 1px; }

.options { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; margin-bottom: .9rem; }
.check { display: flex; align-items: center; gap: .45rem; font-size: .95rem; }
.check input { accent-color: var(--amethyst); }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.btn {
  font: inherit;
  font-size: .92rem;
  font-weight: 500;
  color: var(--moon);
  background: #3a1f6b;
  border: 1px solid #8a5bd8aa;
  border-radius: .4rem;
  padding: .45rem .85rem;
  cursor: pointer;
  transition: background .15s;
}
.btn:hover { background: #4b2a85; }
.btn.primary { background: var(--amethyst); border-color: var(--orchid); color: #fff; }
.btn.primary:hover { background: #9b6ee6; }
.btn.small { font-size: .82rem; padding: .25rem .6rem; }

.hint { margin: .9rem 0 0; font-size: .9rem; color: #c9a2ffcc; }
.status { min-height: 1.5rem; margin: .9rem 0 0; font-size: .92rem; color: var(--orchid); }
.status.error { color: #ff9fb3; }

/* ================= Options dialog, sidebar footer, animations off ================= */

/* ---------- Animations off ---------- */
html[data-motion="off"] { scroll-behavior: auto; }
html[data-motion="off"] *,
html[data-motion="off"] *::before,
html[data-motion="off"] *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
html[data-motion="off"] .spell { opacity: 1 !important; }
html[data-motion="off"] .spell:hover,
html[data-motion="off"] .spell:focus-visible { transform: none; }

/* ---------- The retracted strip (wide screens only): icons and the sigil; everything else waits for the pop-out ---------- */
@media (min-width: 761px) {
  html[data-nav="closed"] .nav-panel:not(.peek) { padding: 1.75rem .55rem; }
  html[data-nav="closed"] .nav-panel:not(.peek) .nav-head { justify-content: center; }
  html[data-nav="closed"] .nav-panel:not(.peek) :is(.brand-text, .nav-toggle, .lbl, li.group) { display: none; }
  html[data-nav="closed"] .nav-panel:not(.peek) .nav-expand { display: grid; }
  html[data-nav="closed"] .nav-panel:not(.peek) li a { justify-content: center; padding: .55rem 0; }
  html[data-nav="closed"] .nav-panel:not(.peek) .leave { justify-content: center; padding: .55rem 0; }
  html[data-nav="closed"] .nav-panel:not(.peek) { cursor: pointer; }
  html[data-nav="closed"] .nav-panel.peek .nav-toggle { display: none; }      /* only an opened sidebar has the « button */
  html[data-nav="open"] .nav-expand { display: none; }
}

/* ---------- Sidebar footer ---------- */
#site-nav .nav-foot { margin-top: auto; padding-top: 1.5rem; display: grid; gap: .5rem; }
#site-nav .nav-foot .leave { margin: 0; }
@media (max-width: 760px) {
  #site-nav .nav-foot { margin: 0 0 0 auto; padding: 0; display: flex; }
}

/* ---------- Options dialog (colours come from the theme variables) ---------- */
#options {
  width: min(27rem, 92vw);
  padding: 1.4rem;
  color: var(--moon);
  background: var(--dusk);
  border: 1px solid var(--amethyst);
  border-radius: .7rem;
  box-shadow: 0 20px 60px #000a;
}
#options::backdrop { background: #000a; }
#options h2 { margin: 0 0 1.1rem; font-size: 1.2rem; }
#options fieldset { margin: 0 0 1.2rem; padding: 0; border: 0; }
#options legend { margin-bottom: .55rem; padding: 0; font-size: .72rem; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--orchid); }
#options small { display: block; font-size: .8rem; line-height: 1.35; opacity: .75; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.choice { display: grid; gap: .25rem; align-content: start; padding: .55rem; cursor: pointer; border: 2px solid transparent; border-radius: .6rem; background: #8a5bd811; }
.choice:hover { background: #8a5bd822; }
.choice:has(input:checked) { border-color: var(--candle); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:focus-visible) { outline: 2px solid var(--candle); outline-offset: 2px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; cursor: pointer; }
#options input[role="switch"] {
  appearance: none; flex: none; width: 2.9rem; height: 1.55rem; margin: 0; cursor: pointer;
  border: 1px solid #0004; border-radius: 1rem;
  background: radial-gradient(circle closest-side, #fff 96%, transparent) .2rem center / 1.15rem 1.15rem no-repeat, var(--track, #8a5bd855);
  transition: background-position .2s, background-color .2s;
}
#options input[role="switch"]:checked {
  background: radial-gradient(circle closest-side, #fff 96%, transparent) calc(100% - .2rem) center / 1.15rem 1.15rem no-repeat, var(--amethyst);
}
#options input[role="switch"]:focus-visible { outline: 2px solid var(--candle); outline-offset: 2px; }

.opt-actions { display: flex; justify-content: flex-end; }
.opt-done { padding: .5rem 1.3rem; font: inherit; font-weight: 600; color: #fff; cursor: pointer; background: var(--amethyst); border: 1px solid var(--orchid); border-radius: .4rem; }
.opt-done:hover { filter: brightness(1.12); }

/* ---------- Added: signed-out link, notes, sign-in-only content ---------- */
a.leave { text-decoration: none; }

/* ---------- Rules several pages used to repeat ---------- */
.btn:disabled { opacity: .45; cursor: default; }
.btn[aria-pressed="true"] { background: var(--amethyst); border-color: var(--candle); }
input[type="range"] { width: 100%; accent-color: var(--amethyst); }
.nomargin { margin: 0; }
.empty-note { margin-top: 1.5rem; color: #d9cbf2; }
.stage-box { margin-top: .75rem; padding: 1rem; background: #22123bcc; border: 1px solid #8a5bd855; border-radius: .6rem; }

/* Category headings in the sidebar (the server sends them when a folder inside pages/ holds pages) */
#site-nav li.group { margin-top: .8rem; padding: 0 .75rem; font-size: .7rem; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--orchid); }
.where { color: inherit; }
html[data-auth="yes"] .signin-only { display: none; }
