:root {
  color-scheme: dark;
  --bg: #0d0c0a;
  --panel: #191714;
  --panel-2: #231f19;
  --ink: #e4dac4;
  --muted: #9e927d;
  --line: #4a3d2b;
  --brass: #b8924f;
  --red: #8d1f1f;
  --red-hot: #c73a30;
  --green: #8ea96c;
  --shadow: rgba(0, 0, 0, 0.45);
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(141, 31, 31, 0.2), transparent 28rem),
    linear-gradient(120deg, rgba(255,255,255,0.03) 0 1px, transparent 1px 6px),
    var(--bg);
}

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

button {
  min-height: 2.25rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: linear-gradient(#30291f, #181511);
  cursor: pointer;
}

button:hover,
button.active,
button.selected {
  border-color: var(--brass);
  color: #fff5db;
}

button.primary {
  border-color: #a74431;
  background: linear-gradient(#9b2a25, #561514);
}

button.subtle {
  color: var(--muted);
  background: #14110d;
}

button.subtle:hover {
  color: var(--ink);
}

button.full {
  width: 100%;
}

input,
select,
textarea {
  width: 100%;
  min-height: 2.35rem;
  border: 1px solid #554731;
  border-radius: 4px;
  color: var(--ink);
  background: #100f0d;
  padding: 0.55rem 0.65rem;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4vw, 4rem);
}

h2 {
  color: #f0dfb8;
}

.app-shell {
  display: grid;
  grid-template-columns: 16rem minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, #17130f, #0b0a08);
  padding: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.seal {
  display: grid;
  place-items: center;
  width: 2.75rem;
  aspect-ratio: 1;
  border: 1px solid var(--brass);
  border-radius: 50%;
  color: var(--brass);
  font-family: Georgia, serif;
  font-size: 1.75rem;
}

.brand strong,
.character-card span {
  display: block;
}

.brand small,
.character-card small,
.eyebrow,
.muted {
  color: var(--muted);
}

.character-list {
  display: grid;
  gap: 0.55rem;
  margin: 1rem 0;
}

.character-card {
  text-align: left;
  padding: 0.75rem;
}

.sidebar-actions,
.topbar-actions,
.toolbar,
.chip-row,
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.assistive-tools {
  border-top: 1px solid #33291e;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
}

.workspace {
  min-width: 0;
  padding: 1rem 1.25rem;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0 1rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 1rem;
}

.eyebrow {
  margin-bottom: 0.2rem;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.stage-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18rem;
  gap: 1rem;
  align-items: start;
}

.creator-main {
  display: grid;
  gap: 0.75rem;
}

.stage-nav {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.5rem;
}

.stage-nav button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem;
}

.stage-nav span {
  display: grid;
  place-items: center;
  width: 1.35rem;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--brass);
  font-size: 0.75rem;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(rgba(255,255,255,0.025), transparent),
    var(--panel);
  box-shadow: 0 12px 40px var(--shadow);
  padding: 1rem;
}

.stage-panel,
.summary-panel {
  min-height: 24rem;
}

.summary-panel {
  position: sticky;
  top: 1rem;
}

.identity-editor {
  display: grid;
  grid-template-columns: 13rem minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.identity-editor.compact {
  grid-template-columns: 12rem minmax(0, 1fr);
}

.portrait-panel {
  display: grid;
  gap: 0.65rem;
}

.portrait-frame {
  display: grid;
  place-items: center;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  background:
    linear-gradient(135deg, rgba(184, 146, 79, 0.08), rgba(0, 0, 0, 0.2)),
    #0f0d0a;
  overflow: hidden;
}

.portrait-frame img,
.summary-portrait {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.summary-portrait {
  display: block;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--line);
  border-radius: 5px;
  margin-bottom: 0.85rem;
}

.portrait-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.file-button {
  display: inline-grid;
  place-items: center;
  min-height: 2.25rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  background: linear-gradient(#30291f, #181511);
  padding: 0 0.75rem;
  cursor: pointer;
}

.file-button input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.grid {
  display: grid;
  gap: 0.8rem;
}

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

.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.option-card {
  display: grid;
  gap: 0.35rem;
  min-height: 8rem;
  padding: 0.85rem;
  text-align: left;
}

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

.notice {
  border-left: 3px solid var(--brass);
  color: #d6c8aa;
  background: rgba(184, 146, 79, 0.08);
  padding: 0.75rem;
}

.mini-list ul {
  padding-left: 1.1rem;
}

.mini-list li {
  margin-bottom: 0.3rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.75rem;
}

.stat-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  border: 1px solid #3d3224;
  border-radius: 5px;
  background: var(--panel-2);
  padding: 0.75rem;
}

.stat-card output {
  color: #fff3ce;
  font-size: 2rem;
  font-weight: 700;
}

.bonus-digit {
  color: var(--brass);
  text-shadow: 0 0 14px rgba(184, 146, 79, 0.35);
}

.ones-digit {
  color: #fff3ce;
  opacity: 0.72;
}

.stat-card label,
.stat-card button,
.bonus {
  grid-column: span 2;
}

.bonus {
  color: var(--green);
  font-size: 0.8rem;
}

.resource-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

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

.number-box {
  border: 1px solid #3b3228;
  border-radius: 5px;
  background: #15130f;
  padding: 0.65rem;
}

.summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem 0.75rem;
}

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

.summary dd {
  margin: 0;
}

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

.identity-panel {
  grid-column: span 2;
}

.wide {
  grid-column: span 3;
}

.compact-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.compact-stats div {
  border: 1px solid #3b3228;
  border-radius: 4px;
  background: #11100d;
  padding: 0.6rem;
}

.compact-stats strong,
.compact-stats span {
  display: block;
}

.compact-stats span {
  color: #fff3ce;
  font-size: 1.6rem;
}

.sheet-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.6rem;
}

.sheet-stat {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  border: 1px solid #3b3228;
  border-radius: 4px;
  background: #11100d;
  padding: 0.6rem;
}

.sheet-stat output {
  color: #fff3ce;
  font-size: 2.15rem;
  font-weight: 700;
  line-height: 1;
}

.sheet-stat > span,
.sheet-stat label {
  grid-column: span 2;
}

.sheet-stat > span {
  color: var(--green);
  font-size: 0.8rem;
}

.sheet-stat label {
  grid-template-columns: 3rem 1fr;
  align-items: center;
}

.sheet-stat input {
  min-height: 2rem;
  padding: 0.35rem 0.45rem;
}

.sheet-stat output .bonus-digit,
.stat-card output .bonus-digit {
  color: var(--brass);
  font-size: 1.18em;
  text-shadow: 0 0 14px rgba(184, 146, 79, 0.35);
}

.sheet-stat output .ones-digit,
.stat-card output .ones-digit {
  color: #fff3ce;
  opacity: 0.72;
}

.tag-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
  gap: 0.5rem;
  margin-top: 0.8rem;
}

.tag-list span {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid #493a28;
  border-radius: 4px;
  background: #12100d;
  padding: 0.55rem;
  line-height: 1.35;
}

.tag-list button {
  min-height: 1.35rem;
  width: 1.35rem;
  padding: 0;
}

.gear-list {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.gear-list article {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) 5rem minmax(10rem, 1fr) auto;
  gap: 0.5rem;
}

.ledger {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.75rem;
}

.ledger article,
.catalog-list article {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.75rem;
  align-items: center;
  border-bottom: 1px solid #3b3228;
  padding: 0.55rem 0;
}

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

.catalog-list {
  max-height: 70vh;
  overflow: auto;
}

.catalog-list small {
  color: var(--muted);
}

.flash {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  border: 1px solid var(--brass);
  border-radius: 4px;
  background: #16120d;
  color: var(--ink);
  padding: 0.8rem 1rem;
  box-shadow: 0 12px 30px var(--shadow);
}

.modal {
  max-width: 28rem;
  border: 1px solid var(--brass);
  border-radius: 6px;
  color: var(--ink);
  background: var(--panel);
  padding: 1rem;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.75);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

@media (max-width: 1100px) {
  .app-shell,
  .stage-layout,
  .sheet-grid,
  .catalog {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .stage-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: auto;
  }

  .wide,
  .identity-panel {
    grid-column: span 1;
  }

  .summary-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .topbar,
  .gear-list article,
  .identity-editor,
  .identity-editor.compact {
    display: grid;
    grid-template-columns: 1fr;
  }

  .grid.two,
  .compact-stats,
  .stage-nav {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 2rem;
  }
}
