:root {
  --bar-h: 96px;
  --gold-1: #fff3c4;
  --gold-2: #f5c542;
  --gold-3: #a8670f;
  --ink: #e9eef6;
  --muted: #8ea3b8;
  --glass: rgba(8, 14, 24, 0.82);
  --line: rgba(255, 210, 120, 0.22);
}

* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
/* in-game phone: no lobby link (the host game handles navigation) */
.embedded #bar a.icon[href="./"] { display: none; }
html, body { height: 100%; background: #03060c; color: var(--ink); font-family: Montserrat, Inter, system-ui, sans-serif; overflow: hidden; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
html, body { -webkit-touch-callout: none; overscroll-behavior: none; height: 100dvh; }
img { -webkit-user-drag: none; pointer-events: none; }

#stage { position: fixed; inset: 0 0 var(--bar-h) 0; }
#stage canvas { display: block; touch-action: none; }

/* ---------- loader ---------- */
#loader {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  background: radial-gradient(ellipse at center, #0e2238 0%, #03060c 70%);
  transition: opacity .8s ease, transform .8s ease;
}
#loader.gone { opacity: 0; transform: scale(1.08); pointer-events: none; }
.load-logo { width: min(560px, 80vw); filter: drop-shadow(0 10px 40px rgba(255, 170, 40, .35)); animation: float 3s ease-in-out infinite; }
.load-track { width: min(420px, 70vw); height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .08); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
#load-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold-3), var(--gold-2), var(--gold-1)); box-shadow: 0 0 16px var(--gold-2); transition: width .2s; }
#load-text { font-family: Montserrat, sans-serif; font-weight: 700; letter-spacing: .2em; color: var(--muted); font-size: 14px; text-transform: uppercase; }
#load-start {
  font-family: Montserrat, sans-serif; font-weight: 900; font-size: 24px; letter-spacing: .1em; padding: 16px 64px; border-radius: 99px;
  color: #2b1403; background: linear-gradient(180deg, var(--gold-1), var(--gold-2) 50%, var(--gold-3));
  box-shadow: 0 0 0 2px #5c360a, 0 8px 30px rgba(245, 197, 66, .45), inset 0 2px 0 rgba(255, 255, 255, .6);
  animation: pulse 1.6s ease-in-out infinite;
}
.load-note { position: absolute; bottom: 24px; font-size: 12px; color: var(--muted); letter-spacing: .08em; }
@keyframes float { 50% { transform: translateY(-8px); } }
@keyframes pulse { 50% { transform: scale(1.05); box-shadow: 0 0 0 2px #5c360a, 0 8px 50px rgba(245, 197, 66, .75), inset 0 2px 0 rgba(255, 255, 255, .6); } }

/* ---------- bottom bar ---------- */
#bar {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--bar-h); z-index: 10;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px; padding: 0 24px;
  background: linear-gradient(180deg, rgba(12, 20, 32, .92), rgba(4, 8, 14, .98));
  border-top: 1px solid var(--line);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .6);
}
#bar::before { content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 1px; background: linear-gradient(90deg, transparent, var(--gold-2), transparent); opacity: .7; }
.left, .controls, .stats, .betbox { display: flex; align-items: center; gap: 10px; }
.stats { justify-content: center; gap: 36px; }
.icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: rgba(255, 255, 255, .05); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08); transition: background .15s; }
.icon:hover { background: rgba(255, 255, 255, .12); }
.icon svg, .round svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#sound.off .wave { opacity: 0; }
#sound.off { color: #6b7c8f; }

.stat { display: flex; flex-direction: column; align-items: center; position: relative; min-width: 120px; }
.stat label { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .12em; text-transform: uppercase; }
.stat label em { font-style: normal; color: #5fd7a0; margin-left: 4px; }
.stat span { font-family: Montserrat, sans-serif; font-weight: 800; font-size: 24px; font-variant-numeric: tabular-nums; }
.stat.win span { color: var(--gold-2); text-shadow: 0 0 18px rgba(245, 197, 66, .5); }
#refill { position: absolute; right: -30px; top: 16px; width: 24px; height: 24px; border-radius: 50%; background: #1b3b2c; color: #5fd7a0; font-weight: 800; box-shadow: inset 0 0 0 1px #2f6e50; }
#refill.pulse { animation: pulse 1s ease-in-out 4; }
.shake { animation: shake .4s; }
#balance-box.credit span { animation: credit 1.1s ease-out; }
@keyframes credit { 0% { color: var(--gold-1); text-shadow: 0 0 24px var(--gold-2), 0 0 48px var(--gold-2); transform: scale(1.18); } 100% { color: var(--ink); text-shadow: none; transform: scale(1); } }
.fly-coin {
  position: fixed; left: -18px; top: -18px; width: 36px; height: 36px; z-index: 60; pointer-events: none; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fffbd6 0 12%, #f7c948 35%, #b7791f 75%, #5c360a 100%);
  box-shadow: 0 0 12px rgba(255, 200, 60, .8), inset 0 0 0 3px rgba(110, 62, 8, .6);
}
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.round { border-radius: 50%; display: grid; place-items: center; position: relative; background: linear-gradient(180deg, #1d2c3e, #0d1624); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .1), 0 4px 12px rgba(0, 0, 0, .5); transition: transform .1s, box-shadow .2s; }
.round:active { transform: scale(.94); }
.round.sm { width: 36px; height: 36px; font-size: 22px; font-weight: 700; }
.round.md { width: 52px; height: 52px; }
.round.on { color: #2b1403; background: linear-gradient(180deg, var(--gold-1), var(--gold-2) 55%, var(--gold-3)); box-shadow: 0 0 20px rgba(245, 197, 66, .6); }
.round.on svg { fill: #2b1403; }
.betbox .stat { min-width: 96px; }

#spin {
  width: 84px; height: 84px; margin-top: -30px; border-radius: 50%; display: grid; place-items: center; color: #2b1403;
  background: radial-gradient(circle at 50% 30%, var(--gold-1), var(--gold-2) 45%, var(--gold-3) 90%);
  box-shadow: 0 0 0 3px #3a2105, 0 0 0 6px rgba(245, 197, 66, .35), 0 10px 30px rgba(0, 0, 0, .7), 0 0 40px rgba(245, 197, 66, .35), inset 0 3px 0 rgba(255, 255, 255, .7);
  transition: transform .12s, filter .2s;
}
#spin:hover { filter: brightness(1.1); }
#spin:active { transform: scale(.93); }
#spin svg { width: 44px; height: 44px; fill: none; stroke: #2b1403; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; transition: transform .4s; }
body.busy #spin svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.autowrap { position: relative; }
#auto-count { position: absolute; top: -6px; right: -6px; font-style: normal; font-size: 11px; font-weight: 800; background: #c0392b; color: #fff; border-radius: 99px; padding: 1px 6px; }
#auto-count:empty { display: none; }
#auto-menu { position: absolute; bottom: 64px; right: 0; display: flex; flex-direction: column; gap: 6px; padding: 8px; background: var(--glass); border: 1px solid var(--line); border-radius: 14px; backdrop-filter: blur(8px); }
#auto-menu button { padding: 8px 20px; border-radius: 10px; font-weight: 700; background: rgba(255, 255, 255, .05); }
#auto-menu button:hover { background: rgba(245, 197, 66, .2); }
body.busy #bet-minus, body.busy #bet-plus { opacity: .35; pointer-events: none; }

/* ---------- paytable ---------- */
#paytable { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(0, 0, 0, .7); backdrop-filter: blur(6px); }
#paytable[hidden] { display: none; }
.pt-card { position: relative; width: min(920px, 94vw); max-height: 86vh; overflow: auto; padding: 32px; border-radius: 20px; background: linear-gradient(180deg, #111d2c, #070c14); border: 1px solid var(--line); box-shadow: 0 30px 80px rgba(0, 0, 0, .8); }
#pt-close { position: absolute; top: 16px; right: 16px; }
.pt-card h2 { font-family: "Cinzel Decorative", serif; font-size: 34px; text-align: center; background: linear-gradient(180deg, var(--gold-1), var(--gold-2), var(--gold-3)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.pt-card h3 { font-family: Montserrat, sans-serif; font-weight: 800; margin: 24px 0 10px; color: var(--gold-2); }
.pt-sub { text-align: center; color: var(--muted); margin: 6px 0 20px; }
#pt-symbols { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.pt-row { display: flex; align-items: center; gap: 14px; padding: 10px; border-radius: 12px; background: rgba(255, 255, 255, .03); }
.pt-row img { width: 72px; height: 72px; object-fit: contain; }
.pt-pays { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; font-size: 13px; font-variant-numeric: tabular-nums; }
.pt-pays b { color: var(--gold-2); }
.pt-special { display: grid; gap: 12px; margin-top: 16px; }
.pt-special div { display: flex; gap: 14px; align-items: center; padding: 12px; border-radius: 12px; background: rgba(245, 197, 66, .06); border: 1px solid var(--line); }
.pt-special img { width: 84px; height: 84px; object-fit: contain; }
.pt-card ul { padding-left: 20px; line-height: 1.7; color: #c9d4e1; }

@media (max-width: 820px) {
  :root { --bar-h: calc(128px + env(safe-area-inset-bottom)); }
  #bar { grid-template-columns: auto 1fr; grid-template-areas: "left stats" "controls controls"; gap: 4px 8px; padding: 6px 10px env(safe-area-inset-bottom); }
  .left { grid-area: left; gap: 6px; }
  .stats { grid-area: stats; gap: 10px; justify-content: flex-end; }
  .controls { grid-area: controls; justify-content: space-between; gap: 6px; }
  .icon { width: 34px; height: 34px; border-radius: 10px; }
  .icon svg { width: 18px; height: 18px; }
  .stat { min-width: 0; }
  .stat label { font-size: 9px; letter-spacing: .08em; }
  .stat label em { display: none; }
  .stat span { font-size: 16px; }
  #refill { position: static; width: 22px; height: 22px; margin-left: 4px; }
  #balance-box { flex-direction: row; flex-wrap: wrap; justify-content: center; column-gap: 0; }
  #balance-box label { width: 100%; text-align: center; }
  .betbox { gap: 4px; }
  .betbox .stat { min-width: 64px; }
  .round.sm { width: 40px; height: 40px; }
  .round.md { width: 46px; height: 46px; }
  .icon { width: 38px; height: 38px; }
  #spin { margin-top: 0; width: 68px; height: 68px; }
  #spin svg { width: 36px; height: 36px; }
}

/* phones held sideways: controls move into a slim column on the right, the game gets full height */
@media (orientation: landscape) and (max-height: 520px) {
  :root { --side-w: calc(116px + env(safe-area-inset-right)); }
  #stage { inset: 0 var(--side-w) 0 0; }
  #bar {
    left: auto; right: 0; top: 0; bottom: 0; width: var(--side-w); height: auto;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
    padding: 6px env(safe-area-inset-right) 6px 6px;
    border-top: 0; border-left: 1px solid var(--line);
    background: linear-gradient(90deg, rgba(8, 14, 24, .88), rgba(4, 8, 14, .98));
    box-shadow: -12px 0 40px rgba(0, 0, 0, .6);
  }
  #bar::before { display: none; }
  .left { gap: 4px; }
  .icon { width: 30px; height: 30px; border-radius: 9px; }
  .icon svg { width: 16px; height: 16px; }
  .stats { flex-direction: column; gap: 4px; padding: 0; }
  .stat { min-width: 0; }
  .stat label { font-size: 9px; letter-spacing: .06em; }
  .stat label em { display: none; }
  .stat span { font-size: 15px; }
  #balance-box { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  #balance-box label { width: 100%; text-align: center; }
  #refill { position: static; width: 18px; height: 18px; margin-left: 3px; font-size: 12px; }
  .controls { flex-direction: column; gap: 8px; }
  .betbox { gap: 2px; }
  .betbox .stat { min-width: 46px; }
  .round.sm { width: 32px; height: 32px; font-size: 18px; }
  .round.md { width: 40px; height: 40px; }
  .round svg { width: 18px; height: 18px; }
  #spin { order: -1; margin: 2px 0; width: 66px; height: 66px; }
  #spin svg { width: 34px; height: 34px; }
  .controls { display: grid; grid-template-columns: 1fr 1fr; justify-items: center; }
  #spin, .betbox { grid-column: 1 / -1; }
  .betbox { order: 1; }
  #auto-menu { bottom: auto; top: -80px; right: 110%; }
}

/* ---------- bonus buy button ---------- */
.buy-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 42px; padding: 0 14px; border-radius: 12px; line-height: 1.05;
  background: linear-gradient(180deg, #7b2bd6, #3c0f7a); box-shadow: inset 0 0 0 1px rgba(210, 150, 255, .5), 0 0 16px rgba(160, 80, 255, .35); }
.buy-btn span { font-size: 10px; font-weight: 900; letter-spacing: .14em; color: #e9d6ff; }
.buy-btn b { font-size: 14px; font-weight: 900; color: #fff; }
.buy-btn:disabled { opacity: .35; }

/* ---------- storm choice / buy confirm ---------- */
.storm-pick { position: fixed; inset: 0; z-index: 45; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 20px;
  background: radial-gradient(ellipse at center, rgba(40, 8, 70, .88), rgba(2, 4, 10, .95)); backdrop-filter: blur(6px); animation: sp-in .4s ease; }
@keyframes sp-in { from { opacity: 0; } }
.storm-pick h2 { font-family: Montserrat, sans-serif; font-weight: 900; font-size: clamp(24px, 4vw, 44px); letter-spacing: .08em;
  background: linear-gradient(180deg, #fff4c9, #f5c542 55%, #b27a1d); -webkit-background-clip: text; background-clip: text; color: transparent; text-align: center; }
.sp-sub { color: #cdb8e8; font-weight: 600; text-align: center; max-width: 560px; }
.sp-cards { display: flex; gap: 18px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.sp-card { width: 230px; padding: 18px 16px 16px; border-radius: 22px; text-align: center; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: linear-gradient(180deg, rgba(60, 20, 100, .9), rgba(14, 6, 30, .95)); box-shadow: inset 0 0 0 1px rgba(210, 160, 255, .35), 0 20px 40px rgba(0, 0, 0, .6);
  transition: transform .18s ease, box-shadow .2s ease; }
.sp-card:hover { transform: translateY(-8px) scale(1.03); box-shadow: inset 0 0 0 2px #f5c542, 0 0 40px rgba(245, 197, 66, .45), 0 24px 50px rgba(0, 0, 0, .7); }
.sp-card img { height: 96px; max-width: 150px; object-fit: contain; filter: drop-shadow(0 8px 16px rgba(0, 0, 0, .6)); }
.sp-card h3 { font-weight: 900; font-size: 20px; letter-spacing: .04em; margin-top: 4px; }
.sp-card b { font-size: 46px; font-weight: 900; line-height: 1; color: #f5c542; text-shadow: 0 0 18px rgba(245, 197, 66, .5); }
.sp-card em { font-style: normal; font-weight: 800; font-size: 12px; letter-spacing: .14em; color: #cdb8e8; text-transform: uppercase; }
.sp-card p { font-size: 13px; color: #e6daf5; line-height: 1.4; min-height: 54px; margin-top: 6px; }
.sp-card .vol { display: block; width: 100%; height: 6px; border-radius: 99px; background: rgba(255, 255, 255, .12); overflow: hidden; margin-top: 6px; }
.sp-card .vol s { display: block; height: 100%; background: linear-gradient(90deg, #4dff9a, #f5c542, #ff4d6d); }
.sp-card small { font-size: 11px; font-weight: 800; letter-spacing: .1em; color: #cdb8e8; text-transform: uppercase; }
.buy-actions { display: flex; gap: 12px; margin-top: 16px; }
.cta-gold { padding: 16px 34px; border-radius: 99px; font-weight: 900; letter-spacing: .08em; color: #2a1602; background: linear-gradient(180deg, #fff3c6, #ffd66e 40%, #b27a1d); box-shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 0 30px rgba(255, 200, 90, .4); }
.cta-ghost { padding: 16px 28px; border-radius: 99px; font-weight: 800; background: rgba(255, 255, 255, .08); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .2); }
@media (max-width: 760px) {
  .sp-cards { gap: 8px; }
  .sp-card { width: 100%; max-width: 420px; flex-direction: row; flex-wrap: wrap; text-align: left; padding: 10px 14px; gap: 2px 10px; }
  .sp-card img { height: 54px; max-width: 64px; }
  .sp-card h3 { font-size: 16px; flex: 1; }
  .sp-card b { font-size: 30px; }
  .sp-card em { width: 100%; display: none; }
  .sp-card p { min-height: 0; font-size: 12px; margin: 0; width: 100%; }
  .buy-btn { height: 34px; padding: 0 8px; }
}
/* narrow phones: the bonus-buy button floats above the bar so balance + win always fit in the top row */
@media (max-width: 560px) and (orientation: portrait) {
  .buy-btn { position: absolute; right: 10px; top: -52px; height: 42px; padding: 0 16px; box-shadow: inset 0 0 0 1px rgba(210, 150, 255, .6), 0 6px 18px rgba(0, 0, 0, .6), 0 0 16px rgba(160, 80, 255, .35); }
  .stats { gap: 12px; }
  .stat label { font-size: 10px; }
}

/* phones sideways: the side column is ~104px wide – icons in a row of three, feature buy full width below, compact bet box */
@media (orientation: landscape) and (max-height: 520px) {
  .left { display: grid; grid-template-columns: repeat(3, 30px); gap: 5px; justify-content: center; }
  .left > :is(#buy, #buybtn, .buy-btn) { grid-column: 1 / -1; width: 100%; justify-content: center; }
  .betbox { gap: 2px; }
  .betbox .stat { min-width: 0; width: 40px; }
  .betbox .round.sm { width: 28px; height: 28px; font-size: 16px; }
  .betbox .stat span { font-size: 13px; }
}