:root {
  color-scheme: light;
  --bg: #F4F3F7; --surface: #FFFFFF; --surface-2: #EFEDF3; --ink: #1C1924; --muted: #6A6377; --line: #DCD7E3;
  --curse: #7A1F3D; --curse-ink: #FFFFFF; --curse-soft: #F4E3EA; --pe: #3446A0; --pe-soft: #E4E7F7; --pv: #B0303F; --pv-soft: #F7E2E4;
  --ok: #2B7550; --ok-soft: #E1F1E8; --warn: #8E5B0E; --warn-soft: #FBEFD9; --bad: #B0303F; --lock: #9C96A6;
  --ui: "Barlow Semi Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --book: "Noto Serif", Georgia, "Times New Roman", serif;
  --r-sm: 6px; --r: 10px;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14121A; --surface: #1D1A25; --surface-2: #26222F; --ink: #ECE8F3; --muted: #A39CB0; --line: #363042;
    --curse: #D9668A; --curse-ink: #1A0D13; --curse-soft: #3A2030; --pe: #8D9BF2; --pe-soft: #252B4A; --pv: #F07A86; --pv-soft: #43222A;
    --ok: #67C59A; --ok-soft: #1C3328; --warn: #E2B15A; --warn-soft: #3A2E17; --bad: #F07A86; --lock: #6E6879;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14121A; --surface: #1D1A25; --surface-2: #26222F; --ink: #ECE8F3; --muted: #A39CB0; --line: #363042;
  --curse: #D9668A; --curse-ink: #1A0D13; --curse-soft: #3A2030; --pe: #8D9BF2; --pe-soft: #252B4A; --pv: #F07A86; --pv-soft: #43222A;
  --ok: #67C59A; --ok-soft: #1C3328; --warn: #E2B15A; --warn-soft: #3A2E17; --bad: #F07A86; --lock: #6E6879;
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--ui); font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--curse); outline-offset: 2px; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.15; }
p { margin: 0 0 .6em; }

/* ---------- topo ---------- */
.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 21; background: var(--surface); }
.top-inner { max-width: 1280px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.seal { width: 34px; height: 34px; border-radius: 7px; background: var(--curse); color: var(--curse-ink); display: grid; place-items: center; font-family: var(--book); font-size: 21px; }
.brand b { font-size: 1.15rem; letter-spacing: .01em; }
.brand small { display: block; color: var(--muted); font-size: .8rem; font-weight: 500; }
.top select { max-width: 220px; }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 7px 12px; border-radius: var(--r-sm); cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--curse); border-color: var(--curse); color: var(--curse-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 3px 8px; font-size: .88rem; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 4px 6px; border-radius: 5px; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

input[type=text], input[type=number], select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 6px 8px; min-width: 0; }
input[type=number] { width: 4.2em; text-align: center; font-variant-numeric: tabular-nums; }
textarea { width: 100%; min-height: 90px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--curse); outline: none; }
input[type=checkbox] { accent-color: var(--curse); width: 17px; height: 17px; vertical-align: middle; }
label.inline { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- banner do personagem ---------- */
.wrap { max-width: 1280px; margin: 0 auto; padding: 18px 16px 60px; }
.banner { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center; margin-bottom: 14px; }
.lvl-seal { width: 76px; height: 76px; border-radius: 50%; border: 3px solid var(--curse); color: var(--curse); display: grid; place-items: center; text-align: center; line-height: 1; position: relative; }
.lvl-seal span { font-size: .72rem; font-weight: 600; letter-spacing: .04em; }
.lvl-seal b { font-size: 2.1rem; font-variant-numeric: tabular-nums; }
.banner h1 { font-size: clamp(1.6rem, 3vw, 2.3rem); }
.banner h1 input { font: inherit; border: 0; border-bottom: 1px dashed transparent; background: transparent; width: 100%; padding: 0; }
.banner h1 input:hover, .banner h1 input:focus { border-bottom-color: var(--line); }
.banner .sub { color: var(--muted); font-size: 1.02rem; margin-top: 2px; }
.banner .sub b { color: var(--ink); font-weight: 600; }
.xp { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: .9rem; color: var(--muted); flex-wrap: wrap; }
.bar { height: 7px; background: var(--surface-2); border-radius: 4px; overflow: hidden; flex: 1; min-width: 120px; max-width: 320px; }
.bar i { display: block; height: 100%; background: var(--curse); }
.banner-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.lvl-up { font-size: 1.08rem; padding: 10px 18px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; scrollbar-width: thin; }
.tab { border: 0; background: transparent; padding: 10px 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; font-size: 1.02rem; }
.tab:hover { color: var(--ink); }
.tab[aria-selected=true] { color: var(--ink); border-bottom-color: var(--curse); }

/* ---------- cartões e grade ---------- */
.grid { display: grid; gap: 14px; }
.g-sheet { grid-template-columns: repeat(12, 1fr); }
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; } .span-3 { grid-column: span 3; }
@media (max-width: 1000px) { .span-3, .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; } .banner { grid-template-columns: auto 1fr; } .banner-actions { grid-column: span 2; flex-direction: row; justify-content: flex-start; align-items: center; flex-wrap: wrap; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; min-width: 0; }
.card > h2 { font-size: 1.05rem; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; color: var(--ink); }
.card > h2 .hint { margin-left: auto; font-weight: 500; font-size: .85rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* atributos */
.attrs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.attr { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; text-align: center; background: var(--surface-2); }
.attr .n { font-weight: 600; font-size: .9rem; color: var(--muted); }
.attr .m { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.05; cursor: pointer; }
.attr .v { font-size: .95rem; cursor: pointer; }
.attr .lim { font-size: .75rem; color: var(--muted); }

/* recursos */
.res { display: grid; gap: 12px; }
.res-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; }
.res-row .lbl { font-weight: 600; }
.res-row .nums { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.res-row .nums b { font-size: 1.2rem; cursor: pointer; }
.res-row .bar { grid-column: span 2; max-width: none; height: 9px; }
.res-pv .bar i { background: var(--pv); } .res-pe .bar i { background: var(--pe); } .res-int .bar i { background: #6E5A9E; }
.state { font-size: .82rem; padding: 2px 8px; border-radius: 20px; background: var(--surface-2); color: var(--muted); font-weight: 600; }

/* estatísticas */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.stat { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; background: var(--surface-2); }
.stat .k { font-size: .82rem; color: var(--muted); font-weight: 600; }
.stat .val { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; cursor: pointer; line-height: 1.1; }
.stat .val small { font-size: .85rem; font-weight: 500; color: var(--muted); }
.clickable { cursor: pointer; border-bottom: 1px dotted var(--muted); }

/* tabelas compactas */
table.t { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.t th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--line); }
table.t td { padding: 4px 6px; border-bottom: 1px solid var(--surface-2); vertical-align: middle; }
table.t td.c, table.t th.c { text-align: center; }
table.t tr:last-child td { border-bottom: 0; }
table.t .tot { font-weight: 700; font-size: 1.08rem; cursor: pointer; text-align: center; min-width: 2.4em; }
.skills-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
@media (max-width: 700px) { .skills-cols { grid-template-columns: 1fr; } }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.tag.curse { background: var(--curse-soft); color: var(--curse); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--pv-soft); color: var(--bad); }
.tag.pe { background: var(--pe-soft); color: var(--pe); }
.scroll-x { overflow-x: auto; }

/* textos do livro */
.book { font-family: var(--book); font-size: .95rem; line-height: 1.6; color: var(--ink); max-width: 76ch; }
.book p { margin: 0 0 .55em; }
.book ul { margin: 0 0 .6em; padding-left: 1.2em; }
.book li { margin-bottom: .35em; }
.book table { border-collapse: collapse; margin: 6px 0 10px; font-family: var(--ui); font-size: .92rem; }
.book table th, .book table td { border: 1px solid var(--line); padding: 4px 9px; text-align: left; }
.book table th { background: var(--curse-soft); color: var(--curse); }
.book .extra { border-left: 3px solid var(--curse-soft); padding-left: 12px; margin-top: 8px; }
.book .extra h4 { font-family: var(--ui); font-size: .95rem; margin-bottom: 4px; color: var(--curse); }

/* habilidades */
.ab-list { display: grid; gap: 8px; }
details.ab { border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); }
details.ab > summary { list-style: none; cursor: pointer; padding: 9px 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
details.ab > summary::-webkit-details-marker { display: none; }
details.ab > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details.ab[open] > summary::before { transform: rotate(90deg); }
details.ab .name { font-weight: 700; font-size: 1.03rem; }
details.ab .meta { color: var(--muted); font-size: .86rem; }
details.ab .body { padding: 2px 14px 12px 30px; }
details.ab.locked { background: var(--surface-2); }
details.ab.locked .name { color: var(--muted); }
.why { font-size: .85rem; color: var(--bad); }
.why.unk { color: var(--warn); }
.group-title { font-size: 1.15rem; margin: 18px 0 8px; display: flex; align-items: baseline; gap: 10px; }
.group-title small { color: var(--muted); font-weight: 500; font-size: .9rem; }

/* listas de seleção (assistentes) */
.pick-list { display: grid; gap: 6px; max-height: 52vh; overflow-y: auto; padding-right: 4px; }
.pick { border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); }
.pick.sel { border-color: var(--curse); box-shadow: inset 0 0 0 1px var(--curse); }
.pick.dis { opacity: .62; background: var(--surface-2); }
.pick-head { display: flex; gap: 10px; align-items: center; padding: 8px 10px; cursor: pointer; flex-wrap: wrap; }
.pick-head input { flex: none; }
.pick-head .name { font-weight: 700; }
.pick-head .toggle { margin-left: auto; }
.pick .body { padding: 0 12px 10px 38px; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(15, 10, 20, .55); z-index: 50; display: grid; place-items: center; padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px)); }
.modal { background: var(--bg); border-radius: 14px; width: min(980px, 100%); max-height: 100%; display: flex; flex-direction: column; border: 1px solid var(--line); overflow: hidden; }
.modal.narrow { width: min(560px, 100%); }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); background: var(--surface); display: flex; align-items: center; gap: 12px; }
.modal-head h2 { font-size: 1.3rem; }
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.steps { display: flex; gap: 4px; flex-wrap: wrap; margin-left: auto; }
.steps span { font-size: .8rem; padding: 3px 8px; border-radius: 20px; background: var(--surface-2); color: var(--muted); font-weight: 600; }
.steps span.on { background: var(--curse); color: var(--curse-ink); }
.steps span.done { background: var(--curse-soft); color: var(--curse); }
.sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 12px; }
.sec > h3 { font-size: 1.1rem; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sec > h3 .st { margin-left: auto; }
.auto-list { margin: 0; padding-left: 1.1em; }
.auto-list li { margin-bottom: 3px; }
.notice { border-radius: var(--r-sm); padding: 9px 12px; background: var(--warn-soft); color: var(--warn); font-size: .92rem; margin-bottom: 10px; }
.notice.info { background: var(--pe-soft); color: var(--pe); }
.notice.bad { background: var(--pv-soft); color: var(--bad); }
.field { display: grid; gap: 4px; }
.field > span { font-size: .85rem; color: var(--muted); font-weight: 600; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.opt-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.opt-card { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px; cursor: pointer; background: var(--surface); text-align: left; }
.opt-card.sel { border-color: var(--curse); box-shadow: inset 0 0 0 1px var(--curse); }
.opt-card b { display: block; }
.opt-card span { font-size: .82rem; color: var(--muted); }
.opt-card:disabled { opacity: .45; cursor: not-allowed; }
.attr-assign { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.attr-assign .attr select, .attr-assign .attr input { width: 100%; margin-top: 4px; }

/* treinamentos */
.train-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.stage { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; padding: 7px 0; border-top: 1px solid var(--surface-2); align-items: start; }
.stage .req { font-size: .82rem; }
.stage.blocked .txt { color: var(--muted); }
.full-bonus { margin-top: 8px; padding: 9px 11px; border-radius: var(--r-sm); background: var(--surface-2); }
.full-bonus.on { background: var(--curse-soft); }

/* listas editáveis */
.edit-table { width: 100%; border-collapse: collapse; }
.edit-table th { text-align: left; font-size: .8rem; color: var(--muted); padding: 4px; font-weight: 600; }
.edit-table td { padding: 3px 4px; vertical-align: top; }
.edit-table input[type=text] { width: 100%; }
.summon { border: 1px solid var(--line); border-radius: var(--r); padding: 12px; background: var(--surface); }

/* popover / toast */
.pop { position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 12px; min-width: 220px; max-width: 340px; box-shadow: 0 8px 28px rgba(0,0,0,.18); font-size: .92rem; }
.pop h4 { font-size: .95rem; margin-bottom: 6px; }
.pop table { width: 100%; border-collapse: collapse; }
.pop td { padding: 2px 0; } .pop td:last-child { text-align: right; font-variant-numeric: tabular-nums; padding-left: 12px; }
.pop tr.total td { border-top: 1px solid var(--line); font-weight: 700; padding-top: 4px; }
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 8px; z-index: 70; font-weight: 600; }

.empty { text-align: center; padding: 70px 20px; }
.empty .seal { width: 64px; height: 64px; font-size: 40px; margin: 0 auto 14px; border-radius: 14px; }
.empty h1 { font-size: 1.8rem; margin-bottom: 8px; }
.empty p { color: var(--muted); max-width: 52ch; margin: 0 auto 18px; }
.search { width: 100%; padding: 8px 10px; margin-bottom: 10px; }
.credits { color: var(--muted); font-size: .85rem; max-width: 80ch; margin-top: 30px; border-top: 1px solid var(--line); padding-top: 14px; }
.hist td { vertical-align: top; }
.hist ul { margin: 0; padding-left: 1.1em; }
@media (max-width: 640px) {
  .top-inner { gap: 8px; } .brand small { display: none; } .top select { max-width: 150px; }
  .lvl-seal { width: 60px; height: 60px; } .lvl-seal b { font-size: 1.6rem; }
  .attrs { grid-template-columns: repeat(2, 1fr); }
  .modal-back { padding: 0; } .modal { border-radius: 0; height: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .top, .tabs, .banner-actions, .btn, .icon-btn { display: none !important; } body { background: #fff; } .card { break-inside: avoid; } }

/* status da nuvem */
.pill { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.pill:hover { border-color: var(--muted); }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--lock); flex: none; }
.pill-ok i { background: var(--ok); } .pill-busy i { background: var(--pe); animation: pulse 1s ease-in-out infinite; } .pill-warn i { background: var(--warn); } .pill-bad i { background: var(--bad); }
.pill-bad { color: var(--bad); } .pill-warn { color: var(--warn); }
.sec h3 .pill { font-size: .8rem; padding: 3px 9px; cursor: default; }
@keyframes pulse { 50% { opacity: .35; } }
@media (max-width: 640px) { .pill { font-size: .8rem; padding: 5px 9px; } }

/* cabeçalho do personagem: selo de tinta como no livro */
.banner { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; overflow: hidden; }
.banner::after { content: "呪"; position: absolute; right: -10px; bottom: -64px; font-family: var(--book); font-size: 220px; line-height: 1; color: var(--curse); opacity: .06; pointer-events: none; }
.banner > * { position: relative; z-index: 1; }
.lvl-seal { background: var(--curse-soft); }
