:root {
  --bg: #0d0d0c; --side: #111110; --panel: #171715; --panel-2: #1e1e1b; --line: #2a2925;
  --text: #f5efdf; --muted: #9b978a; --lime: #a8e63a; --lime-ink: #0d0d0c; --red: #e8664a;
  --cut: 10px; --coin: clamp(170px, 27vh, 280px);
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; color: var(--text); font: 15px/1.5 Inter, system-ui, sans-serif; min-height: 100vh; overflow-x: hidden;
  background:
    radial-gradient(ellipse 55% 40% at 50% 34%, rgba(168,230,58,.075), transparent 70%),
    radial-gradient(ellipse 120% 90% at 50% 40%, transparent 55%, rgba(0,0,0,.55) 100%),
    var(--bg);
  background-size: 140% 140%, 100% 100%, auto;
  animation: bg-drift 18s ease-in-out infinite;
}
@keyframes bg-drift { 0%, 100% { background-position: 50% 30%, 0 0, 0 0 } 50% { background-position: 54% 36%, 0 0, 0 0 } }
.grain {
  position: fixed; inset: -10%; pointer-events: none; z-index: 0; opacity: .07;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grain 9s steps(6) infinite;
}
@keyframes grain { 0%,100% { transform: translate(0) } 25% { transform: translate(-1.5%, 1%) } 50% { transform: translate(1%, -1.5%) } 75% { transform: translate(-1%, -1%) } }
a { color: inherit; }
button { font: inherit; cursor: pointer; }
.mono, pre { font-family: 'JetBrains Mono', ui-monospace, monospace; }

/* angular cut corners */
.cut { clip-path: polygon(0 0, calc(100% - var(--cut)) 0, 100% var(--cut), 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut))); }

/* full-screen app: header / floating coin / controls */
.app { position: relative; z-index: 1; min-height: 100vh; min-height: 100svh; display: flex; flex-direction: column; }

/* header */
.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 28px; gap: 12px; }
.brand { justify-self: start; display: flex; align-items: center; gap: 8px; text-decoration: none; font: 700 18px 'Chakra Petch', sans-serif; letter-spacing: .06em; color: var(--lime); }
.mark { width: 28px; height: 28px; border-radius: 50%; display: block; }
.tabs { display: flex; gap: 8px; }
.tabs a, .connect {
  font: 600 12px 'Chakra Petch', sans-serif; letter-spacing: .08em; text-decoration: none;
  padding: 8px 20px; background: var(--panel); color: var(--muted); border: 0;
  box-shadow: inset 0 0 0 1px var(--line); transition: color .15s, box-shadow .15s, background .15s;
}
.tabs a.on { color: var(--text); background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--lime); }
.tabs a:hover { color: var(--text); }
.connect { justify-self: end; color: var(--lime); box-shadow: inset 0 0 0 1px var(--lime); }
.connect:hover { background: var(--lime); color: var(--lime-ink); }

/* stage: the coin floats in the middle of the screen */
.stage { flex: 1; min-height: calc(var(--coin) + 110px); position: relative; display: grid; place-items: center; perspective: 1100px; }
.halo { position: absolute; width: calc(var(--coin) * 1.7); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, rgba(168,230,58,.14), transparent 62%); filter: blur(10px); animation: halo 5s ease-in-out infinite; }
.float { animation: float 5s ease-in-out infinite; transform-style: preserve-3d; will-change: transform; }
@keyframes float {
  0%, 100% { transform: translateY(8px) rotateX(6deg) rotateZ(-2deg); }
  50%      { transform: translateY(-14px) rotateX(-4deg) rotateZ(2deg); }
}
@keyframes halo { 0%, 100% { opacity: .75; transform: scale(.96) } 50% { opacity: 1; transform: scale(1.04) } }
.shadow {
  position: absolute; top: calc(50% + var(--coin) / 2 + 26px); width: calc(var(--coin) * .62); height: 14px; border-radius: 50%;
  background: radial-gradient(rgba(0,0,0,.85), transparent 70%); animation: shadow 5s ease-in-out infinite;
}
@keyframes shadow { 0%, 100% { transform: scale(1); opacity: .9 } 50% { transform: scale(.72); opacity: .5 } }
.coin { width: var(--coin); height: var(--coin); position: relative; transform-style: preserve-3d; transition: transform 1s cubic-bezier(.2,.7,.2,1); }
.coin .face {
  position: absolute; inset: 0; border-radius: 50%; overflow: hidden; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,.55), 0 0 36px rgba(168,230,58,.16);
}
.coin .face img { width: 100%; height: 100%; object-fit: cover; display: block; transform: scale(1.035); } /* trims the white corners of the art */
.coin .tails { transform: rotateY(180deg); }
.coin.spin { animation: spin .45s linear infinite; }
@keyframes spin { from { transform: rotateY(0) } to { transform: rotateY(360deg) } }

/* WebGL 3D coin (replaces the CSS coin once loaded; the CSS coin stays as fallback and size reference) */
.coin3d { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
body.has3d .float { visibility: hidden; animation: none; }
body.has3d .shadow { animation: none; transition: transform .1s linear; }

/* controls */
main { width: 100%; max-width: 440px; margin: 0 auto; padding: 0 16px 28px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.result { margin: 0; color: var(--muted); text-align: center; min-height: 22px; font-size: 14px; max-width: 320px; }
.result.win { color: var(--lime); font-weight: 600; }
.result.lose { color: var(--red); }
h1 { font: 700 22px 'Chakra Petch', sans-serif; letter-spacing: .06em; margin: 0 0 4px; text-align: center; }

.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: 100%; }
.side-btn {
  --cut: 14px; display: flex; align-items: center; justify-content: center; gap: 10px; height: 64px;
  font: 700 15px 'Chakra Petch', sans-serif; letter-spacing: .1em;
  background: var(--panel); color: var(--muted); border: 0; box-shadow: inset 0 0 0 1px var(--line);
  transition: background .15s, color .15s, box-shadow .15s;
}
.side-btn img { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; opacity: .5; transition: opacity .15s; }
.side-btn.on { background: var(--lime); color: var(--lime-ink); box-shadow: none; }
.side-btn.on img { opacity: 1; }
.side-btn:hover:not(.on) { color: var(--text); box-shadow: inset 0 0 0 1px #3a3833; }

.bet { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.amount { display: flex; align-items: center; gap: 10px; background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); padding: 0 16px; }
.amount span, .amount b { font: 600 12px 'Chakra Petch', sans-serif; letter-spacing: .08em; color: var(--muted); }
.amount input { flex: 1; min-width: 0; background: transparent; border: 0; color: var(--text); font: 600 20px 'Chakra Petch', sans-serif; padding: 10px 0; outline: none; text-align: right; }
.amount:focus-within { box-shadow: inset 0 0 0 1px var(--lime); }
.chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.chips button { --cut: 6px; background: var(--panel); color: var(--muted); border: 0; box-shadow: inset 0 0 0 1px var(--line); padding: 7px 0; font: 600 12px 'Chakra Petch', sans-serif; }
.chips button:hover { color: var(--lime); }

.win-line { color: var(--muted); font-size: 14px; }
.win-line b { color: var(--text); }
.flip { --cut: 14px; width: 100%; border: 0; background: var(--lime); color: var(--lime-ink); font: 700 17px 'Chakra Petch', sans-serif; letter-spacing: .16em; padding: 15px; position: relative; overflow: hidden; transition: filter .15s; }
.flip::after { content: ''; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.35) 50%, transparent 70%); transform: translateX(-120%); }
.flip:hover::after { animation: sweep .8s ease-out; }
@keyframes sweep { to { transform: translateX(120%) } }
.flip:hover { filter: brightness(1.06); }
.flip:disabled { opacity: .45; cursor: not-allowed; }
.flip.small { width: auto; font-size: 13px; padding: 10px 18px; }
.ghost { --cut: 12px; width: 100%; border: 0; background: var(--panel); color: var(--lime); box-shadow: inset 0 0 0 1px var(--lime); font: 700 14px 'Chakra Petch', sans-serif; letter-spacing: .1em; padding: 12px; }
.hint { color: var(--muted); font-size: 12px; }
#pending { width: 100%; display: flex; flex-direction: column; gap: 6px; }
#pending:empty { display: none; }
.pend { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); padding: 10px 12px; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pend button { border: 0; background: var(--lime); color: var(--lime-ink); padding: 6px 12px; font: 600 12px 'Chakra Petch', sans-serif; }

/* below the fold (full mode only) */
.below { position: relative; z-index: 1; max-width: 1080px; margin: 0 auto; padding: 10px 24px 40px; display: flex; flex-direction: column; gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.card, .panel { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); padding: 16px 18px; min-width: 0; border-radius: 16px; }
.card { display: flex; flex-direction: column; }
.card small { color: var(--muted); font: 600 11px 'Chakra Petch', sans-serif; letter-spacing: .1em; }
.card b { font: 700 22px 'Chakra Petch', sans-serif; }
.card i { color: var(--muted); font-style: normal; font-size: 12px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.ph { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
h2 { font: 700 14px 'Chakra Petch', sans-serif; letter-spacing: .1em; margin: 0; }
.live { color: var(--muted); font-size: 12px; display: flex; gap: 6px; align-items: center; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 10px var(--lime); display: inline-block; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow: auto; }
.feed li { display: grid; grid-template-columns: 54px 1fr auto; gap: 10px; padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 13px; align-items: center; }
.feed .empty { display: block; color: var(--muted); }
.feed .w { color: var(--lime); font-weight: 600; }
.feed .l { color: var(--muted); }
.feed a { color: var(--muted); text-decoration: none; }
.badge { font-size: 11px; color: var(--muted); }
.steps { margin: 0 0 12px; padding-left: 18px; color: var(--muted); font-size: 14px; }
.steps b { color: var(--lime); }
.verify { display: flex; gap: 8px; }
.verify input { flex: 1; min-width: 0; background: var(--bg); border: 0; box-shadow: inset 0 0 0 1px var(--line); color: var(--text); padding: 9px 12px; font: inherit; outline: none; }
.vout { background: var(--bg); box-shadow: inset 0 0 0 1px var(--line); padding: 12px; font-size: 12px; color: var(--muted); white-space: pre-wrap; word-break: break-all; margin: 10px 0; border-radius: 10px; }
.head { font-size: 11px; color: var(--muted); word-break: break-all; }
footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; color: var(--muted); font-size: 12px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); box-shadow: inset 0 0 0 1px var(--line); padding: 10px 16px; font-size: 14px; max-width: calc(100% - 32px); z-index: 9; border-radius: 12px; }

/* minimal mode (private TEST): only the coin and the bet */
body.minimal .full-only, body.minimal .win-line, body.minimal .hint { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .float, .halo, .shadow, .grain, body { animation: none !important; }
}
@media (max-width: 640px) {
  :root { --coin: clamp(150px, 42vw, 200px); }
  .top { padding: 12px 16px; grid-template-columns: 1fr auto; }
  .tabs { display: none; }
  .stage { min-height: calc(var(--coin) + 90px); }
  h1 { font-size: 19px; }
  .side-btn { height: 56px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .grid { grid-template-columns: 1fr; }
  .below { padding: 10px 16px 30px; }
}
