:root {
  color-scheme: light;
  --paper: #f5ebd6;
  --paper-deep: #ead9b9;
  --paper-light: #fff9eb;
  --ink: #241d16;
  --muted: #675947;
  --rule: #9c835b;
  --rule-soft: rgba(107, 82, 46, 0.28);
  --green: #516a4d;
  --green-deep: #304335;
  --red: #8f3f32;
  --red-deep: #682b24;
  --gold: #b68338;
  --blue-ink: #263849;
  --shadow: 0 18px 55px rgba(54, 35, 18, 0.2);
  --radius: 6px;
  --font-serif: Georgia, "Times New Roman", serif;
  --font-ui: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: var(--font-ui);
  background:
    linear-gradient(90deg, rgba(81, 106, 77, 0.12), transparent 22%, transparent 78%, rgba(143, 63, 50, 0.11)),
    repeating-linear-gradient(0deg, rgba(36, 29, 22, 0.035) 0, rgba(36, 29, 22, 0.035) 1px, transparent 1px, transparent 5px),
    var(--paper);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  padding: 28px;
}

.screen {
  max-width: 1320px;
  margin: 0 auto;
}

.title-screen {
  min-height: calc(100vh - 56px);
  display: grid;
  place-items: center;
}

.title-frame {
  width: min(920px, 100%);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 249, 235, 0.92), rgba(245, 235, 214, 0.96));
  box-shadow: var(--shadow);
  overflow: hidden;
}

.masthead-art {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 1;
  object-fit: cover;
  border-bottom: 1px solid var(--rule);
}

.title-mark {
  padding: 40px clamp(24px, 7vw, 72px) 24px;
  text-align: center;
}

.volume-line {
  margin: 0 0 8px;
  color: var(--red-deep);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 700;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(3.2rem, 8vw, 6.4rem);
  line-height: 0.95;
}

h2 {
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1.05;
}

h3 {
  font-size: 1.22rem;
  line-height: 1.15;
}

.title-copy {
  max-width: 620px;
  margin: 22px auto 0;
  color: var(--muted);
  font-family: var(--font-serif);
  font-size: clamp(1.08rem, 2vw, 1.35rem);
  line-height: 1.55;
}

.title-actions,
.ending-actions {
  display: flex;
  justify-content: center;
  padding: 0 24px 44px;
}

.ending-actions {
  padding: 22px 24px 0;
}

.button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-weight: 800;
  letter-spacing: 0;
  transition: transform 150ms ease, border-color 150ms ease, background-color 150ms ease, color 150ms ease;
}

.button:focus-visible,
.choice-button:focus-visible,
.option-card:focus-visible,
.trait-card:focus-visible,
.text-input:focus,
.select-input:focus {
  outline: 3px solid rgba(143, 63, 50, 0.35);
  outline-offset: 3px;
}

.button:hover:not(:disabled),
.choice-button:hover:not(:disabled),
.option-card:hover,
.trait-card:hover {
  transform: translateY(-1px);
}

.primary-button {
  color: #fff9eb;
  background: var(--red-deep);
  border-color: #4e1f19;
  box-shadow: 0 7px 16px rgba(104, 43, 36, 0.22);
}

.primary-button:hover:not(:disabled) {
  background: var(--red);
}

.secondary-button {
  color: var(--paper-light);
  background: var(--green-deep);
  border-color: #233429;
}

.ghost-button {
  color: var(--blue-ink);
  background: rgba(255, 249, 235, 0.55);
  border-color: var(--rule-soft);
}

.record-header,
.game-header {
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  border-bottom: 2px double var(--rule);
  padding-bottom: 18px;
}

.setup-screen {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 56px);
}

.setup-form {
  width: min(1000px, 100%);
  margin: 0 auto;
}

.quick-start-frame {
  position: relative;
  width: min(680px, 100%);
  margin: 0 auto;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255, 249, 235, 0.92), rgba(245, 235, 214, 0.96));
  box-shadow: var(--shadow);
  overflow: hidden;
}

.quick-start-art {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 1;
  object-fit: cover;
  border-bottom: 1px solid var(--rule);
}

.quick-start-back {
  position: absolute;
  top: 14px;
  left: 14px;
  min-height: 36px;
  padding: 6px 14px;
  font-size: 0.88rem;
}

.quick-start-body {
  padding: 30px clamp(22px, 6vw, 56px) 38px;
  text-align: center;
}

.quick-start-copy {
  max-width: 460px;
  margin: 14px auto 0;
  color: var(--muted);
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.55;
}

.quick-start-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 18px;
  margin-top: 26px;
  text-align: left;
}

.quick-field-wide {
  grid-column: 1 / -1;
}

.quick-start-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 30px;
}

.start-button {
  min-width: min(300px, 100%);
  min-height: 54px;
  font-size: 1.08rem;
}

.link-button {
  border: none;
  padding: 6px 10px;
  color: var(--blue-ink);
  background: none;
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 4px;
}

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

.link-button:focus-visible {
  outline: 3px solid rgba(143, 63, 50, 0.35);
  outline-offset: 3px;
}

.custom-setup-section {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 22px;
}

.setup-panel,
.ledger-panel,
.event-panel,
.ending-record {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 249, 235, 0.88), rgba(245, 235, 214, 0.9)),
    var(--paper-light);
  box-shadow: 0 10px 30px rgba(54, 35, 18, 0.11);
}

.setup-panel {
  min-width: 0;
  margin: 0;
  padding: 18px;
}

.setup-panel legend {
  padding: 0 8px;
  color: var(--green-deep);
  font-family: var(--font-serif);
  font-size: 1.24rem;
  font-weight: 700;
}

.traits-panel,
.ambition-panel,
.setup-actions {
  grid-column: 1 / -1;
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.text-input,
.select-input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--ink);
  background: #fffaf0;
}

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

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

.option-card,
.trait-card {
  min-width: 0;
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--ink);
  text-align: left;
  background: rgba(255, 249, 235, 0.7);
}

.option-card[aria-checked="true"],
.trait-card[aria-pressed="true"] {
  border-color: var(--red-deep);
  background: rgba(143, 63, 50, 0.09);
  box-shadow: inset 0 0 0 2px rgba(143, 63, 50, 0.18);
}

.option-card strong,
.trait-card strong {
  display: block;
  margin-bottom: 4px;
  color: var(--blue-ink);
}

.option-card span,
.trait-card span,
.small-note {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

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

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

.setup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.game-screen {
  max-width: 1500px;
}

.game-header {
  align-items: stretch;
}

.game-brand {
  display: flex;
  min-width: 0;
  gap: 14px;
  align-items: center;
}

.game-masthead {
  width: 154px;
  height: 76px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  object-fit: cover;
}

.year-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.year-strip span {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 9px 12px;
  color: var(--paper-light);
  font-weight: 800;
  background: var(--green-deep);
}

.year-strip span:first-child {
  background: var(--red-deep);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(440px, 1fr) minmax(270px, 340px);
  gap: 18px;
  align-items: start;
}

.ledger-panel,
.event-panel {
  padding: 18px;
}

.ledger-panel h3,
.event-panel h3 {
  margin-bottom: 14px;
  color: var(--blue-ink);
}

.stat-list {
  display: grid;
  gap: 12px;
}

.compact-stat-list {
  gap: 8px;
}

.compact-stat-list .stat-track {
  height: 8px;
}

.compact-stat-list .stat-label {
  font-size: 0.8rem;
}

.ledger-subheading {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--rule-soft);
  font-size: 1rem;
}

.ledger-detail {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--rule-soft);
}

.ledger-detail summary {
  cursor: pointer;
  color: var(--blue-ink);
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 700;
}

.ledger-detail summary::marker {
  color: var(--red-deep);
}

.ledger-detail .stat-list {
  margin-top: 12px;
}

.stat-row {
  display: grid;
  gap: 5px;
}

.stat-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 800;
}

.stat-label span:last-child {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.stat-track {
  height: 10px;
  border: 1px solid rgba(80, 60, 35, 0.28);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(80, 60, 35, 0.11);
}

.stat-fill {
  height: 100%;
  width: 50%;
  border-radius: inherit;
  background: var(--green);
  transition: width 180ms ease;
}

.stat-fill.warning {
  background: var(--gold);
}

.stat-fill.danger {
  background: var(--red-deep);
}

.condition-notes,
.household-panel {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.condition-pill {
  border-left: 4px solid var(--red-deep);
  padding: 8px 10px;
  color: var(--muted);
  background: rgba(143, 63, 50, 0.08);
  font-size: 0.88rem;
  line-height: 1.35;
}

.event-panel {
  min-height: 560px;
}

.event-panel.notice-mode {
  border-color: var(--red-deep);
  background:
    linear-gradient(180deg, rgba(255, 249, 235, 0.96), rgba(244, 226, 204, 0.92)),
    var(--paper-light);
  box-shadow: inset 0 0 0 3px rgba(143, 63, 50, 0.08), 0 10px 30px rgba(54, 35, 18, 0.11);
}

.event-panel.notice-mode #eventTitle::before {
  content: "Ledger Notice";
  display: block;
  margin-bottom: 8px;
  color: var(--red-deep);
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.event-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.event-meta span {
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius);
  padding: 5px 8px;
  color: var(--green-deep);
  font-size: 0.82rem;
  font-weight: 800;
  background: rgba(81, 106, 77, 0.09);
}

.event-text {
  margin: 0 0 22px;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: clamp(1.22rem, 2vw, 1.55rem);
  line-height: 1.58;
}

.choice-list {
  display: grid;
  gap: 10px;
}

.choice-button {
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--ink);
  text-align: left;
  background: rgba(255, 249, 235, 0.78);
  transition: transform 150ms ease, border-color 150ms ease, background-color 150ms ease;
}

.choice-button:hover:not(:disabled),
.choice-button:focus-visible {
  border-color: var(--red-deep);
  background: #fff8e8;
}

.choice-number {
  display: inline-grid;
  width: 26px;
  height: 26px;
  margin-right: 8px;
  place-items: center;
  border-radius: 50%;
  color: var(--paper-light);
  font-size: 0.82rem;
  font-weight: 900;
  background: var(--blue-ink);
}

.choice-title {
  font-weight: 900;
}

.choice-detail {
  display: block;
  margin: 7px 0 0 34px;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.42;
}

.selected-choice {
  display: grid;
  gap: 5px;
  border: 1px solid rgba(81, 106, 77, 0.35);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: rgba(81, 106, 77, 0.08);
}

.selected-choice span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.selected-choice strong {
  color: var(--blue-ink);
  font-size: 1rem;
}

.outcome-box {
  margin-top: 20px;
  border-top: 2px double var(--rule);
  padding-top: 16px;
}

.event-panel.outcome-mode .outcome-box {
  margin-top: 14px;
}

.outcome-box p {
  margin: 0 0 12px;
  color: var(--blue-ink);
  font-family: var(--font-serif);
  font-size: 1.12rem;
  line-height: 1.5;
}

.effect-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 16px;
}

.effect-chip {
  border: 1px solid var(--rule-soft);
  border-radius: 999px;
  padding: 5px 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  background: rgba(255, 249, 235, 0.68);
}

.effect-chip.good {
  color: var(--green-deep);
  border-color: rgba(81, 106, 77, 0.45);
}

.effect-chip.bad {
  color: var(--red-deep);
  border-color: rgba(143, 63, 50, 0.45);
}

.auto-advance-status {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0;
}

.side-stack {
  display: grid;
  gap: 18px;
}

.goals-panel {
  display: grid;
  gap: 14px;
}

.goal-entry {
  display: grid;
  gap: 7px;
  border-bottom: 1px solid var(--rule-soft);
  padding-bottom: 12px;
}

.goal-entry:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.goal-kicker {
  color: var(--red-deep);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.goal-title-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
  justify-content: space-between;
}

.goal-title-row strong {
  min-width: 0;
  color: var(--blue-ink);
  font-size: 0.95rem;
}

.goal-title-row span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.goal-description {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-serif);
  font-size: 0.9rem;
  line-height: 1.35;
}

.goal-track {
  height: 9px;
  border: 1px solid rgba(80, 60, 35, 0.28);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(80, 60, 35, 0.11);
}

.goal-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--gold);
}

.goal-fill.complete {
  background: var(--green);
}

.goal-empty {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-serif);
  font-size: 0.95rem;
  line-height: 1.35;
}

.household-item {
  display: grid;
  grid-template-columns: 104px 1fr;
  gap: 8px;
  border-bottom: 1px solid var(--rule-soft);
  padding-bottom: 8px;
  font-size: 0.94rem;
}

.household-item strong {
  color: var(--muted);
}

.journal-panel {
  max-height: 520px;
  overflow: auto;
}

.journal-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 22px;
}

.journal-list li {
  color: var(--muted);
  font-family: var(--font-serif);
  line-height: 1.35;
}

.journal-list li::marker {
  color: var(--red-deep);
  font-family: var(--font-ui);
  font-weight: 900;
}

.ending-screen {
  min-height: calc(100vh - 56px);
  display: grid;
  place-items: center;
}

.ending-record {
  width: min(980px, 100%);
  padding: clamp(22px, 5vw, 48px);
}

.ending-summary {
  margin: 18px 0 24px;
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 1.24rem;
  line-height: 1.56;
}

.legacy-badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 18px;
}

.legacy-badge {
  border: 1px solid rgba(38, 56, 73, 0.28);
  border-radius: 999px;
  padding: 7px 10px;
  color: var(--blue-ink);
  background: rgba(81, 106, 77, 0.1);
  font-size: 0.84rem;
  font-weight: 900;
}

.ending-scores {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.score-tile {
  border: 1px solid var(--rule-soft);
  border-radius: var(--radius);
  padding: 12px;
  background: rgba(255, 249, 235, 0.58);
}

.score-tile strong {
  display: block;
  color: var(--blue-ink);
  font-family: var(--font-serif);
  font-size: 1.8rem;
}

.score-tile span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.final-journal {
  max-height: 260px;
  overflow: auto;
  margin-top: 18px;
  box-shadow: none;
}

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

  .side-stack {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px;
  }

  .game-screen {
    gap: 14px;
  }

  .record-header,
  .game-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .custom-setup-section,
  .quick-start-fields,
  .game-layout,
  .side-stack,
  .ending-scores {
    grid-template-columns: 1fr;
  }

  .option-grid,
  .compact-options,
  .trait-grid,
  .ambition-grid {
    grid-template-columns: 1fr;
  }

  .setup-actions,
  .year-strip {
    justify-content: stretch;
  }

  .setup-actions .button,
  .year-strip span {
    flex: 1;
  }

  .year-strip {
    width: 100%;
    gap: 6px;
  }

  .year-strip span {
    min-width: 0;
    padding: 8px 9px;
    text-align: center;
  }

  .game-brand {
    gap: 10px;
  }

  .game-brand h2 {
    font-size: clamp(2.1rem, 10vw, 3rem);
  }

  .game-masthead {
    width: 104px;
    height: 56px;
  }

  .event-panel {
    order: 1;
    min-height: auto;
    padding: 16px;
  }

  .stat-ledger {
    order: 2;
    padding: 14px;
  }

  .side-stack {
    order: 3;
  }

  .ledger-panel h3,
  .event-panel h3 {
    margin-bottom: 10px;
  }

  .stat-ledger h3 {
    font-size: 1.3rem;
  }

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

  .stat-row {
    min-width: 0;
    gap: 4px;
  }

  .stat-label {
    gap: 6px;
    font-size: 0.76rem;
    line-height: 1.12;
  }

  .stat-track,
  .compact-stat-list .stat-track {
    height: 7px;
  }

  .ledger-subheading,
  .ledger-detail {
    margin-top: 12px;
    padding-top: 11px;
  }

  .ledger-subheading,
  .ledger-detail summary {
    font-size: 0.86rem;
  }

  .ledger-detail .stat-list {
    margin-top: 9px;
  }

  .condition-notes {
    gap: 6px;
    margin-top: 12px;
  }

  .condition-pill {
    padding: 7px 9px;
    font-size: 0.78rem;
  }

  .event-meta {
    gap: 6px;
    margin-bottom: 10px;
  }

  .event-meta span {
    padding: 4px 7px;
    font-size: 0.76rem;
  }

  .event-text {
    margin-bottom: 16px;
    font-size: 1.16rem;
    line-height: 1.48;
  }

  .choice-list {
    gap: 8px;
  }

  .choice-button {
    padding: 12px;
  }

  .choice-detail {
    margin-left: 32px;
    font-size: 0.88rem;
  }

  .outcome-box {
    margin-top: 12px;
    padding-top: 12px;
  }

  .outcome-box p {
    font-size: 1.05rem;
  }

  .effect-list {
    gap: 6px;
    margin-bottom: 12px;
  }

  .effect-chip {
    font-size: 0.76rem;
  }

  .selected-choice {
    padding: 10px 12px;
  }

  .household-item {
    grid-template-columns: 92px 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
