* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #1b140d;
  font-family: 'Lilita One', 'Trebuchet MS', system-ui, sans-serif;
  color: #fff7e6; user-select: none; -webkit-user-select: none; touch-action: none;
}
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

:root { --colw: 100vw; --colx: 0px; --die: 64px; }

/* ---------- Top HUD ---------- */
#hud {
  position: fixed; top: calc(env(safe-area-inset-top) + 8px); left: var(--colx); width: var(--colw);
  display: flex; align-items: center; justify-content: space-between; padding: 0 10px; pointer-events: none;
}
.hud-pill {
  display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 12px 0 8px; border-radius: 20px;
  background: linear-gradient(#5a3a20, #3b2513); border: 2px solid #c99a4b;
  box-shadow: 0 2px 0 #20140a, inset 0 1px 0 rgba(255, 230, 170, .25);
  font-size: 20px; text-shadow: 0 2px 0 #2a1a0c;
}
.heart { width: 26px; height: 26px; fill: #ff4b4b; stroke: #8a1010; stroke-width: 1.5; }
.coin {
  width: 24px; height: 24px; border-radius: 50%; display: inline-block;
  background: radial-gradient(circle at 35% 30%, #fff2a8, #ffc928 45%, #c98a06);
  border: 2px solid #8a5a00;
}
.hud-plaque {
  min-width: 120px; text-align: center; padding: 6px 18px; font-size: 22px; letter-spacing: 1px;
  background: linear-gradient(#6b4626, #45291a); border: 2px solid #c99a4b; border-radius: 12px;
  box-shadow: 0 3px 0 #20140a, inset 0 1px 0 rgba(255, 230, 170, .25); text-shadow: 0 2px 0 #2a1a0c;
}
#hearts.hurt { animation: hurt .35s; }
@keyframes hurt { 30% { transform: scale(1.25) rotate(-6deg); background: #a02020; } }

/* ---------- Combo banner ---------- */
#banner {
  position: fixed; left: var(--colx); width: var(--colw); top: 0; height: 0;
  display: flex; justify-content: center; align-items: center; pointer-events: none;
  opacity: 0; transform: scale(.6);
}
#banner.show { animation: banner 1.5s cubic-bezier(.2, 1.6, .4, 1) forwards; }
@keyframes banner {
  0% { opacity: 0; transform: scale(.4); }
  15% { opacity: 1; transform: scale(1.08); }
  25% { transform: scale(1); }
  80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.05) translateY(-14px); }
}
.ribbon {
  position: relative; padding: 10px 44px; font-size: clamp(24px, 8vw, 38px); letter-spacing: 1px; white-space: nowrap;
  color: #ffe9a8; text-shadow: 0 3px 0 #3a1446, 0 0 2px #3a1446;
  background: linear-gradient(#9a4fc0, #6a2b8e 55%, #4e1d6c);
  border-top: 3px solid #f6cf6a; border-bottom: 3px solid #f6cf6a;
  clip-path: polygon(0 0, 100% 0, 94% 50%, 100% 100%, 0 100%, 6% 50%);
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, .35));
}
.burst {
  margin-left: -18px; width: 76px; height: 76px; display: grid; place-items: center;
  font-size: 28px; color: #5a2c00; text-shadow: 0 1px 0 #fff3b0;
  background: radial-gradient(circle at 40% 35%, #fff6b0, #ffcc33 55%, #e79a0a);
  clip-path: polygon(50% 0, 61% 18%, 82% 10%, 80% 32%, 100% 40%, 85% 56%, 96% 76%, 74% 78%, 68% 100%, 50% 86%, 32% 100%, 26% 78%, 4% 76%, 15% 56%, 0 40%, 20% 32%, 18% 10%, 39% 18%);
}
.burst.hide { display: none; }

/* ---------- Dice tray ---------- */
#tray {
  position: fixed; bottom: 0; left: var(--colx); width: var(--colw);
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 12px);
  background:
    repeating-linear-gradient(92deg, rgba(0, 0, 0, .06) 0 3px, transparent 3px 11px),
    linear-gradient(#7a4f2b, #5b3a1f 40%, #46301a);
  border-top: 4px solid #2f1d0e; box-shadow: 0 -6px 18px rgba(0, 0, 0, .45), inset 0 2px 0 rgba(255, 220, 160, .2);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#preview { font-size: 15px; color: #ffe3a8; opacity: .95; text-shadow: 0 1px 0 #2a1a0c; min-height: 18px; text-align: center; }
#preview b { color: #fff; letter-spacing: .5px; }
#preview span { font-family: system-ui, sans-serif; font-weight: 600; font-size: 13px; color: #f4d9a6; }
#timer { width: 100%; display: flex; align-items: center; gap: 6px; }
.glass { font-size: 18px; }
#timer-bar {
  flex: 1; height: 14px; border-radius: 8px; background: #2a1a0c; border: 2px solid #1c1108;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, .6); overflow: hidden;
}
#timer-fill { height: 100%; width: 100%; background: linear-gradient(#ffb347, #f07b12); border-radius: 6px; }
#timer-fill.full { background: linear-gradient(#a6f07a, #4fb02a); }

#dice {
  width: 100%; display: flex; justify-content: space-between; gap: 6px; padding: 10px 10px;
  background: linear-gradient(#3a2414, #2c1a0d); border-radius: 14px; border: 3px solid #a87a3e;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, .6), 0 2px 0 #20140a;
}
.die {
  position: relative; width: var(--die); height: var(--die); border-radius: 22%; flex: none; cursor: pointer;
  background: radial-gradient(circle at 30% 25%, #fffdf6, #f3e7cf 60%, #d9c6a2);
  box-shadow: 0 4px 0 #a8916a, 0 6px 8px rgba(0, 0, 0, .45), inset 0 -3px 0 rgba(0, 0, 0, .08);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: calc(var(--die) * 0.14);
  transition: transform .12s;
}
.die:active { transform: scale(.94); }
.pip { width: 74%; height: 74%; margin: auto; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #5a4a3c, #2a1d14); }
.die.locked { box-shadow: 0 0 0 3px #ffd23f, 0 0 16px 4px rgba(255, 196, 40, .75), 0 4px 0 #a8916a; transform: translateY(-3px); }
.die .lock {
  position: absolute; left: 50%; bottom: -14px; width: 26px; height: 26px; margin-left: -13px; display: none;
}
.die.locked .lock { display: block; }
.die.frozen { background: radial-gradient(circle at 30% 25%, #f4fdff, #bfe9fb 60%, #85c6e6); box-shadow: 0 0 0 3px #9fe3ff, 0 0 14px 3px rgba(140, 220, 255, .8), 0 4px 0 #5f93ad; }
.die .ice { position: absolute; right: -6px; top: -8px; font-size: 20px; display: none; }
.die.frozen .ice { display: block; }
.die.rolling { animation: wobble .12s infinite alternate; }
@keyframes wobble { from { transform: rotate(-9deg) scale(.96); } to { transform: rotate(9deg) scale(1.02); } }
.die .lvl { position: absolute; top: -9px; left: -6px; font-size: 13px; color: #ffd23f; text-shadow: 0 1px 0 #3a2400, 0 0 2px #3a2400; letter-spacing: -2px; }

#buttons { width: 100%; display: flex; gap: 12px; justify-content: center; margin-top: 4px; }
#roll {
  position: relative; flex: 1 1 0; max-width: 220px; height: 60px; border-radius: 32px; cursor: pointer;
  font: inherit; font-size: 30px; letter-spacing: 1px; color: #fff; text-shadow: 0 3px 0 #1f5a12;
  background: linear-gradient(#8ee05a, #4fb02a 55%, #3a8d1c); border: 3px solid #e7c574;
  box-shadow: 0 5px 0 #24560f, 0 8px 12px rgba(0, 0, 0, .4), inset 0 2px 0 rgba(255, 255, 255, .45);
}
#roll:active { transform: translateY(3px); box-shadow: 0 2px 0 #24560f, inset 0 2px 0 rgba(255, 255, 255, .45); }
#roll.off { filter: grayscale(.85) brightness(.8); }
#cast {
  flex: 1 1 0; max-width: 220px; height: 60px; border-radius: 32px; cursor: pointer;
  font: inherit; font-size: 30px; letter-spacing: 1px; color: #fff;
  background: linear-gradient(#8a7a66, #6b5c4a); border: 3px solid #a08a62; text-shadow: 0 3px 0 #3a2c1c;
  box-shadow: 0 5px 0 #3a2c1c, inset 0 2px 0 rgba(255, 255, 255, .25); opacity: .75;
}
#cast.ready {
  opacity: 1; background: linear-gradient(#ffd05a, #f09a1a 55%, #c9700a); border-color: #fff1c9; text-shadow: 0 3px 0 #7a3c00;
  box-shadow: 0 5px 0 #7a3c00, 0 0 22px rgba(255, 190, 60, .8), inset 0 2px 0 rgba(255, 255, 255, .45);
  animation: ready 0.9s ease-in-out infinite alternate;
}
@keyframes ready { to { transform: scale(1.05); box-shadow: 0 5px 0 #7a3c00, 0 0 34px rgba(255, 200, 70, 1), inset 0 2px 0 rgba(255, 255, 255, .45); } }
#cast:active { transform: translateY(3px); }
.nope { animation: nope .3s; }
@keyframes nope { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }
#roll-badge {
  position: absolute; top: -10px; right: -8px; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-size: 20px; text-shadow: none;
  background: radial-gradient(circle at 35% 30%, #ff7a6b, #d6281a); border: 2px solid #fff1c9; box-shadow: 0 2px 0 #6a1008;
}

/* ---------- Overlays ---------- */
#overlay {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(20, 12, 5, .62); padding: 20px;
}
#overlay.show { display: flex; }
.panel {
  width: min(92vw, 420px); max-height: 92vh; overflow: auto; padding: 22px 20px 20px; text-align: center; border-radius: 20px;
  background: linear-gradient(#f6e7c4, #e8d1a2); color: #4a2f17; border: 4px solid #8a5a2b;
  box-shadow: 0 8px 0 #4a2f17, 0 16px 40px rgba(0, 0, 0, .6);
}
.panel h1 { margin: 0; font-size: 52px; font-weight: 400; color: #ffe08a; text-shadow: 0 4px 0 #6a2b8e, 0 0 3px #3a1446; letter-spacing: 1px; }
.panel h2 { margin: 0 0 4px; font-size: 30px; font-weight: 400; color: #6a2b8e; }
.panel p { margin: 6px 0; font-family: system-ui, sans-serif; font-size: 15px; line-height: 1.35; font-weight: 500; }
.panel .tag { font-size: 20px; color: #8a5a2b; margin-bottom: 10px; }
.panel ul { text-align: left; font-family: system-ui, sans-serif; font-size: 14px; font-weight: 500; line-height: 1.4; padding-left: 20px; margin: 10px 0 14px; }
.panel li { margin: 4px 0; }
.btn {
  font: inherit; font-size: 26px; color: #fff; padding: 10px 34px; border-radius: 30px; cursor: pointer; margin-top: 8px;
  background: linear-gradient(#8ee05a, #4fb02a 55%, #3a8d1c); border: 3px solid #e7c574; text-shadow: 0 2px 0 #1f5a12;
  box-shadow: 0 5px 0 #24560f, inset 0 2px 0 rgba(255, 255, 255, .45);
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #24560f; }
.btn.alt { background: linear-gradient(#b98b55, #8a5a2b); text-shadow: 0 2px 0 #3a2410; box-shadow: 0 5px 0 #3a2410; font-size: 20px; }
.cards { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 6px; }
.card {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; cursor: pointer; text-align: left;
  background: #fff8e6; border: 3px solid #c99a4b; box-shadow: 0 4px 0 #8a5a2b; font: inherit; color: inherit;
}
.card:active { transform: translateY(2px); box-shadow: 0 2px 0 #8a5a2b; }
.card.bought { opacity: .45; pointer-events: none; }
.card.poor { opacity: .7; }
.card .ic { width: 52px; height: 52px; flex: none; display: grid; place-items: center; font-size: 34px; }
.card .ic img { max-width: 52px; max-height: 52px; }
.card .nm { font-size: 20px; color: #4a2f17; }
.card .ds { font-family: system-ui, sans-serif; font-size: 13px; font-weight: 600; color: #7a5a3a; }
.card .pr { margin-left: auto; font-size: 18px; color: #8a5a00; white-space: nowrap; }
.legend { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0 4px; }
.legend div { background: #fff8e6; border: 2px solid #d8b77a; border-radius: 10px; padding: 4px 2px; font-size: 13px; }
.legend img { height: 38px; display: block; margin: 0 auto 2px; }

#debug {
  position: fixed; left: 6px; top: 60px; font: 11px/1.3 ui-monospace, monospace; color: #fff;
  background: rgba(0, 0, 0, .55); padding: 4px 6px; border-radius: 4px; display: none; pointer-events: none; white-space: pre;
}
