:root {
  --bg: #1a0613; --maroon: #2a0a1e; --wood1: #7c4a23; --wood2: #4a2810; --felt: #0f5132; --gold: #fbbf24; --gold2: #f59e0b; --ink: #fff7ed;
  --font-d: 'Lilita One', Impact, 'Arial Black', sans-serif; --font-b: 'Nunito', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: radial-gradient(circle at 50% 30%, #3b0f2c, #12030c 70%); color: var(--ink); font-family: var(--font-b); overflow: hidden; touch-action: manipulation; user-select: none; }
button { font-family: inherit; color: inherit; cursor: pointer; }

#app { position: relative; margin: 0 auto; height: 100dvh; max-width: 460px; display: flex; flex-direction: column; background: linear-gradient(#2a0a1e, #1a0613); overflow: hidden; box-shadow: 0 0 0 3px #6b2b12, 0 0 60px rgba(251, 191, 36, .25); }
@media (min-width: 520px) { #app { height: min(100dvh, 920px); margin-top: max(0px, calc((100dvh - 920px) / 2)); border-radius: 22px; } }

#top { text-align: center; padding: 0 8px 4px; background: linear-gradient(#5b1038, #2a0a1e); border-bottom: 3px solid var(--gold2); }
#bulbs { display: flex; justify-content: space-around; padding: 5px 4px 0; }
#bulbs i { width: 9px; height: 9px; border-radius: 50%; background: #fde047; box-shadow: 0 0 8px 2px #fbbf24; animation: twinkle 1s infinite; }
#bulbs i:nth-child(3n+1) { background: #f87171; box-shadow: 0 0 8px 2px #ef4444; animation-delay: .33s; }
#bulbs i:nth-child(3n+2) { background: #60a5fa; box-shadow: 0 0 8px 2px #3b82f6; animation-delay: .66s; }
@keyframes twinkle { 50% { opacity: .35; transform: scale(.8); } }
h1 { margin: 2px 0 0; font: 400 clamp(24px, 7.4vw, 34px)/1.05 var(--font-d); color: var(--gold); letter-spacing: 1px; text-shadow: 0 3px 0 #92400e, 0 0 16px rgba(251, 191, 36, .6); cursor: pointer; }
.subtitle { font: 400 12px var(--font-d); letter-spacing: 3px; color: #fca5a5; }
#disclaimer { text-align: center; font-size: 11px; font-weight: 800; padding: 3px 6px; background: #3b0f2c; color: #fde68a; border-bottom: 1px solid #6b2b12; }

#hud { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 5px 10px; }
.hud-player { display: flex; align-items: center; gap: 6px; font-weight: 800; min-width: 0; max-width: 34%; }
.hud-player span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#avatar { font-size: 20px; }
.hud-chips { display: flex; align-items: center; gap: 5px; font: 400 24px var(--font-d); color: var(--gold); background: #12030c; border: 2px solid var(--gold2); border-radius: 999px; padding: 0 12px 0 4px; }
.coin { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: radial-gradient(#fde68a, #f59e0b); color: #78350f; font-size: 15px; border: 2px solid #b45309; }
.hud-bet { font-size: 12px; text-align: right; color: #fecaca; }
.hud-bet b { color: #fff; font-size: 14px; }

#board { flex: 1 1 0; min-height: 0; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); gap: 8px; margin: 4px 10px; padding: 10px; border-radius: 14px; border: 4px solid var(--wood1); background: repeating-linear-gradient(90deg, #0f5132 0 6px, #0c4429 6px 12px); box-shadow: inset 0 0 28px rgba(0, 0, 0, .6), 0 4px 0 var(--wood2); }
.sq { position: relative; border: 4px solid rgba(255, 255, 255, .85); border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 6px; font-family: var(--font-d); color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, .45); box-shadow: inset 0 -10px 18px rgba(0, 0, 0, .25), 0 4px 0 rgba(0, 0, 0, .45); transition: transform .1s; overflow: hidden; }
.sq:active { transform: scale(.96); }
.sq .nm { font-size: clamp(16px, 5vw, 22px); line-height: 1; }
.sq .tl { font: 800 11px var(--font-b); opacity: .9; letter-spacing: 1px; }
.sq.white { color: #1e293b; text-shadow: none; border-color: #94a3b8; }
.sq .stack { position: absolute; bottom: 8px; left: 50%; width: 44px; height: 44px; transform: translateX(-50%); pointer-events: none; }
.sq .stack i { position: absolute; left: 50%; width: 34px; height: 34px; margin-left: -17px; border-radius: 50%; border: 3px dashed rgba(255, 255, 255, .85); box-shadow: 0 3px 0 rgba(0, 0, 0, .5), inset 0 0 0 3px rgba(0, 0, 0, .2); animation: drop .25s ease-out; }
@keyframes drop { from { transform: translateY(-30px); opacity: 0; } }
.sq .amt { position: absolute; bottom: 2px; left: 0; right: 0; text-align: center; font: 400 13px var(--font-d); color: #fff; text-shadow: 0 1px 3px #000, 0 0 4px #000; }
.sq .hits { position: absolute; top: 4px; right: 6px; font: 400 15px var(--font-d); display: none; }
.sq.hit { animation: winpulse .5s 4; border-color: var(--gold); }
.sq.hit .hits { display: block; color: #fde047; text-shadow: 0 1px 2px #000; }
@keyframes winpulse { 50% { transform: scale(1.06); filter: brightness(1.3); } }
.d10 { background: #3b82f6; } .d50 { background: #22c55e; } .d100 { background: #1f2937; } .d250 { background: #a21caf; }

#chute { position: relative; height: clamp(88px, 15dvh, 130px); margin: 4px 10px; border-radius: 12px; border: 4px solid var(--wood1); background: linear-gradient(#5b3416, #7c4a23 40%, #4a2810); box-shadow: inset 0 0 20px rgba(0, 0, 0, .6), 0 4px 0 var(--wood2); overflow: hidden; }
#chute::before { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(0deg, rgba(0, 0, 0, .08) 0 3px, transparent 3px 9px); pointer-events: none; }
#diceCanvas { width: 100%; height: 100%; display: block; }
#chuteMsg { position: absolute; inset: auto 0 4px; text-align: center; font: 400 15px var(--font-d); color: #fde047; text-shadow: 0 2px 4px #000; pointer-events: none; }

#controls { padding: 4px 10px 0; display: flex; flex-direction: column; gap: 6px; }
#chipRow { display: flex; gap: 6px; justify-content: space-between; }
.chipbtn { flex: 1; height: 44px; border-radius: 999px; border: 3px dashed rgba(255, 255, 255, .85); font: 400 15px var(--font-d); color: #fff; box-shadow: 0 3px 0 rgba(0, 0, 0, .5); }
.chipbtn.maxc { background: linear-gradient(#ef4444, #991b1b); }
.chipbtn.sel { transform: translateY(-4px) scale(1.08); border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold), 0 6px 10px rgba(0, 0, 0, .6); }
#actions { display: flex; gap: 8px; }
.btn { border: 0; border-radius: 12px; font: 400 18px var(--font-d); padding: 0 12px; height: 54px; box-shadow: 0 4px 0 rgba(0, 0, 0, .5); }
.btn small { font: 800 11px var(--font-b); display: block; opacity: .9; }
.btn.primary { flex: 1; background: linear-gradient(#fde047, #f59e0b); color: #5b1a06; animation: glow 1.5s infinite; }
.btn.secondary { background: #3b0f2c; border: 2px solid #9d174d; font-size: 14px; width: 30%; }
.btn.reload { background: linear-gradient(#38bdf8, #0369a1); height: 48px; }
.btn:disabled { filter: grayscale(.8) brightness(.7); animation: none; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .5); }
@keyframes glow { 50% { box-shadow: 0 4px 0 rgba(0, 0, 0, .5), 0 0 18px rgba(253, 224, 71, .8); } }
[hidden] { display: none !important; }

#toolbar { display: flex; gap: 6px; padding: 6px 10px calc(6px + env(safe-area-inset-bottom)); }
#toolbar button { flex: 1; background: #3b0f2c; border: 1px solid #6b2b12; border-radius: 10px; font-weight: 800; font-size: 12px; padding: 8px 2px; }
#toolbar button[aria-pressed="false"] { opacity: .55; }

#toast { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -10px) scale(.9); max-width: 88%; text-align: center; background: rgba(18, 3, 12, .93); border: 3px solid var(--gold); border-radius: 14px; padding: 10px 16px; font: 400 20px var(--font-d); color: #fde047; opacity: 0; pointer-events: none; transition: .2s; z-index: 30; white-space: pre-line; }
#toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
#toast.lose { color: #fca5a5; border-color: #ef4444; }

.modal { position: absolute; inset: 0; z-index: 40; display: none; align-items: flex-end; background: rgba(0, 0, 0, .65); }
.modal.open { display: flex; }
#login { align-items: center; }
.sheet { position: relative; width: 100%; max-height: 86%; overflow: auto; background: linear-gradient(#3b0f2c, #1f0716); border: 3px solid var(--gold2); border-radius: 18px 18px 0 0; padding: 16px; user-select: text; }
#login .sheet { margin: 0 14px; border-radius: 18px; text-align: center; }
.sheet h2 { margin: 0 24px 4px 0; font: 400 24px var(--font-d); color: var(--gold); }
#login h2 { margin: 0 0 4px; }
.close { position: absolute; right: 10px; top: 10px; width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--gold2); background: #12030c; font-size: 16px; }
.hint { font-size: 13px; color: #fecaca; margin: 4px 0 10px; } .hint.err { color: #fca5a5; min-height: 1em; }
#nickInput { width: 100%; height: 48px; border-radius: 12px; border: 3px solid var(--gold2); background: #12030c; color: #fff; font: 800 18px var(--font-b); text-align: center; margin-bottom: 8px; }
.avatars { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-bottom: 12px; }
.avatars button { background: #3b0f2c; border: 1px solid #9d174d; border-radius: 999px; padding: 6px 10px; font-weight: 800; font-size: 13px; }
#loginForm .btn { width: 100%; }
details { background: rgba(0, 0, 0, .25); border-radius: 10px; padding: 8px 10px; margin: 6px 0; font-size: 14px; }
summary { font-weight: 800; color: #fde68a; cursor: pointer; }
table { width: 100%; border-collapse: collapse; font-size: 13px; } th, td { border-bottom: 1px solid #6b2b12; padding: 5px; text-align: left; }
.lb .row { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; padding: 8px; border-radius: 10px; margin-bottom: 5px; background: rgba(0, 0, 0, .28); }
.lb .row.me { outline: 2px solid var(--gold); background: rgba(251, 191, 36, .12); }
.lb .rk { font: 400 18px var(--font-d); color: var(--gold); text-align: center; }
.lb .nm { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb .meta { font-size: 11px; color: #fecaca; }
.lb .ch { font: 400 18px var(--font-d); color: var(--gold); }
.badge { display: inline-block; font: 400 10px var(--font-d); background: linear-gradient(#fde047, #f59e0b); color: #5b1a06; padding: 1px 6px; border-radius: 999px; margin-left: 4px; vertical-align: middle; }

canvas.cutscene { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 50; }

@media (prefers-reduced-motion: reduce) { #bulbs i, .btn.primary { animation: none; } }
