:root {
  --paper: #f4f0e5;
  --paper-light: #fffdf7;
  --ink: #28231d;
  --ink-soft: #695f52;
  --brass: #8c7044;
  --brass-dark: #645033;
  --line: rgba(73, 58, 39, 0.27);
  --line-strong: rgba(73, 58, 39, 0.55);
  --danger: #7a342b;
  --success: #3f6547;
  --shadow: 0 14px 45px rgba(68, 53, 34, 0.08);
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, transparent 0, transparent calc(50% - 1px), rgba(140, 112, 68, 0.035) 50%, transparent calc(50% + 1px)),
    var(--paper);
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--brass-dark); outline-offset: 3px; }

.masthead {
  width: min(1180px, calc(100% - 40px));
  min-height: 130px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line-strong);
}

.wordmark { text-align: center; padding: 22px 40px 16px; position: relative; }
.wordmark h1 { font-size: clamp(2rem, 4vw, 3.45rem); line-height: 0.95; margin: 7px 0 9px; font-weight: 400; letter-spacing: -0.055em; }
.wordmark h1 i { font-weight: 400; }
.rule-mark { display: flex; align-items: center; gap: 10px; color: var(--brass); font-size: 0.75rem; }
.rule-mark::before, .rule-mark::after { content: ''; height: 1px; width: 72px; background: var(--line); }
.rule-mark { justify-content: center; }

.eyebrow, .ledger-label, .section-number {
  display: block;
  color: var(--ink-soft);
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.back-link, .text-button {
  color: var(--ink-soft);
  font-size: 0.78rem;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.text-button { justify-self: end; border: 0; padding: 12px 0; background: transparent; cursor: pointer; border-bottom: 1px solid transparent; }
.back-link:hover, .text-button:hover { color: var(--ink); border-bottom-color: var(--brass); }

.page-shell { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }
.status-ledger { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line-strong); }
.status-ledger > div { min-width: 0; padding: 22px 26px 20px; border-right: 1px solid var(--line); }
.status-ledger > div:first-child { padding-left: 0; }
.status-ledger > div:last-child { border-right: 0; }
.status-ledger strong { display: block; overflow: hidden; margin-top: 7px; font-size: clamp(1.08rem, 2vw, 1.45rem); font-weight: 400; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.85fr); gap: 56px; padding: 54px 0 64px; }
.machine-panel { min-width: 0; }
.machine-heading, .estate-heading { display: flex; align-items: center; gap: 18px; margin-bottom: 26px; }
.machine-heading h2, .estate-heading h2 { margin: 2px 0 0; font-size: 1.75rem; font-weight: 400; }
.machine-heading .text-button { margin-left: auto; }
.section-number { color: var(--brass); }

.slot-machine {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: clamp(14px, 3vw, 26px);
  overflow: hidden;
  border: 1px solid var(--brass-dark);
  background: #d9c79e;
  box-shadow: inset 0 0 0 5px var(--paper-light), inset 0 0 0 6px var(--line-strong), var(--shadow);
}

.slot-machine::before, .slot-machine::after { content: ''; position: absolute; left: 22px; right: 22px; height: 1px; background: rgba(77, 58, 30, 0.35); }
.slot-machine::before { top: 10px; }
.slot-machine::after { bottom: 10px; }

.reel {
  position: relative;
  height: clamp(116px, 19vw, 166px);
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background: var(--paper-light);
  box-shadow: inset 0 10px 25px rgba(63, 47, 26, 0.08), inset 0 -10px 25px rgba(63, 47, 26, 0.08);
}

.reel span { display: block; font-size: clamp(3.3rem, 9vw, 6rem); line-height: 1; transform: translateY(0); }
.reel.rolling span { animation: reel-roll 180ms linear infinite; filter: blur(1px); }
.reel.settle span { animation: reel-settle 280ms cubic-bezier(.17,.89,.32,1.35); }

@keyframes reel-roll {
  from { transform: translateY(-65px); opacity: 0.15; }
  50% { opacity: 0.75; }
  to { transform: translateY(65px); opacity: 0.15; }
}
@keyframes reel-settle { from { transform: translateY(-22px); opacity: 0.4; } to { transform: translateY(0); opacity: 1; } }

.payline { position: absolute; left: 19px; right: 19px; top: 50%; height: 1px; pointer-events: none; background: var(--brass); opacity: 0.55; }
.machine-flourish { position: absolute; left: 50%; bottom: 2px; padding: 0 8px; transform: translateX(-50%); background: #d9c79e; color: var(--brass-dark); font-size: 0.62rem; letter-spacing: 0.25em; }
.result-line { min-height: 48px; margin: 0; padding: 16px 4px 10px; text-align: center; color: var(--ink-soft); font-style: italic; }
.result-line[data-tone="win"] { color: var(--success); }
.result-line[data-tone="loss"] { color: var(--danger); }

.mode-tabs, .asset-tabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line-strong); }
.mode-tabs button, .asset-tabs button { min-width: 0; min-height: 46px; padding: 11px 9px; overflow: hidden; border: 0; border-bottom: 3px solid transparent; background: transparent; cursor: pointer; color: var(--ink-soft); font-size: 0.72rem; letter-spacing: 0.12em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.mode-tabs button[aria-selected="true"], .asset-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brass); }
.mode-tabs button:disabled, .asset-tabs button:disabled { cursor: not-allowed; opacity: 0.45; }
.mode-panel { min-height: 240px; padding: 24px 0 0; }

.choice-label { margin: 0 0 9px; color: var(--ink-soft); font-size: 0.72rem; letter-spacing: 0.14em; text-transform: uppercase; }
.wager-choices, .contract-choices, .selection-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-button { min-width: 58px; min-height: 44px; padding: 8px 13px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-variant-numeric: tabular-nums; }
.choice-button:hover:not(:disabled), .choice-button[aria-pressed="true"] { border-color: var(--brass-dark); background: rgba(140, 112, 68, 0.1); }
.choice-button:disabled { opacity: 0.35; cursor: not-allowed; }
.choice-button.danger { color: var(--danger); border-color: rgba(122, 52, 43, 0.4); }

.primary-button { width: 100%; min-height: 52px; margin-top: 20px; padding: 13px 18px; border: 1px solid var(--brass-dark); background: var(--ink); color: var(--paper-light); cursor: pointer; letter-spacing: 0.1em; text-transform: uppercase; box-shadow: 3px 3px 0 var(--brass); }
.primary-button:hover:not(:disabled) { background: var(--brass-dark); }
.primary-button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--brass); }
.primary-button:disabled { cursor: not-allowed; opacity: 0.4; box-shadow: none; }
.primary-button.quiet { min-height: 46px; margin-top: 14px; background: transparent; color: var(--ink); box-shadow: none; font-size: 0.72rem; }
.primary-button.quiet:hover:not(:disabled) { color: var(--paper-light); background: var(--brass-dark); }

.mode-note, .risk-card { margin: 18px 0 0; padding: 15px 17px; border-left: 2px solid var(--brass); background: rgba(140, 112, 68, 0.075); color: var(--ink-soft); font-size: 0.88rem; line-height: 1.55; }
.risk-card strong { color: var(--ink); font-weight: 400; }
.risk-card.danger { border-left-color: var(--danger); }
.risk-card p { margin: 3px 0; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.stake-list { max-height: 220px; margin-top: 16px; overflow: auto; border-top: 1px solid var(--line); }
.stake-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 11px; min-height: 50px; border-bottom: 1px solid var(--line); cursor: pointer; }
.stake-row input { width: 18px; height: 18px; accent-color: var(--brass-dark); }
.stake-row span { min-width: 0; }
.stake-row small { color: var(--ink-soft); }

.contract-progress { margin-top: 16px; }
.contract-progress header { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 10px; font-size: 0.82rem; }
.marks { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.mark { aspect-ratio: 1; display: grid; place-items: center; border: 1px solid var(--line); color: var(--ink-soft); font-size: 0.72rem; }
.mark.hit { border-color: var(--success); background: rgba(63, 101, 71, 0.13); color: var(--success); }
.mark.miss { color: rgba(105, 95, 82, 0.55); }
.mark.protection { border-color: var(--brass); background: rgba(140, 112, 68, 0.12); color: var(--brass-dark); }

.estate-panel { min-width: 0; padding-left: 34px; border-left: 1px solid var(--line); }
.estate-heading { justify-content: space-between; }
.asset-count { color: var(--ink-soft); font-size: 0.76rem; }
.work-card { margin-bottom: 30px; padding: 22px; border: 1px solid var(--line); background: rgba(255, 253, 247, 0.52); }
.work-card h3 { margin: 5px 0 7px; font-size: 1.2rem; font-weight: 400; }
.work-card p { margin: 0; color: var(--ink-soft); font-size: 0.86rem; line-height: 1.5; }
.work-card .microcopy { min-height: 19px; margin-top: 9px; font-style: italic; }
.asset-tabs { grid-template-columns: 1fr 1fr; }
.asset-list { max-height: 650px; overflow: auto; scrollbar-color: var(--brass) transparent; }
.empty-state { padding: 38px 10px; text-align: center; color: var(--ink-soft); font-style: italic; line-height: 1.6; }
.asset-card { padding: 18px 4px; border-bottom: 1px solid var(--line); }
.asset-card header { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.asset-card h3 { margin: 0; font-size: 1rem; font-weight: 400; }
.asset-card .price { white-space: nowrap; color: var(--brass-dark); font-variant-numeric: tabular-nums; }
.asset-card p { margin: 7px 0 12px; color: var(--ink-soft); font-size: 0.82rem; line-height: 1.45; }
.asset-meta { display: flex; flex-wrap: wrap; gap: 5px 13px; color: var(--ink-soft); font-size: 0.73rem; }
.asset-actions { display: flex; gap: 8px; margin-top: 13px; }
.asset-actions button { min-height: 38px; padding: 7px 12px; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; }
.asset-actions button:hover:not(:disabled) { border-color: var(--brass-dark); background: rgba(140, 112, 68, 0.09); }
.asset-actions button:disabled { cursor: not-allowed; opacity: 0.35; }
.status-badge { padding: 3px 6px; border: 1px solid var(--danger); color: var(--danger); font-size: 0.62rem; letter-spacing: 0.1em; text-transform: uppercase; }

.victory-notice { margin: 0 0 60px; padding: 34px; border: 1px double var(--brass-dark); text-align: center; background: var(--paper-light); }
.victory-notice h2 { margin: 8px 0; font-size: 2rem; font-weight: 400; }
.victory-notice p { margin: 0; color: var(--ink-soft); }
.disclaimer { display: flex; justify-content: space-between; gap: 20px; padding: 20px 0 30px; border-top: 1px solid var(--line-strong); color: var(--ink-soft); font-size: 0.7rem; letter-spacing: 0.04em; }

.ledger-dialog { width: min(520px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; overflow: auto; border: 1px solid var(--brass-dark); background: var(--paper-light); color: var(--ink); box-shadow: 0 25px 80px rgba(40, 35, 29, 0.25); }
.ledger-dialog::backdrop { background: rgba(40, 35, 29, 0.48); backdrop-filter: blur(2px); }
.ledger-dialog form, .dialog-content { position: relative; padding: 34px; }
.ledger-dialog h2 { margin: 7px 0 18px; font-size: 1.8rem; font-weight: 400; }
.ledger-dialog p { color: var(--ink-soft); line-height: 1.55; }
.dialog-close { position: absolute; top: 16px; right: 16px; width: 44px; height: 44px; border: 0; background: transparent; cursor: pointer; font-size: 1.8rem; font-weight: 300; }
.paytable { margin: 0; }
.paytable div { display: flex; justify-content: space-between; gap: 24px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.paytable dt, .paytable dd { margin: 0; }
.paytable dd { color: var(--brass-dark); font-variant-numeric: tabular-nums; }
.dialog-actions { display: flex; gap: 10px; margin-top: 22px; }
.dialog-actions button { flex: 1; min-height: 46px; padding: 10px; border: 1px solid var(--line-strong); background: transparent; cursor: pointer; }
.dialog-actions .danger-action { border-color: var(--danger); color: var(--danger); }
.dialog-actions .emphasis { background: var(--ink); color: var(--paper-light); }

.fatal-error { max-width: 720px; margin: 80px auto; padding: 30px; border: 1px solid var(--danger); color: var(--danger); }

@media (max-width: 820px) {
  .masthead { min-height: 110px; }
  .game-layout { grid-template-columns: minmax(0, 1fr); gap: 42px; padding-top: 38px; }
  .estate-panel { padding-left: 0; border-left: 0; border-top: 1px solid var(--line-strong); padding-top: 38px; }
  .asset-list { max-height: none; }
}

@media (max-width: 560px) {
  body { padding-top: calc(52px + env(safe-area-inset-top)); }
  .masthead, .page-shell { width: min(100% - 24px, 1180px); }
  .masthead { grid-template-columns: 1fr auto; min-height: 96px; }
  .wordmark { grid-column: 1 / -1; grid-row: 1; padding: 16px 0 12px; }
  .wordmark h1 { font-size: 2.15rem; }
  .masthead .back-link, .masthead > .text-button { grid-row: 2; padding: 12px 0 14px; }
  .status-ledger { grid-template-columns: 1fr 1fr; }
  .status-ledger > div { padding: 16px 12px; border-bottom: 1px solid var(--line); }
  .status-ledger > div:first-child {
    position: fixed;
    z-index: 100;
    top: 0;
    left: 0;
    right: 0;
    height: calc(52px + env(safe-area-inset-top));
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: env(safe-area-inset-top) 14px 0;
    border: 0;
    border-bottom: 1px solid var(--brass-dark);
    background: rgba(255, 253, 247, 0.97);
    box-shadow: 0 5px 18px rgba(68, 53, 34, 0.12);
    backdrop-filter: blur(8px);
  }
  .status-ledger > div:first-child strong { margin-top: 0; font-size: 1.18rem; }
  .status-ledger > div:nth-child(2) { padding-left: 0; border-right: 1px solid var(--line); }
  .status-ledger > div:nth-child(3) { border-right: 0; }
  .status-ledger > div:nth-child(4) { grid-column: 1 / -1; padding-left: 0; border-right: 0; }
  .game-layout { padding: 32px 0 48px; }
  .machine-heading { align-items: flex-end; }
  .machine-heading .section-number { display: none; }
  .slot-machine { gap: 6px; padding: 14px; }
  .reel { min-width: 0; height: 108px; }
  .reel span { font-size: 3.4rem; }
  .mode-tabs button { padding-inline: 4px; font-size: 0.63rem; letter-spacing: 0.08em; }
  .mode-grid { grid-template-columns: 1fr; gap: 15px; }
  .choice-button { flex: 1 0 calc(25% - 8px); }
  .marks { gap: 3px; }
  .disclaimer { flex-direction: column; }
  .ledger-dialog form, .dialog-content { padding: 28px 22px; }
  .dialog-actions { flex-direction: column; }
}

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