/* 🎯 Кено Mini App — Shuffle-style, even prettier. Dark navy board, teal picks, gold hits. */
:root {
  --bg: #0c111c;
  --bg2: #0f1626;
  --panel: #141d30;
  --panel2: #1a2438;
  --line: #243150;
  --tile: #1e2a44;
  --tile2: #18233a;
  --ink: #eaf1fb;
  --muted: #8595b1;
  --teal: #2bd4a5;
  --teal-d: #14a583;
  --gold: #ffc848;
  --gold-d: #f0a92b;
  --miss: #38465f;
  --loss: #ff5d6c;
  --r: 14px;
  --tile-r: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1100px 620px at 50% -8%, #1a2740 0%, rgba(26, 39, 64, 0) 60%),
    linear-gradient(180deg, var(--bg2) 0%, var(--bg) 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  overflow-x: hidden;
}
#app {
  display: flex; flex-direction: column;
  min-height: 100vh; min-height: 100dvh;
  max-width: 560px; margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 12px calc(10px + env(safe-area-inset-bottom));
  gap: 10px;
}

/* ---------- topbar ---------- */
#topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.balance {
  font-weight: 800; font-size: 17px; letter-spacing: .2px;
  background: var(--panel); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px; white-space: nowrap;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
}
.balance #balance { color: #fff; }
.history-wrap { display: flex; align-items: center; gap: 6px; min-width: 0; }
.history { display: flex; gap: 5px; overflow: hidden; flex-direction: row-reverse; }
.hpill {
  font-size: 12px; font-weight: 800; padding: 5px 8px; border-radius: 9px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap; animation: pop .3s ease;
}
.hpill.win { color: #06281f; background: linear-gradient(180deg, #44e6b6, var(--teal-d)); border-color: transparent; }
.histpill.stats {
  display: grid; place-items: center; width: 34px; height: 32px; flex: 0 0 auto;
  border-radius: 10px; background: var(--panel2); border: 1px solid var(--line);
  color: var(--muted); cursor: pointer;
}
.histpill.stats:active { transform: scale(.93); }

/* ---------- stage / board ---------- */
#stage { position: relative; }
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  padding: 12px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg2) 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .04);
}
.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  display: grid; place-items: center;
  font-weight: 800; font-size: clamp(13px, 4.4vw, 19px);
  color: #cdd9ee;
  background: linear-gradient(180deg, var(--tile) 0%, var(--tile2) 100%);
  border: 1px solid #2a3a5c;
  border-radius: var(--tile-r);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .18s ease, background .18s ease, color .18s ease, border-color .18s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05), 0 2px 4px rgba(0, 0, 0, .25);
}
.tile:active { transform: scale(.9); }
.tile.pick {
  color: #04261d;
  background: linear-gradient(180deg, #54e9bd 0%, var(--teal) 70%, var(--teal-d) 100%);
  border-color: #6ff0c8;
  box-shadow: 0 0 0 1px rgba(43, 212, 165, .5), 0 6px 16px rgba(20, 165, 131, .45),
    inset 0 1px 0 rgba(255, 255, 255, .4);
  transform: translateY(-1px);
}
.tile.disabled { opacity: .55; pointer-events: none; }

/* reveal states */
.tile.drawn {
  color: #aebbd4;
  background: radial-gradient(circle at 50% 38%, #2c3a59 0%, #1a2336 100%);
  border-color: #3a4a6e;
}
.tile.drawn::after {
  content: ""; position: absolute; inset: 0; border-radius: var(--tile-r);
  box-shadow: inset 0 0 0 2px rgba(120, 140, 175, .35);
}
.tile.hit {
  color: #3a2400;
  background: radial-gradient(circle at 50% 35%, #ffe08a 0%, var(--gold) 55%, var(--gold-d) 100%);
  border-color: #ffd970;
  box-shadow: 0 0 0 2px rgba(255, 200, 72, .55), 0 0 22px rgba(255, 190, 60, .6),
    inset 0 1px 0 rgba(255, 255, 255, .6);
  z-index: 2;
}
.tile.miss { opacity: .5; }
.tile .badge {
  position: absolute; top: -7px; right: -6px;
  font-size: 10px; font-weight: 900; color: #3a2400;
  background: #fff; border-radius: 999px; padding: 1px 5px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .4); opacity: 0; transform: scale(.4);
}
.tile.hit .badge { animation: badgePop .4s cubic-bezier(.2, 1.5, .4, 1) forwards; }

@keyframes reveal { 0% { transform: scale(.4) rotate(-12deg); opacity: 0; } 60% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
@keyframes hitPulse { 0% { transform: scale(.5); } 55% { transform: scale(1.22); } 100% { transform: scale(1); } }
@keyframes badgePop { to { opacity: 1; transform: scale(1); } }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.tile.anim-reveal { animation: reveal .32s ease both; }
.tile.anim-hit { animation: hitPulse .42s cubic-bezier(.2, 1.4, .4, 1) both; }

/* canvas FX overlay (particles, Phase 4) */
#fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; }

/* win popup */
.win-pop {
  position: absolute; left: 50%; top: 44%; transform: translate(-50%, -50%) scale(.6);
  display: grid; place-items: center; gap: 2px; padding: 14px 26px;
  background: rgba(10, 16, 28, .82); backdrop-filter: blur(7px);
  border: 1.5px solid var(--gold); border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .6), 0 0 30px rgba(255, 190, 60, .35);
  opacity: 0; pointer-events: none; z-index: 6; transition: opacity .25s ease, transform .35s cubic-bezier(.2, 1.4, .4, 1);
}
.win-pop.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.win-mult { font-size: 34px; font-weight: 900; color: var(--gold); text-shadow: 0 2px 10px rgba(255, 180, 40, .5); }
.win-amount { font-size: 16px; font-weight: 800; color: #fff; }
.win-pop.big {
  border-color: #ffe08a; padding: 18px 32px;
  box-shadow: 0 14px 50px rgba(0, 0, 0, .7), 0 0 50px rgba(255, 190, 60, .6);
  animation: bigGlow 1s ease-in-out infinite alternate;
}
.win-pop.big .win-mult { font-size: 46px; animation: multThrob .6s ease-in-out infinite alternate; }
@keyframes bigGlow { from { box-shadow: 0 14px 50px rgba(0, 0, 0, .7), 0 0 34px rgba(255, 190, 60, .45); } to { box-shadow: 0 14px 50px rgba(0, 0, 0, .7), 0 0 64px rgba(255, 200, 80, .8); } }
@keyframes multThrob { from { transform: scale(1); } to { transform: scale(1.08); } }

/* screen shake on big wins */
@keyframes shakeSm { 10%, 90% { transform: translateX(-1px); } 30%, 70% { transform: translateX(2px); } 50% { transform: translateX(-3px); } }
@keyframes shakeLg { 0% { transform: translate(0, 0) rotate(0); } 15% { transform: translate(-5px, 2px) rotate(-.5deg); } 35% { transform: translate(5px, -2px) rotate(.5deg); } 55% { transform: translate(-4px, 1px) rotate(-.3deg); } 75% { transform: translate(4px, -1px) rotate(.3deg); } 100% { transform: translate(0, 0) rotate(0); } }
.board.shake-sm { animation: shakeSm .45s ease; }
.board.shake-lg { animation: shakeLg .6s ease; }

.net-status { position: absolute; right: 10px; bottom: 8px; font-size: 10px; color: var(--muted); opacity: .8; }
.net-status .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--loss); margin-left: 3px; }
.net-status .dot.ok { background: var(--teal); box-shadow: 0 0 6px var(--teal); }

/* ---------- live paytable ---------- */
.paytable {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; border-radius: 12px; min-height: 46px;
  background: var(--panel); border: 1px solid var(--line); overflow-x: auto;
}
.pt-cell {
  display: grid; place-items: center; gap: 1px; padding: 5px 2px; border-radius: 8px;
  background: var(--panel2); transition: background .2s ease, transform .2s ease;
}
.pt-cell .pt-h { font-size: 10px; color: var(--muted); font-weight: 700; }
.pt-cell .pt-m { font-size: 12px; font-weight: 800; color: #cfe6ff; white-space: nowrap; }
.pt-cell.zero .pt-m { color: var(--muted); }
.pt-cell.active { background: linear-gradient(180deg, var(--gold), var(--gold-d)); transform: translateY(-2px); }
.pt-cell.active .pt-h, .pt-cell.active .pt-m { color: #3a2400; }

/* ---------- panel ---------- */
#panel { display: flex; flex-direction: column; gap: 10px; }
.risk-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.risk {
  padding: 10px 6px; border-radius: 11px; font-weight: 800; font-size: 14px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted); cursor: pointer;
  transition: all .15s ease;
}
.risk.active { color: #04261d; background: linear-gradient(180deg, #4be3b8, var(--teal-d)); border-color: transparent; box-shadow: 0 4px 14px rgba(20, 165, 131, .4); }
.risk:active { transform: scale(.97); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; color: var(--muted); font-weight: 700; padding-left: 2px; }
.field-row { display: flex; gap: 6px; }
#stake {
  flex: 1; min-width: 0; font-size: 18px; font-weight: 800; color: #fff;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 13px; outline: none;
}
#stake:focus { border-color: var(--teal); }
.chip {
  padding: 0 16px; min-width: 52px; font-weight: 800; font-size: 15px; color: var(--ink);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; cursor: pointer;
}
.chip:active { transform: scale(.95); }

.pick-tools { display: flex; align-items: center; gap: 8px; }
.tool {
  padding: 9px 14px; font-weight: 800; font-size: 13px; color: var(--ink);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; cursor: pointer;
}
.tool:active { transform: scale(.96); }
.pick-count { margin-left: auto; font-weight: 800; font-size: 14px; color: var(--muted); }
.pick-count.full { color: var(--teal); }

.action {
  padding: 16px; font-size: 18px; font-weight: 900; letter-spacing: .3px;
  color: #04261d; border: none; border-radius: 14px; cursor: pointer;
  background: linear-gradient(180deg, #54e9bd 0%, var(--teal) 60%, var(--teal-d) 100%);
  box-shadow: 0 8px 22px rgba(20, 165, 131, .45), inset 0 1px 0 rgba(255, 255, 255, .4);
  transition: transform .1s ease, filter .15s ease;
}
.action:active { transform: translateY(1px) scale(.99); }
.action:disabled { filter: grayscale(.7) brightness(.7); cursor: default; box-shadow: none; color: #9fb0c9; }
.action.busy { filter: brightness(.85); cursor: progress; }

.auto-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.auto-toggle {
  padding: 9px; font-weight: 800; font-size: 13px; color: var(--muted);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; cursor: pointer;
}
.auto-toggle[aria-pressed="true"] { color: var(--gold); border-color: var(--gold-d); box-shadow: inset 0 0 0 1px rgba(255, 200, 72, .35); }

.sound-row { display: flex; align-items: center; gap: 10px; }
.sound-btn { width: 42px; height: 38px; font-size: 18px; background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; cursor: pointer; }
.sound-btn.off { opacity: .6; }
.vol { flex: 1; accent-color: var(--teal); }

.message { min-height: 18px; text-align: center; font-size: 13px; font-weight: 700; color: var(--gold); }
.message.err { color: var(--loss); }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: end center; background: rgba(4, 8, 16, .6); backdrop-filter: blur(3px); }
.modal.hidden { display: none; }
.modal-card { width: 100%; max-width: 560px; max-height: 86vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 20px 20px 0 0; box-shadow: var(--shadow); animation: slideUp .26s ease; }
@keyframes slideUp { from { transform: translateY(40px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 16px; background: var(--panel); border-bottom: 1px solid var(--line); font-weight: 800; }
.modal-close { width: 32px; height: 32px; border-radius: 9px; background: var(--panel2); border: 1px solid var(--line); color: var(--ink); cursor: pointer; }
.modal-body { padding: 16px; }
.fair-intro { font-size: 13px; color: var(--muted); line-height: 1.5; margin-bottom: 14px; }
.fair-label { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; margin: 12px 0 4px; }
.fair-code { display: block; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 11px; color: #bfe6d6; word-break: break-all; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.fair-draw { display: flex; flex-wrap: wrap; gap: 5px; }
.fair-draw span { display: grid; place-items: center; width: 28px; height: 28px; font-weight: 800; font-size: 12px; border-radius: 7px; background: var(--gold); color: #3a2400; }
.fair-sep { height: 1px; background: var(--line); margin: 14px 0; }
.fair-note { font-size: 12px; color: var(--muted); line-height: 1.5; margin-top: 12px; }
.mybets-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.mybets-list li { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 9px 11px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; }
.mybets-list li .m-mult { font-weight: 800; }
.mybets-list li.win .m-mult { color: var(--teal); }
.mybets-list li.loss .m-mult { color: var(--loss); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .05ms !important; }
}
