/* Cantrip CYOA V8.0, styled after Om1cr0n's interactive V7: parchment page, old-paper cards, Marck Script headings,
 * DM Sans centred body text, thick black row rules, blue glow on chosen items, grey points bar at the bottom. */
:root {
  --ink: #212121;              /* card text (V7 perkTextColor) */
  --ink-main: #374151;         /* page text */
  --muted: #4b5563;
  --glow: 0 0 20px rgb(31, 135, 232);   /* V7 chosen shadow */
  --chosen-tint: rgba(0, 0, 255, 0.1);  /* V7 chosen tier */
  --hover: rgba(0, 0, 0, 0.1);
  --link: #0051e1;
  --bar: #4b5563;
  --pill: rgb(87, 85, 122);
  --rule: 5px solid #000;
  --table: 2px solid #1f2937;
  --danger: #b91c1c;
  --head: 'Marck Script', cursive;
  --body: 'DM Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --quote: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; color: var(--ink-main); font-family: var(--body); font-size: 16px; line-height: 1.5;
  background: #e7db9f url(../images/bg-parchment.jpg) repeat;
}
a { color: var(--link); }
button { font-family: inherit; font-size: inherit; color: inherit; }
img { max-width: 100%; }
.loading { text-align: center; padding: 30vh 16px; font-family: var(--head); font-size: 2.4rem; font-weight: 600; color: var(--ink); }

/* ---------- page structure ---------- */
.wrap { max-width: 1400px; margin: 0 auto; padding: 8px 16px 110px; }
.marck { font-family: var(--head); font-weight: 600; }
h1, h2, h3, h4, h5 { font-family: var(--head); font-weight: 600; color: var(--ink); margin: 0; line-height: 1.2; }
.row { margin: 26px 0 40px; display: flex; flex-direction: column; gap: 16px; }
.row-rule { width: 90%; margin: 0 auto; border-bottom: var(--rule); }
.row-title { font-size: clamp(2.4rem, 6vw, 3.75rem); text-align: center; }
.row-sub { font-size: clamp(1.9rem, 4.5vw, 2.6rem); text-align: center; margin-top: 10px; }
.row-text { max-width: 1000px; margin: 0 auto; text-align: center; font-size: 1.125rem; font-weight: 500; color: var(--ink); }
.row-text p { margin: 0 0 10px; }
.cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; }
.cards > * { flex: 0 0 calc((100% / var(--cols, 3)) - 20px); min-width: 300px; max-width: 600px; }
.cards.c2 { --cols: 2; } .cards.c3 { --cols: 3; } .cards.c4 { --cols: 4; }
@media (max-width: 700px) { .cards > * { flex-basis: 100%; min-width: 0; } }

/* ---------- old-paper cards ---------- */
.paper { background: #efe6cf url(../images/paper.jpg) center / cover; color: var(--ink); border-radius: 4px; }
.pick { cursor: pointer; transition: box-shadow .15s; }
.pick:hover { box-shadow: 0 0 8px rgba(31, 135, 232, .35); }
.pick.chosen, .chosen-glow { box-shadow: var(--glow); }
.pick.chosen:hover { box-shadow: var(--glow); }
.pick.locked { cursor: not-allowed; opacity: .55; filter: grayscale(.5); }
.pick.locked:hover { box-shadow: none; }
.hl { border-radius: 4px; }
.hl:hover { background: var(--hover); }
.rule-in { width: 90%; margin: 6px auto 14px; border-bottom: var(--rule); }
.center { text-align: center; }
.italic { font-style: italic; }
.quote { font-family: var(--quote); font-style: italic; font-weight: 500; }
.b { font-weight: 700; }

/* ---------- header ---------- */
.title-block { text-align: center; padding: 6px 0 20px; color: var(--ink); }
.title-block h1 { font-size: clamp(2.6rem, 7vw, 3.75rem); }
.title-block .by { font-family: var(--head); font-size: 1.25rem; margin-top: 4px; }
.title-block .intro { max-width: 1000px; margin: 12px auto 0; font-size: 1.125rem; font-weight: 500; }
.title-block .credit { font-family: var(--head); font-size: 1.25rem; margin-top: 46px; }
.title-block .version { font-family: var(--head); font-size: 1.15rem; margin-top: 2px; }

/* ---------- scenarios ---------- */
.scenario { overflow: hidden; display: flex; flex-direction: column; }
.scenario > img { width: 100%; aspect-ratio: 2 / 1; object-fit: cover; display: block; }
.scenario h3 { font-size: 2.25rem; text-align: center; margin-top: 4px; }
.gain { font-family: var(--head); font-weight: 600; font-size: 1.15rem; text-align: center; }
.scenario .quote { padding: 12px 18px; text-align: center; margin: 0; }
.mods { padding: 0 14px 16px; display: flex; flex-direction: column; gap: 12px; margin-top: auto; }
.mods-title { font-family: var(--head); font-size: 1.5rem; text-align: center; }
.mod { padding: 8px 12px 10px; text-align: center; border-radius: 4px; background: rgba(255, 255, 255, .18); }
.mod h4 { font-size: 1.4rem; }
.mod .gain { font-size: 1rem; }
.mod p { margin: 4px 0 0; }
.general { padding: 14px 18px; text-align: center; }
.general h3 { font-size: 2.25rem; }
.stepper { display: inline-flex; align-items: center; gap: 8px; margin-top: 8px; }
.stepper button { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--ink); background: transparent; cursor: pointer; font-weight: 700; font-size: 1.1rem; }
.stepper button:hover { background: var(--hover); }
.stepper b { font-size: 1.3rem; min-width: 1.2em; }

/* ---------- rules ---------- */
.rules { max-width: 1000px; margin: 0 auto; color: var(--ink); font-size: 1.125rem; font-weight: 500; }
.rules .sec { margin: 6px 0; }
.rules .sec-head { display: flex; align-items: center; justify-content: center; gap: 10px; cursor: pointer; user-select: none; }
.rules .sec-head h4 { font-size: 2.25rem; text-align: center; }
.rules .sec-head .eye { font-size: 1.3rem; opacity: .7; }
.rules .sec-head:hover .eye { color: #ef4444; opacity: 1; }
.rules .sec-body { text-align: center; padding: 4px 0 10px; }
.rules ul { text-align: left; margin: 6px auto; max-width: 960px; padding-left: 1.3em; }
.rules li { margin: 4px 0; }
.table-scroll { overflow-x: auto; margin: 10px auto; }
table.t { border-collapse: collapse; margin: 0 auto; background: transparent; font-size: 1rem; }
table.t th, table.t td { border: var(--table); padding: 4px 10px; vertical-align: middle; text-align: center; }
table.t th { font-weight: 700; }
table.t tr.hl-row td { background: var(--chosen-tint); font-weight: 700; }
.legend { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; font-weight: 700; color: var(--ink); }
.legend span { border-radius: 4px; padding: 0 8px; }

/* ---------- prestidigitation ---------- */
.presti-card { max-width: 1200px; margin: 0 auto; }
.effect { padding: 12px 16px 14px; text-align: center; }
.effect h4 { font-size: 1.6rem; }
.effect .trains { font-size: .95rem; margin: 4px 0 8px; }
.effect .trains a { color: var(--ink); text-decoration: none; }
.effect .trains a:hover { text-decoration: underline; }
.effect .trains a.owned { font-weight: 700; color: var(--link); }
.effect .layer { margin: 6px 0; }
.effect .layer b { display: block; text-decoration: underline; }

/* ---------- quests ---------- */
.quest { display: flex; flex-direction: column; padding: 10px 16px 16px; }
.quest h3 { font-size: 1.5rem; text-align: center; }
.quest h3 img.forbid { width: 22px; height: 22px; vertical-align: -3px; margin: 0 6px; }
.quest .lead { display: flex; gap: 18px; align-items: center; padding: 6px 4px 14px; }
.quest .lead img.icon { width: 64px; height: 64px; object-fit: contain; flex: none; }
.quest .lead .chant { flex: 1; text-align: center; }
.quest .lead .chant.dark { color: #9b1c1c; }
.quest .txt { text-align: center; margin: 0 0 6px; }
.quest ul.rules-list { text-align: left; margin: 0 0 8px; padding-left: 1.3em; }
.quest .meta { text-align: center; margin-top: auto; }
.quest .meta > div { margin: 8px 0; }
.quest .meta b, .quest .txt b { color: var(--ink); }
.quest .opt { padding: 4px 8px; border-radius: 4px; cursor: pointer; }
.quest .opt:hover { background: var(--hover); }
.quest .opt.chosen { box-shadow: var(--glow); }
.quest .valid { text-align: center; font-size: .97rem; }
.quest .valid .total { font-weight: 700; margin-top: 8px; }
.quest .reward { margin: 10px auto 0; text-align: center; }
.quest select, .bar select, .planner select {
  font: inherit; color: var(--ink); background: rgba(255, 255, 255, .55); border: 2px solid var(--ink); border-radius: 4px; padding: 2px 6px; max-width: 100%;
}
.quest .prize-table { margin-top: 8px; }
.meta-pick { max-height: 220px; overflow: auto; columns: 2 160px; text-align: left; margin-top: 6px; }
.meta-pick label { display: block; break-inside: avoid; }
.meta-pick label.no { opacity: .45; text-decoration: line-through; }
.world-tag { text-align: center; font-weight: 700; }

/* ---------- cantrips ---------- */
.filter { width: 100%; max-width: 1200px; margin: 0 auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.filter .line { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; align-items: center; width: 100%; }
.filter input[type=search] { flex: 1; min-width: 200px; max-width: 520px; font: inherit; padding: 4px 12px; border: 2px solid var(--ink); border-radius: 4px; background: rgba(255, 255, 255, .5); color: var(--ink); }
.btn { font: inherit; font-weight: 700; padding: 3px 12px; border-radius: 4px; border: 2px solid var(--ink); background: transparent; color: var(--ink); cursor: pointer; }
.btn:hover { background: var(--hover); }
.btn.on { background: var(--ink); color: #f3ead2; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.school-btn { font-family: var(--head); font-weight: 600; font-size: 1.15rem; padding: 0 8px; border-radius: 4px; cursor: pointer; color: var(--ink); }
.school-btn:hover { background: var(--hover); }
.school-btn.on { box-shadow: var(--glow); }

.cantrip { width: 100%; max-width: 1200px; margin: 0 auto 28px; display: flex; flex-direction: column; gap: 8px; color: var(--ink); scroll-margin-top: 20px; }
.c-head { display: flex; gap: 0; align-items: stretch; }
.c-head .pic { flex: none; display: flex; align-items: center; }
.c-head .pic img { max-height: 120px; height: 120px; width: auto; aspect-ratio: 1; object-fit: cover; border-radius: 4px; display: block; }
.c-head .info { flex: 1; padding: 6px 12px 10px; }
.c-head .tline { display: flex; justify-content: space-around; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.c-head h3 { font-size: 1.875rem; }
.c-head .schools { font-family: var(--head); font-weight: 600; font-size: 1.25rem; }
.c-head .desc { text-align: center; margin: 8px 0 4px; }
.c-head .desc b { font-weight: 700; }
.c-head .desc b.up { color: #1d3fae; }
.c-head .status { display: flex; justify-content: center; gap: 14px; flex-wrap: wrap; font-size: .95rem; }
.c-head .status .cost { font-weight: 700; }
.c-head .status a { cursor: pointer; text-decoration: underline; color: var(--ink); font-weight: 700; }
.c-head .status a.forget { color: var(--danger); }
@media (max-width: 640px) {
  .c-head { flex-direction: column; }
  .c-head .pic { justify-content: center; padding-top: 8px; }
}
.c-attrs { padding: 6px 10px; }
.c-attrs table.t { font-size: .92rem; width: 100%; }
.c-attrs td.lab { font-weight: 700; white-space: nowrap; }
.c-attrs .chg { color: #1d3fae; font-weight: 700; }
.areas { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 1000px) { .areas { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .areas { grid-template-columns: 1fr; } }
.area { padding: 8px; text-align: center; display: flex; flex-direction: column; gap: 6px; }
.area h4 { font-size: 1.25rem; }
.tier { padding: 4px 6px 6px; border-radius: 4px; cursor: pointer; }
.tier:hover { background: var(--hover); }
.tier.got { background: rgba(0, 0, 255, 0.05); }
.tier.cur { background: var(--chosen-tint); box-shadow: var(--glow); }
.tier .tn { font-weight: 700; text-decoration: underline; }
.tier .td { margin-top: 4px; }
.tier .tm { margin-top: 4px; font-weight: 700; }
.tier .note { font-style: italic; font-size: .9rem; }
.over-box { width: 80%; margin: 4px auto 0; text-align: center; padding: 8px 14px 10px; cursor: pointer; }
@media (max-width: 640px) { .over-box { width: 100%; } }
.over-box h4 { font-size: 1.25rem; }
.over-box .on { font-weight: 700; text-decoration: underline; }
.over-box p { margin: 6px 0; }
.over-box.locked { cursor: not-allowed; }
.over-box .need { font-size: .9rem; font-style: italic; }
.addendum { width: 90%; margin: 0 auto; padding: 6px 12px 10px; text-align: center; }
@media (max-width: 640px) { .addendum { width: 100%; } }
.addendum .toggle { font-family: var(--head); font-weight: 600; font-size: 1.25rem; cursor: pointer; user-select: none; }
.addendum .toggle:hover { text-decoration: underline; }
.addendum table.t { font-size: .9rem; }
.addendum td.label { font-weight: 700; }
.c-foot { text-align: center; font-size: .92rem; }
.empty { text-align: center; padding: 20px; font-style: italic; color: var(--ink); }

/* ---------- grimoire ---------- */
.grim .sheet { padding: 14px 18px; }
.ledger { width: 100%; }
.ledger td { text-align: left !important; }
.ledger td.num { text-align: right !important; white-space: nowrap; }
.ledger tr.total td { font-weight: 700; }
.g-cantrip { padding: 12px 14px; text-align: center; }
.g-cantrip .gh { display: flex; gap: 12px; align-items: center; justify-content: center; }
.g-cantrip .gh img { width: 60px; height: 60px; border-radius: 4px; object-fit: cover; }
.g-cantrip h4 { font-size: 1.6rem; }
.planner { margin-top: 8px; text-align: left; }
.planner summary { cursor: pointer; font-family: var(--head); font-weight: 600; font-size: 1.2rem; text-align: center; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin: 16px 0; }

/* ---------- bottom bar (V7) ---------- */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: var(--bar); color: #e5e7eb;
  display: flex; align-items: center; justify-content: space-around; gap: 8px; padding: 8px; font-size: 1.125rem;
}
.bar .icon-btn { background: none; border: none; cursor: pointer; padding: 4px; color: #1f2937; display: flex; align-items: center; }
.bar .icon-btn:hover { color: #fdba74; }
.bar .icon-btn svg { width: 28px; height: 28px; }
.bar .mid { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; }
.bar .pill { background: var(--pill); color: #c4c0f2; border-radius: 999px; padding: 4px 14px; white-space: nowrap; }
.bar .pill.neg { background: #7f1d1d; color: #fecaca; }
.bar .detail { font-size: .9rem; color: #d1d5db; white-space: nowrap; }
.bar select { background: #374151; color: #e5e7eb; border-color: #1f2937; font-size: .95rem; }
@media (max-width: 640px) { .bar .detail { display: none; } .bar select { max-width: 120px; } }

.toast { position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%); background: #1f2937; color: #f9fafb; padding: 8px 18px; border-radius: 999px; z-index: 99; }
footer { text-align: center; color: var(--ink); margin-top: 50px; font-family: var(--head); font-size: 1.2rem; }

/* flex/grid children may shrink below their content (wide tables scroll inside .table-scroll instead) */
.cantrip, .cantrip > *, .c-head .info, .area, .row > *, .cards > * { min-width: 0; }
.table-scroll { max-width: 100%; }
