/* 💣 Мины Mini App — Shuffle-style, even prettier. Dark navy, gold gems, red mines. */
:root {
  --bg: #0c111c;
  --bg2: #0f1626;
  --panel: #141d30;
  --panel2: #1a2438;
  --line: #243150;
  --tile-a: #233252;
  --tile-b: #1a2740;
  --tile-edge: #31436b;
  --ink: #eaf1fb;
  --muted: #8595b1;
  --teal: #2bd4a5;
  --teal-d: #14a583;
  --gold: #ffc848;
  --gold-d: #f0a92b;
  --mine: #ff4d52;
  --mine-d: #d62f37;
  --purple: #7c5cff;
  --purple-d: #5a3ee0;
  --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: 1040px; 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: 700; font-size: 17px; letter-spacing: .2px;
  background: var(--panel); border: 1px solid var(--line);
  padding: 8px 14px; border-radius: 999px; white-space: nowrap;
}
.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: 700; 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; }
.hpill.loss { color: #fff; background: linear-gradient(180deg, #ff6a6f, var(--mine-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); }

/* ---------- layout: column (mobile) → row (desktop) ---------- */
#layout { display: flex; flex-direction: column; gap: 12px; }
#stage { order: 1; position: relative; }
#panel { order: 2; display: flex; flex-direction: column; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
@media (min-width: 760px) {
  #layout { flex-direction: row; align-items: flex-start; }
  #panel { order: 1; flex: 0 0 320px; }
  #stage { order: 2; flex: 1; }
}

/* ---------- control panel ---------- */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tab { padding: 9px; border-radius: 9px; font-weight: 700; font-size: 14px; background: transparent; border: none; color: var(--muted); cursor: pointer; }
.tab.active { background: var(--panel2); color: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05); }

.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: 17px; font-weight: 700; 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 14px; min-width: 48px; font-weight: 700; font-size: 15px; color: var(--ink); background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; cursor: pointer; }
.chip:active { transform: scale(.95); }

.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stepper { display: flex; gap: 6px; }
.stepper #mines { flex: 1; min-width: 0; text-align: center; font-size: 16px; font-weight: 700; color: #fff; background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; padding: 11px 4px; outline: none; -moz-appearance: textfield; }
.stepper #mines::-webkit-outer-spin-button, .stepper #mines::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.step { width: 40px; font-size: 20px; font-weight: 700; color: var(--ink); background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; cursor: pointer; }
.step:active { transform: scale(.93); }
.readout { display: grid; place-items: center; font-size: 16px; font-weight: 700; color: var(--gold); background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; padding: 11px; }

.tool { padding: 11px; font-weight: 700; font-size: 14px; color: var(--ink); background: var(--panel2); border: 1px solid var(--line); border-radius: 11px; cursor: pointer; }
.tool:active { transform: scale(.97); }
.tool:disabled { opacity: .45; cursor: default; }

.action {
  padding: 16px; font-size: 18px; font-weight: 800; 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.cashout {
  color: #fff;
  background: linear-gradient(180deg, #9b7cff 0%, var(--purple) 55%, var(--purple-d) 100%);
  box-shadow: 0 8px 22px rgba(124, 92, 255, .45), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.action.busy { filter: brightness(.85); cursor: progress; }

.profit-box { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.profit-box.hidden { display: none; }
.profit-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.profit-label { font-size: 12px; color: var(--muted); font-weight: 700; }
.profit-row.next .profit-label, .profit-row.next .profit-amt { opacity: .75; }
.mult-tag { display: inline-block; margin-left: 4px; font-size: 12px; font-weight: 800; color: var(--teal); }
.profit-amt { font-size: 15px; font-weight: 800; color: #fff; }
.profit-sep { height: 1px; background: var(--line); margin: 8px 0; }

.auto-panel { display: flex; flex-direction: column; gap: 8px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.auto-panel.hidden { display: none; }
.auto-hint { font-size: 12px; color: var(--muted); line-height: 1.4; }
.auto-panel input { font-size: 15px; font-weight: 700; color: #fff; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px; outline: none; width: 100%; }
.auto-toggle { padding: 11px; font-weight: 800; font-size: 14px; color: #04261d; background: linear-gradient(180deg, #54e9bd, var(--teal-d)); border: none; border-radius: 11px; cursor: pointer; }
.auto-toggle[aria-pressed="true"] { color: #fff; background: linear-gradient(180deg, #ff6a6f, var(--mine-d)); }

.bottom-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.turbo { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; color: var(--muted); cursor: pointer; }
.turbo input { accent-color: var(--gold); }
.sound-row { display: flex; align-items: center; gap: 8px; flex: 1; max-width: 160px; }
.sound-btn { width: 40px; height: 36px; font-size: 17px; 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(--mine); }

/* ---------- board ---------- */
.board {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px;
  padding: 12px; aspect-ratio: 1 / 1; width: 100%; margin: 0 auto;
  /* Square board: width is bounded by the column, but ALSO by the viewport HEIGHT so a wide-but-short
     window (e.g. desktop dragged wider while still single-column, or landscape phone) can never blow
     the 1:1 board up past the screen. Layered fallbacks: no min() → 620px; min()+vh; min()+dvh. */
  max-width: 620px;
  max-width: min(620px, calc(100vh - 140px));
  max-width: min(620px, calc(100dvh - 140px));
  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; display: grid; place-items: center;
  font-size: clamp(22px, 7vw, 40px); border-radius: var(--tile-r); cursor: pointer;
  background: linear-gradient(180deg, var(--tile-a) 0%, var(--tile-b) 100%);
  border: 1px solid var(--tile-edge);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 3px 6px rgba(0, 0, 0, .3);
  transition: transform .12s ease, box-shadow .18s ease, filter .18s ease, background .2s ease;
}
.tile:not(.revealed):not(.disabled):hover { transform: translateY(-2px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .1), 0 6px 14px rgba(0, 0, 0, .4); }
.tile:not(.revealed):not(.disabled):active { transform: scale(.92); }
.tile.disabled { cursor: default; }
.tile.pick { box-shadow: 0 0 0 2px var(--purple), inset 0 1px 0 rgba(255, 255, 255, .1); }  /* autoplay pre-pick */
.tile .glyph { opacity: 0; transform: scale(.3); }

/* revealed gem (player's safe pick) */
.tile.gem {
  background: radial-gradient(circle at 50% 38%, #2a3a5c 0%, #1a2742 100%);
  border-color: #3a4a72;
}
.tile.gem .glyph.gem-i { opacity: 1; }
/* a mine (shown at game end) */
.tile.mine {
  background: radial-gradient(circle at 50% 40%, #3a1417 0%, #230c0e 100%);
  border-color: #5a1d22;
}
.tile.mine .glyph.mine-i { opacity: 1; }
/* the exact mine the player hit */
.tile.boom {
  background: radial-gradient(circle at 50% 40%, #ff7a4d 0%, var(--mine) 50%, var(--mine-d) 100%) !important;
  border-color: #ffae7a !important;
  box-shadow: 0 0 0 2px rgba(255, 90, 70, .6), 0 0 26px rgba(255, 80, 60, .7) !important; z-index: 2;
}
/* a safe cell the player didn't pick, faded in at game end */
.tile.safe-other { opacity: .5; }
.tile.safe-other .glyph.gem-i { opacity: .55; }

.glyph { position: absolute; transition: opacity .2s ease, transform .35s cubic-bezier(.2, 1.5, .4, 1); }
.tile.gem .glyph.gem-i, .tile.boom .glyph.mine-i, .tile.mine .glyph.mine-i { transform: scale(1); }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes tilePop { 0% { transform: scale(.55) rotate(-8deg); } 60% { transform: scale(1.14); } 100% { transform: scale(1); } }
.tile.anim { animation: tilePop .34s cubic-bezier(.2, 1.4, .4, 1); }

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

/* win popup */
.win-pop {
  position: absolute; left: 50%; top: 46%; 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: 800; color: var(--gold); text-shadow: 0 2px 10px rgba(255, 180, 40, .5); }
.win-amount { font-size: 16px; font-weight: 700; color: #fff; }

.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(--mine); margin-left: 3px; }
.net-status .dot.ok { background: var(--teal); box-shadow: 0 0 6px var(--teal); }

/* screen shake (big explosion) */
@keyframes shakeLg { 0% { transform: translate(0, 0) rotate(0); } 15% { transform: translate(-6px, 3px) rotate(-.6deg); } 35% { transform: translate(6px, -3px) rotate(.6deg); } 55% { transform: translate(-5px, 2px) rotate(-.4deg); } 75% { transform: translate(4px, -2px) rotate(.3deg); } 100% { transform: translate(0, 0); } }
.board.shake { animation: shakeLg .55s ease; }

/* ---------- 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; }
@media (min-width: 760px) { .modal { place-items: center; } .modal-card { border-radius: 20px; } }
@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: 700; }
.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-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.win .m-mult { color: var(--teal); font-weight: 800; }
.mybets-list li.loss .m-mult { color: var(--mine); font-weight: 800; }

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