:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #faf4e7;
  color: #f4f0e9;
  --surface: #202629;
  --field: #171c20;
  --edge: #40474b;
  --muted: #bdc3c4;
  --gold: #f0c581;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; line-height: 1.5; }
p, h1, h2, h3 { margin: 0; }
button, input, select { font: inherit; }

.shell {
  max-width: 78rem;
  margin: auto;
  padding: clamp(1rem, 3.5vw, 3rem);
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1.25rem;
  padding: 1.65rem clamp(1rem, 3.5vw, 2.25rem);
  border: 1px solid #66543c;
  border-radius: 1rem;
  background: linear-gradient(110deg, #342a20, #242728 72%);
}

h1 {
  font: 600 clamp(2rem, 5vw, 3.6rem)/1.06 Georgia, serif;
  letter-spacing: -.035em;
}

h2 { font: 600 1.65rem/1.2 Georgia, serif; }
h3 { font-size: 1rem; }

.file-actions { display: flex; flex-wrap: wrap; gap: .45rem; }
button {
  min-height: 2.75rem;
  padding: .45rem .8rem;
  cursor: pointer;
  border: 1px solid var(--edge);
  border-radius: .5rem;
  background: var(--field);
  color: inherit;
  font-size: .875rem;
  font-weight: 650;
}

button:hover { border-color: var(--gold); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.primary { background: var(--gold); color: #211a12; border-color: var(--gold); }
.primary:hover { background: #ffdaa0; }
.file-status { margin: .8rem .15rem 1.35rem; color: #57514a; font-size: .875rem; }
.file-status.error { color: #8b291d; }

.workbench {
  display: grid;
  grid-template-columns: minmax(15rem, 1fr) minmax(0, 3fr);
  gap: 1rem;
  align-items: start;
}

.surface { border: 1px solid var(--edge); background: var(--surface); border-radius: .8rem; min-width: 0; }
.character { padding: 1.15rem; }
.character h3 { margin-top: 1.25rem; }
.character-fields { display: grid; grid-template-columns: minmax(0, 2fr) minmax(4.15rem, 1fr); gap: .75rem; margin-top: 1rem; }
.character-fields > :nth-child(-n + 2) { grid-column: 1 / -1; }
.field-hint, .save-hint { color: var(--muted); font-size: .875rem; }
.field-hint { margin-top: .28rem; }
.save-hint { margin-bottom: .85rem; }
.ability-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; margin-top: .65rem; }
.ability-grid > div { position: relative; }
.ability-grid input { padding-inline-end: 2rem; appearance: textfield; }
.ability-grid input::-webkit-inner-spin-button { display: none; }
.modifier { position: absolute; bottom: .66rem; right: .45rem; pointer-events: none; color: var(--gold); font-size: .875rem; }

.section-nav { display: flex; flex-wrap: wrap; gap: .35rem; padding: .65rem; border-bottom: 1px solid var(--edge); }
.section-nav button { background: transparent; border-color: transparent; color: var(--muted); }
.section-nav button:hover { color: var(--gold); }
.section-nav [aria-pressed="true"] { background: #392f23; border-color: #6b583d; color: var(--gold); }
.tool { padding: clamp(.8rem, 2.25vw, 1.35rem); }
.tool-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.options { display: grid; grid-template-columns: 1fr 1fr 2fr; gap: .7rem; margin-bottom: 1rem; }
.field { display: grid; gap: .28rem; min-width: 0; }
.field-label { font-size: .875rem; color: var(--muted); overflow-wrap: anywhere; }

input:not([type="checkbox"]), select {
  width: 100%;
  min-width: 0;
  min-height: 2.65rem;
  color: inherit;
  background: var(--field);
  border: 1px solid var(--edge);
  border-radius: .4rem;
  padding: .4rem .55rem;
}

select {
  appearance: none;
  padding-inline-end: 1.5rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--gold) 51%),
    linear-gradient(135deg, var(--gold) 50%, transparent 51%);
  background-position: calc(100% - .75rem) center, calc(100% - .5rem) center;
  background-size: .25rem .25rem;
  background-repeat: no-repeat;
}

.entries { display: grid; gap: .7rem; }
.entry { min-width: 0; margin: 0; border: 1px solid var(--edge); border-radius: .55rem; padding: .72rem; }
.entry legend { padding-inline: .35rem; color: var(--gold); font-weight: 650; font-size: .875rem; }
.entry-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(6rem, 100%), 1fr)); align-items: end; gap: .65rem; }
.entry-fields > :first-child { grid-column: span 2; }
.fifth-save-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: .65rem; }
.save-ability { display: grid; align-items: center; min-height: 2.65rem; color: var(--gold); }
.checkbox { display: flex; align-items: center; gap: .45rem; min-height: 2.65rem; padding-inline: .15rem; }
.checkbox input { margin: 0; width: 1.1rem; height: 1.1rem; accent-color: var(--gold); }
.check-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: .75rem; }
.check { display: grid; align-content: start; gap: .75rem; padding: 1rem; }
.check .primary { justify-self: start; }

.results:not(:empty) { margin-top: 1rem; overflow: hidden; border: 1px solid var(--edge); border-radius: .55rem; }
.tool > .results:not(:empty) { margin: 0 0 .9rem; }
.result-summary, .result-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .65rem .8rem;
  overflow-wrap: anywhere;
}

.result-summary { background: #392f23; color: var(--gold); }
.result-summary strong { font-size: 1.6rem; }
.result-line { background: var(--field); }
.result-line + .result-line { border-top: 1px solid var(--edge); }
.result-detail p { color: var(--muted); font-size: .875rem; }
.result-detail p:empty { display: none; }
.result-number { color: var(--gold); }
.empty-result { padding: .65rem .8rem; }
.print-value { display: none; }

@media (max-width: 49rem) {
  .workbench { grid-template-columns: minmax(0, 1fr); }
  .ability-grid { grid-template-columns: repeat(auto-fit, minmax(6.2rem, 1fr)); }
}

@media (max-width: 28rem) {
  .shell { padding: .65rem; }
  .options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .options > :last-child { grid-column: 1 / -1; }
  .entry-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fifth-save-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-nav button { padding-inline: .55rem; }
}

@media print {
  :root { color-scheme: light; color: black; background: white; --gold: black; --muted: #333; --edge: #aaa; }
  .shell { padding: 0; }
  .masthead { border: 0; padding: 0 0 .75rem; background: white; }
  .file-actions, .file-status, .section-nav, .primary, .results, .field-hint, .save-hint, input, select { display: none !important; }
  .workbench { display: block; }
  .surface { background: white; border: 0; }
  .character, .tool { padding: .45rem 0; }
  .entry, .character { break-inside: avoid; }
  .entries { gap: .25rem; }
  .entry { padding: .35rem; }
  .modifier { position: static; display: block; }
  .print-value { display: block; overflow-wrap: anywhere; }
}
