:root {
  --bg-dark: #120e0b;
  --bg-parchment: #f5eedb;
  --bg-parchment-deep: #ebe0c5;
  --bg-input: #faf5ea;
  --ink-primary: #21150c;
  --ink-secondary: #4a3725;
  --ink-muted: #6e5842;
  --gold-ornament: #9e7a36;
  --gold-bright: #c89d47;
  --gold-glow: rgba(200, 157, 71, 0.25);
  --wax-red: #8a1f1d;
  --wax-red-hover: #a12724;
  --border-double: #b3996d;
  --border-subtle: #d3c4a5;
  --success-green: #2a5a2e;
  --font-main: 'Caudex', Georgia, 'Times New Roman', serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(circle at 50% 10%, rgba(158, 122, 54, 0.15), transparent 60%),
    linear-gradient(180deg, #18120e 0%, #0c0907 100%);
  color: var(--ink-primary);
  min-height: 100vh;
  padding: 2.5rem 1rem;
  line-height: 1.6;
}

.page-container {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

/* Parchment Card Container */
.parchment-scroll {
  background: var(--bg-parchment);
  background-image: 
    radial-gradient(ellipse at 50% 0%, rgba(255, 255, 255, 0.4), transparent 70%),
    radial-gradient(circle at 100% 100%, rgba(160, 130, 80, 0.1), transparent 50%);
  border: 1px solid var(--border-double);
  box-shadow: 
    0 0 0 4px #2b1f14,
    0 0 0 7px var(--border-double),
    0 15px 35px rgba(0, 0, 0, 0.6);
  border-radius: 4px;
  padding: 2.5rem 2.2rem;
  position: relative;
}

/* Banner / Proclamation Header */
.banner-card {
  text-align: center;
}

.ornament-top,
.ornament-bottom {
  font-size: 1.1rem;
  color: var(--gold-ornament);
  letter-spacing: 0.8rem;
  margin: 0.5rem 0;
  user-select: none;
}

.seal-mark {
  display: flex;
  justify-content: center;
  margin-bottom: 0.8rem;
}

.wax-seal {
  width: 72px;
  height: 72px;
  background: radial-gradient(circle at 35% 35%, #ab2926, var(--wax-red), #5e1110);
  border-radius: 50%;
  border: 2px solid #ff9b98;
  box-shadow: 
    0 4px 10px rgba(0, 0, 0, 0.5),
    inset 0 2px 4px rgba(255, 255, 255, 0.3),
    inset 0 -3px 6px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: bold;
}

.wax-seal.blason-seal {
  width: 96px;
  height: 96px;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
}

.seal-blason-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.45));
}

.wax-seal span {
  font-size: 1.5rem;
  line-height: 1;
}

.wax-seal small {
  font-size: 0.55rem;
  letter-spacing: 0.15rem;
  text-transform: uppercase;
  margin-top: 2px;
}

.royal-title {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--wax-red);
  letter-spacing: 0.05rem;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
}

.royal-subtitle {
  font-style: italic;
  color: var(--ink-secondary);
  font-size: 1.05rem;
  margin-bottom: 1.8rem;
}

.proclamation-text {
  text-align: justify;
  text-justify: inter-word;
  background: rgba(235, 224, 197, 0.4);
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  padding: 1.5rem 1.2rem;
  margin: 1.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  font-size: 1.12rem;
}

.proclamation-text .salutation {
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--ink-primary);
  text-align: center;
}

.proclamation-text strong {
  color: var(--wax-red);
}

.proclamation-text .final-call {
  font-size: 1.15rem;
  text-align: center;
  font-style: italic;
}

.domain-ref {
  margin-top: 1.5rem;
}

.scroll-cta {
  display: inline-block;
  background: var(--wax-red);
  color: #fff;
  text-decoration: none;
  padding: 0.75rem 1.6rem;
  border-radius: 3px;
  font-weight: 700;
  font-size: 1.05rem;
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
  transition: all 0.2s ease;
  border: 1px solid #c24643;
}

.scroll-cta:hover {
  background: var(--wax-red-hover);
  box-shadow: 0 6px 14px rgba(0,0,0,0.4);
  transform: translateY(-1px);
}

/* Enrollment Form Card */
.sheet-card {
  border-color: var(--gold-ornament);
}

.sheet-header {
  text-align: center;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--border-double);
  padding-bottom: 1.2rem;
}

.sheet-badge {
  display: inline-block;
  background: var(--gold-bright);
  color: #2b1f14;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1rem;
  text-transform: uppercase;
  padding: 0.2rem 0.6rem;
  border-radius: 2px;
  margin-bottom: 0.5rem;
}

.sheet-header h2 {
  font-size: 1.9rem;
  color: var(--ink-primary);
  font-weight: 700;
}

.sheet-desc {
  font-style: italic;
  color: var(--ink-muted);
  font-size: 0.95rem;
  margin-top: 0.3rem;
}

.form-section {
  border: 1px solid var(--border-subtle);
  background: rgba(250, 245, 234, 0.4);
  padding: 1.4rem;
  border-radius: 3px;
  margin-bottom: 1.8rem;
}

.form-section legend {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--wax-red);
  padding: 0 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05rem;
}

.identity-layout {
  display: flex;
  gap: 1.8rem;
  align-items: flex-start;
}

.avatar-portrait-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
  padding-top: 0.4rem;
}

.avatar-frame {
  width: 120px;
  height: 120px;
  border-radius: 4px;
  background: radial-gradient(circle at 35% 35%, #24180f, #140d08);
  border: 2px solid var(--border-double);
  box-shadow: 
    0 0 0 2px #18110b,
    0 0 0 4px var(--gold-ornament),
    0 6px 14px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.avatar-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.avatar-btn-group {
  display: flex;
  gap: 0.35rem;
  width: 100%;
}

.btn-avatar-action {
  font-family: var(--font-main);
  background: var(--bg-parchment-deep);
  border: 1px solid var(--border-double);
  color: var(--ink-primary);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.35rem 0.45rem;
  border-radius: 2px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  transition: all 0.2s ease;
  flex: 1;
  text-align: center;
}

.btn-avatar-action:hover {
  background: #e2d3b0;
  border-color: var(--gold-bright);
}

.avatar-customizer {
  background: rgba(235, 224, 197, 0.7);
  border: 1px double var(--gold-ornament);
  border-radius: 3px;
  padding: 1.2rem;
  margin-top: 1.2rem;
  animation: fadeIn 0.25s ease-out;
}

.avatar-customizer.hidden {
  display: none;
}

.customizer-header {
  border-bottom: 1px dashed var(--border-double);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.customizer-header h3 {
  font-size: 1.15rem;
  color: var(--wax-red);
  font-weight: 700;
}

.customizer-subtitle {
  font-size: 0.85rem;
  font-style: italic;
  color: var(--ink-muted);
}

.customizer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.8rem;
}

.customizer-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
  padding-top: 0.6rem;
  border-top: 1px dashed var(--border-double);
}

.identity-fields {
  flex-grow: 1;
}

.grid-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.8rem;
}

.field-group.full-width {
  grid-column: 1 / -1;
}

label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink-primary);
}

.req {
  color: var(--wax-red);
}

input[type="text"],
input[type="number"],
select,
textarea {
  font-family: var(--font-main);
  background: var(--bg-input);
  border: 1px solid var(--border-double);
  color: var(--ink-primary);
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  border-radius: 2px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.08);
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--wax-red);
  box-shadow: 0 0 0 2px rgba(138, 31, 29, 0.25);
}

/* Dice Roller & Allocation Panel */
.dice-roller-panel {
  background: rgba(235, 224, 197, 0.6);
  border: 1px double var(--gold-ornament);
  border-radius: 3px;
  padding: 1.2rem;
  margin-bottom: 1.4rem;
  text-align: center;
}

.roller-intro {
  font-size: 0.95rem;
  color: var(--ink-secondary);
  line-height: 1.5;
  margin-bottom: 0.9rem;
}

.roller-actions {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.btn-primary-roll {
  font-family: var(--font-main);
  background: linear-gradient(180deg, #c89d47 0%, #9e7a36 100%);
  border: 1px solid #73541c;
  color: #1a120b;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0.65rem 1.6rem;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
  transition: all 0.2s ease;
}

.btn-primary-roll:hover {
  background: linear-gradient(180deg, #d6ac59 0%, #ab853e 100%);
  transform: translateY(-1px);
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.35);
}

.dice-pool-container {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border-double);
  animation: fadeIn 0.3s ease-out;
}

.dice-pool-container.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.pool-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  text-align: left;
}

.pool-block {
  background: var(--bg-parchment);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  padding: 0.6rem 0.8rem;
}

.pool-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-muted);
  margin-bottom: 0.4rem;
}

.dice-badges {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.die-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 0.35rem;
  background: radial-gradient(circle at 35% 35%, #faf6eb, #e4d7be);
  border: 1px solid var(--border-double);
  border-radius: 3px;
  font-weight: 700;
  font-size: 1rem;
  color: var(--wax-red);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  user-select: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.4rem;
}

.stat-box {
  background: var(--bg-parchment-deep);
  border: 1px solid var(--border-subtle);
  padding: 0.75rem 0.5rem;
  text-align: center;
  border-radius: 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  transition: border-color 0.2s;
}

.stat-box[data-stat-group="3d6"] {
  border-left: 3px solid var(--wax-red);
}

.stat-box[data-stat-group="2d6plus6"] {
  border-left: 3px solid var(--gold-ornament);
}

.stat-box label {
  font-size: 0.95rem;
  display: block;
  font-weight: 700;
}

.stat-box label small {
  display: block;
  font-size: 0.7rem;
  font-weight: normal;
  color: var(--ink-muted);
}

.stat-box input.stat-readonly {
  width: 100%;
  max-width: 65px;
  text-align: center;
  font-weight: 700;
  font-size: 1.35rem;
  padding: 0.25rem 0;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--ink-primary);
  cursor: default;
}

.stat-box input.stat-readonly:focus {
  outline: none;
  box-shadow: none;
}

.stat-swap-select {
  font-family: var(--font-main);
  background: var(--bg-parchment);
  border: 1px solid var(--border-double);
  color: var(--ink-primary);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.25rem 0.35rem;
  border-radius: 2px;
  width: 100%;
  cursor: pointer;
}

.stat-swap-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.stat-swap-select:focus {
  outline: none;
  border-color: var(--wax-red);
}

/* Derived Stats Panel */
.derived-stats-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.8rem;
  background: rgba(235, 224, 197, 0.8);
  border: 1px double var(--gold-ornament);
  border-radius: 3px;
  padding: 0.9rem;
  text-align: center;
}

.derived-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.derived-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink-secondary);
}

.derived-val {
  font-size: 1.45rem;
  color: var(--wax-red);
  line-height: 1.2;
}

.derived-sub {
  font-size: 0.75rem;
  color: var(--ink-muted);
  font-style: italic;
}

/* Actions & Buttons */
.form-actions {
  display: flex;
  justify-content: center;
  margin-top: 1.5rem;
}

.btn-primary {
  font-family: var(--font-main);
  background: var(--wax-red);
  border: 2px solid #5a1210;
  color: #fff;
  font-weight: 700;
  font-size: 1.15rem;
  padding: 0.85rem 2.2rem;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary:hover:not(:disabled) {
  background: var(--wax-red-hover);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Feedback Messages */
.feedback-msg {
  display: none;
  padding: 0.8rem 1rem;
  margin-top: 1rem;
  border-radius: 2px;
  font-size: 0.95rem;
  text-align: center;
}

.feedback-msg.error {
  display: block;
  background: #fdf2f2;
  border: 1px solid #e07171;
  color: #8a1f1d;
}

.feedback-msg.success {
  display: block;
  background: #f2f7f2;
  border: 1px solid #7bc582;
  color: #235427;
}

/* Success Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.85);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-content {
  max-width: 580px;
  width: 100%;
  text-align: center;
  animation: modalIn 0.25s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-content h3 {
  font-size: 1.8rem;
  color: var(--wax-red);
  margin: 0.8rem 0 0.4rem 0;
}

.card-preview {
  background: var(--bg-input);
  border: 1px dashed var(--border-double);
  padding: 1rem;
  margin: 1.2rem 0;
  text-align: left;
  font-size: 0.95rem;
  max-height: 240px;
  overflow-y: auto;
}

.card-preview h4 {
  color: var(--wax-red);
  font-size: 1.1rem;
  margin-bottom: 0.3rem;
}

.card-preview .card-line {
  margin-bottom: 0.25rem;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* Footer */
.page-footer {
  text-align: center;
  color: #9c8a77;
  font-size: 0.85rem;
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* Responsive */
@media (max-width: 700px) {
  body {
    padding: 1rem 0.5rem;
  }
  .parchment-scroll {
    padding: 1.6rem 1.1rem;
  }
  .royal-title {
    font-size: 1.7rem;
  }
  .identity-layout {
    flex-direction: column;
    align-items: center;
  }
  .identity-fields {
    width: 100%;
  }
  .grid-fields {
    grid-template-columns: 1fr;
  }
  .customizer-grid {
    grid-template-columns: 1fr;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .derived-stats-panel {
    grid-template-columns: 1fr;
    gap: 0.6rem;
  }
}
