:root {
  --bg: #f7f9fc;
  --surface: #fff;
  --ink: #172336;
  --muted: #687589;
  --blue: #276a83;
  --blue-dark: #17485d;
  --blue-pale: #e9f3f6;
  --line: #d8e0e9;
  --line-strong: #afbbc9;
  --danger: #a34040;
  --success: #267154;
  --shadow: 0 18px 55px rgba(40, 64, 89, 0.09);
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { min-height: 100vh; margin: 0; background-image: linear-gradient(rgba(39,106,131,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(39,106,131,.035) 1px, transparent 1px); background-size: 32px 32px; }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }

.masthead { width: min(1240px, calc(100% - 48px)); min-height: 104px; margin: 0 auto; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; border-bottom: 1px solid var(--line-strong); }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 50px; height: 50px; display: grid; place-items: center; position: relative; border-radius: 12px; background: var(--ink); color: white; font-weight: 750; letter-spacing: -.05em; }
.brand-mark span { position: absolute; right: 4px; bottom: 3px; color: #8fc9d8; font: 600 8px/1 ui-monospace, monospace; letter-spacing: 0; }
.brand h1 { margin: 3px 0 0; font-size: clamp(1.45rem, 3vw, 2.2rem); line-height: 1; letter-spacing: -.045em; }
.eyebrow, .ledger-label, .work-index { display: block; color: var(--muted); font-size: .65rem; font-weight: 750; letter-spacing: .14em; text-transform: uppercase; }
.back-link, .text-button { color: var(--muted); font-size: .7rem; font-weight: 700; letter-spacing: .1em; text-decoration: none; text-transform: uppercase; }
.text-button { justify-self: end; padding: 11px 0; border: 0; border-bottom: 1px solid transparent; background: transparent; cursor: pointer; }
.back-link:hover, .text-button:hover { color: var(--blue-dark); border-bottom-color: var(--blue); }

.page-shell { width: min(1240px, calc(100% - 48px)); margin: 0 auto; }
.status-ledger { display: grid; grid-template-columns: repeat(4, 1fr); padding: 18px 0; border-bottom: 1px solid var(--line-strong); }
.status-ledger > div { min-width: 0; padding: 5px 24px; border-right: 1px solid var(--line); }
.status-ledger > div:first-child { padding-left: 0; }
.status-ledger > div:last-child { border: 0; }
.status-ledger strong { display: block; overflow: hidden; margin-top: 6px; font: 650 clamp(1.05rem, 2vw, 1.4rem)/1.1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: -.04em; text-overflow: ellipsis; white-space: nowrap; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, .9fr); gap: 34px; padding: 38px 0 58px; }
.machine-panel, .estate-panel { min-width: 0; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.9); box-shadow: var(--shadow); }
.machine-panel { padding: clamp(20px, 3vw, 34px); }
.estate-panel { padding: 28px; }
.machine-heading, .estate-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.machine-heading h2, .estate-heading h2 { margin: 4px 0 0; font-size: 1.65rem; letter-spacing: -.035em; }
.asset-count { padding: 5px 9px; border-radius: 99px; background: var(--blue-pale); color: var(--blue-dark); font-size: .7rem; font-weight: 700; }

.slot-machine { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; padding: 42px 14px 20px; overflow: hidden; border: 1px solid #9aabb9; border-radius: 12px; background: #dce5eb; box-shadow: inset 0 0 0 5px #edf2f5; }
.terminal-strip { position: absolute; top: 0; left: 0; right: 0; height: 30px; display: flex; align-items: center; justify-content: space-between; padding: 0 14px; border-bottom: 1px solid #b6c2cc; color: #5d6e7d; font: 650 .57rem/1 ui-monospace, monospace; letter-spacing: .08em; }
.reel { min-width: 0; height: clamp(110px, 16vw, 154px); display: grid; place-items: center; overflow: hidden; border: 1px solid #9cabb7; border-radius: 6px; background: var(--surface); box-shadow: inset 0 9px 22px rgba(49,74,95,.07), inset 0 -9px 22px rgba(49,74,95,.07); }
.reel span { color: var(--ink); font: 500 clamp(3rem, 7vw, 5rem)/1 ui-monospace, monospace; }
.reel.rolling span { animation: reel-roll 150ms linear infinite; filter: blur(1px); }
.reel.settle span { animation: reel-settle 220ms cubic-bezier(.2,.8,.2,1.2); }
@keyframes reel-roll { from { transform: translateY(-55px); opacity: .15; } 50% { opacity: .8; } to { transform: translateY(55px); opacity: .15; } }
@keyframes reel-settle { from { transform: translateY(-15px); opacity: .4; } to { transform: translateY(0); opacity: 1; } }
.payline { position: absolute; left: 10px; right: 10px; top: calc(50% + 10px); height: 1px; background: var(--blue); opacity: .42; pointer-events: none; }
.machine-flourish { position: absolute; right: 14px; bottom: 5px; color: #687988; font: 600 .52rem/1 ui-monospace, monospace; letter-spacing: .08em; }
.result-line { min-height: 48px; margin: 0; padding: 15px 0 8px; color: var(--muted); text-align: center; font-size: .86rem; }
.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); }
.asset-tabs { grid-template-columns: 1fr 1fr; }
.mode-tabs button, .asset-tabs button { min-width: 0; min-height: 44px; padding: 9px 6px; overflow: hidden; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-size: .68rem; font-weight: 750; letter-spacing: .08em; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.mode-tabs button[aria-selected="true"], .asset-tabs button[aria-selected="true"] { border-bottom-color: var(--blue); color: var(--blue-dark); }
.mode-tabs button:disabled { opacity: .35; cursor: not-allowed; }
.mode-panel { min-height: 235px; padding-top: 22px; }
.choice-label { margin: 0 0 9px; color: var(--muted); font-size: .66rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.wager-choices, .contract-choices, .selection-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-button { min-width: 60px; min-height: 42px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 7px; background: white; cursor: pointer; font: 650 .8rem/1 ui-monospace, monospace; }
.choice-button:hover:not(:disabled), .choice-button[aria-pressed="true"] { border-color: var(--blue); background: var(--blue-pale); color: var(--blue-dark); }
.choice-button:disabled { opacity: .35; cursor: not-allowed; }
.choice-button.danger { border-color: #d8a6a6; color: var(--danger); }
.primary-button { width: 100%; min-height: 50px; margin-top: 18px; padding: 12px 18px; border: 1px solid var(--blue-dark); border-radius: 8px; background: var(--blue-dark); color: white; cursor: pointer; font-size: .72rem; font-weight: 780; letter-spacing: .09em; text-transform: uppercase; box-shadow: 0 7px 18px rgba(23,72,93,.15); }
.primary-button:hover:not(:disabled) { background: var(--blue); }
.primary-button:disabled { opacity: .35; cursor: not-allowed; box-shadow: none; }
.primary-button.quiet { min-height: 44px; background: white; color: var(--blue-dark); box-shadow: none; }
.primary-button.quiet:hover:not(:disabled) { background: var(--blue-pale); }
.mode-note, .risk-card { margin: 16px 0 0; padding: 14px 16px; border: 1px solid #d5e4e9; border-radius: 8px; background: #f3f8fa; color: var(--muted); font-size: .81rem; line-height: 1.5; }
.risk-card strong { color: var(--ink); }
.risk-card.danger { border-color: #e1bcbc; background: #fff8f8; }
.risk-card p { margin: 3px 0; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stake-list { max-height: 210px; margin-top: 14px; overflow: auto; border-top: 1px solid var(--line); }
.stake-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; min-height: 48px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: .82rem; }
.stake-row input { width: 18px; height: 18px; accent-color: var(--blue); }
.stake-row small { color: var(--muted); }
.contract-progress { margin-top: 16px; }
.contract-progress header { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 8px; color: var(--muted); font-size: .72rem; }
.marks { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.mark { aspect-ratio: 1; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font-size: .65rem; }
.mark.hit { border-color: var(--success); background: #edf8f2; color: var(--success); }
.mark.miss { opacity: .65; }
.mark.protection { border-color: var(--blue); background: var(--blue-pale); color: var(--blue-dark); }

.work-card { margin-bottom: 25px; padding: 18px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfe; }
.work-index { color: var(--success); }
.work-card h3 { margin: 6px 0; font-size: 1.05rem; }
.work-card p { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.5; }
.work-card .microcopy { min-height: 18px; margin-top: 8px; }
.asset-list { max-height: 620px; overflow: auto; }
.empty-state { padding: 34px 12px; color: var(--muted); text-align: center; font-size: .84rem; line-height: 1.6; }
.asset-card { padding: 16px 2px; border-bottom: 1px solid var(--line); }
.asset-card header { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.asset-card h3 { margin: 0; font-size: .91rem; }
.asset-card .price { color: var(--blue-dark); font: 650 .78rem/1 ui-monospace, monospace; white-space: nowrap; }
.asset-card p { margin: 7px 0 10px; color: var(--muted); font-size: .77rem; line-height: 1.45; }
.asset-meta { display: flex; flex-wrap: wrap; gap: 5px 12px; color: var(--muted); font: .68rem/1.4 ui-monospace, monospace; }
.asset-actions { display: flex; gap: 7px; margin-top: 11px; }
.asset-actions button { min-height: 36px; padding: 7px 11px; border: 1px solid var(--line-strong); border-radius: 6px; background: white; cursor: pointer; color: var(--blue-dark); font-size: .65rem; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.asset-actions button:hover:not(:disabled) { border-color: var(--blue); background: var(--blue-pale); }
.asset-actions button:disabled { opacity: .35; cursor: not-allowed; }
.status-badge { padding: 2px 5px; border: 1px solid var(--danger); border-radius: 4px; color: var(--danger); font-size: .57rem; letter-spacing: .07em; text-transform: uppercase; }

.victory-notice { margin-bottom: 46px; padding: 30px; border: 1px solid var(--blue); border-radius: 14px; background: linear-gradient(135deg,#fff,#edf6f8); box-shadow: var(--shadow); text-align: center; }
.victory-notice h2 { margin: 8px 0; font-size: 1.8rem; letter-spacing: -.04em; }
.victory-notice p { margin: 0; color: var(--muted); }
.disclaimer { display: flex; justify-content: space-between; gap: 18px; padding: 20px 0 28px; border-top: 1px solid var(--line-strong); color: var(--muted); font-size: .66rem; }

.ledger-dialog { width: min(520px, calc(100% - 28px)); max-height: calc(100vh - 28px); padding: 0; overflow: auto; border: 1px solid var(--line-strong); border-radius: 14px; background: white; color: var(--ink); box-shadow: 0 25px 80px rgba(23,35,54,.25); }
.ledger-dialog::backdrop { background: rgba(23,35,54,.45); backdrop-filter: blur(2px); }
.ledger-dialog form, .dialog-content { position: relative; padding: 30px; }
.ledger-dialog h2 { margin: 7px 0 17px; font-size: 1.55rem; }
.ledger-dialog p { color: var(--muted); line-height: 1.55; }
.dialog-close { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; border: 0; background: transparent; cursor: pointer; font-size: 1.6rem; }
.paytable { margin: 0; }
.paytable div { display: flex; justify-content: space-between; gap: 20px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.paytable dd { margin: 0; color: var(--blue-dark); font-family: ui-monospace, monospace; }
.dialog-actions { display: flex; gap: 9px; margin-top: 20px; }
.dialog-actions button { flex: 1; min-height: 44px; padding: 9px; border: 1px solid var(--line-strong); border-radius: 7px; background: white; cursor: pointer; }
.dialog-actions .danger-action { border-color: var(--danger); color: var(--danger); }
.dialog-actions .emphasis { border-color: var(--blue-dark); background: var(--blue-dark); color: white; }
.fatal-error { max-width: 700px; margin: 70px auto; padding: 28px; border: 1px solid var(--danger); color: var(--danger); }

@media (max-width: 860px) {
  .game-layout { grid-template-columns: minmax(0,1fr); }
  .asset-list { max-height: none; }
}

@media (max-width: 580px) {
  body { padding-top: calc(52px + env(safe-area-inset-top)); }
  .masthead, .page-shell { width: calc(100% - 24px); }
  .masthead { grid-template-columns: 1fr auto; min-height: 112px; }
  .brand { grid-column: 1 / -1; grid-row: 1; margin: 14px 0 5px; }
  .brand-mark { width: 42px; height: 42px; }
  .masthead .back-link, .masthead > .text-button { grid-row: 2; padding-bottom: 12px; }
  .status-ledger { grid-template-columns: 1fr 1fr; padding: 0; }
  .status-ledger > div { padding: 14px 10px; 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(--line-strong);
    background: rgba(255,255,255,.96);
    box-shadow: 0 5px 18px rgba(40,64,89,.12);
    backdrop-filter: blur(8px);
  }
  .status-ledger > div:first-child strong { margin-top: 0; font-size: 1.12rem; }
  .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-top: 24px; }
  .machine-panel, .estate-panel { padding: 18px 14px; border-radius: 12px; }
  .slot-machine { gap: 5px; padding: 39px 10px 18px; }
  .terminal-strip { padding: 0 10px; }
  .reel { height: 102px; }
  .reel span { font-size: 3rem; }
  .mode-tabs button { padding-inline: 2px; font-size: .58rem; letter-spacing: .04em; }
  .choice-button { flex: 1 0 calc(25% - 8px); }
  .mode-grid { grid-template-columns: 1fr; }
  .marks { gap: 3px; }
  .disclaimer { flex-direction: column; }
  .dialog-actions { flex-direction: column; }
}

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