:root {
  color-scheme: dark;
  --bg: #101113;
  --panel: #191b1f;
  --panel-2: #22252b;
  --ink: #f2f2f0;
  --muted: #aaa59d;
  --line: #343842;
  --accent: #d33b6b;
  --accent-ink: #ffffff;
  --soft: #2a2e36;
  --field: #111317;
  --statblock-bg: #cccccc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--ink);
  padding: 0.45rem 0.7rem;
  cursor: pointer;
}

button:hover {
  border-color: #6a7180;
  background: #2d323b;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 3;
}

.app-header h1,
.app-header p {
  margin: 0;
}

.app-header h1 {
  font-size: 1.1rem;
}

.app-header p {
  color: var(--muted);
  margin-top: 0.15rem;
  font-size: 0.88rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
  justify-content: flex-end;
}

.template-picker {
  width: 12rem;
}

.template-picker select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.42rem 0.5rem;
  background: var(--field);
  color: var(--ink);
}

.template-status {
  align-self: center;
  max-width: 16rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 118px minmax(0, 700px) minmax(300px, 380px);
  gap: 0.65rem;
  align-items: start;
  max-width: 1230px;
  margin: 0 auto;
  padding: 0.65rem;
}

.side-nav {
  position: sticky;
  top: 4.2rem;
  display: grid;
  gap: 0.15rem;
}

.side-nav a {
  color: var(--ink);
  text-decoration: none;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  font-size: 0.88rem;
}

.side-nav a:hover,
.side-nav a.active {
  background: var(--soft);
}

.editor,
.preview {
  display: grid;
  gap: 0.75rem;
}

.panel,
.preview {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
}

.section-title,
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.section-controls {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.section-title h2,
.preview-header h2 {
  margin: 0;
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preview-header span {
  color: var(--muted);
  font-size: 0.9rem;
}

.grid {
  display: grid;
  gap: 0.45rem 0.55rem;
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(8rem, max-content));
}

.grid.five {
  grid-template-columns: repeat(auto-fit, minmax(5rem, max-content));
}

.compact-fields {
  grid-template-columns: repeat(3, max-content);
  align-items: end;
}

.helper-panel .section-title {
  margin-bottom: 0;
}

#levelHelperBody {
  margin-top: 0.6rem;
}

.helper-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(7rem, 1fr) auto);
  gap: 0.45rem 0.5rem;
  align-items: end;
  margin-top: 0.55rem;
}

.helper-grid label {
  width: auto;
}

.helper-grid button {
  min-width: 5.8rem;
}

.field-xs {
  width: 5.5rem;
}

.field-sm {
  width: 7rem;
}

.field-md {
  width: 10rem;
}

.field-lg {
  width: 14rem;
}

.field-xl {
  width: 18rem;
}

label {
  display: grid;
  gap: 0.25rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.field-hint {
  min-height: 1em;
  color: #d4c9b4;
  font-size: 0.76rem;
}

.inline-field {
  margin-left: auto;
}

.section-controls .inline-field {
  margin-left: 0;
}

.output-field output {
  width: 100%;
  min-height: 2.05rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.42rem 0.5rem;
  background: var(--soft);
  color: var(--ink);
}

input,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.42rem 0.5rem;
  background: var(--field);
  color: var(--ink);
}

input[type="number"] {
  max-width: 5.5rem;
}

input[type="checkbox"] {
  width: auto;
}

textarea {
  min-height: 5rem;
  resize: vertical;
}

.field-toggle {
  display: flex;
  align-items: center;
  align-self: end;
  gap: 0.4rem;
  min-height: 2.15rem;
  color: var(--muted);
}

.add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px auto;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.add-row.wide {
  grid-template-columns: minmax(0, 1fr) auto;
}

.picker-row {
  display: grid;
  grid-template-columns: minmax(16rem, 1fr) auto;
  gap: 0.5rem;
  align-items: start;
  margin-bottom: 0.6rem;
}

.picker-row.ranked {
  grid-template-columns: minmax(16rem, 1fr) 5.5rem auto;
}

.option-list {
  display: grid;
  gap: 0.25rem;
  max-height: 11rem;
  overflow: auto;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.option-list.compact {
  max-height: 8rem;
}

.option-button {
  display: grid;
  gap: 0.1rem;
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.5rem;
  background: transparent;
  border-color: transparent;
}

.option-button:hover {
  background: var(--soft);
  border-color: var(--line);
}

.option-button.selected {
  background: #3b1725;
  border-color: var(--accent);
}

.option-label {
  color: var(--ink);
  font-weight: 700;
}

.option-meta,
.option-empty {
  color: var(--muted);
  font-size: 0.82rem;
}

.item-list {
  display: grid;
  gap: 0.4rem;
}

.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: start;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.item-fields {
  display: grid;
  gap: 0.5rem;
}

.item-title {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) 5.5rem;
  gap: 0.5rem;
}

.item-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.item-controls {
  display: grid;
  gap: 0.35rem;
}

.item button {
  padding: 0.45rem 0.65rem;
}

.item button:disabled {
  cursor: default;
  opacity: 0.45;
}

.empty-state {
  padding: 0.75rem;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.warning-list,
.todo-list {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.65rem;
}

.warning-list[hidden],
.todo-list[hidden] {
  display: none;
}

.warning-item,
.todo-list {
  border: 1px solid #8d6a21;
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  background: #251e12;
  color: #f3d99b;
}

.todo-list strong {
  display: block;
  margin-bottom: 0.25rem;
  color: #ffe6a6;
}

.todo-list ul {
  margin: 0;
  padding-left: 1.1rem;
}

.preview {
  position: sticky;
  top: 4.2rem;
}

.level-summary {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: none;
  letter-spacing: 0;
}

.level-input {
  display: grid;
  grid-template-columns: auto 5.5rem;
  gap: 0.45rem;
  align-items: center;
  margin-left: auto;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.level-input input {
  width: 100%;
}

.level-summary strong {
  min-width: 2rem;
  border-radius: 6px;
  padding: 0.2rem 0.45rem;
  background: var(--accent);
  color: var(--accent-ink);
  text-align: center;
}

.level-breakdown {
  margin: -0.25rem 0 0.6rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.statblock-preview {
  border: 2px solid #111;
  background: var(--statblock-bg);
  color: #111;
  font-size: 0.9rem;
}

.preview-row {
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid #111;
}

.preview-black {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  background: #000;
  color: #fff;
  font-weight: 700;
}

.preview-subtitle {
  font-style: italic;
}

.preview-attributes {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 0;
}

.preview-attributes div {
  display: grid;
  grid-template-rows: auto auto;
  text-align: center;
  border-right: 1px solid #111;
}

.preview-attributes div:last-child {
  border-right: 0;
}

.preview-attributes strong {
  background: #000;
  color: #fff;
  padding: 0.35rem 0.25rem;
}

.preview-attributes span {
  padding: 0.3rem 0.25rem;
}

.preview-section-title {
  background: #000;
  color: #fff;
  font-weight: 700;
}

.preview-list {
  line-height: 1.45;
}

.preview-list strong {
  color: #7d002b;
}

.inline-ccs {
  font-family: "Mentor Sans Std Black", "Arial Black", Arial, sans-serif;
  font-size: 8pt;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0.014cm;
  text-transform: uppercase;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 118px minmax(0, 1fr);
  }

  .preview {
    position: static;
    grid-column: 2;
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
    position: static;
  }

  .header-actions {
    justify-content: start;
  }

  .template-picker,
  .template-status {
    width: 100%;
    max-width: none;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-nav,
  .preview {
    position: static;
    grid-column: auto;
  }

  .side-nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid.two,
  .grid.five,
  .compact-fields,
  .helper-grid,
  .add-row,
  .add-row.wide,
  .picker-row,
  .picker-row.ranked,
  .item-title {
    grid-template-columns: 1fr;
  }

  .field-xs,
  .field-sm,
  .field-md,
  .field-lg,
  .field-xl,
  .helper-grid label,
  input[type="number"] {
    width: 100%;
    max-width: none;
  }
}
