/* Battleworld companion site
   Palette: river-slate ink on reed-grey page; copper (Pebble's shell) is the single accent. */
:root {
  --page: #E9EDE6;
  --panel: #F4F6F1;
  --ink: #1E2A2E;
  --ink-soft: #4E5E5F;
  --rule: #BCC6BE;
  --reed: #5E7F42;
  --copper: #A4642F;
  --copper-soft: #E7C8A9;
  --water: #2E5E73;
  --hatch: rgba(30, 42, 46, 0.07);
  --ui: "Bricolage Grotesque", system-ui, sans-serif;
  --read: "Literata", Georgia, serif;
  --rail-w: 15.5rem;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #132024; --panel: #192A2F; --ink: #DCE4DE; --ink-soft: #9AABA6; --rule: #2E4146;
    --reed: #93B373; --copper: #D69257; --copper-soft: #5A3B22; --water: #7FB0C4; --hatch: rgba(220, 228, 222, 0.06);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #132024; --panel: #192A2F; --ink: #DCE4DE; --ink-soft: #9AABA6; --rule: #2E4146;
  --reed: #93B373; --copper: #D69257; --copper-soft: #5A3B22; --water: #7FB0C4; --hatch: rgba(220, 228, 222, 0.06);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font-family: var(--ui); font-size: 1rem; line-height: 1.5; }
a { color: inherit; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--copper); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: var(--page); padding: .5rem 1rem; z-index: 1000; }
.skip:focus { left: 1rem; }
.noscript { padding: 2rem; }

/* Shell: notebook spine on the left, content on the right */
.shell { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100vh; }
.rail {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1.75rem;
  padding: 1.5rem 1.25rem; border-right: 1px solid var(--rule);
  background: linear-gradient(90deg, var(--panel), var(--page));
}
.brand { font-weight: 800; font-size: 1.75rem; letter-spacing: -0.02em; text-decoration: none; font-variation-settings: "opsz" 96; }
.tabs { display: flex; flex-direction: column; gap: .15rem; }
.tabs a { text-decoration: none; padding: .55rem .75rem; border-radius: .35rem; font-weight: 600; color: var(--ink-soft); border-left: 3px solid transparent; }
.tabs a:hover { color: var(--ink); background: var(--hatch); }
.tabs a[aria-current="page"] { color: var(--ink); border-left-color: var(--copper); background: var(--hatch); }

/* The bookmark ribbon: the one bold element */
.ribbon {
  margin-top: auto; position: relative; padding: 1rem .9rem 1.4rem; color: #FBF4EC;
  background: var(--copper); border-radius: .3rem .3rem 0 0;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% calc(100% - .9rem), 0 100%);
}
.ribbon label { display: block; font-size: .85rem; font-weight: 600; }
.ribbon select { width: 100%; margin: .35rem 0 .4rem; font: inherit; font-weight: 600; padding: .35rem .4rem; border-radius: .25rem; border: 0; background: #FBF4EC; color: #3B2410; }
.ribbon-note { margin: 0 0 .6rem; font-size: .8rem; opacity: .9; }
.author-toggle { display: flex !important; gap: .4rem; align-items: center; font-weight: 400 !important; font-size: .8rem !important; }

main { min-width: 0; padding: 2rem clamp(1rem, 4vw, 3rem) 4rem; }
main:focus { outline: none; }
h1, h2, h3 { line-height: 1.15; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 4vw, 3rem); font-weight: 800; margin: 0 0 .5rem; }
h2 { font-size: 1.5rem; font-weight: 700; margin: 2rem 0 .75rem; }
h3 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; }
.lede { color: var(--ink-soft); max-width: 42rem; font-size: 1.1rem; margin: 0 0 1.5rem; }
.muted { color: var(--ink-soft); }
.back { display: inline-block; margin-bottom: 1rem; color: var(--ink-soft); text-decoration: none; }
.back:hover { color: var(--ink); text-decoration: underline; }
.btn { display: inline-block; font: inherit; font-weight: 600; padding: .6rem 1rem; border-radius: .35rem; border: 1px solid var(--ink); background: var(--ink); color: var(--page); text-decoration: none; cursor: pointer; }
.btn.secondary { background: transparent; color: var(--ink); }
.btn:hover { filter: brightness(1.1); }
.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }

/* Pending art plate: where generated images will appear */
.plate { margin: 0; width: 100%; position: relative; overflow: hidden; border-radius: .4rem; background: var(--panel); border: 1px solid var(--rule); }
.plate img { width: 100%; height: 100%; object-fit: cover; }
.plate.contain img { object-fit: contain; background: #fff; }
.plate.pending {
  display: flex; flex-direction: column; justify-content: flex-end; padding: .75rem;
  background-image: repeating-linear-gradient(135deg, var(--hatch) 0 2px, transparent 2px 10px); background-color: var(--panel);
}
.plate.pending .plate-title { font-weight: 600; font-size: .9rem; }
.plate.pending .plate-path { font-size: .75rem; color: var(--ink-soft); word-break: break-all; }
.ratio-1 { aspect-ratio: 1 / 1; }
.ratio-2 { aspect-ratio: 2 / 1; }
.ratio-43 { aspect-ratio: 4 / 3; }
.ratio-34 { aspect-ratio: 3 / 4; }

/* Home */
.home-hero { display: grid; gap: 1.5rem; }
.home-hero h1 { font-size: clamp(3rem, 9vw, 6.5rem); font-weight: 800; letter-spacing: -0.04em; margin: 0; font-variation-settings: "opsz" 96; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: 1rem; margin-top: 2rem; }
.home-grid a { text-decoration: none; padding: 1rem; border: 1px solid var(--rule); border-radius: .4rem; background: var(--panel); }
.home-grid a:hover { border-color: var(--ink-soft); }
.home-grid strong { display: block; font-size: 1.1rem; }

/* Cards and grids */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr)); gap: 1rem; }
.card { text-decoration: none; display: flex; flex-direction: column; gap: .5rem; }
.card .name { font-weight: 700; font-size: 1.05rem; }
.card .meta { font-size: .85rem; color: var(--ink-soft); }
.card:hover .name { text-decoration: underline; }
.locked { opacity: .55; }
.badge { display: inline-block; font-size: .75rem; padding: .1rem .45rem; border-radius: 1rem; border: 1px solid var(--rule); color: var(--ink-soft); }
.badge.spoiler { border-color: var(--copper); color: var(--copper); }

.filters { display: flex; flex-wrap: wrap; gap: .75rem; margin-bottom: 1.25rem; }
.filters input, .filters select { font: inherit; padding: .45rem .6rem; border-radius: .3rem; border: 1px solid var(--rule); background: var(--panel); color: var(--ink); }

/* Family page */
.family-head { display: grid; grid-template-columns: minmax(12rem, 18rem) 1fr; gap: 1.5rem; align-items: start; }
.forms { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: .9rem; }
.form-card .stage { font-size: .8rem; color: var(--ink-soft); }
.prose { max-width: 46rem; }
.prose table { border-collapse: collapse; width: 100%; font-size: .9rem; margin: 1rem 0; display: block; overflow-x: auto; }
.prose th, .prose td { border-bottom: 1px solid var(--rule); padding: .4rem .5rem; text-align: left; vertical-align: top; }
.prose code { font-size: .85em; }
.prose blockquote { margin: 1rem 0; padding-left: 1rem; border-left: 3px solid var(--rule); color: var(--ink-soft); }

/* Novel */
.toc { list-style: none; padding: 0; margin: 0; max-width: 40rem; }
.toc li { border-bottom: 1px solid var(--rule); }
.toc a { display: grid; grid-template-columns: 3rem 1fr auto; gap: .75rem; align-items: baseline; padding: .9rem .25rem; text-decoration: none; }
.toc .num { font-weight: 800; color: var(--copper); font-size: 1.25rem; }
.toc .t { font-family: var(--read); font-size: 1.15rem; }
.toc .w { font-size: .8rem; color: var(--ink-soft); }
.toc .read .t::after { content: " (read)"; font-family: var(--ui); font-size: .8rem; color: var(--reed); }
.reader { max-width: 36rem; margin: 0 auto; font-family: var(--read); font-size: 1.15rem; line-height: 1.72; }
.reader h1 { font-family: var(--ui); font-size: 1rem; font-weight: 600; color: var(--copper); margin: 0; letter-spacing: 0; }
.reader h2 { font-family: var(--read); font-size: clamp(1.8rem, 4vw, 2.4rem); font-weight: 600; margin: .25rem 0 2.5rem; }
.reader p { margin: 0 0 1.05em; }
.reader hr { border: 0; text-align: center; margin: 2rem 0; }
.reader hr::after { content: "~"; color: var(--ink-soft); font-size: 1.4rem; }
/* Chapter navigation bar (top of reader) */
.chap-bar { max-width: 36rem; margin: 0 auto 1.75rem; display: flex; align-items: center; justify-content: space-between; gap: .6rem 1rem; flex-wrap: wrap; padding-bottom: .9rem; border-bottom: 1px solid var(--rule); }
.chap-bar .back { margin: 0; }
.chap-where { display: flex; flex-direction: column; gap: .1rem; }
.chap-jump { display: flex; align-items: center; gap: .4rem; min-width: 0; }
.chap-jump select { font: inherit; font-size: .95rem; color: var(--ink); background: var(--panel); border: 1px solid var(--rule); border-radius: .35rem; padding: .4rem .5rem; min-width: 0; max-width: 16rem; cursor: pointer; }
.chap-jump select:hover { border-color: var(--copper); }
.chap-step { white-space: nowrap; text-decoration: none; font-weight: 600; font-size: .9rem; color: var(--ink); padding: .4rem .6rem; border: 1px solid var(--rule); border-radius: .35rem; }
.chap-step:hover { border-color: var(--copper); color: var(--copper); }
.chap-step.is-off { opacity: .35; pointer-events: none; }
.chap-count { font-size: .8rem; color: var(--ink-soft); white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 560px) { .chap-where { flex-direction: row; align-items: baseline; justify-content: space-between; flex-basis: 100%; } .chap-jump { order: 3; flex-basis: 100%; } .chap-jump select { flex: 1; max-width: none; } }
.reader-nav { max-width: 36rem; margin: 3rem auto 0; display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; font-family: var(--ui); }

/* Map */
.map-wrap { display: grid; grid-template-columns: 1fr 17rem; gap: 1rem; }
#map { height: calc(100vh - 9rem); min-height: 28rem; border-radius: .4rem; border: 1px solid var(--rule); background: #2E5E73; }
.map-side { display: flex; flex-direction: column; gap: 1rem; font-size: .9rem; }
.map-side fieldset { border: 1px solid var(--rule); border-radius: .4rem; padding: .6rem .8rem; margin: 0; }
.map-side legend { font-weight: 700; padding: 0 .3rem; }
.map-side label { display: flex; gap: .45rem; align-items: center; padding: .15rem 0; }
.leaflet-container { font-family: var(--ui); }
.lbl-land { font-weight: 800; font-size: 15px; color: #1E2A2E; text-shadow: 0 0 3px #E9EDE6; white-space: nowrap; letter-spacing: .02em; }
.lbl-sea { font-style: italic; font-size: 13px; color: #DDEBF0; white-space: nowrap; }
.lbl-feature { font-size: 12px; color: #2B3B2E; white-space: nowrap; font-style: italic; }
.popup-plate { width: 220px; margin-top: .4rem; }
.popup-plate .plate { aspect-ratio: 4/3; }
.sheet-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: 1rem; margin-top: 1rem; }

.dialog { position: fixed; inset: 0; background: rgba(10, 16, 18, .75); display: none; align-items: center; justify-content: center; padding: 1rem; z-index: 2000; }
.dialog.open { display: flex; }
.dialog-inner { background: var(--page); border-radius: .5rem; padding: 1rem; max-width: 72rem; width: 100%; }

/* Mobile: the spine becomes a bottom bar */
@media (max-width: 52rem) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: fixed; bottom: 0; top: auto; left: 0; right: 0; height: auto; z-index: 1500; flex-direction: row; align-items: center; gap: .5rem; padding: .4rem .6rem; border-right: 0; border-top: 1px solid var(--rule); background: var(--panel); }
  .brand { display: none; }
  .tabs { flex-direction: row; flex: 1; justify-content: space-around; }
  .tabs a { padding: .5rem .4rem; font-size: .85rem; border-left: 0; border-bottom: 3px solid transparent; }
  .tabs a[aria-current="page"] { border-bottom-color: var(--copper); }
  .ribbon { margin: 0; padding: .35rem .5rem; clip-path: none; border-radius: .3rem; max-width: 8.5rem; }
  .ribbon label[for], .ribbon-note, .author-toggle { display: none !important; }
  .ribbon select { margin: 0; font-size: .8rem; }
  main { padding: 1.25rem 1rem 6rem; }
  .map-wrap, .family-head { grid-template-columns: 1fr; }
  #map { height: 60vh; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
.lbl-capital { display: inline-block; transform: translate(10px, -50%); font-size: 12px; font-weight: 600; color: #1E2A2E; background: rgba(233, 237, 230, .88); padding: 0 .3rem; border-radius: 2px; white-space: nowrap; }

.forms .plate.pending .plate-path, .grid .plate.pending .plate-path { font-size: .68rem; }


/* ---------- Read aloud ---------- */
.tts-bar { position: sticky; top: 0; z-index: 20; max-width: 36rem; margin: 0 auto 1.5rem; padding: .6rem .75rem .5rem; background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; font-family: var(--ui); font-size: .9rem; box-shadow: 0 4px 14px rgba(0,0,0,.06); }
.tts-row { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .5rem; }
.tts-btn { font: inherit; border: 1px solid var(--rule); background: var(--page); color: var(--ink); border-radius: 7px; padding: .35rem .6rem; cursor: pointer; min-height: 2.2rem; }
.tts-btn:hover { border-color: var(--copper); }
.tts-btn:focus-visible, .tts-field select:focus-visible { outline: 2px solid var(--copper); outline-offset: 2px; }
.tts-main { background: var(--copper); border-color: var(--copper); color: #fff; font-weight: 600; min-width: 5.5rem; }
.tts-bar.is-playing .tts-main { background: var(--ink); border-color: var(--ink); color: var(--page); }
.tts-field { display: inline-flex; align-items: center; gap: .3rem; color: var(--ink-soft); }
.tts-field select { font: inherit; color: var(--ink); background: var(--page); border: 1px solid var(--rule); border-radius: 7px; padding: .3rem .35rem; max-width: 13rem; }
.tts-voice { flex: 1 1 12rem; }
.tts-voice select { width: 100%; max-width: none; }
.tts-more { flex-basis: 100%; color: var(--ink-soft); }
.tts-more summary { cursor: pointer; width: max-content; }
.tts-more label { display: block; margin: .3rem 0; color: var(--ink); }
.tts-more p { margin: .3rem 0 0; font-size: .82rem; }
.tts-progress { height: 3px; background: var(--rule); border-radius: 3px; margin-top: .5rem; overflow: hidden; }
.tts-progress span { display: block; height: 100%; width: 0; background: var(--copper); transition: width .3s ease; }
.tts-status { margin: .3rem 0 0; min-height: 0; font-size: .82rem; color: var(--ink-soft); }
.tts-status:empty { display: none; }
.reader.tts-ready .tts-w { cursor: pointer; border-radius: 3px; }
.reader.tts-ready .tts-w:hover { text-decoration: underline dotted var(--ink-soft); text-underline-offset: 3px; }
.reader .tts-s-on { background: color-mix(in srgb, var(--copper-soft) 55%, transparent); }
.reader .tts-w-on { background: var(--copper); color: #fff; box-shadow: 0 0 0 2px var(--copper); }
@media (prefers-reduced-motion: reduce) { .tts-progress span { transition: none; } }
@media (max-width: 640px) { .tts-bar { border-radius: 0; margin-left: -1rem; margin-right: -1rem; } .tts-field select { max-width: 9rem; } }

.tts-btn, .tts-field select { -webkit-appearance: none; appearance: none; }
.tts-btn { background: color-mix(in srgb, var(--page) 70%, var(--panel)); color: var(--ink); line-height: 1.2; }
.tts-btn:hover { background: var(--page); color: var(--copper); }
.tts-field select { padding-right: 1.4rem; background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%); background-position: right .65rem center, right .4rem center; background-size: .25rem .25rem; background-repeat: no-repeat; }
.tts-main, .tts-main:hover { background: var(--copper); border-color: var(--copper); color: var(--page); }
.tts-bar.is-playing .tts-main { background: var(--ink); border-color: var(--ink); color: var(--page); }
.tts-more summary { color: var(--ink-soft); }

/* Novel contents: parts and arcs */
.toc-part { max-width: 40rem; margin: 2rem 0 0; }
.toc-part-h { font-family: var(--read); font-size: 1.6rem; margin: 0 0 .25rem; padding-bottom: .5rem; border-bottom: 2px solid var(--copper); }
.toc-arc { font-family: var(--read); font-size: 1.15rem; margin: 1.25rem 0 .25rem; color: var(--ink-soft); }
.toc-label { display: inline-block; font-family: var(--ui); font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--copper); margin-right: .5rem; vertical-align: .2em; }

/* Permanent labels for key story sites on the world map */
.leaflet-tooltip.lbl-site { background: rgba(30,42,46,.82); color: #F3EBDD; border: 1px solid #B0703D; border-radius: 3px; padding: 1px 6px; font: 700 12px/1.3 var(--ui); box-shadow: none; }
.leaflet-tooltip.lbl-site::before { display: none; }
