/* ---------- Tokens ---------- */
:root {
  --bg: #f4eee2;
  --surface: #fbf8f1;
  --surface-2: #ece4d3;
  --text: #2a241c;
  --muted: #74685a;
  --line: #d9cdb6;
  --accent: #8a531a;
  --accent-soft: #e9d8bc;
  --link: #7a4a12;
  --link-visited: #6b4a6b;
  --red: #a33a2a;
  --shadow: 0 10px 40px rgba(40, 28, 10, .18);
  --fs: 18px;
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --bar-h: 48px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16130f; --surface: #1f1b16; --surface-2: #2a251e; --text: #e9e1d2; --muted: #a39682;
    --line: #3a332a; --accent: #d9a85b; --accent-soft: #3a2e1d; --link: #e0b06a; --link-visited: #c9a3c9;
    --red: #e0725f; --shadow: 0 10px 40px rgba(0, 0, 0, .5); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16130f; --surface: #1f1b16; --surface-2: #2a251e; --text: #e9e1d2; --muted: #a39682;
  --line: #3a332a; --accent: #d9a85b; --accent-soft: #3a2e1d; --link: #e0b06a; --link-visited: #c9a3c9;
  --red: #e0725f; --shadow: 0 10px 40px rgba(0, 0, 0, .5); color-scheme: dark;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 var(--sans);
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--link); }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 2px;
  height: calc(var(--bar-h) + var(--top));
  padding: var(--top) max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.bar-title {
  flex: 1; min-width: 0; text-align: center; text-decoration: none; color: var(--text);
  font: 600 16px/1 var(--serif); letter-spacing: .01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px;
}
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; flex: none; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg circle[r="1.4"] { fill: var(--text); stroke: none; }
.icon-btn.is-hidden { visibility: hidden; }
.progress {
  position: absolute; left: 0; bottom: -1px; height: 2px; width: 0; background: var(--accent);
  opacity: 0; transition: width .3s ease, opacity .3s ease;
}
.progress.on { opacity: 1; width: 70%; transition: width 4s cubic-bezier(.1,.6,.2,1), opacity .1s; }
.progress.done { opacity: 0; width: 100%; transition: width .2s ease, opacity .4s ease .2s; }

/* ---------- Layout ---------- */
main {
  max-width: 760px; margin: 0 auto; outline: none;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(48px + var(--bottom)) max(16px, env(safe-area-inset-left));
}

/* ---------- Home ---------- */
.hero { padding: 20px 2px 8px; }
.hero h1 { font: 700 34px/1.1 var(--serif); margin: 0 0 6px; letter-spacing: -.01em; }
.hero p { margin: 0; color: var(--muted); }
.home-search {
  display: flex; align-items: center; gap: 10px; width: 100%; margin: 18px 0 8px;
  padding: 13px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: 16px; text-align: left;
}
.home-search svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.section-label {
  font: 600 12px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  margin: 26px 2px 10px; display: flex; justify-content: space-between; align-items: baseline;
}
.section-label button { font-size: 12px; letter-spacing: .04em; color: var(--accent); text-transform: none; }
.games { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 560px) { .games { grid-template-columns: repeat(3, 1fr); } }
.game {
  display: flex; flex-direction: column; justify-content: flex-end; min-height: 76px;
  padding: 12px 14px; border-radius: 14px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); position: relative; overflow: hidden;
}
.game:active { background: var(--surface-2); }
.game b { font: 600 17px/1.2 var(--serif); }
.game span { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.game::before {
  content: ""; position: absolute; top: 12px; left: 14px; width: 18px; height: 3px; border-radius: 2px;
  background: var(--g, var(--accent));
}
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a, .list button.row {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px 14px;
  text-decoration: none; color: var(--text); text-align: left; min-height: 48px;
}
.list a:active, .list button.row:active { background: var(--surface-2); }
.list .ns { font-size: 12px; color: var(--muted); }
.list .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .chev { color: var(--muted); }
.empty { color: var(--muted); padding: 4px 2px; font-size: 15px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  color: var(--text); font-size: 14px; text-decoration: none;
}
.chip:active { background: var(--surface-2); }

/* ---------- Article chrome ---------- */
.kicker {
  font: 600 12px/1 var(--sans); letter-spacing: .1em; text-transform: uppercase; color: var(--accent);
  margin: 10px 0 6px;
}
.kicker a { color: inherit; text-decoration: none; }
.page-title { font: 700 30px/1.15 var(--serif); margin: 0 0 4px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.redirect-note { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.page-actions { display: flex; gap: 8px; margin: 12px 0 18px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px; color: var(--text); text-decoration: none;
}
.pill svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pill.on svg { fill: var(--accent); stroke: var(--accent); }
.page-foot {
  margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted);
}
.error-box { padding: 28px 4px; }
.error-box h2 { font: 700 24px/1.2 var(--serif); margin: 0 0 8px; }
.error-box p { color: var(--muted); }
.btn {
  display: inline-block; padding: 10px 16px; border-radius: 12px; background: var(--accent); color: var(--bg);
  text-decoration: none; font-weight: 600; margin: 4px 6px 4px 0;
}
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--line); }

/* skeleton */
.skel { border-radius: 8px; background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s linear infinite; margin: 10px 0; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- Article body (UESP HTML) ---------- */
.article { font: var(--fs)/1.6 var(--serif); overflow-wrap: break-word; }
.article p { margin: 0 0 .9em; }
.article h2, .article h3, .article h4, .article h5 { font-family: var(--serif); line-height: 1.25; }
.article h3 { font-size: 1.15em; margin: 1.4em 0 .5em; }
.article h4, .article h5 { font-size: 1.02em; margin: 1.2em 0 .4em; }
.article ul, .article ol { padding-left: 1.3em; margin: 0 0 1em; }
.article li { margin: .2em 0; }
.article dl { margin: 0 0 1em; }
.article dt { font-weight: 700; margin-top: .5em; }
.article dd { margin-left: 1em; }
.article a { text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--link) 35%, transparent); }
.article a.ext::after { content: " ↗"; font-size: .75em; opacity: .7; }
.article a.image, .article a.mw-file-description, .article a:has(> img) { border: 0; }
.article .redlink { color: var(--red); }
.article blockquote { margin: 1em 0; padding: .2em 0 .2em 1em; border-left: 3px solid var(--accent-soft); color: var(--muted); }
.article pre, .article code { font-family: ui-monospace, Menlo, monospace; font-size: .85em; }
.article pre { white-space: pre-wrap; background: var(--surface); padding: 10px; border-radius: 8px; border: 1px solid var(--line); }
.article hr { border: 0; border-top: 1px solid var(--line); margin: 1.5em 0; }
.article sup, .article sub { line-height: 0; }

/* Images */
.article img { max-width: 100%; height: auto; vertical-align: middle; }
.article .thumb, .article figure, .article .floatright, .article .floatleft, .article .tright, .article .tleft {
  float: none !important; clear: both; margin: 1em auto !important; max-width: 100%;
  display: table; text-align: center;
}
.article .thumbinner { width: auto !important; max-width: 100%; }
.article .thumbcaption, .article figcaption { font: 13.5px/1.4 var(--sans); color: var(--muted); padding: 6px 2px 0; text-align: left; }
.article .magnify { display: none; }
/* Small inline icons (e.g., game icons) shouldn't be blown up */
.article img[width] { max-width: 100%; }

/* Inline-styled widths, floats and multi-column lists are the main cause of
   UESP breaking on phones. Tame them. */
.article [style*="width"]:not(img):not(td):not(th) { max-width: 100% !important; }
.article div[style*="float"], .article table[style*="float"] { float: none !important; margin-left: 0 !important; margin-right: 0 !important; }
.article [style*="column"] { column-count: 1 !important; columns: auto !important; }
@media (min-width: 640px) { .article [style*="column"] { column-count: 2 !important; } }
.article [style*="position:absolute"], .article [style*="position: absolute"] { position: static !important; }

/* Tables: everything scrolls horizontally inside its own box */
.tscroll {
  overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 0 1.2em; max-width: 100%;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
}
.tscroll.fits { border: 0; background: none; }
.article table { border-collapse: collapse; font: 14px/1.4 var(--sans); margin: 0; }
.tscroll > table { min-width: 100%; }
.article table[style*="width"] { width: auto !important; }
.tscroll > table.infobox, .tscroll > table.wikitable.infobox { width: 100% !important; }
.article th, .article td { padding: 6px 8px; vertical-align: top; border: 1px solid var(--line); }
.tscroll > table > * > tr > :is(th, td) { border-top: 0; }
.article th { background: var(--surface-2); text-align: left; font-weight: 600; }
.article table.hiddentable td, .article table.hiddentable th,
.article table:not(.wikitable):not(.infobox) td { border: 0; }
.article table:not(.wikitable):not(.infobox) th { background: none; }
.article caption { font-weight: 600; padding: 8px; text-align: left; }
/* Neutralise hard-coded light backgrounds in dark mode */
:root[data-theme="dark"] .article [style*="background"],
:root[data-theme="dark"] .article [bgcolor] { background: var(--surface-2) !important; color: var(--text) !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .article [style*="background"],
  :root:not([data-theme="light"]) .article [bgcolor] { background: var(--surface-2) !important; color: var(--text) !important; }
}
:root[data-theme="dark"] .article [style*="color"] { color: inherit !important; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .article [style*="color"] { color: inherit !important; } }

/* Notices, hatnotes, boxes */
.article .hatnote, .article .dablink, .article .rellink { font-style: italic; color: var(--muted); font-size: .9em; margin: 0 0 .8em; }
.article .notice, .article .mbox, .article .ambox, .article .messagebox, .article .ombox, .article .tmbox {
  display: block; width: auto !important; margin: 0 0 1em !important; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line) !important; background: var(--surface) !important; font: 14px/1.45 var(--sans);
}
.article .notice table, .article .mbox table { font-size: inherit; }

/* Hidden-by-default UESP/MediaWiki chrome */
.article .mw-editsection, .article .toc, .article #toc, .article .navbox, .article .catlinks,
.article .printfooter, .article .mw-empty-elt, .article .noprint.navbox, .article .metadata.navbox { display: none !important; }

/* Collapsible sections */
.sec { border-top: 1px solid var(--line); }
.sec > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 14px 0; font: 700 1.3em/1.25 var(--serif); -webkit-user-select: none; user-select: none;
}
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary::after {
  content: ""; margin-left: auto; flex: none; width: 9px; height: 9px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg) translate(-3px, -3px);
  transition: transform .2s;
}
.sec:not([open]) > summary::after { transform: rotate(-45deg); }
.sec > summary h2 { font: inherit; margin: 0; }
.sec-body { padding-bottom: 8px; }

/* ---------- Search overlay ---------- */
.search-overlay {
  position: fixed; inset: 0; z-index: 40; background: var(--bg);
  padding-top: var(--top); display: flex; flex-direction: column;
}
.search-row { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.search-row input {
  flex: 1; min-width: 0; font-size: 17px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); outline: none; -webkit-appearance: none; appearance: none;
}
.search-row input:focus { border-color: var(--accent); }
.text-btn { color: var(--accent); font-size: 16px; padding: 8px 4px; }
.suggest { list-style: none; margin: 0; padding: 0 0 var(--bottom); overflow-y: auto; flex: 1; }
.suggest li { border-bottom: 1px solid var(--line); }
.suggest a { display: block; padding: 12px 16px; color: var(--text); text-decoration: none; }
.suggest a:active { background: var(--surface-2); }
.suggest .ns { display: block; font-size: 12px; color: var(--muted); }
.suggest .hint { color: var(--muted); padding: 14px 16px; font-size: 15px; }
.results .snip { display: block; font-size: 14px; color: var(--muted); margin-top: 3px; }
.results .snip .searchmatch { color: var(--text); font-weight: 600; }

/* ---------- Bottom sheet ---------- */
.scrim { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.35); animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 78vh;
  display: flex; flex-direction: column; background: var(--surface); border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow); animation: up .25s cubic-bezier(.2,.8,.2,1);
  padding-bottom: var(--bottom); max-width: 760px; margin: 0 auto;
}
.sheet-handle { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 4px; flex: none; }
.sheet-body { overflow-y: auto; padding: 4px 16px 16px; }
.sheet h3 { font: 600 12px/1 var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 14px 2px 8px; }
.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.sheet .list { background: var(--bg); }
.toc a { padding: 10px 14px; min-height: 44px; }
.toc .l2 { padding-left: 30px; font-size: 15px; }
.toc .l3 { padding-left: 46px; font-size: 14px; color: var(--muted); }
.toc .num { color: var(--muted); font-size: 13px; min-width: 1.8em; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: var(--top) 12px var(--bottom);
  animation: fade .2s;
}
.lightbox img { max-width: 100%; max-height: 80vh; object-fit: contain; }
.lightbox-cap { color: #ddd; font-size: 14px; margin-top: 12px; text-align: center; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--bottom)); transform: translateX(-50%); z-index: 70;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); animation: fade .2s;
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
