:root {
  --paper: #ECE3CF;
  --ink: #161412;
  --red: #C8241C;
  --red-on-ink: #E8574E;
  --muted: #5A544A;
  --rule: #CFC4AC;
  --on-ink-muted: #C9BFA8;
  --display: Oswald, "Arial Narrow", sans-serif;
  --body: "PT Sans", system-ui, sans-serif;
  --safe-top: var(--tg-content-safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-bottom: var(--tg-content-safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ink); }
body {
  font-family: var(--body);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }
a { color: inherit; }

#app {
  position: relative;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  overflow: hidden;
}

.screen { position: relative; min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: var(--safe-bottom); }
.d { font-family: var(--display); }

/* ——— top bar ——— */
.bar {
  position: relative; z-index: 3;
  display: flex; align-items: stretch; justify-content: space-between;
  min-height: 60px; padding-top: var(--safe-top);
  background: var(--ink); color: var(--paper);
}
.bar__brand { display: flex; align-items: center; padding: 0 20px; font-family: var(--display); font-weight: 700; font-size: 24px; letter-spacing: .06em; }
.bar__meta { display: flex; align-items: center; padding: 0 12px 0 16px; font-family: var(--display); font-weight: 500; font-size: 13px; letter-spacing: .08em; white-space: nowrap; }
.bar__right { display: flex; align-items: stretch; }
.bar__icon { width: 42px; min-height: 60px; font-family: var(--display); font-weight: 700; font-size: 22px; color: var(--paper); }
.bar__red {
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px 0 32px; background: var(--red); color: var(--paper);
  clip-path: polygon(18px 0, 100% 0, 100% 100%, 0 100%);
  font-family: var(--display); font-weight: 700; font-size: 18px; letter-spacing: .08em; text-decoration: none;
}
.bar__timer { font-size: 32px; letter-spacing: 0; min-width: 96px; padding: 0 16px 0 28px; }
.bar__timer.is-low { animation: pulse 1s steps(2, jump-none) infinite; }
@keyframes pulse { 50% { background: var(--ink); } }

/* ——— poster pieces ——— */
.poster { position: absolute; inset: 0; pointer-events: none; }
.poster svg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }

.coinwrap { position: relative; width: var(--coin); height: var(--coin); perspective: 900px; }
.coinwrap::before {
  content: ""; position: absolute; inset: 0; transform: translate(8%, 8%);
  border-radius: 50%; background: var(--ink);
}
.coin { position: absolute; inset: 0; transform-style: preserve-3d; }
.coin__face { position: absolute; inset: 0; width: 100%; height: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; user-select: none; -webkit-user-drag: none; }
.coin__face--tails { transform: rotateY(180deg); }

.sticker {
  position: absolute; display: flex; flex-direction: column; padding: 6px 12px 8px;
  background: var(--red); color: var(--paper); transform: rotate(-12deg);
  font-family: var(--display); line-height: 1;
}
.sticker b { font-weight: 700; font-size: 26px; }
.sticker span { font-weight: 500; font-size: 15px; margin-top: 3px; }
.sticker--loss { background: var(--ink); }
.sticker.pop { animation: pop .3s cubic-bezier(.16, 1, .3, 1); }
@keyframes pop { from { transform: rotate(-12deg) scale(.4); opacity: 0; } }

.tag { display: inline-block; padding: 3px 10px; background: var(--ink); color: var(--paper); font-family: var(--display); font-weight: 500; font-size: 13px; letter-spacing: .2em; }
.label { font-family: var(--display); font-weight: 600; font-size: 14px; letter-spacing: .16em; }
.muted { color: var(--muted); }

/* ——— buttons ——— */
.btn {
  display: flex; align-items: center; justify-content: center;
  min-height: 60px; padding: 0 20px;
  font-family: var(--display); font-weight: 700; font-size: 24px; letter-spacing: .06em; text-decoration: none; text-align: center;
}
.btn--red { background: var(--red); color: var(--paper); clip-path: polygon(0 0, 100% 0, 95% 100%, 0 100%); }
.btn--ink { background: var(--ink); color: var(--paper); }
.btn--line { border: 3px solid var(--ink); font-weight: 600; font-size: 19px; }
.btn--line-light { border: 3px solid var(--paper); color: var(--paper); font-weight: 600; font-size: 18px; }
.btn:disabled { opacity: .45; }

/* ——— cover ——— */
.cover__top { position: relative; height: 440px; }
.cover__vol { position: absolute; left: 22px; top: calc(24px + var(--safe-top)); font-family: var(--display); font-weight: 600; font-size: 13px; letter-spacing: .22em; color: var(--red); }
.cover__title { position: absolute; left: 16px; top: calc(44px + var(--safe-top)); margin: 0; font-family: var(--display); font-weight: 700; font-size: min(22vw, 96px); line-height: 1; }
.cover__formula { position: absolute; left: 22px; top: calc(150px + var(--safe-top)); transform: rotate(-6deg); transform-origin: left center; display: flex; align-items: baseline; gap: 12px; }
.cover__formula b { font-family: var(--display); font-weight: 700; font-size: 48px; line-height: 1; color: var(--red); }
.cover__formula span { font-family: var(--display); font-weight: 500; font-size: 12px; letter-spacing: .1em; line-height: 1.25; }
.cover__coin { position: absolute; right: 24px; top: calc(210px + var(--safe-top)); --coin: 200px; transform: rotate(-8deg); }
.panel { position: relative; z-index: 2; flex: 1; display: flex; flex-direction: column; gap: 14px; padding: 24px 22px 26px; background: var(--ink); color: var(--paper); }
.panel__lead { margin: 0; font-family: var(--display); font-weight: 600; font-size: 26px; line-height: 1.15; }
.panel__lead em { font-style: normal; color: var(--red-on-ink); }
.panel__text { margin: 0; font-size: 16px; line-height: 1.45; color: #DDD4C0; }
.panel__row {
  display: flex; justify-content: space-between; align-items: center; min-height: 48px;
  border-top: 2px solid #3A3631; border-bottom: 2px solid #3A3631;
  color: var(--paper); text-decoration: none; text-align: left; width: 100%;
}
.panel__row .d { font-weight: 500; font-size: 14px; letter-spacing: .14em; color: var(--on-ink-muted); }
.panel__row strong { font-family: var(--display); font-weight: 600; font-size: 16px; }
.panel .btn--red { margin-top: auto; min-height: 72px; font-size: 30px; letter-spacing: .08em; }
.resume { margin-top: auto; display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.resume .btn--red { margin-top: 0; flex-direction: column; gap: 2px; font-size: 26px; line-height: 1; }
.resume .btn--red small { font-weight: 500; font-size: 14px; letter-spacing: .04em; opacity: .85; }
.resume .btn--line-light { min-height: 72px; padding: 0 16px; }
.sheet__text { margin: 0 0 18px; font-size: 16px; line-height: 1.45; }
.sheet__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ——— gate ——— */
.gate__head { position: relative; height: 250px; }
.gate__title { position: absolute; left: 22px; top: 36px; transform: rotate(-5deg); transform-origin: left center; margin: 0; font-family: var(--display); font-weight: 700; font-size: 60px; line-height: .95; }
.gate__body { position: relative; z-index: 2; flex: 1; display: flex; flex-direction: column; gap: 18px; padding: 0 22px 26px; }
.gate__body p { margin: 0; font-size: 17px; line-height: 1.45; }
.channel { display: flex; align-items: center; gap: 14px; padding: 14px; background: var(--ink); color: var(--paper); text-decoration: none; }
.channel img { flex-shrink: 0; width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.channel strong { display: block; font-family: var(--display); font-weight: 600; font-size: 19px; }
.channel span { display: block; font-size: 14px; line-height: 1.35; color: var(--on-ink-muted); }
.gate__actions { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.gate__body .gate__note { font-size: 14px; color: var(--muted); text-align: center; }
.gate__body .gate__error { padding: 10px 12px; border: 3px solid var(--red); color: var(--red); font-weight: 700; font-size: 15px; }

/* ——— game ——— */
.stage { position: relative; height: 250px; flex-shrink: 0; }
.stage .coinwrap { position: absolute; left: 50%; top: 22px; --coin: 200px; margin-left: -110px; }
.stage .sticker { left: 60%; top: 8px; }
.capital { position: relative; z-index: 2; padding: 0 20px; transform: rotate(-4deg); transform-origin: left center; }
.capital__tags { display: flex; align-items: center; gap: 12px; }
.record { font-family: var(--display); font-weight: 600; font-size: 14px; letter-spacing: .08em; color: var(--red); }
.record.is-new { animation: record 1.4s cubic-bezier(.16, 1, .3, 1); }
@keyframes record { 0% { background: var(--red); color: var(--paper); box-shadow: 0 0 0 4px var(--red); } 70% { background: var(--red); color: var(--paper); box-shadow: 0 0 0 4px var(--red); } }
.capital__value { display: block; font-family: var(--display); font-weight: 700; line-height: 1; white-space: nowrap; }
.history { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 3px; padding: 14px 20px 0; }
.spark { flex: 1; display: flex; align-items: center; min-height: 0; max-height: 110px; padding: 10px 20px 0; }
.spark svg { max-height: 90px; }
.history i { display: flex; align-items: center; justify-content: center; height: 24px; font-style: normal; font-weight: 700; font-size: 14px; line-height: 1; }
.history i.win { background: #FFFFFF; border: 2px solid var(--ink); color: var(--ink); }
.history i.loss { background: var(--red); border: 2px solid var(--red); color: var(--paper); }
.history i.empty { border: 2px dashed var(--rule); }
.controls { display: flex; flex-direction: column; gap: 10px; padding: 12px 20px 20px; margin-top: auto; }
.rule { height: 5px; background: var(--ink); }
.betbox { display: flex; align-items: center; gap: 12px; }
.betbox .label { font-size: 13px; }
.betbox__hint { font-style: normal; font-family: var(--display); font-weight: 600; font-size: 13px; letter-spacing: .08em; color: var(--red); white-space: nowrap; }
.betbox__pct { font-family: var(--display); font-weight: 700; font-size: 26px; color: var(--red); }
.betbox b { flex: 1; font-family: var(--display); font-weight: 700; font-size: 34px; line-height: 1; white-space: nowrap; }
.betgrab { display: flex; flex-direction: column; gap: 10px; user-select: none; -webkit-user-select: none; }
.slider { position: relative; }
.slider canvas { display: block; width: 100%; height: 64px; touch-action: none; cursor: ew-resize; }
.sides { display: grid; grid-template-columns: 1fr 1fr; }
.side { min-height: 88px; font-family: var(--display); font-weight: 700; font-size: 34px; color: var(--paper); }
.side--heads { background: var(--red); clip-path: polygon(0 0, 100% 0, 86% 100%, 0 100%); }
.side--tails { background: var(--ink); margin-left: -24px; padding-left: 24px; clip-path: polygon(12% 0, 100% 0, 100% 100%, 0 100%); }
.side:disabled { opacity: .55; }

/* ——— all-in: the whole capital on one flip ——— */
.screen::after {
  content: ""; position: fixed; inset: 0; z-index: 5; pointer-events: none;
  box-shadow: inset 0 0 0 0 rgba(200, 36, 28, 0); transition: box-shadow .5s ease;
}
.screen.allin::after { box-shadow: inset 0 0 90px 24px rgba(200, 36, 28, .55); animation: allin-pulse 1.2s ease-in-out infinite; }
.screen.allin-flight .stage { z-index: 4; }
.screen.allin-flight::after { box-shadow: inset 0 0 160px 60px rgba(200, 36, 28, .8); }
.screen.allin .capital__value, .screen.allin .betbox b { animation: tremble .11s steps(2, jump-none) infinite; }
.screen.allin .betbox__pct { color: var(--paper); background: var(--red); padding: 0 8px; }
@keyframes allin-pulse { 50% { box-shadow: inset 0 0 120px 36px rgba(200, 36, 28, .7); } }
@keyframes tremble { 0% { transform: translate(0.6px, -0.4px); } 100% { transform: translate(-0.6px, 0.5px); } }
.flash { position: fixed; inset: 0; z-index: 6; pointer-events: none; animation: flash .7s ease-out forwards; }
.flash--win { background: #FFFFFF; }
.flash--loss { background: var(--red); }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }

/* ——— result ——— */
.result__head { position: relative; padding: 26px 20px 8px; }
.result__stamp { display: inline-block; padding: 5px 14px 7px; background: var(--red); color: var(--paper); transform: rotate(-5deg); transform-origin: left center; font-family: var(--display); font-weight: 700; font-size: 24px; letter-spacing: .06em; }
.result__stamp--ink { background: var(--ink); }
.result__final { display: block; margin-top: 10px; font-family: var(--display); font-weight: 700; line-height: 1; white-space: nowrap; }
.result__sub { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-family: var(--display); font-weight: 500; font-size: 16px; letter-spacing: .04em; }
.result__sub b { padding: 1px 8px; background: var(--ink); color: var(--paper); font-weight: 600; }
.result__coin { position: absolute; right: -22px; top: -18px; --coin: 104px; transform: rotate(14deg); }
.result__head > :not(.result__coin) { position: relative; z-index: 1; }
.rank { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 6px 20px 0; border-bottom: 3px solid var(--red); text-decoration: none; text-align: left; }
.rank b { font-family: var(--display); font-weight: 700; font-size: 24px; color: var(--red); }
.rank span { font-family: var(--display); font-weight: 500; font-size: 16px; letter-spacing: .06em; }
.frame { position: relative; margin: 26px 20px 0; border: 3px solid var(--ink); padding: 18px 10px 8px 6px; }
.frame__label { position: absolute; left: 10px; top: -11px; padding: 1px 8px; background: var(--paper); font-family: var(--display); font-weight: 600; font-size: 12px; letter-spacing: .14em; }
.chart { display: block; width: 100%; height: 190px; overflow: visible; }
.chart text { font-family: var(--display); font-size: 11px; fill: var(--muted); }
.chart .lbl { font-weight: 700; font-size: 13px; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 16px 20px 0; }
.stat { padding: 10px 12px; background: var(--ink); color: var(--paper); }
.stat b { display: block; font-family: var(--display); font-weight: 700; font-size: 28px; line-height: 1.1; }
.stat b.hot { color: var(--red-on-ink); }
.stat span { font-size: 13px; color: var(--on-ink-muted); }
.result__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 20px 24px; }
.result__actions .btn { font-size: 18px; padding: 0 10px; }

/* ——— board ——— */
.board__head { position: relative; padding: 22px 22px 0; }
.board__title { margin: 0; font-family: var(--display); font-weight: 700; font-size: 56px; line-height: 1.08; }
.board__star { position: absolute; right: 14px; top: 12px; width: 120px; height: 120px; transform: rotate(-12deg); }
.tabs { display: flex; margin-top: 16px; }
.tab { min-height: 44px; padding: 0 18px; border: 3px solid var(--ink); font-family: var(--display); font-weight: 600; font-size: 15px; letter-spacing: .12em; }
.tab + .tab { border-left: 0; }
.tab[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.board__note { margin: 12px 0 0; font-size: 14px; line-height: 1.4; color: var(--muted); }
.rows { list-style: none; margin: 14px 22px 0; padding: 0; }
.row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 48px; border-bottom: 1.5px solid var(--rule); }
.row__n { font-family: var(--display); font-weight: 600; font-size: 17px; padding-left: 10px; }
.row__n.top { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0; background: var(--red); color: var(--paper); font-weight: 700; font-size: 18px; }
.row__name { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__name small { color: var(--muted); font-size: 13px; }
.row__cents { font-family: var(--display); font-weight: 600; font-size: 19px; }
.row.is-me { background: rgba(200, 36, 28, .08); }
.board__empty { margin: 24px 22px; font-size: 16px; line-height: 1.45; }
.me { position: sticky; bottom: 0; margin-top: auto; padding: 14px 22px calc(18px + var(--safe-bottom)); background: var(--ink); color: var(--paper); }
.me .row { border: 0; min-height: 36px; }
.me .row__cents { color: var(--red-on-ink); font-size: 22px; font-weight: 700; }
.me p { margin: 6px 0 0; font-size: 14px; line-height: 1.4; color: var(--on-ink-muted); }

/* ——— sheet (rules) ——— */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; background: rgba(22, 20, 18, .6); }
.sheet__box { width: 100%; max-width: 480px; padding: 24px 22px calc(26px + var(--safe-bottom)); background: var(--paper); }
.sheet--log .sheet__box { display: flex; flex-direction: column; max-height: 88dvh; }
.log { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -22px 16px; padding: 0 22px; display: block; overscroll-behavior: contain; }
.log__row { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto auto; align-items: center; gap: 10px; min-height: 50px; border-bottom: 1.5px solid var(--rule); font-size: 15px; }
.log__row--start { color: var(--muted); }
.log__n { font-family: var(--display); font-weight: 600; font-size: 15px; color: var(--muted); }
.log__bet { display: flex; flex-direction: column; line-height: 1.2; }
.log__bet small { font-size: 12px; color: var(--muted); }
.log__delta { font-family: var(--display); font-weight: 600; font-size: 15px; white-space: nowrap; }
.log__delta.is-loss { color: var(--red); }
.log__cap { font-family: var(--display); font-weight: 700; font-size: 17px; white-space: nowrap; text-align: right; min-width: 78px; }
.rank--plain { border-bottom-color: var(--ink); }
.sheet__box h2 { margin: 0 0 12px; font-family: var(--display); font-weight: 700; font-size: 34px; }
.sheet--rules ol { margin: 0 0 18px; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; }
.sheet--rules li { display: flex; gap: 14px; font-size: 16px; line-height: 1.4; }
.sheet--rules li b { font-family: var(--display); font-size: 26px; line-height: 1; color: var(--red); width: 16px; flex-shrink: 0; }

/* ——— misc ——— */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); z-index: 30; transform: translateX(-50%);
  max-width: 440px; width: calc(100% - 32px); padding: 12px 16px; background: var(--ink); color: var(--paper);
  font-size: 15px; line-height: 1.35; border: 3px solid var(--red);
}
.center { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; padding: 32px 22px; }
.center h1 { margin: 0; font-family: var(--display); font-weight: 700; font-size: 48px; line-height: 1; }
.center p { margin: 0; font-size: 17px; line-height: 1.45; }
.loading { flex: 1; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 40px; letter-spacing: .06em; }

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