:root {
  --bg: #f2eded;
  --surface: #ffffff;
  --panel: #faf8f8;
  --border: #d6c8c8;
  --red: #550000;
  --red-light: #CD0606;
  --red-tint: rgba(139, 26, 26, 0.1);
  --text: #1a1010;
  --text-mid: #5a4040;
  --text-muted: #8a7272;
  --ink: #2a1414;
  --dark: #220202;
  --grid: rgba(139, 26, 26, 0.06);
  --grid-major: rgba(139, 26, 26, 0.11);
  --serif: 'Noto Serif', Georgia, serif;
  --sans: 'Nunito', system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171010;
    --surface: #221818;
    --panel: #2a1e1e;
    --border: #44302f;
    --red: #CD0606;
    --red-light: #e04848;
    --red-tint: rgba(196, 48, 48, 0.16);
    --text: #f5eaea;
    --text-mid: #cfb0b0;
    --text-muted: #937676;
    --grid: rgba(255, 255, 255, 0.035);
    --grid-major: rgba(255, 255, 255, 0.07);
    color-scheme: dark;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  overflow-y: scroll;
}

body {
  margin: 0;
  padding-bottom: 32px;
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid-major) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-major) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 24px 24px, 24px 24px;
  background-position: -1px -1px;
  color: var(--text);
  font-family: var(--sans);
}

.page {
  max-width: 1312px;
  margin: 0 auto;
  padding: 24px 16px 0;
}

.header {
  padding: 14px 16px;
  border-bottom: 4px solid var(--red-light);
  background: var(--dark);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .50)
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: 1280px;
  margin: 0 auto;
}

.header img {
  width: 52px;
  height: 52px;
  cursor: pointer;
}

.header img:hover {
  animation: spin 1.1s cubic-bezier(.45, 0, .25, 1);
}

.header h1 {
  margin: 0;
  color: #fff;
  font-family: var(--serif);
  font-size: 1.4rem;
  line-height: 1.15;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.header p {
  margin: 3px 0 0;
  color: rgba(255, 255, 255, .62);
  font-size: .72rem;
  letter-spacing: .08em;
  text-transform: lowercase;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

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

.stage {
  min-width: 0;
}

.sheet {
  --px: calc(100cqw / 1250);
  position: relative;
  width: 100%;
  aspect-ratio: 1250 / 1150;
  overflow: hidden;
  container-type: inline-size;
  border-radius: 10px;
  background: #ddd6d2;
  box-shadow: 0 2px 5px rgba(0, 0, 0, .20)
}

.sheet > * {
  position: absolute;
}

.sheet .background {
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.figure {
  isolation: isolate;
  pointer-events: none;
}

.figure canvas,
.figure .layers,
.figure .layers img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.sheet-field {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: calc(var(--px) * 4);
  outline: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  transition: background .15s, box-shadow .15s;
}

.sheet-field:hover {
  background: rgba(139, 26, 26, .07);
}

.sheet-field:focus {
  background: rgba(255, 255, 255, .6);
  box-shadow: 0 0 0 calc(var(--px) * 2.5) rgba(139, 26, 26, .5);
}

.sheet-field::placeholder {
  color: rgba(90, 60, 60, .42);
  font-style: italic;
  font-weight: 400;
}

input.sheet-field {
  padding: 0 calc(var(--px) * 4);
  font-size: calc(var(--px) * 24);
  font-weight: 600;
}

textarea.sheet-field {
  overflow: hidden;
  resize: none;
  font-size: calc(var(--px) * 19);
  line-height: calc(var(--px) * 28);
}

.bars {
  display: block;
  pointer-events: none;
}

.bar-handle {
  border-radius: calc(var(--px) * 8);
  cursor: ew-resize;
  touch-action: none;
}

.bar-handle:focus-visible {
  outline: calc(var(--px) * 3) solid rgba(139, 26, 26, .6);
  outline-offset: calc(var(--px) * 2);
}

.credits {
  margin: 10px 2px 0;
  color: var(--text-muted);
  font-size: .8rem;
  line-height: 1.5;
}

.credits span,
.credits a {
  color: var(--red);
  font-weight: 700;
}

.credits a {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.credits a:hover {
  color: var(--red-light);
  text-decoration-thickness: 2px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.card {
  overflow: hidden;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 2px 5px rgba(0, 0, 0, .20)
}

.card h2,
.card summary {
  margin: 0;
  padding: 8px 12px;
  color: #fff;
  font: 700 .8rem var(--serif);
  letter-spacing: .1em;
  text-transform: lowercase;
}

.card h2 {
  background: var(--red);
}

.card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--red);
  cursor: pointer;
  list-style: none;
}

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

.card summary::after {
  content: '+';
  font: 400 1.25rem/1 var(--sans);
  letter-spacing: 0;
  transition: transform .3s cubic-bezier(.2, .7, .2, 1);
}

.card.is-open summary::after {
  transform: rotate(45deg);
}

.card .reveal {
  overflow: hidden;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  transition: transform .15s;
}

.swatch:hover {
  transform: scale(1.12);
}

.swatch[aria-pressed="true"] {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--surface) inset;
  transform: scale(1.08);
}

.custom-skin {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: .72rem;
}

.custom-skin input {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 50%;
  background: none;
  cursor: pointer;
}

.slot {
  display: grid;
  grid-template-columns: 96px 1fr;
  overflow: hidden;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.slot-label {
  display: flex;
  align-items: center;
  padding: 0 9px;
  background: var(--dark);
  color: #fff;
  font-size: .64rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: lowercase;
}

.slot-controls {
  display: flex;
  align-items: center;
  min-width: 0;
}

.slot-item {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  padding: 5px 0;
}

.slot-name {
  font-size: .82rem;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.slot-name.none {
  color: var(--text-muted);
  font-style: italic;
  font-weight: 400;
}

.slot-count {
  color: var(--text-muted);
  font-size: .64rem;
  font-variant-numeric: tabular-nums;
}

.arrow {
  display: flex;
  align-items: center;
  align-self: stretch;
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: none;
  color: var(--text-mid);
  cursor: pointer;
  transition: color .15s, background .15s;
}

.arrow:hover {
  background: var(--red-tint);
  color: var(--red);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 10px;
  color: var(--text-mid);
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--red);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--text-mid);
  font-size: .72rem;
  font-weight: 700;
}

.field input,
.field textarea {
  width: 100%;
  padding: 6px 8px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font: 400 .88rem var(--sans);
}

.field textarea {
  min-height: 80px;
  resize: vertical;
  line-height: 1.45;
}

.field input:focus,
.field textarea:focus {
  outline: 2px solid var(--red);
  outline-offset: 1px;
}

.sliders {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slider {
  display: grid;
  grid-template-columns: 92px 1fr 30px;
  align-items: center;
  gap: 8px;
  font-size: .78rem;
  font-weight: 700;
}

.slider input {
  width: 100%;
  accent-color: var(--red);
}

.slider output {
  color: var(--red);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: 700 .84rem var(--sans);
  cursor: pointer;
  transition: all .15s;
}

.button:hover {
  border-color: var(--red);
  color: var(--red);
}

.button.primary {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.button.primary:hover {
  border-color: var(--red-light);
  background: var(--red-light);
  color: #fff;
}

.actions .primary {
  flex: 1 1 100%;
  justify-content: center;
}

.hint {
  margin: 0;
  color: var(--text-muted);
  font-size: .74rem;
  line-height: 1.45;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 4, 4, .7);
}

.modal {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(760px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 16px;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}

.modal h2 {
  margin: 0;
  font: 700 1.05rem var(--serif);
}

.modal img {
  display: block;
  width: 100%;
  height: auto;
  border: 1.5px solid var(--border);
  border-radius: 8px;
}

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

.status {
  color: var(--text-muted);
  font-size: .78rem;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .header img:hover {
    animation: none;
  }

  .card summary::after {
    transition: none;
  }
}
