/* DICE — оформление в одном ключе с 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);
}

.splash[hidden] { display: none; }
.splash {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--bg);
}
.splash .logo { font-size: 26px; }
.splash-dots { display: flex; gap: 7px; }
.splash-dots i {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--panel-3);
  animation: splash-pulse 1s infinite ease-in-out;
}
.splash-dots i:nth-child(2) { animation-delay: 0.15s; }
.splash-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes splash-pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50%      { opacity: 1;    transform: scale(1); }
}

/* ---------- Главный экран ---------- */

.home[hidden], #app[hidden] { display: none; }

.home {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  height: 100dvh;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
}

.home-top { text-align: center; margin-top: 4px; }
.home .logo { font-size: 26px; }
.home-sub { margin-top: 6px; color: var(--muted); font-size: 14px; }

.home-balance {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--panel-2), var(--panel-3));
}
.home-balance-label { color: var(--muted); font-size: 13px; }
.home-balance-value {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 26px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}
.home-balance-value .coin { width: 22px; height: 22px; font-size: 13px; }

.home-play {
  min-height: 62px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(180deg, var(--green), var(--green-2));
  color: #fff;
  font-size: 21px;
  font-weight: 900;
  cursor: pointer;
}
.home-play:active { transform: scale(0.99); }

.home-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.home-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 76px;
  padding: 8px 4px;
  border: 0;
  border-radius: 14px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
}
.home-tile[hidden] { display: none; }
.home-tile:active { background: var(--panel-3); }
.tile-ico { font-size: 22px; line-height: 1; }

.home-wide {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 0 16px;
  border: 0;
  border-radius: 13px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.home-wide:active { background: var(--panel-3); }
.home-wide b { color: var(--gold); font-variant-numeric: tabular-nums; }

/* Выбор языка */
.lang-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.lang-row button {
  min-height: 54px;
  border: 2px solid transparent;
  border-radius: 13px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.lang-row button.on { border-color: var(--green); background: var(--panel-3); }

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

.logo-sm { font-size: 15px; }

.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 .die {
  display: inline-block;
  width: 15px;
  height: 15px;
  vertical-align: -2px;
  border-radius: 4px;
  /* Грань кубика с одной точкой: точка — радиальным градиентом поверх золота,
     цветом фона. inset-тенью тут не обойтись — она рисует рамку, а не точку. */
  background:
    radial-gradient(circle at 50% 50%, var(--bg) 0 26%, transparent 27%),
    linear-gradient(160deg, #ffe07a, #f0b429);
  color: transparent;
}
.home .logo .die, .splash .logo .die { width: 22px; height: 22px; vertical-align: -3px; }

.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: 200px;
  background: var(--bg);
}

.dice {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 10px 16px 4px;
}

/* Лента последних бросков */
.recent {
  display: flex;
  gap: 6px;
  height: 24px;
  align-items: center;
  overflow: hidden;
}
.recent span {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--panel-2);
  color: var(--muted);
  animation: recent-in 0.25s ease-out;
}
.recent span.win { background: rgba(51, 200, 90, 0.16); color: var(--green); }
.recent span.lose { background: rgba(239, 75, 75, 0.14); color: var(--red); }
@keyframes recent-in { from { transform: translateY(-6px); opacity: 0; } }

/* Выпавшее число */
.roll-box { text-align: center; }
.roll-value {
  font-size: 58px;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
  transition: color 0.15s;
}
.roll-value.win { color: var(--green); }
.roll-value.lose { color: var(--red); }
.roll-value.pop { animation: roll-pop 0.32s ease-out; }
@keyframes roll-pop { from { transform: scale(0.82); } 60% { transform: scale(1.06); } }
.roll-caption { margin-top: 8px; font-size: 13px; color: var(--muted); }

/* Шкала: две части, порог между ними задаёт игрок */
.scale { width: 100%; max-width: 520px; }
.scale-track {
  position: relative;
  display: flex;
  height: 46px;
  border-radius: 12px;
  overflow: visible;
}
.zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: width 0.12s ease-out;
  overflow: hidden;
  white-space: nowrap;
}
.zone span { padding: 0 6px; opacity: 0.9; }
#zone-a { border-radius: 12px 0 0 12px; }
#zone-b { border-radius: 0 12px 12px 0; }
.zone.win { background: linear-gradient(180deg, #2ea94e, #248a41); color: #eaffef; }
.zone.lose { background: linear-gradient(180deg, #3a4059, #2f3448); color: var(--muted); }

/* Граница между частями — то самое число, которое выставляет игрок */
.edge {
  position: absolute;
  top: -7px;
  bottom: -7px;
  width: 2px;
  margin-left: -1px;
  background: var(--text);
  border-radius: 2px;
  transition: left 0.12s ease-out;
}
.edge span {
  position: absolute;
  left: 50%;
  bottom: -22px;
  transform: translateX(-50%);
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* Метка броска */
.marker {
  position: absolute;
  top: -14px;
  width: 0;
  opacity: 0;
  transition: opacity 0.15s;
}
.marker.on { opacity: 1; }
.marker i {
  position: absolute;
  left: -7px;
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 10px solid var(--gold);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.45));
}

.ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 26px;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Переключатель стороны */
.dir-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.dir-btn:active { background: var(--panel-2); }
.dir-btn b { color: var(--gold); font-variant-numeric: tabular-nums; }
.dir-swap { color: var(--muted); font-size: 15px; }

.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); }

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

.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; }

/* Шанс выигрыша */

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

/* Ползунок шанса. Разметку рисуем сами: системный вид у range в WebView
   разный на каждой платформе и ломает вёрстку панели. */
.chance-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}
.chance-slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--panel-3);
}
.chance-slider::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--panel-3);
}
.chance-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}
.chance-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: var(--gold);
}
.chance-slider:disabled { opacity: 0.5; cursor: default; }

.chance-quick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.chance-quick button {
  height: 26px;
  border: 0;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.chance-quick button.on { background: var(--panel-3); color: var(--text); }
.chance-quick button:disabled { opacity: 0.45; cursor: default; }

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

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

.payline { display: flex; gap: 8px; }
.payline div {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border-radius: 10px;
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.payline span { font-size: 10px; color: var(--muted); }
.payline b {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
}
#mult-value { color: var(--gold); }
#payout-value { color: var(--green); }

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

/* Таблица «шанс -> множитель» в справке */
.mult-table { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.mult-table div {
  padding: 7px 8px;
  border-radius: 10px;
  background: var(--panel-2);
  text-align: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.mult-table b { display: block; margin-top: 2px; color: var(--gold); font-size: 14px; }

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

/* 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: 4px;
}
.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 chance" "action action";
  }
  .bet-block { grid-area: bet; }
  .chance-block { grid-area: chance; }
  .action-block { grid-area: action; }
  .action-block { flex-direction: row; align-items: stretch; }
  .payline { flex: 0 0 44%; }
  .btn-play { min-height: 60px; }
  .chance-quick { grid-template-columns: repeat(3, 1fr); }
  .roll-value { font-size: 46px; }
  .dice { gap: 14px; }
}

/* Совсем низкие экраны: лента бросков — первое, чем можно пожертвовать. */
@media (max-height: 620px) {
  .recent { display: none; }
  .roll-value { font-size: 40px; }
  .dice { gap: 10px; }
}
