/* Chicken Road — оформление под оригинал: тёмно-синий, скруглённые панели. */

:root {
  --bg: #1e2130;
  --panel: #272b3d;
  --panel-2: #2f3448;
  --panel-3: #383e56;
  --stroke: #414867;
  --text: #eef0f8;
  --muted: #8e95b3;
  --green: #33c85a;
  --green-2: #28a749;
  --red: #ef4b4b;
  --gold: #f5c451;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Убирает 300ms задержку тапа в мобильных WebView. */
button, input, .chip, .menu-item { touch-action: manipulation; }

/* body ниже стоит user-select:none, и поля ввода наследуют его —
   в WebView Telegram из-за этого в них НЕЛЬЗЯ печатать. Возвращаем полям право. */
input, textarea, select {
  -webkit-user-select: text;
  user-select: text;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- Верхняя панель ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  flex: 0 0 auto;
}

.logo {
  font-weight: 900;
  font-size: 17px;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.logo .egg {
  display: inline-block;
  width: 13px;
  height: 16px;
  vertical-align: -3px;
  border-radius: 50% 50% 46% 46% / 60% 60% 40% 40%;
  background: linear-gradient(160deg, #ffe07a, #f0b429);
  color: transparent;
}

.topbar-right { display: flex; align-items: center; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.chip-ghost { color: var(--text); }
.chip-icon { padding: 0 10px; font-size: 16px; }
.chip-balance { font-variant-numeric: tabular-nums; font-weight: 700; }

.icon-i {
  display: inline-grid;
  place-items: center;
  width: 15px; height: 15px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  font-size: 10px;
  font-style: italic;
  font-weight: 700;
}

.coin {
  display: inline-grid;
  place-items: center;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: linear-gradient(160deg, #6f7bd6, #4a55a8);
  font-size: 11px;
  font-weight: 800;
}

/* ---------- Сцена ---------- */

.stage { position: relative; flex: 1 1 auto; min-height: 0; }
#road { display: block; width: 100%; height: 100%; }

.stage-toast {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%) translateY(-12px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(20, 22, 34, 0.92);
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
}
.stage-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.stage-toast.win { background: rgba(30, 130, 60, 0.95); }
.stage-toast.lose { background: rgba(150, 40, 40, 0.95); }

/* ---------- Итог раунда ---------- */

.result[hidden] { display: none; }
.result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(15, 17, 26, 0.72);
  backdrop-filter: blur(3px);
  z-index: 20;
  animation: fade-in 0.18s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }

.result-card {
  min-width: 240px;
  max-width: 86%;
  padding: 20px 24px 18px;
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  text-align: center;
  animation: pop-in 0.22s cubic-bezier(0.2, 1.2, 0.4, 1);
}
@keyframes pop-in { from { transform: scale(0.88); opacity: 0; } }

.result-emoji { font-size: 40px; line-height: 1; }
.result-title { margin-top: 6px; font-size: 17px; font-weight: 700; }
.result-mult {
  margin-top: 10px;
  font-size: 34px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}
.result.lose .result-mult { color: var(--red); }
.result-sum {
  margin-top: 2px;
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--green);
}
.result.lose .result-sum { color: var(--red); }

.result-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.result-again {
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--green), var(--green-2));
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}
.result-change {
  height: 40px;
  border: 0;
  border-radius: 11px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.result-again:active, .result-change:active { transform: scale(0.98); }

/* ---------- Нижняя панель ---------- */

.panel {
  flex: 0 0 auto;
  padding: 10px 12px 14px;
  background: var(--panel);
  border-radius: 18px 18px 0 0;
}

.panel-row {
  display: grid;
  grid-template-columns: minmax(150px, 190px) 1fr minmax(130px, 200px);
  gap: 12px;
  align-items: stretch;
}

/* Ставка */

.bet-block { display: flex; flex-direction: column; gap: 8px; }

.bet-input {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: stretch;
  height: 48px;
  border-radius: 10px;
  background: var(--panel-2);
  overflow: hidden;
}
.bet-side {
  height: 100%;
  border: 0;
  background: var(--panel-3);
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.bet-side:active { background: var(--stroke); }
.bet-side:disabled { opacity: 0.4; cursor: default; }

#bet-value {
  width: 100%;
  height: 100%;          /* на всю высоту — иначе зона тапа 19px и пальцем не попасть */
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: center;
  font-size: 16px;       /* меньше 16px — iOS зумит страницу при фокусе */
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  outline: none;
}
#bet-value:disabled { color: var(--muted); }

.bet-quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.bet-quick button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 40px;          /* 40 вместо 32 — попасть пальцем */
  border: 0;
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.bet-quick button .coin { width: 14px; height: 14px; font-size: 9px; }
.bet-quick button:active { background: var(--panel-3); }
.bet-quick button.on { background: var(--panel-3); box-shadow: inset 0 0 0 2px var(--stroke); }
.bet-quick button:disabled { opacity: 0.45; cursor: default; }

/* Сложность */

.diff-block { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.diff-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.diff-chance b { color: var(--text); font-variant-numeric: tabular-nums; }

.diff-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 11px;
  background: var(--panel-2);
}
.diff-tabs button {
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.diff-tabs button.active { background: var(--panel-3); color: var(--text); }
.diff-tabs button:disabled { opacity: 0.45; cursor: default; }

/* Кнопки действия */

.action-block { display: flex; gap: 8px; }
.btn-cashout[hidden] { display: none; }
.btn-play, .btn-cashout {
  flex: 1;
  min-height: 78px;
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.06s, filter 0.15s;
}
.btn-play { background: linear-gradient(180deg, var(--green), var(--green-2)); }
.btn-play:active, .btn-cashout:active { transform: scale(0.98); }
.btn-play:disabled { filter: grayscale(0.6) brightness(0.7); cursor: default; }

.btn-cashout {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: linear-gradient(180deg, #f0a638, #d98420);
}
.cash-label { font-size: 13px; font-weight: 700; opacity: 0.9; }
.cash-amount { font-size: 22px; font-variant-numeric: tabular-nums; }

/* ---------- Шторки ---------- */

/* display:flex сильнее браузерного [hidden]{display:none} — гасим явно. */
.sheet[hidden] { display: none; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 12, 20, 0.65);
  backdrop-filter: blur(2px);
}
.sheet-body {
  width: 100%;
  max-width: 520px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } }

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-close {
  width: 32px; height: 32px;
  border: 0;
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

.menu-item[hidden] { display: none; }
.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px;
  margin-bottom: 8px;
  border: 0;
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.menu-item b { color: var(--muted); font-weight: 700; }

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.stats div {
  padding: 10px 12px;
  border-radius: 11px;
  background: var(--panel-2);
  font-size: 12px;
  color: var(--muted);
}
.stats div b {
  display: block;
  margin-top: 3px;
  font-size: 16px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.help-list { margin: 0 0 12px; padding-left: 20px; }
.help-list li { margin-bottom: 7px; }
.help-note { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

.list-body { display: flex; flex-direction: column; gap: 7px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 13px;
  border-radius: 11px;
  background: var(--panel-2);
  font-size: 13px;
}
.row .row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row .row-sub { color: var(--muted); font-size: 11px; }
.row .win { color: var(--green); font-weight: 700; font-variant-numeric: tabular-nums; }
.row .lose { color: var(--red); font-weight: 700; font-variant-numeric: tabular-nums; }
.empty { padding: 24px; text-align: center; color: var(--muted); }

.field { display: block; margin-bottom: 10px; }
.field span { display: block; margin-bottom: 5px; font-size: 12px; color: var(--muted); }
.field input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  outline: none;
}
.field input:read-only { color: var(--muted); }

.btn-wide {
  width: 100%;
  height: 44px;
  margin-top: 4px;
  border: 0;
  border-radius: 11px;
  background: var(--panel-3);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.fair-result {
  margin-top: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
}
.fair-link {
  display: inline-block;
  margin-top: 12px;
  color: #7d8ce8;
  font-size: 13px;
  text-decoration: none;
}

/* ---------- Узкие экраны ---------- */

@media (max-width: 620px) {
  .panel-row {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "bet diff" "action action";
  }
  .bet-block { grid-area: bet; }
  .diff-block { grid-area: diff; }
  .action-block { grid-area: action; }
  .btn-play, .btn-cashout { min-height: 60px; }
  .hide-sm { display: none; }
  .diff-head { flex-direction: column; align-items: flex-start; gap: 2px; }
  .diff-tabs { grid-template-columns: repeat(2, 1fr); }
}
