/* app.css - builder interface. Same family as the Character Builder: stone page, lapis actions, stat-block red. */
:root {
  --page: #e8ebee;
  --panel: #ffffff;
  --ink: #1d2230;
  --muted: #5e6573;
  --line: #d3d8de;
  --soft: #f3f5f7;
  --accent: #2f4b7c;
  --accent-soft: #e3e9f4;
  --rule: #8c1c13;
  --warn: #9a5b00;
  --warn-soft: #fbf0dc;
  --bad: #a3221a;
  --ok: #2e7d4f;
  --radius: 6px;
  --serif: "Alegreya", Georgia, "Times New Roman", serif;
  --sans: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.15; margin: 0; }

/* top bar */
.top { position: sticky; top: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 16px; background: var(--ink); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 19px; font-weight: 700; margin-right: 8px; }
.brand-mark { width: 18px; height: 18px; background: var(--rule); transform: rotate(45deg); border: 2px solid #fff; }
.top-spacer { flex: 1; }
.tbtn { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff; padding: 5px 12px; border-radius: var(--radius); cursor: pointer; font-size: 15px; }
.tbtn:hover { background: rgba(255,255,255,.1); }
.tbtn.primary { background: #fff; color: var(--ink); border-color: #fff; font-weight: 700; }
.tbtn.file { display: inline-flex; align-items: center; }
.tsel { width: auto; min-width: 0; background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.35); border-radius: var(--radius); min-height: 32px; padding: 3px 6px; }
.tsel option { color: var(--ink); }
.tcheck input { width: auto; min-height: 0; }
.tcheck { font-size: 14px; display: inline-flex; gap: 5px; align-items: center; opacity: .9; }
.save-state { font-size: 13px; opacity: .7; }

/* layout */
.shell { display: grid; grid-template-columns: minmax(340px, 470px) minmax(0, 1fr); gap: 20px; padding: 20px; max-width: 1560px; margin: 0 auto; align-items: start; }
.col-left { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; padding-right: 4px; scrollbar-width: thin; }
.src-note { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 24px; }
@media (max-width: 1100px) { .shell { grid-template-columns: 1fr; padding: 12px; } .col-left { position: static; max-height: none; overflow: visible; } }

.panel { background: var(--panel); border-radius: 10px; padding: 18px 20px; margin-bottom: 16px; border: 1px solid var(--line); }
.panel > h2 { font-size: 23px; margin-bottom: 4px; }
.lead { color: var(--muted); margin: 0 0 12px; }
.small { font-size: 14px; }
.muted { color: var(--muted); }
.help { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.field { margin: 12px 0; }
.field > label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .row2 { grid-template-columns: 1fr; } }
input[type=text], input[type=search], input[type=number], select, textarea { width: 100%; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 9px; background: #fff; min-height: 36px; }
textarea { min-height: 70px; resize: vertical; }
input.num { width: 64px; }
.btn { border: 1px solid var(--line); background: var(--soft); border-radius: var(--radius); padding: 6px 14px; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 700; }
.btn.primary:hover { background: #253d66; }
.btn.big { width: 100%; padding: 11px; font-size: 17px; margin-top: 6px; }
.btn.ghost { background: transparent; }
.btn.danger, .link.danger { color: var(--bad); }
.icon { border: 1px solid var(--line); background: #fff; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; line-height: 1; padding: 0; }
.icon:hover { border-color: var(--accent); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 2px 0; text-decoration: underline; text-underline-offset: 2px; }

/* party */
.quick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.quick .lbl { font-weight: 700; }
table.party { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
table.party th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 500; padding: 2px 4px; }
table.party td { padding: 3px 4px; }
table.party td.idx { color: var(--muted); width: 20px; }

/* segmented + chips */
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; border: 1px solid var(--line); background: #fff; border-radius: var(--radius); padding: 6px 10px; cursor: pointer; text-align: center; }
.seg button span { display: flex; flex-direction: column; line-height: 1.2; }
.seg button small { color: var(--muted); font-size: 12.5px; }
.seg button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.seg button.on small { color: #dbe4f5; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 3px 11px; cursor: pointer; font-size: 14.5px; display: inline-flex; align-items: center; gap: 4px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.chip .x { border: 0; background: none; cursor: pointer; color: inherit; padding: 0 2px; }
.opts { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.opts select { width: auto; min-height: 30px; padding: 2px 6px; }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.inline { display: flex; align-items: center; gap: 8px; }

/* monster search */
.msearch { position: relative; }
.mresults { display: flex; flex-direction: column; max-height: 300px; overflow: auto; }
.mres { display: flex; flex-direction: column; align-items: flex-start; text-align: left; border: 0; border-bottom: 1px solid var(--soft); background: #fff; padding: 5px 8px; cursor: pointer; }
.mres:hover, .mres:focus { background: var(--accent-soft); }
.mres .meta { font-size: 13px; color: var(--muted); }
.more { font-size: 13px; color: var(--muted); padding: 4px 8px; }
.allylist { list-style: none; padding: 0; margin: 0 0 8px; }
.allylist li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 4px 0; border-bottom: 1px solid var(--soft); }
.count { display: inline-flex; align-items: center; gap: 6px; }
.count b { min-width: 20px; text-align: center; font-size: 17px; }

/* suggestions */
.sugs { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 10px; }
.sug { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: linear-gradient(#fff, var(--soft)); }
.sug-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 14.5px; }
.sug ul { margin: 0; padding-left: 16px; flex: 1; }
.sug li { margin: 2px 0; }
.warnbox { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: var(--radius); }

/* current encounter */
.cur-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.encname { flex: 1; font-family: var(--serif); font-size: 19px; min-width: 200px; }
.rate { margin: 12px 0; padding: 10px 12px; border-radius: 8px; background: var(--soft); border-left: 4px solid var(--muted); }
.rate-head { display: flex; gap: 6px; align-items: baseline; margin-bottom: 6px; }
.rate-head b { font-size: 18px; }
.rate-head .rxp { margin-left: auto; font-weight: 700; }
.bar { position: relative; height: 12px; background: #dde2e8; border-radius: 6px; margin: 6px 0 20px; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; background: var(--muted); }
.bar .mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); }
.bar .mark span { position: absolute; top: 18px; left: -4px; font-size: 11px; color: var(--muted); }
.rate-low { border-left-color: var(--ok); } .rate-low .fill { background: var(--ok); }
.rate-trivial .fill { background: #8fb39d; }
.rate-moderate { border-left-color: #c58a00; } .rate-moderate .fill { background: #c58a00; }
.rate-high { border-left-color: var(--rule); } .rate-high .fill { background: var(--rule); }
.rate-beyond, .rate-extreme { border-left-color: #4a0b06; background: #f6e3e1; } .rate-beyond .fill, .rate-extreme .fill { background: #4a0b06; }
.warns { margin: 8px 0 12px; padding: 8px 12px 8px 30px; background: var(--warn-soft); color: #5f3a00; border-radius: var(--radius); font-size: 14.5px; }
.warns li { margin: 2px 0; }
.groups { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.grp { border: 1px solid var(--line); border-left: 4px solid var(--rule); border-radius: 8px; padding: 10px 12px; }
.grp.ally { border-left-color: var(--ok); background: #f4faf6; }
.grp-main { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; align-items: center; }
.grp-name { font-weight: 700; font-size: 17px; }
.grp-name .muted { font-weight: 400; }
.grp-stats { display: flex; gap: 10px; flex-wrap: wrap; font-size: 14.5px; }
@media (max-width: 700px) { .grp-main { grid-template-columns: 1fr; } }
.grp-atk { font-size: 14.5px; margin-top: 6px; }
.grp-atk .lbl { font-weight: 700; color: var(--muted); }
.grp-tools { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-top: 6px; font-size: 14.5px; }
.grp-tools .swap { width: auto; max-width: 280px; min-height: 30px; padding: 2px 6px; font-size: 14px; }
.role { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; padding: 1px 7px; border-radius: 10px; margin-left: 8px; vertical-align: middle; font-family: var(--sans); font-weight: 700; }
.role-ally { background: #dff1e6; color: var(--ok); }
.sbwrap { margin-top: 10px; }
.notes { font-family: var(--sans); }

/* dialogs */
.dlg { border: 0; border-radius: 10px; padding: 0; width: min(620px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.dlg::backdrop { background: rgba(20,24,34,.45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); margin: 0; }
.dlg-head .x { border: 0; background: none; font-size: 24px; cursor: pointer; }
.dlg-foot { padding: 12px 18px; border-top: 1px solid var(--line); text-align: right; }
.enc-list { list-style: none; margin: 0; padding: 8px 18px 16px; max-height: 70vh; overflow: auto; }
.enc-list li { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--soft); }
.enc-list .btns { display: flex; gap: 6px; flex-shrink: 0; }
.print-opts { padding: 14px 18px; display: flex; flex-direction: column; gap: 8px; }

/* glossary popups */
.ref-tip { cursor: help; text-decoration: underline dotted; text-decoration-thickness: 1px; text-underline-offset: 2px; }
.ref-tip:hover, .ref-tip:focus { color: var(--accent); outline: none; }
.gloss-pop { position: absolute; z-index: 1000; width: min(440px, calc(100vw - 16px)); max-height: min(70vh, 640px); overflow: auto; background: #fff; color: #1d1f24; border: 1px solid #c9ccd3; border-top: 3px solid var(--rule); border-radius: 6px; box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 10px 12px; font-size: 14px; line-height: 1.45; text-align: left; font-style: normal; font-weight: normal; }
.gloss-pop.pinned { border-top-color: var(--accent); }
.gloss-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.gloss-head b { font-size: 15px; }
.gloss-kind { color: #6b7080; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; flex: 1; }
.gloss-x { border: 0; background: none; cursor: pointer; color: #6b7080; font-size: 14px; padding: 0 2px; }
.gloss-body p { margin: 0 0 6px; }
.gloss-body .statblock { box-shadow: none; margin: 0; }
.gspell, .gitem { background: var(--soft); border-radius: 4px; padding: 6px 8px; margin-bottom: 6px; font-size: 13.5px; }
.etable { border-collapse: collapse; font-size: 13.5px; margin: 4px 0 8px; }
.etable th, .etable td { border-bottom: 1px solid var(--line); padding: 2px 6px; text-align: left; }
.print-view { display: none; }
.simnote { font-size: 12.5px; color: var(--accent); }
.check.small { font-size: 14px; margin-top: 6px; }

/* tabs + NPC maker */
.tabs { display: flex; gap: 4px; max-width: 1560px; margin: 14px auto 0; padding: 0 20px; }
.tabs button { border: 1px solid var(--line); border-bottom: 0; background: var(--soft); padding: 8px 20px; border-radius: 8px 8px 0 0; cursor: pointer; font-family: var(--serif); font-size: 17px; }
.tabs button.on { background: var(--panel); font-weight: 700; box-shadow: inset 0 3px 0 var(--rule); }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.npcdesc { background: #fff; border: 1px solid #d9ccb0; border-bottom: 0; border-radius: 4px 4px 0 0; padding: 8px 14px; font-size: 14px; }
.npcdesc .npcsub { font-weight: 700; color: var(--rule); margin-bottom: 3px; }
.npccard .statblock { border-radius: 0 0 4px 4px; }
.npclist { list-style: none; margin: 0; padding: 0; }
.npclist li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 7px 8px; border-bottom: 1px solid var(--soft); border-radius: 6px; }
.npclist li.on { background: var(--accent-soft); }
.npclist .btns { display: flex; gap: 12px; }

/* ================================================================ phones & tablets */
.tbtn.menu { display: none; }
.top-more { display: contents; }
.tbtn { white-space: nowrap; }
.zoombtn { position: absolute; right: 10px; z-index: 3; margin-top: 6px; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,.92); font-size: 20px; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.dmap.zoom, .tmap.zoom { overflow: auto; max-height: 75vh; -webkit-overflow-scrolling: touch; }
.dmap.zoom svg, .tmap.zoom svg { width: 260%; max-width: none; }
@media (min-width: 1101px) { .zoombtn { display: none; } }
@media (max-width: 1000px) {
  .top { flex-wrap: nowrap; padding: 6px 10px; gap: 6px; }
  .top.open { flex-wrap: wrap; }
  .brand { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tbtn { min-height: 40px; }
  .tbtn.menu { display: inline-block; font-size: 20px; padding: 2px 12px; }
  .top-more { display: none; }
  .top.open .top-more { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; width: 100%; order: 10; padding: 4px 0 2px; }
  .top.open .top-spacer { display: none; }
}
@media (max-width: 760px) {
  .tabs { margin: 8px 0 0; padding: 0 8px; overflow-x: auto; scrollbar-width: none; position: sticky; top: 52px; z-index: 15; background: var(--page); }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { white-space: nowrap; padding: 8px 14px; font-size: 16px; flex: none; }
  .shell { padding: 0 8px 20px; gap: 10px; }
  .panel { padding: 14px 12px; border-radius: 8px; }
  .btn { min-height: 40px; }
  .btn.small { min-height: 34px; }
  input[type=text], input[type=number], input[type=search], select, textarea { font-size: 16px; }
  .dlg { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto auto 0; border-radius: 14px 14px 0 0; }
  .gloss-pop { position: fixed !important; left: 0 !important; right: 0; top: auto !important; bottom: 0; width: 100%; max-height: 62vh; border-radius: 12px 12px 0 0; font-size: 15px; padding: 12px 16px 20px; box-shadow: 0 -8px 30px rgba(0,0,0,.25); }
  .gloss-x { font-size: 22px; padding: 0 6px; }
  .src-note { padding: 0 12px 16px; }
}
.jump { display: none; }
@media screen and (max-width: 1100px) {
  .jump { display: flex; position: fixed; right: 10px; bottom: calc(12px + env(safe-area-inset-bottom)); z-index: 25; gap: 6px; }
  .jump .jb { font-family: var(--sans); font-size: 14px; font-weight: 700; padding: 9px 13px; border-radius: 22px; border: 0; background: var(--ink); color: #fff; white-space: nowrap; box-shadow: 0 3px 12px rgba(0,0,0,.3); }
  .src-note { padding-bottom: 70px; }
  .shell > .col-left, .shell > .col-right { scroll-margin-top: 110px; }
}
@media print { .jump, .zoombtn { display: none !important; } }

.tbtn.home { text-decoration: none; font-size: 18px; padding: 2px 10px; display: inline-flex; align-items: center; }
.toast { position: fixed; left: 50%; bottom: 70px; transform: translateX(-50%) translateY(10px); background: var(--ok, #2e7d4f); color: #fff; padding: 10px 18px; border-radius: 22px; font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: 92vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.sug.used { outline: 2px solid #2e7d4f; background: #f1f8f3; }
.btn.primary.done { background: #2e7d4f; border-color: #2e7d4f; }
.lootbox { border: 1px solid var(--line); border-left: 4px solid #c9a227; border-radius: 6px; padding: 10px 12px; margin: 12px 0; background: #fffdf5; }
.lootbox h3 { margin: 0 0 6px; font-size: 17px; }
.lootlines > div { margin: 3px 0; }
ul.flav { margin: 2px 0 0 18px; padding: 0; }
.pv-loot ul.flav { margin-left: 5mm; }
@media print { .toast { display: none !important; } }
.placeloc.linked { background: #eef6f0; border: 1px solid #b9dcc4; border-radius: 6px; padding: 6px 10px; }
.linkbadge { background: #e2f1e8; color: #2e7d4f; border-radius: 12px; padding: 3px 10px; font-size: 13px; font-weight: 700; align-self: center; }
.liblist { list-style: none; margin: 0; padding: 0; }
.liblist li { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; border-top: 1px solid var(--soft); padding: 8px 4px; }
.liblist li.on { background: #eef6f0; border-radius: 6px; }
.liblist .libmain { flex: 1; min-width: 0; }
.liblist .btns { display: flex; gap: 6px; align-items: center; flex: none; }
.libnote { color: #5a4a2a; margin-top: 2px; white-space: pre-line; }
.libsave { margin-top: 8px; align-items: center; }
