/* app.css - builder interface. Cool stone page, lapis actions, stat-block red for the live summary. */
:root {
  --page: #e8ebee;
  --panel: #ffffff;
  --ink: #1d2230;
  --muted: #5e6573;
  --line: #d3d8de;
  --soft: #f3f5f7;
  --accent: #2f4b7c;
  --accent-ink: #ffffff;
  --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; height: 100%; }
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; 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, 0.35); color: #fff; padding: 5px 12px; border-radius: var(--radius); cursor: pointer; font-size: 15px; }
.tbtn:hover { background: rgba(255, 255, 255, 0.1); }
.tbtn.primary { background: #fff; color: var(--ink); border-color: #fff; font-weight: 700; }
.tbtn.file { display: inline-flex; align-items: center; }
.tsel { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.35); border-radius: var(--radius); min-height: 32px; padding: 3px 6px; }
.tsel option { color: var(--ink); }
.level-list { display: flex; flex-direction: column; gap: 8px; padding: 14px 18px 18px; }
.pill.new { background: var(--accent); color: #fff; }
.choice.isnew { background: linear-gradient(90deg, var(--accent-soft), transparent 60%); padding-left: 10px; border-radius: 4px; }
.save-state { font-size: 13px; opacity: 0.7; }

/* ---------------------------------------------------------------- layout */
.shell { display: grid; grid-template-columns: 210px minmax(0, 1fr) 300px; gap: 20px; padding: 20px; max-width: 1500px; margin: 0 auto; align-items: start; }
.steps { position: sticky; top: 72px; }
.steps ol { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps li { margin-bottom: 2px; }
.steps button { width: 100%; display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 8px; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: var(--radius); cursor: pointer; font-size: 16px; }
.steps button:hover { background: rgba(255, 255, 255, 0.6); }
.steps button[aria-current="step"] { background: var(--panel); font-weight: 700; box-shadow: inset 3px 0 0 var(--accent); }
.steps .num { width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid var(--muted); display: grid; place-items: center; font-size: 13px; color: var(--muted); }
.steps button.done .num { background: var(--ok); border-color: var(--ok); color: #fff; }
.steps .badge { font-size: 12px; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 1px 7px; font-weight: 700; }

.main { min-width: 0; }
.panel { background: var(--panel); border-radius: 10px; padding: 22px 26px; margin-bottom: 18px; border: 1px solid var(--line); }
.panel > h2 { font-size: 26px; margin-bottom: 4px; }
.panel .lead { color: var(--muted); margin: 0 0 16px; max-width: 70ch; }
.panel h3 { font-size: 19px; margin: 18px 0 8px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 160px; }
.field > span { font-size: 14px; color: var(--muted); }
input[type=text], input[type=number], input[type=search], select, textarea { border: 1px solid var(--line); border-radius: var(--radius); padding: 7px 10px; background: #fff; min-height: 38px; }
textarea { width: 100%; min-height: 90px; resize: vertical; }
input[type=number] { width: 80px; }
.btn { border: 1px solid var(--line); background: var(--soft); border-radius: var(--radius); padding: 7px 14px; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.small { padding: 3px 9px; font-size: 14px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.muted { color: var(--muted); }
.note { font-size: 14px; color: var(--muted); }
.warnbox { background: var(--warn-soft); color: #5a3a00; border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; font-size: 15px; }

/* ---------------------------------------------------------------- picker cards (class / species / background) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.card { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: var(--radius); padding: 10px 12px; cursor: pointer; }
.card:hover { border-color: var(--accent); }
.card[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); background: var(--accent-soft); }
.card b { display: block; font-family: var(--serif); font-size: 18px; }
.card small { color: var(--muted); }
.srcfilter { margin: 0 0 10px; }

/* ---------------------------------------------------------------- choices */
.choice { border-top: 1px solid var(--line); padding: 14px 0 6px; }
.choice.sub { margin-left: 22px; border-top-style: dashed; }
.choice-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.choice-head h4 { margin: 0; font-size: 17px; font-family: var(--sans); font-weight: 700; }
.pill { font-size: 13px; border-radius: 10px; padding: 1px 9px; font-weight: 700; }
.pill.open { background: var(--warn-soft); color: var(--warn); }
.pill.ok { background: #e2f1e8; color: var(--ok); }
.pill.bad { background: #f8e1df; color: var(--bad); }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 18px; padding: 4px 12px; cursor: pointer; background: #fff; font-size: 15px; user-select: none; }
.opt:hover { border-color: var(--accent); }
.opt.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.opt.dim { opacity: 0.45; }
.opt input { display: none; }
.optlist { border: 1px solid var(--line); border-radius: var(--radius); max-height: 460px; overflow: auto; }
.optrow { display: grid; grid-template-columns: 24px 1fr auto; gap: 8px; align-items: start; padding: 6px 10px; border-bottom: 1px solid var(--soft); }
.optrow:last-child { border-bottom: 0; }
.optrow.on { background: var(--accent-soft); }
.optrow.dim { opacity: 0.5; }
.optrow label { cursor: pointer; }
.optrow .meta { font-size: 13px; color: var(--muted); }
.optrow .info { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 14px; padding: 0 4px; }
.optrow .desc { grid-column: 2 / 4; font-size: 14px; background: var(--soft); border-radius: var(--radius); padding: 8px 12px; }
.optrow .desc p { margin: 0 0 6px; }
.lvlhead { position: sticky; top: 0; background: #fff; font-family: var(--serif); font-weight: 700; padding: 4px 10px; border-bottom: 1px solid var(--line); color: var(--rule); z-index: 1; }
.searchbar { margin-bottom: 6px; width: 100%; max-width: 360px; }
.chosen { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { background: var(--accent); color: #fff; border-radius: 14px; padding: 2px 4px 2px 11px; font-size: 14px; display: inline-flex; align-items: center; gap: 4px; }
.chip button { background: none; border: 0; color: #fff; cursor: pointer; font-size: 16px; line-height: 1; }
.abgrid { display: grid; grid-template-columns: repeat(3, auto); gap: 6px 14px; align-items: center; justify-content: start; }
.abgrid .seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.abgrid .seg button { border: 0; background: #fff; padding: 4px 12px; cursor: pointer; border-left: 1px solid var(--line); }
.abgrid .seg button:first-child { border-left: 0; }
.abgrid .seg button.on { background: var(--accent); color: #fff; }
.details-text { font-size: 15px; background: var(--soft); border-radius: var(--radius); padding: 10px 14px; margin: 8px 0; max-height: 320px; overflow: auto; }
.details-text p { margin: 0 0 8px; }
.details-text table { border-collapse: collapse; font-size: 14px; margin: 6px 0; }
.details-text td, .details-text th { border-bottom: 1px solid var(--line); padding: 2px 8px; text-align: left; }
.details-text ul { margin: 0 0 8px 18px; padding: 0; }
.details-text .inset { border-left: 3px solid var(--line); padding-left: 10px; }

/* ---------------------------------------------------------------- class rows */
.clsrow { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.clsrow-head { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.clsrow-head h3 { margin: 0; font-size: 22px; flex: 1; min-width: 140px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius); }
.stepper button { border: 0; background: var(--soft); width: 34px; height: 36px; cursor: pointer; font-size: 18px; }
.stepper input { border: 0; width: 46px; text-align: center; min-height: 36px; }
.featlist { list-style: none; padding: 0; margin: 8px 0 0; columns: 2; column-gap: 24px; font-size: 15px; }
.featlist li { break-inside: avoid; padding: 2px 0; }
.featlist .lv { display: inline-block; width: 26px; color: var(--muted); font-size: 13px; }
details.more summary { cursor: pointer; color: var(--accent); font-size: 15px; margin-top: 8px; }

/* ---------------------------------------------------------------- abilities */
.abtable { border-collapse: collapse; width: 100%; max-width: 640px; }
.abtable th, .abtable td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: center; }
.abtable th:first-child, .abtable td:first-child { text-align: left; }
.abtable td.final { font-family: var(--serif); font-size: 22px; font-weight: 700; }
.abtable td.mod { font-weight: 700; color: var(--accent); }
.abtable .bon { font-size: 13px; color: var(--muted); }

/* ---------------------------------------------------------------- equipment */
.invtable { width: 100%; border-collapse: collapse; font-size: 15px; }
.invtable th { text-align: left; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); padding: 6px; }
.invtable td { border-bottom: 1px solid var(--soft); padding: 5px 6px; vertical-align: middle; }
.invtable input[type=number] { width: 64px; min-height: 30px; padding: 3px 6px; }
.invtable select { min-height: 30px; padding: 2px 6px; max-width: 170px; }
.invtable .pack td { color: var(--muted); font-size: 14px; }
.invtable .pack td:first-child { padding-left: 22px; }
.results { border: 1px solid var(--line); border-radius: var(--radius); max-height: 280px; overflow: auto; margin-top: 6px; }
.results button { display: flex; justify-content: space-between; width: 100%; border: 0; border-bottom: 1px solid var(--soft); background: #fff; text-align: left; padding: 6px 10px; cursor: pointer; }
.results button:hover { background: var(--accent-soft); }
.coinrow { display: flex; gap: 10px; flex-wrap: wrap; }
.coinrow .field { min-width: 0; }
.coinrow input { width: 90px; }
.eqopt { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 6px 0 12px; }
.eqopt label { display: contents; cursor: pointer; }

/* ---------------------------------------------------------------- issues */
.issues { list-style: none; margin: 0; padding: 0; }
.issues li { padding: 8px 12px; border-left: 3px solid var(--warn); background: var(--warn-soft); margin-bottom: 6px; border-radius: 0 var(--radius) var(--radius) 0; }
.issues li button { background: none; border: 0; color: var(--accent); cursor: pointer; text-decoration: underline; padding: 0 0 0 6px; }
.okbox { padding: 12px 14px; background: #e2f1e8; color: var(--ok); border-radius: var(--radius); font-weight: 700; }

/* ---------------------------------------------------------------- live stat block (the memorable bit) */
.stat { position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow: auto; background: #fdfcf9; border-top: 5px solid var(--rule); border-bottom: 5px solid var(--rule); padding: 14px 16px; font-size: 14.5px; box-shadow: 0 1px 3px rgba(29, 34, 48, 0.12); }
.stat h2 { font-family: var(--serif); font-size: 24px; color: var(--rule); font-variant: small-caps; line-height: 1.05; }
.stat .sub { font-style: italic; color: var(--muted); margin: 2px 0 6px; }
.stat .taper { height: 4px; margin: 8px 0; background: linear-gradient(90deg, var(--rule), var(--rule) 60%, transparent); clip-path: polygon(0 0, 100% 50%, 0 100%); }
.stat p { margin: 2px 0; }
.stat b.k { color: var(--rule); font-weight: 700; }
.stat .abrow { display: grid; grid-template-columns: repeat(6, 1fr); text-align: center; gap: 2px; margin: 4px 0; }
.stat .abrow div { font-size: 13px; }
.stat .abrow strong { display: block; color: var(--rule); font-size: 12px; }
.stat .open { margin-top: 10px; font-size: 14px; }
.stat .open button { background: none; border: 0; color: var(--warn); cursor: pointer; padding: 0; text-align: left; font-weight: 700; }
.stat .ok { color: var(--ok); font-weight: 700; }

/* ---------------------------------------------------------------- dialogs, toast */
.dlg { border: 0; border-radius: 10px; padding: 0; width: min(560px, 94vw); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3); }
.dlg::backdrop { background: rgba(20, 24, 34, 0.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: 26px; cursor: pointer; }
.char-list { list-style: none; margin: 0; padding: 6px 0; max-height: 60vh; overflow: auto; }
.char-list li { display: flex; align-items: center; gap: 8px; padding: 8px 18px; }
.char-list li.cur { background: var(--accent-soft); }
.char-list .open-c { flex: 1; text-align: left; border: 0; background: none; cursor: pointer; }
.char-list .open-c b { font-family: var(--serif); font-size: 18px; display: block; }
.dlg-foot { padding: 12px 18px; border-top: 1px solid var(--line); text-align: right; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 18px; border-radius: 20px; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.toast.show { opacity: 1; }

/* ---------------------------------------------------------------- sheet view */
.sheet-view { background: #c9ced5; min-height: 100vh; }
.sheet-bar { position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; padding: 10px 16px; background: var(--ink); }
#sheet-host { padding: 20px 0; overflow-x: auto; }

@media (max-width: 1180px) {
  .shell { grid-template-columns: 190px minmax(0, 1fr); }
  .stat { display: none; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; padding: 12px 16px; }
  .steps { position: static; }
  .steps ol { display: flex; overflow-x: auto; gap: 4px; }
  .steps button { grid-template-columns: 24px auto auto; white-space: nowrap; }
  .panel { padding: 16px; }
  .featlist { columns: 1; }
  .top { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  .top, .shell, .sheet-bar, .toast, dialog { display: none !important; }
  body, .sheet-view { background: #fff; }
  .sheet-view { display: block !important; }
  #sheet-host { padding: 0; }
}

.badline { color: var(--bad); font-weight: 700; margin: 8px 0 0; }
.okline { color: var(--ok); font-weight: 700; margin: 8px 0 0; }
.choice.bad { border-left: 4px solid var(--bad); padding-left: 10px; background: #fdf1f0; border-radius: 4px; }
.stepissues { background: #fdf1f0; border-left: 4px solid var(--bad); border-radius: 6px; padding: 10px 16px; margin-bottom: 14px; color: #5a1410; }
.stepissues ul { margin: 6px 0 0 18px; padding: 0; }
.rolls { display: flex; gap: 10px; flex-wrap: wrap; }
.rollv { border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 10px; background: #fff; }
.rollv b { font-family: var(--serif); font-size: 20px; }
.recbox { display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap; background: var(--accent-soft); border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; }
.sheet-bar { flex-wrap: wrap; align-items: center; }
.sheet-opts { display: flex; flex-wrap: wrap; gap: 4px 12px; color: #fff; font-size: 14px; max-width: 1000px; }
.sopt { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; white-space: nowrap; }
.dlg.wide { width: min(1400px, 96vw); max-height: 92vh; }
.sub-compare { overflow: auto; max-height: calc(92vh - 70px); padding: 0 18px 18px; }
.cmp { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.cmp th, .cmp td { vertical-align: top; text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); min-width: 220px; max-width: 320px; font-size: 14.5px; }
.cmp thead th { position: sticky; top: 0; background: #fff; z-index: 2; border-bottom: 2px solid var(--rule); }
.cmp thead th b { font-family: var(--serif); font-size: 18px; display: block; }
.cmp th.lv { min-width: 70px; width: 70px; position: sticky; left: 0; background: #fff; z-index: 1; color: var(--rule); font-family: var(--serif); }
.cmp thead th.lv { z-index: 3; }
.cmp td.intro { font-style: italic; color: var(--muted); }
.cmp details summary { cursor: pointer; font-weight: 700; color: var(--ink); }
.cmp details .details-text { max-height: none; font-size: 14px; }
.cmp .cur { background: var(--accent-soft); }
.cmp .src { font-size: 12px; color: var(--muted); font-weight: 400; }
.cmp-tools { display: flex; gap: 10px; align-items: center; padding: 10px 0; position: sticky; left: 0; }
.subdetail h4 { margin: 12px 0 4px; font-size: 16px; }
.spellblock { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; padding: 6px 0 8px; margin-bottom: 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
.spellblock > div:first-child { grid-column: 1 / 3; color: var(--rule); }
.resrow { display: flex; align-items: center; border-bottom: 1px solid var(--soft); }
.resrow .resadd { flex: 1; display: flex; justify-content: space-between; border: 0; background: #fff; text-align: left; padding: 6px 10px; cursor: pointer; }
.resrow .resadd:hover { background: var(--accent-soft); }
.results .details-text { margin: 0 8px 8px; }
.info { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 14px; padding: 0 6px; }
.invinfo td { background: #fff; }
.results button.info { width: auto; display: inline-block; border-bottom: 0; padding: 6px 10px; flex: none; white-space: nowrap; }
.results .resrow .resadd { width: auto; }
.profbox { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 15px; background: var(--soft); border-radius: var(--radius); padding: 10px 14px; margin: 6px 0 14px; }
.profbox b { color: var(--rule); }
.pill.noprof { background: #f8e1df; color: var(--bad); margin-left: 6px; }
.pill.yesprof { background: #e2f1e8; color: var(--ok); margin-left: 6px; }

/* glossary popups (hover / click on rules terms) */
.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, #2b4c8c); outline: none; }
.gloss-pop { position: absolute; z-index: 1000; width: min(420px, calc(100vw - 16px)); max-height: min(60vh, 520px); overflow: auto;
  background: #fff; color: #1d1f24; border: 1px solid #c9ccd3; border-top: 3px solid #8c1c13; border-radius: 6px;
  box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 10px 12px; font-size: 13.5px; line-height: 1.45; text-align: left; font-style: normal; font-weight: normal; }
.gloss-pop[hidden] { display: none !important; }
.gloss-pop.pinned { border-top-color: #2b4c8c; }
.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 ul { margin: 0 0 6px 18px; padding: 0; }
.gloss-body .spellblock { margin-bottom: 8px; }
@media print { .gloss-pop { display: none !important; } .ref-tip { text-decoration: none; cursor: auto; } }

/* ================================================================ phones & tablets */
.tbtn.menu, .stepbar, .stat-backdrop, .stat .stat-x { display: none; }
.top-more { display: contents; }
.sheet-optbox > summary { list-style: none; display: none; }
.sheet-optbox > summary::-webkit-details-marker { display: none; }
@media (max-width: 1180px) {
  /* summary as a slide-up drawer */
  .stat { display: block; position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 40; max-height: 82vh; border-radius: 14px 14px 0 0; border-bottom: 0;
    transform: translateY(105%); transition: transform .22s ease; box-shadow: 0 -8px 30px rgba(0,0,0,.25); padding-bottom: 24px; }
  body.show-stat .stat { transform: none; }
  body.show-stat .stat-backdrop { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(20,24,34,.45); }
  .stat .stat-x { display: block; position: absolute; right: 10px; top: 8px; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
  .stepbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--ink); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 6px; }
  .stepbar button { flex: 1; min-height: 44px; border: 1px solid rgba(255,255,255,.3); background: transparent; color: #fff; border-radius: var(--radius); font-size: 15px; padding: 4px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .stepbar .sb-sum { flex: 0 0 auto; background: #fff; color: var(--ink); font-weight: 700; }
  .stepbar button:disabled { opacity: .35; }
  #builder { padding-bottom: 80px; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); padding: 10px 10px 80px; gap: 10px; }
  .top { flex-wrap: wrap; padding: 6px 10px; gap: 6px; }
  .brand { font-size: 17px; margin-right: 0; }
  .brand span:last-child { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #btn-chars { display: none; }
  .save-state { display: none; }
  .tbtn { min-height: 40px; padding: 6px 12px; }
  .tbtn.menu { display: inline-block; font-size: 20px; padding: 2px 12px; }
  .top-more { display: none; }
  .top.open .top-more { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; order: 10; padding: 4px 0 2px; }
  .top.open #btn-chars { display: inline-block; order: 9; }
  .steps { position: sticky; top: 52px; z-index: 10; margin: 0 -10px; background: var(--page); padding: 4px 10px; }
  .steps ol { scrollbar-width: none; }
  .steps ol::-webkit-scrollbar { display: none; }
  .steps button { padding: 8px 10px; min-height: 40px; }
  .panel { padding: 14px 14px; border-radius: 8px; }
  .panel > h2 { font-size: 23px; }
  .field { min-width: 0; flex: 1 1 140px; }
  .row > .field input, .row > .field select { width: 100%; }
  .opt { padding: 7px 13px; }
  .btn { min-height: 40px; }
  .btn.small { min-height: 34px; padding: 4px 11px; }
  .optrow { padding: 9px 8px; grid-template-columns: 26px 1fr auto; }
  .optrow input[type=checkbox], .optrow input[type=radio] { width: 20px; height: 20px; }
  .optlist { max-height: 60vh; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .choice.sub { margin-left: 8px; }
  .abgrid { grid-template-columns: 1fr; }
  .abtable th, .abtable td { padding: 6px 4px; }
  .invtable { display: block; overflow-x: auto; }
  .invtable select { max-width: 130px; }
  .details-text { max-height: none; }
  .spellblock { grid-template-columns: 1fr; }
  .spellblock > div:first-child { grid-column: 1; }
  .clsrow { padding: 10px; }
  .featlist { columns: 1; }
  .dlg { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto auto 0; border-radius: 14px 14px 0 0; }
  .char-list li { flex-wrap: wrap; }
  .char-list .open-c { flex: 1 1 100%; }
  .toast { bottom: 80px; }
  /* glossary popup becomes a bottom sheet */
  .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; }
  .ref-tip { text-decoration-thickness: 1.5px; }
  /* sheet view */
  .sheet-bar { padding: 6px 8px; gap: 6px; }
  .sheet-optbox > summary { display: inline-block; }
  .sheet-optbox[open] { width: 100%; order: 10; }
  .sheet-optbox[open] > summary { margin-bottom: 6px; }
  .sheet-opts { gap: 8px 14px; font-size: 15px; }
  .sopt input { width: 18px; height: 18px; }
  #sheet-host { padding: 8px 6px; }
}
@media (min-width: 761px) { .sheet-optbox { display: contents; } }
@media (max-width: 760px) {
  .top { flex-wrap: nowrap; }
  .top.open { flex-wrap: wrap; }
  .top-spacer { display: none; }
  .brand { flex: 1 1 auto; min-width: 0; }
  .brand span:last-child { max-width: none; }
  #btn-sheet { white-space: nowrap; }
}
.tbtn { white-space: nowrap; }
@media (max-width: 1000px) {
  .top { flex-wrap: nowrap; padding: 6px 10px; gap: 6px; }
  .top.open { flex-wrap: wrap; }
  .top-spacer, .save-state, #btn-chars { display: none; }
  .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; gap: 6px; width: 100%; order: 10; padding: 4px 0 2px; }
  .top.open #btn-chars { display: inline-block; order: 9; }
}

.tbtn.home { text-decoration: none; font-size: 18px; padding: 2px 10px; display: inline-flex; align-items: center; }
