:root {
  --bg: #e6e9ec; --surface: #f6f7f8; --surface-2: #ecEFF1; --ink: #172029; --muted: #55616c; --line: #c5ccd2;
  --iron: #2c4660; --iron-ink: #ffffff; --ember: #c2480f; --ember-ink: #ffffff; --danger: #a31f1f; --warn-bg: #fbe9cf; --warn-ink: #5a3600;
  --focus: #1d6fd8; --radius: 6px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --s-abjuration: #3b78b8; --s-conjuration: #8a5aa8; --s-divination: #3d9a9a; --s-enchantment: #c0508a;
  --s-evocation: #c2480f; --s-illusion: #6e6fc4; --s-necromancy: #4c6b3c; --s-transmutation: #b8872a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12171c; --surface: #1b2229; --surface-2: #232c35; --ink: #e5eaee; --muted: #9aa7b2; --line: #33404b;
    --iron: #9dbbd8; --iron-ink: #10161b; --ember: #ee7f3f; --ember-ink: #1a0c02; --danger: #ff8a80; --warn-bg: #4a3513; --warn-ink: #ffe2b0;
    --focus: #7db4ff;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--sans); }
#app { height: 100dvh; display: flex; flex-direction: column; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.6rem; } h3 { font-size: 1.15rem; margin-top: 1.25rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.loading, .fatal { padding: 2rem; } .fatal { color: var(--danger); font-weight: 600; }

/* шапка */
.app-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem .75rem; padding: .6rem 1rem; background: var(--iron); color: var(--iron-ink); }
.brand { display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; }
.brand-name { font: 700 1.35rem var(--serif); letter-spacing: .01em; }
.dataset-badge { font-size: .8rem; opacity: .85; border: 1px solid currentColor; border-radius: 99px; padding: 0 .6rem; }
.head-actions { display: flex; gap: .4rem; }
.app-head .btn { background: transparent; color: inherit; border-color: color-mix(in srgb, currentColor 55%, transparent); }
.app-head .btn.primary { background: var(--ember); color: var(--ember-ink); border-color: var(--ember); }

/* кнопки и поля */
.btn { font: inherit; font-size: .95rem; min-height: 40px; padding: .35rem .9rem; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: var(--radius); cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--iron); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--ember); border-color: var(--ember); color: var(--ember-ink); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 32px; padding: .15rem .6rem; font-size: .85rem; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem .55rem; min-height: 40px; max-width: 100%; }
textarea { width: 100%; resize: vertical; }
input[type="text"], input[type="search"] { width: 100%; }
input[type="checkbox"] { min-height: 0; width: 1.1rem; height: 1.1rem; accent-color: var(--iron); }
.field { margin-bottom: .9rem; display: flex; flex-direction: column; gap: .25rem; }
.field > label, .field > .label, legend { font-weight: 600; font-size: .9rem; }
.field-error { color: var(--danger); margin: .25rem 0; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.inline { display: inline-flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: .35rem; font-weight: 400 !important; }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); margin: 0 0 1rem; padding: .75rem 1rem; }
.error-list { border: 2px solid var(--danger); border-radius: var(--radius); padding: .5rem 1rem; margin-bottom: 1rem; }
.banner { background: var(--warn-bg); color: var(--warn-ink); padding: .5rem 1rem; font-size: .9rem; }

/* вкладки */
.tabs { display: flex; gap: 0; overflow-x: auto; background: var(--surface); border-bottom: 1px solid var(--line); scrollbar-width: thin; }
.tab { flex: 0 0 auto; padding: .7rem 1rem; color: var(--muted); text-decoration: none; border-bottom: 3px solid transparent; white-space: nowrap; font-weight: 500; }
.tab.active { color: var(--ink); border-bottom-color: var(--ember); font-weight: 700; }
.tab .count { margin-left: .4rem; font-size: .75rem; background: var(--surface-2); border-radius: 99px; padding: 0 .45rem; }

/* раскладка */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(300px, 400px) 1fr; }
.list-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--surface); }
.detail-pane { overflow-y: auto; padding: 1.25rem clamp(1rem, 3vw, 2.5rem) 3rem; }
.search-row { padding: .6rem .75rem .3rem; }
.filters { padding: 0 .75rem; }
.filters-box > summary { cursor: pointer; font-size: .9rem; color: var(--muted); padding: .2rem 0; }
.filters-grid { display: flex; flex-wrap: wrap; gap: .5rem .75rem; padding: .4rem 0 .6rem; align-items: end; }
.flt { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); gap: .15rem; }
.flt select { min-width: 8.5rem; }
.chip { border: 1px solid var(--line); border-radius: 99px; padding: .25rem .7rem; min-height: 36px; background: var(--surface-2); font-size: .9rem; }
.list-head { display: flex; justify-content: space-between; align-items: center; padding: .25rem .75rem; gap: .5rem; border-bottom: 1px solid var(--line); }
.cards { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.cards.inset { border: 1px solid var(--line); border-radius: var(--radius); }
.item { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.item.selected { background: var(--surface-2); }
.item-link { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: .55rem .75rem; text-decoration: none; color: inherit; border-left: 5px solid var(--line); }
.item-link:hover { background: var(--surface-2); }
.item-name { font-weight: 600; } .item-en { display: block; font-weight: 400; font-size: .82rem; color: var(--muted); }
.item-meta { font-size: .82rem; color: var(--muted); display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.item-link.missing { color: var(--danger); }
.empty { padding: 1.25rem .75rem; color: var(--muted); list-style: none; }
.fav { border: 0; background: transparent; font-size: 1.35rem; width: 44px; cursor: pointer; color: var(--muted); }
.fav.on { color: var(--ember); }
.kind-action { border-left-color: var(--iron); } .kind-condition { border-left-color: #7b6b2a; }
.school-abjuration { border-left-color: var(--s-abjuration); } .school-conjuration { border-left-color: var(--s-conjuration); } .school-divination { border-left-color: var(--s-divination); }
.school-enchantment { border-left-color: var(--s-enchantment); } .school-evocation { border-left-color: var(--s-evocation); } .school-illusion { border-left-color: var(--s-illusion); }
.school-necromancy { border-left-color: var(--s-necromancy); } .school-transmutation { border-left-color: var(--s-transmutation); }
span.badge.school-abjuration, .badge.school-conjuration, .badge.school-divination, .badge.school-enchantment, .badge.school-evocation, .badge.school-illusion, .badge.school-necromancy, .badge.school-transmutation { border-left-width: 1px; }
.badge.school-abjuration { background: var(--s-abjuration); } .badge.school-conjuration { background: var(--s-conjuration); } .badge.school-divination { background: var(--s-divination); }
.badge.school-enchantment { background: var(--s-enchantment); } .badge.school-evocation { background: var(--s-evocation); } .badge.school-illusion { background: var(--s-illusion); }
.badge.school-necromancy { background: var(--s-necromancy); } .badge.school-transmutation { background: var(--s-transmutation); }
.badge[class*="school-"] { color: #fff; border-color: transparent; }

/* значки */
.badges { display: flex; flex-wrap: wrap; gap: .35rem; margin: .5rem 0; }
.badge { display: inline-block; font-size: .78rem; padding: .05rem .55rem; border: 1px solid var(--line); border-radius: 99px; background: var(--surface-2); color: var(--ink); line-height: 1.5; }
.badge.mine { background: var(--iron); color: var(--iron-ink); border-color: var(--iron); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }

/* карточка */
.card-view, .set-view { max-width: 46rem; }
.card-head .back { display: none; margin-left: -.9rem; }
.title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: .5rem; }
.title-row .fav { font-size: 1.8rem; }
.orig-name { margin: -.25rem 0 0; color: var(--muted); font-style: italic; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; margin: .6rem 0 1rem; }
.params { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 1rem 0; padding: .8rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.params dt { color: var(--muted); } .params dd { margin: 0; }
.notice { background: var(--warn-bg); color: var(--warn-ink); padding: .5rem .75rem; border-radius: var(--radius); font-size: .92rem; }
.prose { font-size: 1.02rem; max-width: 68ch; } .prose p { margin: .6rem 0; } .prose ul { padding-left: 1.3rem; margin: .5rem 0; }
.table-wrap { overflow-x: auto; margin: .75rem 0; }
.prose table { border-collapse: collapse; min-width: 60%; } .prose th, .prose td { border: 1px solid var(--line); padding: .3rem .6rem; text-align: left; } .prose th { background: var(--surface-2); }
.higher, .original, .source, .dice-inline { margin-top: 1rem; }
details > summary { cursor: pointer; font-weight: 600; padding: .3rem 0; }
.original { border-left: 3px solid var(--line); padding-left: .9rem; }
.orig-pre { white-space: pre-wrap; font-family: var(--sans); }
.tags { display: flex; gap: .3rem; flex-wrap: wrap; } .tag { font-size: .8rem; color: var(--muted); border: 1px dashed var(--line); padding: 0 .5rem; border-radius: 4px; }
.license { color: var(--muted); }
.placeholder { max-width: 32rem; margin: 3rem auto; text-align: center; }

/* броски */
.dice-panel { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; background: var(--surface); }
.dice-row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; }
.dice-row label { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); gap: .15rem; }
.dice-row input[type="number"] { width: 5.5rem; }
.mod-input { display: inline-flex; gap: .25rem; } .mod-input input { width: 5rem; text-align: center; } .step { width: 40px; font-size: 1.2rem; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); border-radius: var(--radius); cursor: pointer; }
.roll-btn { min-width: 8rem; }
.roll-out { margin-top: .6rem; min-height: 0; }
.roll-result { display: flex; align-items: baseline; gap: .9rem; flex-wrap: wrap; }
.roll-total { font: 700 2.6rem/1 var(--serif); color: var(--ember); font-variant-numeric: tabular-nums; }
.roll-text { font-family: var(--mono); font-size: 1rem; overflow-wrap: anywhere; }
.roll-history { margin: .5rem 0 0; padding-left: 1.2rem; color: var(--muted); font: .82rem var(--mono); }
.named-rolls { margin-top: 1.25rem; } .named-roll { border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem .9rem; margin-bottom: .6rem; background: var(--surface); }
.named-roll-head { display: flex; gap: .75rem; flex-wrap: wrap; align-items: baseline; justify-content: space-between; }
.formula-preview { font-family: var(--mono); color: var(--muted); }
.named-roll-controls { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-top: .3rem; }
.mod-req { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); } .mod-req input { width: 6rem; }
.roll-row { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.roll-row input[type="number"] { width: 4.5rem; }
.roll-row.readonly { grid-template-columns: 1fr auto; }

/* диалоги, тосты */
.dlg { border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(32rem, calc(100vw - 1.5rem)); max-height: calc(100dvh - 2rem); background: var(--surface); color: var(--ink); }
.dlg.wide { width: min(44rem, calc(100vw - 1.5rem)); }
.dlg::backdrop { background: rgba(10, 15, 20, .55); }
.dlg[open] { display: flex; flex-direction: column; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: .5rem .5rem .5rem 1rem; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 1.25rem; } .dlg-body { padding: 1rem; overflow-y: auto; } .dlg-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .75rem 1rem; border-top: 1px solid var(--line); }
.set-checks { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.import-counts { padding-left: 1.2rem; } .warn-text { color: var(--danger); font-weight: 600; }
.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .4rem; z-index: 100; width: min(30rem, calc(100vw - 1.5rem)); }
.toast { background: var(--ink); color: var(--bg); padding: .6rem .9rem; border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.toast.error { background: var(--danger); color: #fff; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: .6rem 0; border-top: 1px solid var(--line); }

/* узкие экраны: список и просмотр сменяют друг друга */
@media (max-width: 899px) {
  .layout { grid-template-columns: 1fr; }
  .layout[data-view="list"] .detail-pane { display: none; }
  .layout[data-view="detail"] .list-pane { display: none; }
  .card-head .back { display: inline-block; }
  .detail-pane { padding: .75rem 1rem 3rem; }
  .params { grid-template-columns: 1fr; gap: 0; } .params dt { margin-top: .5rem; font-size: .85rem; }
  .roll-row { grid-template-columns: 1fr; }
  .brand-name { font-size: 1.15rem; }
  .app-head { padding: .5rem .75rem; }
  .app-head .btn { min-height: 38px; padding: .25rem .6rem; }
  .roll-total { font-size: 2.2rem; }
}
@media (prefers-reduced-motion: no-preference) { .toast { animation: pop .18s ease-out; } @keyframes pop { from { transform: translateY(8px); opacity: 0; } } }
