:root {
  color-scheme: dark;
  --ink: #f2ece1;
  --muted: #b9b0a3;
  --line: #413c36;
  --line-strong: #645c52;
  --paper: #151515;
  --panel: #1e1d1b;
  --panel-soft: #26231f;
  --accent: #d46a4c;
  --accent-strong: #f09a73;
  --gold: #d6a64a;
  --blue: #72b7d0;
  --green: #8cbf7e;
  --danger: #ff8f8f;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: linear-gradient(120deg, #111111 0%, #171615 48%, #101414 100%);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.modal-open {
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.auth-view {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  background: rgba(30, 29, 27, 0.94);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  margin: 0 auto;
  max-width: 420px;
  padding: 22px;
  width: min(100%, 420px);
}

.auth-card-title {
  align-items: center;
  display: grid;
  gap: 14px;
  grid-template-columns: 52px minmax(0, 1fr);
}

.auth-card h1 {
  font-size: 24px;
  line-height: 1.1;
  margin: 0;
}

.auth-mode-toggle {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.auth-mode-toggle .tab-button {
  width: 100%;
}

.auth-field {
  display: grid;
  gap: 6px;
}

.auth-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.auth-field input {
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  min-height: 40px;
  padding: 8px 10px;
  width: 100%;
}

.auth-field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 93, 127, 0.16);
  outline: none;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 760;
  min-height: 18px;
  margin: 0;
}

.google-auth-button {
  align-items: center;
  background: #f7f3ea;
  border: 1px solid #d8d0c2;
  border-radius: 8px;
  color: #1f1e1c;
  display: flex;
  font-weight: 800;
  justify-content: center;
  min-height: 40px;
  padding: 8px 12px;
}

.google-auth-button:hover,
.google-auth-button:focus {
  filter: brightness(1.04);
  outline: none;
}

.sheet-identity {
  align-items: center;
  display: grid;
  gap: 14px;
  grid-template-columns: 52px minmax(0, 1fr);
  min-width: 0;
}

.sigil {
  align-items: center;
  background: var(--accent);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.08);
  display: flex;
  font-size: 17px;
  font-weight: 850;
  height: 52px;
  justify-content: center;
  width: 52px;
}

.primary-button,
.ghost-button,
.danger-button,
.small-button {
  border-radius: 8px;
  border: 1px solid transparent;
  min-height: 38px;
  padding: 8px 12px;
}

.primary-button {
  background: var(--accent);
  color: #191312;
  font-weight: 750;
}

.ghost-button {
  background: var(--panel-soft);
  border-color: var(--line);
  color: var(--ink);
}

.danger-button {
  background: #342020;
  border-color: #704242;
  color: var(--danger);
}

.small-button {
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
  min-height: 32px;
  padding: 5px 9px;
}

.small-button:hover,
.ghost-button:hover,
.primary-button:hover {
  filter: brightness(1.04);
}

.workspace {
  margin: 0 auto;
  min-width: 0;
  padding: 18px 22px 24px;
  width: min(100%, 1560px);
}

.sheet-header {
  align-items: center;
  background: rgba(30, 29, 27, 0.86);
  border: 1px solid rgba(100, 92, 82, 0.9);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  justify-content: space-between;
  padding: 9px 12px;
}

.sheet-header .sigil,
.sheet-header .overline {
  display: none;
}

.sheet-header .sheet-identity {
  gap: 0;
  grid-template-columns: minmax(0, 1fr);
}

.overline {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sheet-header h2 {
  font-size: 20px;
  line-height: 1.12;
  margin: 0;
  overflow-wrap: anywhere;
}

.sheet-header p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-controls {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 6px;
  justify-content: flex-end;
  max-width: none;
}

.character-picker {
  display: block;
  min-width: 170px;
}

.character-picker span {
  display: none;
}

.character-picker select {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  min-height: 32px;
  padding: 5px 8px;
  width: 100%;
}

.save-status {
  color: var(--accent-strong);
  font-weight: 800;
  min-width: 54px;
}

.user-badge {
  color: var(--muted);
  font-weight: 760;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dev-account-select {
  background: #24221f;
  border: 1px dashed var(--line-strong);
  border-radius: 7px;
  color: var(--ink);
  min-height: 32px;
  max-width: 220px;
  padding: 5px 8px;
}

.save-path {
  display: none;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 10px 0 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.mobile-tab-menu-button {
  align-items: center;
  background: rgba(38, 35, 31, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: none;
  font-weight: 800;
  gap: 10px;
  justify-content: flex-start;
  margin: 10px 0;
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

.hamburger-icon {
  display: grid;
  gap: 4px;
  width: 18px;
}

.hamburger-icon span {
  background: var(--ink);
  border-radius: 999px;
  display: block;
  height: 2px;
  width: 18px;
}

.tab-button {
  background: rgba(38, 35, 31, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  flex: 0 0 auto;
  min-height: 34px;
  padding: 6px 11px;
}

.tab-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #191312;
}

.summary-strip {
  align-items: stretch;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.summary-tile {
  background: rgba(30, 29, 27, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  flex: 1 1 112px;
  min-height: 50px;
  min-width: 104px;
  padding: 7px 9px;
}

.summary-tile.compact-summary-tile {
  flex: 0 0 74px;
  min-width: 74px;
  padding: 6px 7px;
}

.summary-tile-header {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: space-between;
  min-height: 18px;
}

.summary-tile span {
  color: var(--muted);
  display: block;
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
}

.summary-tile.compact-summary-tile span {
  font-size: 9px;
  white-space: nowrap;
}

.summary-tile strong {
  display: block;
  font-size: 20px;
  line-height: 1.12;
  margin-top: 2px;
}

.summary-tile.compact-summary-tile strong {
  font-size: 18px;
}

.summary-icon-button {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  display: inline-flex;
  font-size: 11px;
  font-weight: 850;
  height: 22px;
  justify-content: center;
  min-width: 24px;
  padding: 0 5px;
}

.summary-icon-button:hover,
.summary-icon-button:focus {
  background: #201f1d;
  border-color: var(--line);
  color: var(--ink);
  outline: none;
}

.hp-summary-tile.editing {
  min-height: 78px;
}

.hp-adjust-row {
  align-items: center;
  display: flex;
  gap: 5px;
  margin-top: 5px;
}

.hp-adjust-input {
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 28px;
  min-width: 0;
  padding: 3px 6px;
  width: 100%;
}

.hp-adjust-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 93, 127, 0.16);
  outline: none;
}

.hp-adjust-apply {
  color: var(--accent-strong);
}

.hp-adjust-error {
  color: var(--danger);
  font-size: 11px;
  line-height: 1.2;
  margin-top: 4px;
}

.sheet-content {
  display: grid;
  gap: 16px;
}

.section-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.panel {
  background: rgba(30, 29, 27, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.24);
  min-width: 0;
  padding: 16px;
}

.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;
}

.panel-title {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 13px;
}

.panel-title h3 {
  font-size: 16px;
  margin: 0;
}

.panel-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.field-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 5px;
  grid-column: span 4;
  min-width: 0;
}

.field.wide {
  grid-column: span 12;
}

.field.half {
  grid-column: span 6;
}

.field.third {
  grid-column: span 4;
}

.field.quarter {
  grid-column: span 3;
}

.field label,
.mini-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.field input,
.field select,
.field textarea,
.table-input,
.formula-editor {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

.field textarea,
.formula-editor {
  min-height: 88px;
  resize: vertical;
}

.field-static {
  align-items: center;
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  display: flex;
  min-height: 38px;
  padding: 8px 10px;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.table-input:focus,
.formula-editor:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 93, 127, 0.16);
  outline: none;
}

.field input:disabled,
.field select:disabled,
.field textarea:disabled,
.table-input:disabled {
  background: #1a1918;
  color: #837b70;
  cursor: not-allowed;
  opacity: 1;
}

.derived-box {
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  grid-column: span 4;
  min-height: 66px;
  min-width: 0;
  padding: 10px;
}

.derived-box.half {
  grid-column: span 6;
}

.derived-box.wide {
  grid-column: span 12;
}

.derived-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.derived-box strong {
  font-size: 24px;
  line-height: 1.1;
}

.stat-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
}

.stat-card {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 12px;
}

.stat-card header {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.stat-card h4 {
  font-size: 14px;
  margin: 0;
}

.stat-card strong {
  color: var(--accent-strong);
  font-size: 24px;
}

.number-line {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) minmax(52px, 64px);
  min-width: 0;
}

.number-line strong {
  color: var(--accent-strong);
  font-size: 16px;
  text-align: right;
}

.data-table {
  border-collapse: collapse;
  width: 100%;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 790;
  white-space: nowrap;
}

.data-table td.total-cell,
.data-table th.total-cell {
  text-align: right;
  width: 72px;
}

.data-table td.skill-total-cell,
.data-table th.skill-total-cell {
  text-align: center;
  width: 72px;
}

.data-table td.skill-total-cell strong {
  color: var(--accent-strong);
  font-size: 16px;
}

.data-table td.narrow,
.data-table th.narrow {
  text-align: center;
  width: 48px;
}

.data-table td.actions,
.data-table th.actions {
  text-align: right;
  width: 56px;
}

.table-input {
  min-height: 32px;
  padding: 5px 7px;
}

.table-input[type="number"] {
  min-width: 0;
}

.table-check {
  height: 18px;
  width: 18px;
}

.badge {
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  font-weight: 760;
  padding: 4px 8px;
  white-space: nowrap;
}

.spell-rule-badge {
  border-color: rgba(214, 166, 74, 0.46);
  color: var(--ink);
}

.spell-remaining-badge {
  border-color: rgba(140, 191, 126, 0.5);
  color: var(--ink);
}

.spell-summary-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 0;
  position: relative;
}

.spell-summary-badges .spell-info-badge {
  overflow: visible;
  text-overflow: clip;
  white-space: nowrap;
}

.spell-summary-main .spell-sr-badge-wrap {
  display: inline-flex;
  overflow: visible;
  position: relative;
  white-space: normal;
}

.spell-sr-trigger {
  appearance: none;
  cursor: pointer;
  font-family: inherit;
  line-height: inherit;
}

.spell-sr-trigger:hover,
.spell-sr-trigger[aria-expanded="true"] {
  color: var(--ink);
}

.spell-sr-popover {
  background: #201f1d;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.38);
  color: var(--ink);
  display: grid;
  gap: 6px;
  left: 0;
  line-height: 1.35;
  padding: 10px;
  position: absolute;
  width: min(320px, 82vw);
  white-space: normal;
  z-index: 25;
}

.spell-sr-popover-below {
  top: calc(100% + 6px);
}

.spell-sr-popover-above {
  bottom: calc(100% + 6px);
}

.spell-sr-popover code {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--accent);
  font-size: 12px;
  padding: 6px 7px;
  white-space: normal;
}

.spell-sr-popover p {
  color: var(--muted);
  margin: 0;
}

.spell-info-badge {
  background: #201f1d;
  border-color: var(--line-strong);
  color: var(--ink);
}

.spell-school-abjuration {
  background: rgba(114, 183, 208, 0.16);
  border-color: rgba(114, 183, 208, 0.54);
}

.spell-school-conjuration {
  background: rgba(140, 191, 126, 0.16);
  border-color: rgba(140, 191, 126, 0.54);
}

.spell-school-divination {
  background: rgba(214, 166, 74, 0.16);
  border-color: rgba(214, 166, 74, 0.56);
}

.spell-school-enchantment {
  background: rgba(212, 106, 76, 0.18);
  border-color: rgba(212, 106, 76, 0.58);
}

.spell-school-evocation {
  background: rgba(255, 143, 143, 0.16);
  border-color: rgba(255, 143, 143, 0.58);
}

.spell-school-illusion {
  background: rgba(170, 140, 220, 0.18);
  border-color: rgba(170, 140, 220, 0.56);
}

.spell-school-necromancy {
  background: rgba(124, 150, 128, 0.18);
  border-color: rgba(124, 150, 128, 0.58);
}

.spell-school-transmutation {
  background: rgba(100, 190, 174, 0.16);
  border-color: rgba(100, 190, 174, 0.56);
}

.spell-school-other {
  background: rgba(185, 176, 163, 0.12);
  border-color: rgba(185, 176, 163, 0.44);
}

.spell-sr-no,
.spell-save-none {
  background: rgba(140, 191, 126, 0.14);
  border-color: rgba(140, 191, 126, 0.52);
}

.spell-sr-yes,
.spell-save-applies {
  background: rgba(212, 106, 76, 0.16);
  border-color: rgba(212, 106, 76, 0.58);
}

.spell-sr-varies,
.spell-save-partial {
  background: rgba(214, 166, 74, 0.15);
  border-color: rgba(214, 166, 74, 0.54);
}

.formula-row,
.item-row,
.spell-row,
.attack-row,
.feature-row,
.temporary-effect-row {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 12px;
}

.spell-row {
  grid-template-columns: minmax(180px, 1.25fr) repeat(3, minmax(82px, 0.5fr)) minmax(150px, 1fr) auto;
}

.spell-row.compact {
  gap: 0;
  grid-template-columns: 1fr;
  padding: 10px 12px;
}

.spell-level-stack {
  display: grid;
  gap: 18px;
}

.spell-level-section {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding-top: 14px;
}

.spell-level-section:first-child {
  border-top: 0;
  padding-top: 0;
}

.spell-level-title {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
}

.spell-level-title h3 {
  margin: 0;
}

.spell-level-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.spell-usage-field,
.feature-use-field {
  align-items: center;
  display: flex;
  gap: 6px;
}

.spell-usage-field input,
.feature-use-field input {
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 30px;
  padding: 3px 5px;
  width: 58px;
}

.spell-usage-field input:focus,
.feature-use-field input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 93, 127, 0.16);
  outline: none;
}

.spell-level-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 4px 0 6px;
}

.item-row {
  grid-template-columns: minmax(160px, 1.2fr) minmax(110px, 0.8fr) 70px 82px 82px minmax(120px, 0.9fr) 74px auto;
}

.item-row.collapsed {
  gap: 0;
  padding: 10px 12px;
}

.attack-row {
  grid-template-columns: minmax(170px, 1.2fr) minmax(95px, 0.7fr) 94px 72px 72px 72px 110px auto;
}

.attack-row-header {
  align-items: center;
  border-bottom: 1px solid rgba(100, 92, 82, 0.45);
  display: flex;
  gap: 12px;
  grid-column: 1 / -1;
  justify-content: space-between;
  min-width: 0;
  padding-bottom: 10px;
}

.attack-row-header > div:first-child {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.attack-row-header strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attack-row-actions {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.attack-total-box {
  min-height: 42px;
  min-width: 86px;
  padding: 7px 9px;
}

.combat-panel {
  gap: 0;
}

.combat-panel-summary {
  cursor: pointer;
  list-style: none;
}

.combat-panel-summary::-webkit-details-marker {
  display: none;
}

.combat-panel-summary::before {
  color: var(--accent);
  content: ">";
  font-weight: 900;
  margin-right: 8px;
}

.combat-panel[open] > .combat-panel-summary::before {
  content: "v";
}

.combat-panel-body,
.combat-panel > .data-table,
.combat-panel > .situational-save-bonuses {
  margin-top: 12px;
}

.feature-row {
  grid-template-columns: minmax(180px, 1fr) minmax(130px, 0.7fr) minmax(180px, 1fr) 74px auto;
}

.feature-row.compact {
  gap: 0;
  grid-template-columns: 1fr;
  overflow: visible;
  padding: 10px 12px;
}

.temporary-effect-row.compact {
  gap: 0;
  grid-template-columns: 1fr;
  padding: 10px 12px;
}

.formula-row {
  grid-template-columns: minmax(160px, 0.9fr) minmax(220px, 1.4fr) minmax(150px, 0.65fr) auto;
}

.spell-row > .field.wide,
.spell-editor > .field.wide,
.item-editor > .field.wide,
.feature-editor > .field.wide,
.temporary-effect-row > .field.wide,
.formula-row > .field.wide,
.attack-row > .field.wide,
.feature-row > .field.wide {
  grid-column: auto;
}

.item-summary {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-column: 1 / -1;
  grid-template-columns: 78px 32px minmax(0, 1fr) auto auto;
  min-width: 0;
}

.item-toggle {
  align-items: center;
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  height: 32px;
  justify-content: center;
  width: 32px;
}

.item-toggle:hover {
  border-color: var(--line-strong);
}

.item-summary-main {
  display: grid;
  gap: 3px;
  min-width: 0;
  position: relative;
}

.item-summary-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feature-summary {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-column: 1 / -1;
  grid-template-columns: 32px minmax(0, 1fr) auto auto auto;
  min-width: 0;
}

.spell-summary {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-column: 1 / -1;
  grid-template-columns: 32px minmax(0, 1fr) auto auto auto auto;
  min-width: 0;
}

.temporary-effect-summary {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-column: 1 / -1;
  grid-template-columns: 32px minmax(0, 1fr) auto auto auto auto auto;
  min-width: 0;
}

.feature-summary-main {
  display: grid;
  gap: 3px;
  min-width: 0;
  position: relative;
}

.spell-summary-main {
  display: grid;
  gap: 3px;
  min-width: 0;
  position: relative;
}

.temporary-effect-summary-main {
  display: grid;
  gap: 3px;
  min-width: 0;
  position: relative;
}

.feature-summary-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spell-summary-main span,
.temporary-effect-summary-main span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spell-summary-lines {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.spell-summary-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.spell-summary-line {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  gap: 7px;
  grid-template-columns: 84px minmax(0, 1fr);
  line-height: 1.35;
  min-width: 0;
}

.spell-summary-main .spell-summary-line span,
.spell-summary-main .spell-sr-popover span {
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
}

.spell-summary-line-label {
  color: var(--ink);
  font-weight: 760;
}

.spell-summary-line-value {
  color: var(--muted);
}

.spell-summary-main .spell-summary-line .spell-summary-text-value {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
}

.inline-feature-name {
  width: 100%;
}

.inline-suggestion-anchor {
  min-width: 0;
  position: relative;
}

.core-feat-suggestions,
.core-spell-suggestions,
.core-item-suggestions,
.temporary-effect-suggestions {
  background: #201f1d;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.35);
  display: grid;
  gap: 3px;
  left: 0;
  max-height: 260px;
  overflow: auto;
  padding: 5px;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 40;
}

.core-feat-suggestion,
.core-spell-suggestion,
.core-item-suggestion,
.temporary-effect-suggestion {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  font: inherit;
  gap: 2px;
  padding: 7px 8px;
  text-align: left;
}

.core-feat-suggestion:hover,
.core-feat-suggestion:focus,
.core-spell-suggestion:hover,
.core-spell-suggestion:focus,
.core-item-suggestion:hover,
.core-item-suggestion:focus,
.temporary-effect-suggestion:hover,
.temporary-effect-suggestion:focus {
  background: rgba(214, 166, 74, 0.12);
  border-color: rgba(214, 166, 74, 0.35);
  outline: none;
}

.core-feat-suggestion span,
.core-spell-suggestion span,
.core-item-suggestion span,
.temporary-effect-suggestion span {
  font-weight: 800;
}

.core-feat-suggestion small,
.core-feat-suggestion-empty,
.core-spell-suggestion small,
.core-spell-suggestion-empty,
.core-item-suggestion small,
.core-item-suggestion-empty,
.temporary-effect-suggestion small,
.temporary-effect-suggestion-empty {
  color: var(--muted);
  font-size: 12px;
}

.core-feat-suggestion-empty,
.core-spell-suggestion-empty,
.core-item-suggestion-empty,
.temporary-effect-suggestion-empty {
  padding: 8px;
}

.inline-spell-name {
  width: 100%;
}

.inline-temporary-effect-name {
  width: 100%;
}

.inline-item-name {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  min-height: 30px;
  min-width: 0;
  padding: 3px 5px;
  width: 100%;
}

.inline-item-name:focus {
  background: #201f1d;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 93, 127, 0.16);
  outline: none;
}

.inline-item-name::placeholder {
  color: var(--muted);
  font-weight: 700;
}

.item-summary-qty {
  align-items: center;
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.inline-item-qty {
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 30px;
  padding: 3px 5px;
  width: 48px;
}

.inline-item-qty:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 93, 127, 0.16);
  outline: none;
}

.item-effect-summary {
  color: var(--accent-strong);
  font-size: 13px;
}

.item-summary-check {
  align-items: center;
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.item-editor {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-column: 1 / -1;
  grid-template-columns: minmax(160px, 1.2fr) minmax(110px, 0.8fr) 70px 82px 82px minmax(120px, 0.9fr) 74px auto;
  padding-top: 12px;
}

.feature-editor {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-column: 1 / -1;
  grid-template-columns: minmax(160px, 0.8fr) minmax(220px, 1.2fr);
  margin-top: 12px;
  padding-top: 12px;
}

.feature-details {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-column: 1 / -1;
  margin-top: 10px;
  padding-top: 10px;
}

.feature-detail {
  display: grid;
  gap: 4px;
}

.feature-detail span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.feature-detail p {
  line-height: 1.45;
  margin: 0;
}

.feature-detail a {
  color: var(--blue);
  overflow-wrap: anywhere;
}

.feature-detail ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
}

.spell-details {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  margin-top: 10px;
  padding-top: 10px;
}

.spell-detail {
  display: grid;
  gap: 4px;
  grid-column: span 4;
  min-width: 0;
}

.spell-detail-wide {
  grid-column: 1 / -1;
}

.spell-detail span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.spell-detail p {
  line-height: 1.45;
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.spell-rulebook-description-body {
  color: var(--ink);
  display: grid;
  font-size: 14px;
  gap: 10px;
  line-height: 1.5;
}

.spell-rulebook-description-body p {
  margin: 0;
}

.spell-description-heading,
.spell-description-section h4 {
  border-bottom: 1px solid var(--line);
  color: var(--accent);
  font-size: 13px;
  font-weight: 820;
  line-height: 1.25;
  margin: 4px 0 0;
  padding-bottom: 6px;
}

.spell-description-section {
  display: grid;
  gap: 5px;
}

.spell-description-list-item {
  padding-left: 18px;
  position: relative;
}

.spell-description-list-item::before {
  color: var(--accent);
  content: "•";
  left: 2px;
  position: absolute;
}

.spell-editor {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-column: 1 / -1;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  margin-top: 12px;
  padding-top: 12px;
}

.item-editor > .item-link {
  grid-column: span 5;
}

.item-notes {
  grid-column: 1 / -1;
}

.feature-editor > .feature-prerequisites,
.feature-editor > .feature-benefit,
.feature-editor > .feature-normal,
.feature-editor > .feature-special,
.feature-editor > .feature-notes,
.feature-editor > .temporary-effect-link,
.feature-editor > .temporary-effect-notes,
.feature-editor > .item-effects {
  grid-column: 1 / -1;
}

.feature-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  grid-column: 1 / -1;
}

.spell-editor > .field.spell-description,
.spell-editor > .field.spell-notes,
.spell-editor > .field.spell-area {
  grid-column: 1 / -1;
}

.spell-editor > .field.spell-notes textarea {
  min-height: 130px;
}

.spell-editor > .field.spell-description textarea {
  min-height: 220px;
}

.spell-editor > .field.spell-area textarea {
  min-height: 82px;
}

.item-effects {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  padding-top: 10px;
}

.item-effects-title {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.item-effects-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.situational-save-bonuses {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
}

.situational-save-bonuses h4 {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  margin: 0;
}

.compact-table td {
  padding-bottom: 8px;
  padding-top: 8px;
}

.effect-row {
  align-items: end;
  border-top: 1px solid rgba(100, 92, 82, 0.45);
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(140px, 0.8fr) minmax(220px, 1.3fr) minmax(130px, 0.75fr) 86px auto;
  padding-top: 10px;
}

.effect-row > .field.wide {
  grid-column: auto;
}

.effect-notes {
  grid-column: 1 / -1;
}

.spell-description,
.spell-notes,
.attack-notes,
.feature-notes {
  grid-column: 1 / -1;
}

.row-stack {
  display: grid;
  gap: 10px;
}

.dashed-add-button {
  align-items: center;
  background: rgba(32, 31, 29, 0.55);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--accent-strong);
  cursor: pointer;
  display: flex;
  font-weight: 800;
  justify-content: center;
  min-height: 54px;
  padding: 12px;
  width: 100%;
}

.dashed-add-button:hover,
.dashed-add-button:focus {
  background: #201f1d;
  border-color: var(--accent);
  outline: none;
}

.planner-intro {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.planner-plan {
  display: grid;
  gap: 14px;
}

.planner-budget-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
}

.planner-budget-card {
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 9px 10px;
}

.planner-budget-card span,
.planner-budget-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.planner-budget-card strong {
  color: var(--ink);
  font-size: 18px;
  line-height: 1.1;
}

.planner-budget-card.is-complete {
  border-color: rgba(140, 191, 126, 0.58);
}

.planner-budget-card.is-over {
  border-color: rgba(255, 143, 143, 0.72);
}

.planner-budget-card.is-over strong {
  color: var(--danger);
}

.planner-warnings {
  background: rgba(212, 106, 76, 0.12);
  border: 1px solid rgba(212, 106, 76, 0.42);
  border-radius: 8px;
  color: var(--ink);
  display: grid;
  gap: 5px;
  font-size: 13px;
  padding: 10px;
}

.planner-feature-hints {
  background: rgba(32, 31, 29, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
}

.planner-feature-hints h4,
.planner-choice-grid h4 {
  font-size: 13px;
  margin: 0 0 8px;
}

.planner-feature-hints ul {
  color: var(--muted);
  margin: 0;
  padding-left: 18px;
}

.planner-choice-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.planner-choice-grid section {
  background: rgba(32, 31, 29, 0.42);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  padding: 12px;
}

.planner-choice-list {
  display: grid;
  gap: 8px;
}

.planner-choice-row {
  align-items: center;
  display: grid;
  gap: 7px;
  grid-template-columns: minmax(0, 1fr) 76px 32px;
  min-width: 0;
}

.planner-choice-row-wide {
  grid-template-columns: 74px minmax(140px, 0.9fr) minmax(180px, 1.1fr) 32px;
}

.planner-choice-row .icon-button {
  min-height: 32px;
}

.companion-panel {
  display: grid;
  gap: 14px;
}

.companion-progress-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
}

.companion-special-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.companion-layout {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.companion-layout section {
  background: rgba(32, 31, 29, 0.42);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  padding: 12px;
}

.companion-layout h4,
.companion-section-title h4 {
  font-size: 13px;
  margin: 0 0 8px;
}

.companion-ability-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.companion-ability-card {
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 9px;
}

.companion-ability-card label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 820;
}

.companion-ability-card strong {
  font-size: 13px;
}

.companion-attacks {
  grid-column: span 2;
}

.companion-section-title {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.companion-attack-row {
  grid-template-columns: minmax(140px, 1fr) minmax(110px, 0.7fr) minmax(110px, 0.7fr) 72px 72px 72px 86px auto;
}

.muted {
  color: var(--muted);
}

.link-button {
  align-items: center;
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue);
  display: inline-flex;
  justify-content: center;
  min-height: 36px;
  padding: 7px 10px;
  text-decoration: none;
}

.skill-rulebook-link {
  background: transparent;
  border: 0;
  color: var(--blue);
  font-weight: 760;
  min-height: 0;
  padding: 0;
  text-align: left;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.skill-rulebook-link:hover,
.skill-rulebook-link:focus-visible {
  color: var(--accent-strong);
}

.skill-rulebook-link:focus-visible {
  border-radius: 4px;
  outline: 2px solid rgba(214, 166, 74, 0.55);
  outline-offset: 2px;
}

.rules-modal {
  display: grid;
  inset: 0;
  padding: 20px;
  place-items: center;
  position: fixed;
  z-index: 100;
}

.rules-modal[hidden] {
  display: none !important;
}

.rules-modal-backdrop {
  background: rgba(8, 8, 8, 0.78);
  inset: 0;
  position: absolute;
}

.rules-modal-panel {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr;
  height: min(820px, calc(100vh - 40px));
  min-height: 360px;
  overflow: hidden;
  position: relative;
  width: min(1180px, calc(100vw - 40px));
  z-index: 1;
}

.rules-modal-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 14px;
  justify-content: space-between;
  padding: 14px 16px;
}

.rules-modal-header h2 {
  font-size: 18px;
  line-height: 1.2;
  margin: 0;
}

.rules-modal-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.rules-modal-status {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  min-height: 18px;
}

.rules-modal-url {
  background: #201f1d;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 36px;
  min-width: min(360px, 42vw);
  padding: 7px 10px;
}

.rules-modal-url:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(40, 93, 127, 0.16);
  outline: none;
}

.rules-frame-shell {
  background: #0f0f0f;
  min-height: 0;
}

.rules-frame-shell iframe {
  background: #fff;
  border: 0;
  display: block;
  height: 100%;
  width: 100%;
}

.rulebook-search-row {
  display: grid;
  gap: 8px;
}

.rulebook-search-input {
  font-size: 16px;
  min-height: 44px;
}

.rulebook-status {
  font-size: 12px;
  font-weight: 720;
}

.rulebook-reference-column {
  align-content: start;
  display: grid;
  gap: 16px;
  grid-column: span 12;
  min-width: 0;
}

.rulebook-editor-panel {
  align-self: start;
  gap: 10px;
  padding: 10px;
}

.rulebook-editor-panel .panel-title {
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.rulebook-editor-panel .panel-title h3 {
  font-size: 16px;
}

.rulebook-editor-panel .panel-actions {
  align-items: flex-end;
  flex-direction: column;
  gap: 6px;
}

.rulebook-editor-toolbar {
  align-items: end;
  display: grid;
  gap: 6px;
  grid-template-columns: minmax(92px, 120px) minmax(0, 1fr);
}

.rulebook-editor-toolbar .field {
  gap: 4px;
}

.rulebook-editor-toolbar .field label,
.rulebook-editor-toolbar .field span {
  font-size: 11px;
}

.rulebook-editor-toolbar .table-input {
  min-height: 32px;
  padding: 6px 8px;
}

.rulebook-editor-nav {
  display: flex;
  gap: 6px;
  grid-column: 1 / -1;
}

.rulebook-editor-current {
  align-items: start;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(280px, 0.9fr) minmax(420px, 1.1fr);
  min-width: 0;
}

.rulebook-editor-current-header {
  align-items: start;
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr) auto;
}

.rulebook-editor-current-header h3 {
  font-size: 14px;
  line-height: 1.2;
  margin: 0 0 3px;
}

.rulebook-editor-save-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: flex-end;
}

.rulebook-editor-save-actions .small-button,
.rulebook-editor-nav .small-button,
.rulebook-editor-grid-actions .small-button {
  min-height: 28px;
  padding: 5px 8px;
}

.rulebook-editor-crop,
.rulebook-editor-edit {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.rulebook-editor-edit {
  grid-template-columns: minmax(0, 1fr);
}

.rulebook-editor-edit > .field,
.rulebook-editor-edit > .rulebook-editor-grid-wrap,
.rulebook-editor-edit > .rulebook-editor-grid-actions,
.rulebook-editor-edit > .rulebook-editor-pane-toolbar,
.rulebook-editor-edit > .rulebook-editor-preview {
  grid-column: 1 / -1;
  width: 100%;
}

.rulebook-editor-pane-toolbar {
  align-items: center;
  display: flex;
  justify-content: flex-end;
}

.rulebook-editor-ai-feedback-field textarea {
  min-height: 56px;
  resize: vertical;
}

.segmented-control {
  background: #121211;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: inline-flex;
  gap: 2px;
  padding: 2px;
}

.segmented-control button {
  background: transparent;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 760;
  min-height: 26px;
  padding: 4px 9px;
}

.segmented-control button.active {
  background: var(--accent);
  color: #18130a;
}

.segmented-control button:focus-visible {
  outline: 2px solid rgba(214, 166, 74, 0.55);
  outline-offset: 2px;
}

.rulebook-editor-image-toolbar {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.rulebook-editor-image-toolbar strong {
  color: var(--ink);
}

.rulebook-editor-image-actions {
  display: flex;
  gap: 5px;
}

.rulebook-editor-image-scroll {
  background: #f4ecd4;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 560px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  touch-action: pan-x pan-y;
}

.rulebook-editor-image-scroll img {
  background: #f4ecd4;
  display: block;
  height: auto;
  max-width: none;
  min-width: 50%;
  object-fit: contain;
  object-position: top left;
  user-select: none;
  -webkit-user-drag: none;
  width: var(--rulebook-editor-image-width, 100%);
}

.rulebook-editor-sweep {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.rulebook-editor-column-delete,
.rulebook-editor-row-delete {
  align-items: center;
  height: 20px;
  justify-content: center;
  line-height: 1;
  margin-top: 0;
  min-width: 20px;
  padding: 0;
}

.rulebook-editor-column-delete {
  font-size: 10px;
  height: 22px;
  padding: 0 6px;
  width: 100%;
}

.rulebook-editor-grid-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  justify-self: stretch;
  max-height: 560px;
  max-width: 100%;
  min-width: 0;
  overflow: auto;
  width: 100%;
}

.rulebook-editor-grid {
  border-collapse: collapse;
  font-size: 11px;
  min-width: 100%;
  table-layout: fixed;
  width: 100%;
}

.rulebook-editor-grid th,
.rulebook-editor-grid td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 3px;
  vertical-align: top;
}

.rulebook-editor-grid th {
  background: #161514;
  color: var(--muted);
  font-size: 10px;
  font-weight: 760;
  left: 0;
  max-width: 42px;
  min-width: 42px;
  position: sticky;
  text-align: left;
  width: 42px;
  z-index: 1;
}

.mini-button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  font-size: 10px;
  font-weight: 760;
  margin-top: 4px;
  padding: 2px 4px;
}

.mini-button:hover,
.mini-button:focus-visible {
  border-color: var(--accent);
  color: var(--ink);
}

.rulebook-editor-grid textarea {
  font-size: 11px;
  line-height: 1.25;
  min-height: 28px;
  min-width: 0;
  padding: 4px 5px;
  resize: vertical;
  width: 100%;
}

.rulebook-editor-header-cell {
  align-items: start;
  display: grid;
  gap: 5px;
  grid-template-columns: minmax(0, 1fr);
}

.rulebook-editor-header-cell textarea {
  min-height: 34px;
  min-width: 0;
}

.rulebook-editor-body-cell {
  display: grid;
}

.rulebook-editor-grid-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rulebook-editor-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  overflow: hidden;
}

.rulebook-editor-preview-scroll {
  max-height: 560px;
  overflow: auto;
  scrollbar-gutter: stable;
}

.rulebook-rendered-table {
  border-collapse: collapse;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.35;
  min-width: 100%;
  width: max-content;
}

.rulebook-rendered-table th,
.rulebook-rendered-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  max-width: 240px;
  min-width: 72px;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.rulebook-rendered-table thead th {
  background: #181716;
  color: var(--ink);
  font-weight: 820;
}

.rulebook-rendered-group-row th {
  background: rgba(214, 166, 74, 0.16);
  color: var(--accent);
  font-size: 11px;
  text-align: center;
}

.rulebook-rendered-group-row th.is-empty {
  background: #181716;
}

.rulebook-rendered-table tbody th {
  color: var(--ink);
  font-weight: 780;
  white-space: nowrap;
}

.rulebook-results {
  display: grid;
  gap: 10px;
}

.rulebook-result {
  align-items: start;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 12px;
}

.rulebook-result-main {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.rulebook-result-title {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rulebook-result-title-area {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 0;
  text-align: left;
  width: 100%;
}

.rulebook-result-title-area:hover .rulebook-result-title strong,
.rulebook-result-title-area:focus-visible .rulebook-result-title strong {
  color: var(--accent);
}

.rulebook-result-title-area:focus-visible {
  border-radius: 6px;
  outline: 2px solid rgba(214, 166, 74, 0.55);
  outline-offset: 4px;
}

.rulebook-result-title strong {
  font-size: 15px;
}

.rulebook-result-path {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rulebook-result p {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.rulebook-table-links {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rulebook-table-links-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rulebook-result mark,
.rulebook-drawer-text mark {
  background: rgba(214, 166, 74, 0.26);
  border: 1px solid rgba(214, 166, 74, 0.36);
  border-radius: 4px;
  color: var(--ink);
  padding: 0 2px;
}

.rulebook-drawer-shell {
  inset: 0;
  pointer-events: none;
  position: fixed;
  z-index: 90;
}

.rulebook-drawer-backdrop {
  background: rgba(8, 8, 8, 0.58);
  border: 0;
  inset: 0;
  pointer-events: auto;
  position: absolute;
  width: 100%;
}

.rulebook-drawer {
  background: var(--panel);
  border-left: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  height: 100%;
  margin-left: auto;
  max-width: calc(100vw - 24px);
  pointer-events: auto;
  position: relative;
  width: min(720px, 52vw);
}

.rulebook-drawer-header {
  align-items: start;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 16px;
}

.rulebook-drawer-header h2 {
  font-size: 20px;
  line-height: 1.2;
  margin: 0 0 4px;
  overflow-wrap: anywhere;
}

.rulebook-drawer-meta {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
}

.rulebook-report-button {
  margin-left: auto;
}

.rulebook-issue-modal {
  display: grid;
  inset: 0;
  padding: 18px;
  place-items: center;
  position: fixed;
  z-index: 120;
}

.rulebook-issue-backdrop {
  background: rgba(8, 8, 8, 0.68);
  border: 0;
  inset: 0;
  position: absolute;
  width: 100%;
}

.rulebook-issue-panel {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  max-width: 620px;
  padding: 18px;
  position: relative;
  width: min(100%, 620px);
}

.rulebook-issue-header {
  align-items: start;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.rulebook-issue-header h2 {
  font-size: 20px;
  line-height: 1.2;
  margin: 0;
}

.rulebook-issue-header p {
  color: var(--muted);
  margin: 4px 0 0;
}

.rulebook-issue-field textarea {
  min-height: 150px;
}

.rulebook-issue-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.rulebook-issue-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.rulebook-issue-error,
.rulebook-issue-success {
  margin: 0;
}

.rulebook-drawer > .rulebook-table-links {
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
}

.rulebook-drawer-body {
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.rulebook-drawer-text {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.62;
  overflow-wrap: anywhere;
}

.rulebook-drawer-text h3 {
  border-bottom: 1px solid var(--line);
  font-size: 18px;
  line-height: 1.25;
  margin: 0 0 14px;
  padding-bottom: 10px;
}

.rulebook-block {
  margin: 0 0 12px;
}

.rulebook-block-labeled {
  display: grid;
  gap: 4px;
}

.rulebook-block-label {
  color: var(--accent);
  font-size: 11px;
  font-weight: 820;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rulebook-block-list-item {
  padding-left: 18px;
  position: relative;
}

.rulebook-block-list-item::before {
  color: var(--accent);
  content: "•";
  left: 2px;
  position: absolute;
}

.rulebook-table-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px;
}

.rulebook-table-preview-header {
  align-items: start;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.rulebook-table-preview-header h3 {
  font-size: 16px;
  line-height: 1.25;
  margin: 0 0 4px;
}

.rulebook-table-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rulebook-table-rendered {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  overflow: hidden;
}

.rulebook-table-rendered-scroll {
  max-height: min(70vh, 620px);
  overflow: auto;
  scrollbar-gutter: stable;
}

.rulebook-table-preview .rulebook-rendered-table th {
  position: static;
  top: auto;
  z-index: auto;
}

.rulebook-original-table-image {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.rulebook-original-table-image summary {
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 820;
  list-style-position: inside;
  padding: 8px 10px;
  text-transform: uppercase;
}

.rulebook-original-table-image[open] summary {
  border-bottom: 1px solid var(--line);
}

.rulebook-original-table-image .rulebook-table-image {
  border: 0;
  border-radius: 0;
}

.rulebook-table-image {
  background: #0f0f0f;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  margin: 0;
  overflow: hidden;
  padding: 10px;
}

.rulebook-table-image-header {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.rulebook-table-image-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 820;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rulebook-table-image img {
  background: #f4ecd4;
  border-radius: 6px;
  display: block;
  height: auto;
  max-height: 520px;
  object-fit: contain;
  object-position: top left;
  width: 100%;
}

.rulebook-table-scroll {
  overflow: auto;
}

.rulebook-subtables {
  display: grid;
  gap: 12px;
}

.rulebook-subtable {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  overflow: hidden;
  padding: 10px;
}

.rulebook-subtable-title {
  color: var(--ink);
  font-size: 13px;
  font-weight: 820;
}

.rulebook-subtable .rulebook-table-scroll {
  margin: 0 -10px -10px;
}

.rulebook-table-preview table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 100%;
}

.rulebook-table-preview th,
.rulebook-table-preview td {
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}

.rulebook-table-preview th {
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-weight: 780;
  position: sticky;
  top: 0;
  z-index: 1;
}

.rulebook-table-preview pre {
  color: var(--ink);
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  margin: 0;
  max-height: 380px;
  overflow: auto;
  white-space: pre-wrap;
}

@media (max-width: 760px) {
  .rulebook-editor-toolbar,
  .rulebook-editor-current {
    grid-template-columns: 1fr;
  }

  .rulebook-editor-current-header {
    grid-template-columns: 1fr;
  }

  .rulebook-editor-save-actions {
    justify-content: flex-start;
  }
}

.json-pane {
  position: relative;
}

.json-pane.is-collapsed::after {
  background: linear-gradient(to bottom, rgba(16, 16, 16, 0), #101010 78%);
  border-radius: 0 0 8px 8px;
  bottom: 1px;
  content: "";
  height: 72px;
  left: 1px;
  pointer-events: none;
  position: absolute;
  right: 1px;
}

.json-view {
  background: #101010;
  border-radius: 8px;
  color: #f5efe4;
  margin: 0;
  max-height: 180px;
  min-height: 0;
  overflow: hidden;
  padding: 16px;
  white-space: pre;
}

.json-pane.is-expanded .json-view {
  max-height: min(72vh, 820px);
  overflow: auto;
}

.ai-summary-view {
  max-height: 160px;
}

.json-pane.is-expanded .ai-summary-view {
  max-height: min(58vh, 640px);
}

.json-action-status {
  font-size: 12px;
  font-weight: 720;
}

.empty-state {
  background: rgba(30, 29, 27, 0.72);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

@media (max-width: 1100px) {
  .summary-strip {
    grid-template-columns: repeat(6, minmax(96px, 1fr));
  }

  .span-4,
  .span-5,
  .span-6,
  .span-7,
  .span-8,
  .rulebook-reference-column {
    grid-column: span 12;
  }

  .stat-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .spell-row,
  .spell-editor,
  .spell-details,
  .item-row,
  .item-editor,
  .feature-editor,
  .temporary-effect-row,
  .formula-row,
  .attack-row,
  .companion-attack-row,
  .feature-row,
  .effect-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .planner-choice-grid,
  .companion-layout {
    grid-template-columns: 1fr;
  }

  .companion-attacks {
    grid-column: span 1;
  }

  .spell-detail {
    grid-column: span 1;
  }

  .spell-detail-wide {
    grid-column: 1 / -1;
  }

  .item-editor > .item-link {
    grid-column: span 2;
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 18px;
  }

  .mobile-tab-menu-button {
    display: flex;
  }

  .tabs {
    display: none;
    gap: 6px;
    margin: -2px 0 10px;
    overflow: visible;
    padding: 8px;
    background: rgba(30, 29, 27, 0.9);
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .tabs.mobile-open {
    display: grid;
  }

  .tab-button {
    display: flex;
    justify-content: flex-start;
    text-align: left;
    width: 100%;
  }

  .rules-modal {
    padding: 10px;
  }

  .rules-modal-panel {
    height: calc(100vh - 20px);
    width: calc(100vw - 20px);
  }

  .rules-modal-header {
    align-items: flex-start;
    display: grid;
  }

  .rules-modal-actions {
    justify-content: flex-start;
  }

  .rulebook-result {
    grid-template-columns: 1fr;
  }

  .rulebook-result > .small-button {
    justify-self: start;
  }

  .rulebook-drawer {
    width: min(100vw, 620px);
  }

  .rulebook-drawer-header {
    grid-template-columns: 1fr;
  }

  .rulebook-report-button {
    margin-left: 0;
  }

  .rulebook-issue-modal {
    padding: 10px;
  }

  .rulebook-issue-panel {
    max-height: calc(100vh - 20px);
    overflow: auto;
    padding: 14px;
  }

  .rulebook-issue-header {
    grid-template-columns: 1fr;
  }

  .sheet-header {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr;
    padding: 9px 10px;
  }

  .header-controls {
    gap: 6px;
    justify-content: flex-start;
    max-width: none;
  }

  .character-picker {
    flex: 1 1 180px;
    min-width: 0;
  }

  .save-path {
    text-align: left;
  }

  .summary-strip,
  .stat-grid,
  .companion-ability-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-tile,
  .summary-tile.compact-summary-tile {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
  }

  .field,
  .field.half,
  .field.third,
  .field.quarter,
  .derived-box,
  .derived-box.half {
    grid-column: span 12;
  }

  .effect-row {
    grid-template-columns: 1fr;
  }

  .planner-choice-row,
  .planner-choice-row-wide,
  .attack-row,
  .companion-attack-row {
    grid-template-columns: 1fr;
  }

  .attack-row-header {
    align-items: stretch;
    display: grid;
    gap: 10px;
  }

  .attack-row-actions {
    justify-content: space-between;
  }

  .attack-total-box {
    min-width: 78px;
  }

  .spell-row {
    grid-template-columns: 1fr;
  }

  .item-summary {
    align-items: start;
    grid-template-columns: 58px 32px minmax(0, 1fr);
  }

  .item-summary-qty {
    grid-column: 1;
    grid-row: 1;
  }

  .item-summary > .item-toggle {
    grid-column: 2;
    grid-row: 1;
  }

  .item-summary-main {
    grid-column: 3;
    grid-row: 1;
  }

  .item-summary > .badge {
    grid-column: 3;
    grid-row: 2;
  }

  .item-summary-check {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  .inline-item-qty {
    max-width: 54px;
  }

  .feature-summary {
    align-items: start;
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .temporary-effect-summary {
    align-items: start;
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .spell-summary {
    align-items: start;
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .feature-summary > .link-button,
  .feature-summary > .small-button,
  .feature-use-field,
  .temporary-effect-summary > .link-button,
  .temporary-effect-summary > .small-button,
  .temporary-effect-active,
  .spell-summary > .badge,
  .spell-rulebook-link,
  .spell-summary > .small-button,
  .spell-summary > .link-button {
    grid-column: 2;
    justify-self: start;
    max-width: 100%;
  }

  .feature-summary > .link-button,
  .feature-summary > .small-button,
  .temporary-effect-summary > .link-button,
  .temporary-effect-summary > .small-button,
  .spell-summary > .link-button,
  .spell-summary > .small-button {
    min-height: 32px;
    padding: 6px 9px;
  }

  .spell-editor,
  .spell-details,
  .item-editor,
  .feature-editor,
  .temporary-effect-editor {
    grid-template-columns: 1fr;
  }

  .spell-detail {
    grid-column: 1 / -1;
  }

  .effect-row > .field.wide,
  .spell-row > .field.wide,
  .spell-editor > .field.wide,
  .spell-description,
  .spell-notes,
  .item-editor > .field.wide,
  .feature-editor > .field.wide,
  .temporary-effect-row > .field.wide,
  .temporary-effect-editor > .field.wide,
  .item-editor > .item-link {
    grid-column: 1 / -1;
  }

  .table-wrap {
    overflow: visible;
  }

  .skills-table,
  .skills-table thead,
  .skills-table tbody,
  .skills-table tr,
  .skills-table td,
  .active-effects-table,
  .active-effects-table thead,
  .active-effects-table tbody,
  .active-effects-table tr,
  .active-effects-table td,
  .combat-saves-table,
  .combat-saves-table thead,
  .combat-saves-table tbody,
  .combat-saves-table tr,
  .combat-saves-table td {
    display: block;
    width: 100%;
  }

  .skills-table thead,
  .active-effects-table thead,
  .combat-saves-table thead {
    display: none;
  }

  .skills-table tbody,
  .active-effects-table tbody,
  .combat-saves-table tbody {
    display: grid;
    gap: 8px;
  }

  .skills-table tr {
    background: var(--panel-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 6px 8px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 9px;
  }

  .skills-table td {
    border-bottom: 0;
    padding: 0;
  }

  .skills-table td:nth-child(1) {
    align-items: center;
    display: flex;
    grid-column: 1;
    grid-row: 1;
    min-width: 24px;
  }

  .skills-table td:nth-child(2) {
    align-items: center;
    display: flex;
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
  }

  .skills-table td:nth-child(3) {
    align-items: center;
    display: flex;
    grid-column: 3;
    grid-row: 1;
    justify-content: flex-end;
  }

  .skills-table td:nth-child(n+4) {
    align-items: center;
    display: grid;
    gap: 6px;
    grid-column: 1 / -1;
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .skills-table td:nth-child(4)::before { content: "Ability"; }
  .skills-table td:nth-child(5)::before { content: "Ranks"; }
  .skills-table td:nth-child(6)::before { content: "Misc"; }
  .skills-table td:nth-child(7)::before { content: "ACP"; }
  .skills-table td:nth-child(8)::before { content: "Trained"; }
  .skills-table td:nth-child(9)::before { content: "Actions"; }

  .skills-table td:nth-child(n+4)::before,
  .active-effects-table td::before,
  .combat-saves-table td::before {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
  }

  .active-effects-table tr,
  .combat-saves-table tr {
    background: var(--panel-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 7px;
    padding: 9px;
  }

  .active-effects-table td,
  .combat-saves-table td {
    align-items: center;
    border-bottom: 0;
    display: grid;
    gap: 8px;
    grid-template-columns: 92px minmax(0, 1fr);
    padding: 0;
  }

  .active-effects-table td:nth-child(1)::before { content: "Source"; }
  .active-effects-table td:nth-child(2)::before { content: "Effect"; }
  .active-effects-table td:nth-child(3)::before { content: "Target"; }
  .active-effects-table td:nth-child(4)::before { content: "Type"; }
  .active-effects-table td:nth-child(5)::before { content: "Bonus"; }

  .combat-saves-table td:nth-child(1)::before { content: "Save"; }
  .combat-saves-table td:nth-child(2)::before { content: "Progression"; }
  .combat-saves-table td:nth-child(3)::before { content: "Base"; }
  .combat-saves-table td:nth-child(4)::before { content: "Magic"; }
  .combat-saves-table td:nth-child(5)::before { content: "Misc"; }
  .combat-saves-table td:nth-child(6)::before { content: "Temp"; }
  .combat-saves-table td:nth-child(7)::before { content: "Total"; }

  .active-effects-table .total-cell,
  .combat-saves-table .total-cell {
    text-align: left;
  }
}
