:root {
  color-scheme: dark;
  --bg: #120c24;
  --surface: #1d1538;
  --surface-2: #271d4a;
  --border: #3a2d62;
  --text: #efeafd;
  --muted: #b9b0d6;
  --accent: #f7c348;
  --accent-ink: #3a2202;
  --gold-hi: #ffe7a3;
  --gold-rim: #d39b2f;
  --win: #34e3b4;
  --lose: #ff6b7d;
  --fair: #7aa7ff;
  --radius: 12px;
  --gutter: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: radial-gradient(ellipse 120% 60% at 50% 0%, #2c1f57 0%, var(--bg) 60%, #0b0716 100%) fixed var(--bg); color: var(--text); line-height: 1.45; min-height: 100vh; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 var(--gutter); }

/* header */
.site-header { border-bottom: 1px solid var(--border); background: rgba(15, 10, 31, .9); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20; }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { font-weight: 900; font-size: 1.15rem; letter-spacing: .02em; text-decoration: none; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; }
.nav { flex-wrap: wrap; }
.nav a { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; padding: 8px 12px; border-radius: 12px; color: var(--muted); font-weight: 600; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { color: #fff; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--gold-rim), 0 0 14px rgba(247, 195, 72, .15); }

main { padding: 24px 0 48px; }
h1 { font-size: 2rem; font-weight: 900; margin: 0 0 6px; color: var(--gold-hi); text-shadow: 0 3px 0 #6b3f04, 0 0 24px rgba(247, 195, 72, .3); }

/* icons (sprite from assets/icons.js) */
.icon { width: 1.3em; height: 1.3em; flex: none; vertical-align: -.3em; filter: drop-shadow(0 2px 1.5px rgba(0, 0, 0, .45)); }
.icon--lg { width: 1.9em; height: 1.9em; vertical-align: -.55em; }
.icon--btn { width: 1.7em; height: 1.7em; margin: -6px 0; }
.icon--coin { width: 2.4rem; height: 2.4rem; }
.lede { color: var(--muted); margin: 0 0 20px; max-width: 70ch; }
.lede strong { color: var(--text); }

/* controls */
.controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 14px; }
.search { flex: 1 1 260px; min-width: 0; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.search::placeholder { color: var(--muted); }
select.sort { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: .9rem; }
.chip:hover { background: var(--surface-2); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.chip small { opacity: .75; margin-left: 4px; }
.count { color: var(--muted); font-size: .9rem; margin: 0 0 12px; }

/* knife cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; content-visibility: auto; contain-intrinsic-size: 260px; }
.card h3 { margin: 0; font-size: .98rem; line-height: 1.25; overflow-wrap: anywhere; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge { font-size: .72rem; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; line-height: 1.3; background: var(--tag-bg); color: var(--tag-ink); border: 1px solid color-mix(in srgb, var(--tag-bg) 70%, #fff 30%); white-space: nowrap; }
.meta .tag { font-size: .68rem; padding: 1px 6px; margin-left: 2px; vertical-align: 1px; }
.value { font-size: 1.25rem; font-weight: 800; color: var(--accent); line-height: 1.1; }
.value small { display: block; font-size: .75rem; font-weight: 500; color: var(--muted); margin-top: 2px; }
.stats { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 700; color: var(--text); margin-top: auto; }
.stats > span { display: inline-flex; align-items: center; gap: 5px; }
.stats .icon { width: 1.25rem; height: 1.25rem; }

/* image tile (real image or placeholder) */
.tile { --c: #888; position: relative; display: grid; place-items: center; aspect-ratio: 1; width: 100%; border-radius: 10px; overflow: hidden; background: linear-gradient(145deg, color-mix(in srgb, var(--c) 45%, #120c24), color-mix(in srgb, var(--c) 12%, #120c24)); border: 1px solid color-mix(in srgb, var(--c) 40%, transparent); }
.tile img { width: 100%; height: 100%; object-fit: contain; }
.tile__ini { font-weight: 800; font-size: 1.9rem; letter-spacing: .03em; color: color-mix(in srgb, var(--c) 70%, #fff); text-shadow: 0 2px 10px rgba(0,0,0,.4); }
.tile--sm { width: 40px; flex: none; border-radius: 8px; }
.tile--sm .tile__ini { font-size: .95rem; }

.empty { color: var(--muted); padding: 40px 0; text-align: center; }

/* trade calculator */
.trade { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.side { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; min-width: 0; }
.side h2 { margin: 0 0 10px; font-size: 1.05rem; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.side h2 .total { color: var(--accent); font-weight: 800; font-size: 1.15rem; }
.picker { position: relative; margin-bottom: 10px; }
.picker input { width: 100%; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); }
.results { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; margin: 0; padding: 4px; list-style: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.5); max-height: 340px; overflow: auto; }
.results[hidden] { display: none; }
.results li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.results li[aria-selected="true"], .results li:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.results .meta { flex: 1; min-width: 0; }
.results .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .meta span { font-size: .78rem; color: var(--muted); }
.results .v { font-weight: 700; color: var(--accent); white-space: nowrap; }
.results .none { color: var(--muted); cursor: default; justify-content: center; }

.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.items .hint { color: var(--muted); font-size: .9rem; padding: 14px 4px; text-align: center; }
.row { display: flex; align-items: center; gap: 10px; padding: 6px; background: var(--surface-2); border-radius: 10px; }
.row .meta { flex: 1; min-width: 0; }
.row .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta span { font-size: .78rem; color: var(--muted); }
.qty { display: inline-flex; align-items: center; gap: 2px; }
.qty button, .remove { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; line-height: 1; }
.qty button:hover, .remove:hover { background: var(--border); }
.qty output { min-width: 26px; text-align: center; font-weight: 700; }
.row .line { min-width: 56px; text-align: right; font-weight: 700; }

.verdict { grid-column: 1 / -1; border-radius: var(--radius); padding: 18px; border: 1px solid var(--border); background: var(--surface); text-align: center; }
.verdict .label { font-size: 1.6rem; font-weight: 800; margin: 0; }
.verdict .detail { color: var(--muted); margin: 6px 0 0; }
.verdict .detail b { color: var(--text); }
.verdict[data-state="win"] { border-color: var(--win); } .verdict[data-state="win"] .label { color: var(--win); }
.verdict[data-state="lose"] { border-color: var(--lose); } .verdict[data-state="lose"] .label { color: var(--lose); }
.verdict[data-state="fair"] { border-color: var(--fair); } .verdict[data-state="fair"] .label { color: var(--fair); }
.bars { display: grid; gap: 8px; margin: 14px auto 0; max-width: 560px; text-align: left; font-size: .85rem; color: var(--muted); }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .25s; }
.bar.get > i { background: var(--fair); }
.actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 9px 18px; border-radius: 14px; border: 1px solid var(--border); background: linear-gradient(180deg, #33275e, #231a45); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), inset 0 -3px 0 rgba(0, 0, 0, .3); cursor: pointer; font-weight: 700; text-decoration: none; }
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { cursor: default; opacity: .55; filter: saturate(.6); }
.btn.primary { color: var(--accent-ink); border: 0; background: linear-gradient(180deg, #fff0a8 0%, #f7c348 50%, #c8861a 100%); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .7), inset 0 -4px 0 #8a5608, 0 4px 14px rgba(247, 195, 72, .3); }
.btn.go { color: #053b30; border: 0; background: linear-gradient(180deg, #8affdc 0%, #2fd8a8 50%, #0f9a78 100%); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .6), inset 0 -4px 0 #087259, 0 4px 14px rgba(47, 216, 168, .28); }
.note { grid-column: 1 / -1; color: var(--muted); font-size: .85rem; text-align: center; margin: 0; }

footer { border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; padding: 20px 0 32px; }
footer p { margin: 0 0 6px; }

@media (max-width: 760px) {
  .trade { grid-template-columns: 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  h1 { font-size: 1.35rem; }
  /* names stay readable: controls wrap onto their own line */
  .row { flex-wrap: wrap; }
  .row .meta { flex: 1 1 120px; }
  .row .meta b { white-space: normal; overflow-wrap: anywhere; }
  .row .qty { margin-left: auto; }
  .row .line { margin-left: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .bar > i, .crash-display, .crash-rocket, .mine { transition: none; }
  .crash-stage[data-state="active"] .crash-rocket, .mine .icon { animation: none; }
}

/* play page */
.account { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; justify-content: space-between; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.account p { margin: 0; color: var(--muted); max-width: 60ch; }
.account code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.account__meta { display: flex; flex-direction: column; line-height: 1.25; }
.account__balance { display: flex; align-items: center; gap: 10px; line-height: 1.1; padding: 6px 18px 6px 10px; border-radius: 999px; background: linear-gradient(180deg, #2a1d4f, #170f2e); border: 2px solid var(--gold-rim); box-shadow: 0 0 18px rgba(247, 195, 72, .2); }
.account__balance > span { display: flex; flex-direction: column; }
.account__balance small { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.account__balance b { font-size: 1.5rem; color: var(--gold-hi); }

.play-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.game { background: linear-gradient(180deg, #221940 0%, #140e28 100%); border: 1px solid var(--border); border-radius: 20px; padding: 18px; min-width: 0; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 12px 32px rgba(0, 0, 0, .35); }
.game.wide { margin-top: 16px; }
.game h2 { margin: 0 0 14px; font-size: 1.35rem; font-weight: 900; color: var(--gold-hi); text-shadow: 0 2px 0 #6b3f04; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.game__title { display: inline-flex; align-items: center; gap: 10px; }
.game__tag { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 700; color: #ffd0d6; text-shadow: none; background: #3a1530; border: 1px solid #7d2440; border-radius: 999px; padding: 4px 10px 4px 6px; }
.fields { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.field input, .field select { padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); min-width: 96px; text-transform: none; letter-spacing: 0; font-size: 1rem; }
.mine-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.mine { aspect-ratio: 1; display: grid; place-items: center; padding: 0; border-radius: 14px; border: 2px solid #6450b0; background: linear-gradient(180deg, #4d3795 0%, #2c1d5c 100%); box-shadow: inset 0 2px 0 rgba(255, 255, 255, .2), inset 0 -5px 0 #1a1036, 0 3px 8px rgba(0, 0, 0, .35); cursor: pointer; transition: transform .12s, filter .12s; }
.mine:hover:not(:disabled) { filter: brightness(1.18); transform: translateY(-2px); }
.mine:disabled { cursor: default; }
.mine:disabled:not([data-state="safe"]):not([data-state="mine"]) { filter: saturate(.75) brightness(.92); }
.mine .icon { width: 60%; height: 60%; filter: drop-shadow(0 4px 3px rgba(0, 0, 0, .5)); animation: pop .22s ease-out; }
.mine[data-state="safe"] { background: radial-gradient(circle at 50% 40%, #17705d 0%, #0b3a31 75%); border-color: var(--win); box-shadow: inset 0 2px 0 rgba(198, 255, 241, .35), inset 0 -5px 0 #062a23, 0 0 16px rgba(52, 227, 180, .35); }
.mine[data-state="mine"] { background: radial-gradient(circle at 50% 40%, #7a1830 0%, #3a0a18 75%); border-color: #ff4a62; box-shadow: inset 0 2px 0 rgba(255, 194, 200, .35), inset 0 -5px 0 #2a0610, 0 0 18px rgba(255, 74, 98, .45); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.crash-stage { position: relative; height: 200px; margin-bottom: 14px; border-radius: 16px; overflow: hidden; border: 1px solid var(--border); background: linear-gradient(0deg, rgba(255, 255, 255, .04) 1px, transparent 1px) 0 0 / 100% 40px, linear-gradient(90deg, rgba(255, 255, 255, .04) 1px, transparent 1px) 0 0 / 56px 100%, radial-gradient(ellipse at 70% 30%, #2b1c5c 0%, #110a24 70%); box-shadow: inset 0 0 40px rgba(0, 0, 0, .5); }
.crash-display { position: absolute; left: 18px; top: 50%; transform: translateY(-50%); display: flex; align-items: center; gap: 8px; font-size: 3rem; font-weight: 900; line-height: 1; color: #fff4c2; text-shadow: 0 4px 0 #6b3f04, 0 0 24px rgba(247, 195, 72, .5); font-variant-numeric: tabular-nums; }
.crash-rocket { position: absolute; right: 8%; bottom: 14%; width: 84px; height: 84px; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .5)) drop-shadow(0 0 14px rgba(255, 176, 46, .45)); transition: transform .5s, opacity .5s; }
.crash-stage[data-state="active"] .crash-rocket { animation: climb 1.2s ease-in-out infinite alternate; }
.crash-stage[data-state="crashed"] { border-color: #7d2440; }
.crash-stage[data-state="crashed"] .crash-display { color: var(--lose); text-shadow: 0 4px 0 #4a0612, 0 0 24px rgba(255, 74, 98, .5); }
.crash-stage[data-state="crashed"] .crash-rocket { transform: rotate(130deg) translate(10px, -10px); opacity: .5; filter: grayscale(.6) drop-shadow(0 6px 10px rgba(0, 0, 0, .5)); }
.crash-stage[data-state="cashed"] { border-color: var(--win); }
.crash-stage[data-state="cashed"] .crash-display { color: var(--win); text-shadow: 0 4px 0 #063f34, 0 0 24px rgba(52, 227, 180, .5); }
@keyframes climb { from { transform: translate(0, 4px); } to { transform: translate(-6px, -8px); } }
.game__foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.game__foot .muted, .muted { color: var(--muted); }
[data-kind="good"] { color: var(--win); }
[data-kind="bad"] { color: var(--lose); }
.seed { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .72rem; overflow-wrap: anywhere; margin: 10px 0 0; min-height: 1.4em; }
.seed .icon { width: 1.4em; height: 1.4em; }
.seed:has(span:empty) .icon { visibility: hidden; }
.seed span { min-width: 0; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.history li { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; font-size: .9rem; }
.history__reason { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.history b { display: inline-flex; align-items: center; gap: 6px; }
.rank { display: inline-grid; place-items: center; min-width: 1.6em; color: var(--muted); font-weight: 800; }
.rank .icon { width: 1.6em; height: 1.6em; }
.history__when { color: var(--muted); font-size: .78rem; }
.history b { margin-left: auto; }
.history .up { color: var(--win); }
.history .down { color: var(--lose); }

@media (max-width: 760px) {
  .play-grid { grid-template-columns: 1fr; }
  .crash-display { font-size: 2.2rem; }
  .crash-rocket { width: 64px; height: 64px; }
}
.invite-field { flex: 1 1 320px; }
.invite-field input { width: 100%; }
