/* MedIdle Wiki. One stylesheet, no build step: the same manuscript look as the game, in a light
   and a dark form that follow the reader's system setting. */
:root {
  --bg: #efe4cb;
  --surface: #fbf6e8;
  --inset: #f1e6cd;
  --ink: #2c2014;
  --muted: #6b5942;
  --link: #7c3210;
  --border: #c9b287;
  --frame: #a78a55;
  --accent: #4e6a2e;
  --accent-ink: #fff9e8;
  --warn: #8a4a12;
  --shadow: 0 1px 2px rgba(60, 40, 10, 0.18);
  --display: 'Alegreya', 'Iowan Old Style', Georgia, serif;
  --body: 'Alegreya Sans', 'Segoe UI', system-ui, sans-serif;
  --caps: 'Cinzel', 'Alegreya', Georgia, serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171c22;
    --surface: #20272f;
    --inset: #2a323c;
    --ink: #ece4d2;
    --muted: #a9a08d;
    --link: #e6b96e;
    --border: #3d4853;
    --frame: #5d6b78;
    --accent: #7fa24f;
    --accent-ink: #10150c;
    --warn: #e0a05a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-padding-top: 1rem; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 1.0625rem/1.5 var(--body); }
img { max-width: 100%; height: auto; }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
h1, h2, h3, h4 { font-family: var(--display); line-height: 1.15; margin: 0 0 0.5rem; }
h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); font-weight: 800; }
h2 { font-size: 1.5rem; font-weight: 700; margin-top: 2rem; padding-bottom: 0.25rem; border-bottom: 1px solid var(--border); }
h3 { font-size: 1.2rem; font-weight: 700; margin-top: 1.25rem; }
h4 { font: 700 0.75rem/1.2 var(--caps); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
p { margin: 0 0 0.75rem; }
ul, ol { margin: 0 0 0.75rem; padding-left: 1.3rem; }
li { margin: 0.2rem 0; }
code { font-size: 0.9em; background: var(--inset); padding: 0.05em 0.3em; border-radius: 3px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--accent-ink); padding: 0.5rem 0.75rem; z-index: 10; }
.skip:focus { left: 0.5rem; top: 0.5rem; }
.muted { color: var(--muted); }
.lead { font-size: 1.15rem; max-width: 70ch; }
.note { background: var(--inset); border-left: 4px solid var(--frame); padding: 0.5rem 0.75rem; border-radius: 0 4px 4px 0; max-width: 80ch; }
.missing { color: var(--warn); border-bottom: 1px dashed currentColor; cursor: help; }
.count { font: 700 0.8rem var(--body); color: var(--muted); background: var(--inset); padding: 0.05rem 0.45rem; border-radius: 999px; vertical-align: middle; }
.tag { font: 700 0.7rem var(--caps); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 0 0.45rem; }

/* ---------------------------------------------------------------- frame */
header.site { background: var(--surface); border-bottom: 2px solid var(--frame); box-shadow: var(--shadow); }
.bar { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; max-width: 1180px; margin: 0 auto; padding: 0.5rem 1rem; }
.brand { display: inline-flex; align-items: center; gap: 0.5rem; font: 800 1.5rem var(--display); color: var(--ink); text-decoration: none; }
.brand span { font: 700 0.8rem var(--caps); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); align-self: flex-end; padding-bottom: 0.3rem; }
.search { position: relative; flex: 1 1 260px; }
.search input, .filter input { width: 100%; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--frame); border-radius: 6px; padding: 0.45rem 0.7rem; }
#search-results { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 0.25rem; list-style: none; background: var(--surface); border: 1px solid var(--frame); border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); max-height: 70vh; overflow: auto; }
#search-results li { margin: 0; }
#search-results a { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.4rem 0.6rem; border-radius: 4px; color: var(--ink); text-decoration: none; }
#search-results a span { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
#search-results [aria-selected='true'] a, #search-results a:hover { background: var(--inset); }
#search-results .empty { padding: 0.4rem 0.6rem; color: var(--muted); }
.play { font: 700 0.95rem var(--body); background: var(--accent); color: var(--accent-ink); text-decoration: none; padding: 0.45rem 0.9rem; border-radius: 6px; white-space: nowrap; }
nav.main { display: flex; flex-wrap: wrap; gap: 0.15rem 0.25rem; max-width: 1180px; margin: 0 auto; padding: 0 0.75rem 0.4rem; align-items: center; }
nav.main a, nav.main summary { font: 700 0.95rem var(--body); color: var(--ink); text-decoration: none; padding: 0.3rem 0.6rem; border-radius: 6px; cursor: pointer; }
nav.main a:hover, nav.main summary:hover { background: var(--inset); }
nav.main a[aria-current] { background: var(--inset); box-shadow: inset 0 -3px 0 var(--accent); }
.more { position: relative; }
.more summary { list-style: none; }
.more summary::after { content: ' ▾'; }
.more summary::-webkit-details-marker { display: none; }
.more > div { position: absolute; z-index: 15; top: 100%; left: 0; min-width: 12rem; display: grid; background: var(--surface); border: 1px solid var(--frame); border-radius: 6px; padding: 0.25rem; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25); }
main { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
footer.site { border-top: 1px solid var(--border); color: var(--muted); font-size: 0.95rem; }
footer.site p { max-width: 1180px; margin: 0 auto; padding: 0.6rem 1rem 0; }
footer.site p:last-child { padding-bottom: 1.5rem; }
.crumbs { font-size: 0.95rem; color: var(--muted); margin-bottom: 0.5rem; }

/* ---------------------------------------------------------------- pieces */
.ent { display: inline-flex; align-items: center; gap: 0.3rem; vertical-align: middle; }
.ico { width: 24px; height: 24px; object-fit: contain; flex-shrink: 0; }
.ico--big { width: 40px; height: 40px; vertical-align: middle; margin-right: 0.4rem; }
.entity-head { display: flex; gap: 1.25rem; align-items: flex-start; flex-wrap: wrap; }
.entity-head > div { flex: 1 1 320px; min-width: 0; }
.portrait { width: 192px; height: 192px; object-fit: contain; background: var(--surface); border: 1px solid var(--frame); border-radius: 8px; box-shadow: var(--shadow); padding: 0.5rem; }
.portrait--item { width: 128px; height: 128px; }
.banner { display: block; width: 100%; height: clamp(140px, 28vw, 300px); object-fit: cover; border: 1px solid var(--frame); border-radius: 8px; box-shadow: var(--shadow); margin-bottom: 1rem; }
.banner--small { height: clamp(100px, 18vw, 180px); }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.6rem; }
.chips span { font: 700 0.8rem var(--body); background: var(--inset); border: 1px solid var(--border); border-radius: 999px; padding: 0.05rem 0.6rem; }
.facts { margin: 0.5rem 0 0; display: grid; gap: 0.3rem; }
.facts > div { display: grid; grid-template-columns: minmax(8.5rem, 11rem) 1fr; gap: 0.75rem; padding: 0.3rem 0; border-top: 1px solid var(--border); }
.facts dt { font-weight: 700; color: var(--muted); }
.facts dd { margin: 0; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.75rem; }
.stats > div { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem 0.75rem; }
.stats dl { margin: 0; display: grid; gap: 0.1rem; }
.stats dl > div { display: flex; justify-content: space-between; gap: 1rem; }
.stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.ways { list-style: none; padding: 0; display: grid; gap: 0.4rem; }
.ways li { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 0.45rem 0.7rem; }
.gate, .objectives { padding-left: 1.2rem; }
.objectives > li { margin: 0.5rem 0; }
.prompt { margin: 0.3rem 0; padding-left: 0.75rem; border-left: 3px solid var(--border); color: var(--muted); }
.stage { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.25rem 1rem 0.5rem; margin: 0.75rem 0; }
.stage h3 { margin-top: 0.75rem; }

.table-wrap { overflow-x: auto; margin: 0 0 1rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 1rem; }
caption { text-align: left; font-weight: 700; padding: 0.5rem 0.7rem; color: var(--muted); }
th, td { text-align: left; vertical-align: top; padding: 0.4rem 0.7rem; border-bottom: 1px solid var(--border); }
th { font: 700 0.75rem/1.3 var(--caps); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); background: var(--inset); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
table.wide td { min-width: 5rem; }

.tiles { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0.35rem; }
.tiles li { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 0.3rem 0.5rem; min-width: 0; }
.tiles .ent { max-width: 100%; }
.cards { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0.75rem; }
.cards li { margin: 0; }
.card { display: grid; gap: 0.25rem; height: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); }
.card:hover { border-color: var(--frame); }
.card img { width: 100%; height: 130px; object-fit: cover; border-radius: 5px; }
.card--small img { width: 64px; height: 64px; object-fit: contain; }
.card strong { font: 700 1.2rem var(--display); color: var(--link); }
.card span { color: var(--muted); font-size: 0.97rem; }
.card--text { padding: 0.75rem 0.9rem; align-content: start; }
.hero { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.hero img { width: 96px; height: 96px; }
.emblems { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; text-align: center; }
.emblems a { display: grid; justify-items: center; gap: 0.25rem; text-decoration: none; font: 700 1.05rem var(--display); }
.chain-card, .person { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.9rem 1rem; margin: 0.75rem 0; }
.chain-card > div, .person > div { flex: 1 1 300px; min-width: 0; }
.chain-card h2, .person h2 { margin-top: 0; border: 0; padding: 0; }
.chain { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.25rem 1rem 0.75rem; margin-top: 1.5rem; }
.chain h2 { font-size: 1.15rem; border: 0; margin-top: 0.75rem; }
.chain li[aria-current] { color: var(--ink); }
.dungeon, .project { margin-top: 1.5rem; }
.jump { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.jump a { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 0.1rem 0.7rem; text-decoration: none; font-weight: 700; font-size: 0.95rem; }
.filter label { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; font-weight: 700; }
.filter input { flex: 1 1 220px; max-width: 26rem; }
[hidden] { display: none !important; }

.spoiler { background: var(--inset); border: 1px dashed var(--frame); border-radius: 6px; margin: 0.5rem 0; }
.spoiler summary { cursor: pointer; font-weight: 700; padding: 0.4rem 0.7rem; }
.spoiler > div { padding: 0 0.9rem 0.6rem; }
.prose { max-width: 78ch; }
.prose h2 { margin-top: 1.75rem; }

@media (max-width: 620px) {
  .facts > div { grid-template-columns: 1fr; gap: 0; }
  .portrait { width: 128px; height: 128px; }
  .play { order: 3; }
}
@media print {
  header.site .search, .play, nav.main, .filter, .skip { display: none; }
  .spoiler { display: none; }
}
