:root {
  color-scheme: dark;
  --bg: #06101a;
  --panel: #0b1c29;
  --panel-2: #102839;
  --line: rgba(255,255,255,.11);
  --text: #f7fafc;
  --muted: #93a7b7;
  --gold: #f5c84c;
  --orange: #ff7a17;
  --orange-2: #ff9e2c;
  --green: #48d47c;
  --danger: #ff5f5f;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at 50% 0%, #18364d 0, #081723 38%, #030912 100%); }
body {
  min-height: 100vh;
  color: var(--text);
  font-family: Tahoma, Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; }
button:focus-visible { outline: 3px solid rgba(255,194,61,.65); outline-offset: 2px; }

.app-shell {
  width: min(100%, 470px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(20px, env(safe-area-inset-bottom));
}

.topbar {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  direction: ltr;
  margin-bottom: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: 12px;
  color: #0b1620;
  background: linear-gradient(145deg, #ffe571, #f2a81b);
  font-weight: 900;
  box-shadow: 0 7px 22px rgba(244,176,31,.28), inset 0 1px rgba(255,255,255,.7);
}
.brand-title { font-weight: 1000; letter-spacing: 1.5px; font-size: 20px; }
.icon-btn {
  width: 42px; height: 42px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: white;
  background: rgba(12,31,45,.8);
  box-shadow: inset 0 1px rgba(255,255,255,.05);
}

.game-card, .rules-card {
  background: linear-gradient(180deg, rgba(17,43,60,.97), rgba(7,19,29,.98));
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(0,0,0,.36), inset 0 1px rgba(255,255,255,.04);
  overflow: hidden;
}
.score-strip {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--line);
  background: rgba(3,12,19,.7);
}
.score-strip > div { padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.score-strip > div + div { border-right: 1px solid var(--line); }
.label { color: var(--muted); font-size: 12px; }
.score-strip strong { color: var(--gold); font-size: 18px; direction: ltr; }

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 720 / 940;
  overflow: hidden;
  background: #c4a46f;
  cursor: pointer;
}
canvas { width: 100%; height: 100%; display: block; touch-action: manipulation; }
.loading {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 12px;
  background: linear-gradient(#07131d, #102c3e);
  z-index: 5;
  transition: opacity .35s ease, visibility .35s ease;
}
.loading.is-hidden { opacity: 0; visibility: hidden; }
.loading span {
  width: 38px; height: 38px; border: 4px solid rgba(255,255,255,.15); border-top-color: var(--orange);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.loading b { font-size: 13px; color: #c6d4dd; }
@keyframes spin { to { transform: rotate(360deg); } }
.tap-hint {
  position: absolute;
  left: 50%; bottom: 34%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center;
  color: white; font-weight: 900; text-shadow: 0 2px 8px #000;
  pointer-events: none;
  animation: hintPulse 1.1s ease-in-out infinite;
  z-index: 3;
}
.tap-hint.is-hidden { display: none; }
.tap-hint .finger { font-size: 43px; filter: drop-shadow(0 5px 6px rgba(0,0,0,.5)); }
.tap-hint span:last-child { padding: 6px 11px; border-radius: 999px; background: rgba(3,12,18,.65); font-size: 12px; }
@keyframes hintPulse { 50% { transform: translateX(-50%) scale(.93) translateY(7px); opacity: .72; } }

.controls { padding: 12px; background: linear-gradient(180deg, #0c2231, #081823); }
.build-btn, .cashout-btn {
  width: 100%; min-height: 58px; border: 0; border-radius: 16px;
  font-weight: 1000; font-size: 21px; color: white;
  cursor: pointer;
}
.build-btn {
  background: linear-gradient(180deg, var(--orange-2), var(--orange));
  box-shadow: 0 6px 0 #bd4605, 0 13px 24px rgba(255,104,13,.2), inset 0 1px rgba(255,255,255,.55);
}
.build-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #bd4605, inset 0 1px rgba(255,255,255,.4); }
.build-btn.is-ready { animation: glow 1.2s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 6px 0 #bd4605, 0 0 28px rgba(255,138,27,.6), inset 0 1px rgba(255,255,255,.55); } }

.bet-row { margin-top: 12px; display: grid; grid-template-columns: 70px 1fr 70px; gap: 9px; direction: ltr; }
.mini-btn, .stepper {
  min-height: 52px; border-radius: 13px; border: 1px solid rgba(255,255,255,.13);
  background: #07131e; color: white;
}
.mini-btn { font-weight: 1000; cursor: pointer; }
.max-btn { color: var(--gold); }
.multiplier-btn { color: #9ee0ff; }
.stepper { display: grid; grid-template-columns: 48px 1fr 48px; overflow: hidden; }
.stepper button { border: 0; color: white; background: #163448; font-size: 25px; cursor: pointer; }
.stepper button:active { background: var(--orange); }
.stepper output { display: grid; place-items: center; direction: ltr; font-weight: 900; }
.cashout-btn {
  margin-top: 12px;
  min-height: 48px;
  font-size: 17px;
  color: #06130c;
  background: linear-gradient(180deg, #72eaa0, #36bf6b);
  box-shadow: 0 5px 0 #187f40;
}
.cashout-btn:disabled { filter: grayscale(.8); opacity: .45; box-shadow: none; cursor: not-allowed; }
.cashout-btn:not(:disabled):active { transform: translateY(3px); box-shadow: 0 2px 0 #187f40; }

.rules-card { margin-top: 12px; padding: 15px 17px; }
.rules-card h2 { font-size: 16px; margin: 0 0 6px; }
.rules-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }

.modal {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  padding: 18px;
  background: rgba(1,6,10,.76);
  backdrop-filter: blur(7px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(100%, 390px);
  padding: 24px;
  border-radius: 24px;
  text-align: center;
  background: linear-gradient(180deg, #15364a, #081823);
  border: 1px solid rgba(255,255,255,.15);
  box-shadow: 0 30px 90px #000;
}
.result-icon { font-size: 54px; }
.modal-card h2 { margin: 10px 0 6px; }
.modal-card p { color: var(--muted); margin: 0 0 10px; }
.modal-card > strong { display: block; color: var(--green); font-size: 31px; direction: ltr; margin-bottom: 18px; }
.modal-actions { display: grid; gap: 9px; }
.modal-actions button { min-height: 49px; border: 0; border-radius: 13px; font-weight: 900; cursor: pointer; }
.modal-actions .primary { color: white; background: linear-gradient(var(--orange-2), var(--orange)); }
.modal-actions .secondary { color: #09150e; background: linear-gradient(#7ce9a3, #38bd69); }

@media (max-width: 370px) {
  .brand-title { font-size: 17px; }
  .score-strip > div { padding: 10px; }
  .label { font-size: 11px; }
  .score-strip strong { font-size: 15px; }
}
