:root {
  --bg: #f7f2e7;
  --bg-alt: #f0f2f1;
  --panel: #f0f2f1;
  --panel-strong: #f6efe3;
  --ink: #264653;
  --muted: #5b6e76;
  --heading: #3f7cba;
  --accent: #f4a261;
  --accent-deep: #d68b45;
  --line: rgba(38, 70, 83, 0.18);
  --shadow: 0 18px 32px rgba(38, 70, 83, 0.12);
  --radius: 0;
  --radius-sm: 0;
  --font-display: "Cinzel", "Times New Roman", serif;
  --font-body: "Open Sans", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    linear-gradient(180deg, rgba(247, 242, 231, 0.96), rgba(247, 242, 231, 0.96)),
    #f7f2e7;
  font-size: 16px;
  line-height: 1.5;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.08;
  background:
    radial-gradient(circle at 15% 10%, rgba(63, 124, 186, 0.18), transparent 25%),
    radial-gradient(circle at 80% 0%, rgba(244, 162, 97, 0.16), transparent 24%);
}

.shell {
  position: relative;
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 22px 24px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin: 0 -22px 18px;
  padding: 52px 34px 28px;
  min-height: 190px;
  background:
    linear-gradient(180deg, rgba(38, 70, 83, 0.62), rgba(38, 70, 83, 0.78)),
    url("https://herosgambit.com.au/images/1920/24228204/high-angle-of-color-dices-in-different-shapes-scattered-on-table-with-small-toy-animals-and-pencils-during-game-vl46lgS6UveiPt20Qunmmw.jpeg") center center / cover;
  color: #fff7ef;
  box-shadow: none;
}

.hero h1,
.panel h2,
.sheet h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.01em;
}

.hero h1 {
  font-size: clamp(2.2rem, 3.2vw, 3.2rem);
  line-height: 1;
  color: #fff;
}

.hero-version {
  margin: 8px 0 0;
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 247, 239, 0.78);
}

.lede {
  max-width: 60ch;
  color: rgba(255, 247, 239, 0.95);
  margin: 10px 0 0;
  font-size: 1rem;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.72rem;
  opacity: 0.82;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-identity {
  grid-column: 1;
  grid-row: 1;
}

.panel-attributes {
  grid-column: 2;
  grid-row: 1;
}

.panel-skills {
  grid-column: 3;
  grid-row: 1;
}

.panel-derived {
  grid-column: 1;
  grid-row: 2;
}

.panel-health {
  grid-column: 2;
  grid-row: 2;
}

.panel-gear {
  grid-column: 3;
  grid-row: 2;
}

.panel-output {
  grid-column: 1 / span 3;
  grid-row: 3;
}

.stack-lg > * + * {
  margin-top: 14px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.section-heading h2 {
  font-size: 1.28rem;
  color: var(--heading);
}

.hero-actions,
.inline-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  border: 1px solid var(--heading);
  border-radius: 0;
  padding: 9px 14px;
  font: inherit;
  font-weight: 400;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
  font-size: 0.94rem;
}

.button:hover {
  transform: translateY(-1px);
}

.button.solid {
  background: var(--heading);
  border-color: var(--heading);
  color: #f7f2e7;
}

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

.button.ghost:hover,
.button.solid:hover {
  text-decoration: none;
}

.hidden {
  display: none;
}

.grid {
  display: grid;
  gap: 12px;
}

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

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

.grid.compact > * {
  min-height: 0;
}

.field {
  display: grid;
  gap: 7px;
  font-size: 0.92rem;
}

.field span {
  font-weight: 700;
}

.field-hint {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  font: inherit;
}

textarea {
  resize: none;
  min-height: 96px;
}

.race-card,
.derived-card,
.sheet-block,
.stat-card {
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel-strong);
}

.race-card {
  padding: 0;
  border: 0;
  background: transparent;
}

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

.core-fact {
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fff;
}

.core-fact:first-child {
  grid-column: 1 / -1;
}

.core-fact-label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.core-fact-value {
  font-size: 0.92rem;
  line-height: 1.42;
  color: var(--ink);
}

.core-list {
  margin: 0;
  padding-left: 18px;
}

.core-list li + li {
  margin-top: 4px;
}

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

.stat-card {
  padding: 12px;
  display: grid;
  gap: 8px;
  background: #fff;
}

.stat-top {
  display: flex;
  justify-content: flex-start;
  gap: 10px;
  align-items: baseline;
}

.stat-name {
  font-weight: 700;
  color: var(--heading);
}

.stat-meta {
  color: var(--muted);
  font-size: 0.8rem;
}

.stepper {
  display: grid;
  grid-template-columns: 34px 1fr 34px;
  gap: 8px;
  align-items: center;
}

.stepper button {
  border-radius: 0;
  border: 1px solid var(--line);
  background: var(--bg-alt);
  padding: 7px 0;
  font: inherit;
  font-size: 1rem;
  color: var(--heading);
}

.stepper output {
  display: block;
  text-align: center;
  font-size: 1.18rem;
  font-weight: 700;
  color: var(--heading);
}

.derived-card {
  padding: 12px;
  background: #fff;
  border-top: 3px solid var(--heading);
}

.derived-card strong {
  display: block;
  font-size: 1.28rem;
  color: var(--heading);
}

.health-strip {
  padding: 12px;
  border-radius: 0;
  border: 1px solid var(--line);
  background: #fff;
}

.panel-gear,
.panel-output,
.panel-derived,
.panel-attributes,
.panel-skills {
  align-self: stretch;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  padding: 6px 10px;
  border-radius: 0;
  border: 1px solid rgba(90, 53, 31, 0.14);
  background: rgba(240, 242, 241, 0.8);
  font-size: 0.78rem;
}

.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

.gear-select {
  min-height: 205px;
  padding: 6px;
  font-size: 0.86rem;
}

.gear-select option {
  padding: 6px 8px;
}

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

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

.output-summary {
  display: block;
}

.summary-card {
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: #fff;
}

.summary-card h3 {
  margin: 0;
  font-size: 1.32rem;
  color: var(--heading);
}

.summary-lede,
.summary-paragraph {
  margin: 8px 0 0;
  font-size: 0.92rem;
  line-height: 1.45;
}

.summary-paragraph strong {
  color: var(--heading);
}

.print-sheet-only {
  display: none;
}

.sheet-quickfacts {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
}

.sheet-inline-block {
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: #fff;
}

.sheet-inline-block strong {
  color: var(--heading);
}

.sheet-inline-block p,
.sheet-paragraph {
  margin: 8px 0 0;
  line-height: 1.45;
}

.sheet-bullet-list {
  margin: 8px 0 0;
  padding-left: 18px;
}

.sheet-bullet-list li + li {
  margin-top: 4px;
}

.sheet-kicker {
  display: block;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-size: 0.72rem;
  color: var(--muted);
}

.sheet-header {
  padding: 20px;
  border-radius: 0;
  color: #fff6ed;
  background:
    linear-gradient(180deg, rgba(38, 70, 83, 0.7), rgba(38, 70, 83, 0.8)),
    url("https://herosgambit.com.au/images/1024/24116711/HGmaplogo-hires-nICJDyULd8OVMYma-K2KbA.png") center center / cover;
}

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

.sheet-block-wide {
  grid-column: 1 / -1;
}

.sheet-block {
  padding: 16px;
  background: #fff;
}

.sheet-block h3 {
  font-size: 1.15rem;
  line-height: 1.2;
}

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

.sheet-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid rgba(63, 124, 186, 0.12);
  padding-bottom: 6px;
}

.sheet-milestones {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
}

.sheet-milestone-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(63, 124, 186, 0.12);
}

.sheet-milestone-boxes {
  white-space: nowrap;
  letter-spacing: 0.14em;
}

.gear-columns h3 {
  margin: 0;
  font-family: var(--font-display);
  color: var(--heading);
}

.hero .button.ghost {
  color: #fff7ef;
  border-color: rgba(255, 247, 239, 0.55);
}

.hero .button.solid {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.panel h3,
.sheet h3 {
  color: var(--heading);
}

.field span,
.section-heading .inline-meta,
.health-strip > span {
  color: var(--ink);
}

a {
  color: var(--heading);
}

a:hover {
  color: var(--accent-deep);
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 1fr 1fr;
  }

  .panel-identity,
  .panel-derived,
  .panel-output,
  .panel-attributes,
  .panel-health,
  .panel-gear,
  .panel-skills {
    grid-column: auto;
    grid-row: auto;
  }
}

@media (max-width: 760px) {
  .shell {
    padding: 0 16px 24px;
  }

  .hero,
  .section-heading,
  .sheet-grid,
  .sheet-quickfacts,
  .output-summary,
  .grid.two,
  .grid.three,
  .gear-columns,
  .layout {
    grid-template-columns: 1fr;
    display: grid;
  }

  .hero {
    align-items: start;
    margin: 0 -16px 20px;
    padding: 80px 24px 30px;
    min-height: 240px;
  }

  .hero-actions,
  .section-heading {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .stepper {
    grid-template-columns: 52px 1fr 52px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  .core-facts {
    grid-template-columns: 1fr;
  }

  .sheet-milestones {
    grid-template-columns: 1fr;
  }

  .gear-select {
    min-height: 165px;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 9mm;
  }

  body {
    background: #fff;
    font-size: 9.2pt;
    line-height: 1.25;
  }

  body::before,
  .hero,
  .button,
  .field,
  .section-heading .hero-actions,
  #new-character,
  #random-character,
  #random-gear,
  #export-json,
  #print-sheet {
    display: none !important;
  }

  .shell {
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .layout {
    display: block;
  }

  .panel {
    box-shadow: none;
    border: none;
    padding: 0;
    background: transparent;
  }

  .stack-lg > * + * {
    margin-top: 0;
  }

  .section-heading {
    margin-bottom: 4mm;
  }

  .section-heading .eyebrow {
    margin-bottom: 1mm;
  }

  .section-heading h2 {
    font-size: 15pt;
    line-height: 1.1;
  }

  .sheet {
    gap: 3mm;
  }

  .output-summary {
    display: none !important;
  }

  .print-sheet-only {
    display: grid !important;
  }

  .sheet-quickfacts,
  .sheet-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3mm;
  }

  .sheet-header,
  .sheet-inline-block,
  .sheet-block {
    color: #000;
    background: #fff;
    border: 1px solid #ddd;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .sheet-header {
    padding: 4mm;
    background: #fff;
    color: #000;
    min-height: auto;
  }

  .sheet-header .eyebrow {
    color: #666;
    margin-bottom: 1mm;
  }

  .sheet-header h3 {
    font-size: 18pt;
    line-height: 1.05;
    margin-bottom: 1mm;
  }

  .sheet-header p,
  .sheet-inline-block p,
  .sheet-paragraph {
    margin: 0;
    font-size: 8.6pt;
    line-height: 1.25;
  }

  .sheet-inline-block,
  .sheet-block {
    padding: 3mm;
  }

  .sheet-block h3 {
    font-size: 10pt;
    margin-bottom: 2mm;
  }

  .sheet-list {
    gap: 1.2mm;
  }

  .sheet-row {
    gap: 3mm;
    padding-bottom: 0.8mm;
    font-size: 8.8pt;
    line-height: 1.15;
  }

  .sheet-row strong {
    white-space: nowrap;
  }

  .sheet-milestones {
    grid-template-columns: 1fr 1fr;
    gap: 1.4mm 3mm;
  }

  .sheet-milestone-row {
    gap: 2mm;
    padding-bottom: 0.6mm;
    font-size: 8.5pt;
    line-height: 1.15;
  }

  .sheet-milestone-boxes {
    letter-spacing: 0.08em;
  }

  .sheet-kicker {
    font-size: 6.8pt;
    margin-bottom: 1mm;
  }

  .muted {
    color: #666 !important;
  }

  main.layout > section:not(:last-of-type) {
    display: none !important;
  }

  #character-sheet-print {
    width: 100%;
  }
}
