/* Colours come from the Telegram theme, so the app matches light and dark
   Telegram; the fallbacks are for an ordinary browser. */
:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --card: var(--tg-theme-secondary-bg-color, #232e3c);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #8b9aa8);
  --accent: var(--tg-theme-button-color, #5288c1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --win: #2fbf71;
  --loss: #e5534b;
  --gold: #f5b942;
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
.hidden { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center;
  justify-content: space-between; padding: 12px 16px; background: var(--bg);
}
.brand { font-weight: 700; font-size: 17px; }
.balance {
  background: var(--card); border-radius: 20px; padding: 6px 12px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.offline { margin: 0 16px 8px; padding: 8px 12px; border-radius: 10px; background: var(--loss); color: #fff; font-size: 13px; }
main { padding: 0 16px; }
h2 { font-size: 20px; margin: 8px 0 4px; }
.hint { color: var(--hint); font-size: 13px; }
.center { text-align: center; }

/* tables */
.tables { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.table-card {
  background: var(--card); border-radius: var(--radius); padding: 14px; display: flex;
  flex-direction: column; gap: 10px;
}
.table-card .stake { font-size: 24px; font-weight: 800; }
.table-card .waiting { font-size: 12px; color: var(--hint); }
.table-card .waiting.hot { color: var(--win); font-weight: 600; }
.table-card .row { display: flex; gap: 6px; }

.btn {
  flex: 1; display: block; width: 100%; padding: 12px 14px; border-radius: 12px; font-weight: 600;
  background: var(--accent); color: var(--accent-text); text-align: center;
}
.btn.small { padding: 8px 10px; font-size: 14px; }
.btn.ghost { background: transparent; color: var(--link); box-shadow: inset 0 0 0 1.5px var(--link); }
.btn.gold { background: var(--gold); color: #1d1d1d; }
.btn:disabled { opacity: .45; }
.btn + .btn { margin-top: 10px; }
.row .btn + .btn { margin-top: 0; }
.link-btn { color: var(--hint); font-size: 13px; padding: 6px 0; text-decoration: underline; }

.panel { background: var(--card); border-radius: var(--radius); padding: 18px; margin: 14px 0; }
.big-timer { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; margin: 6px 0; }
.spinner {
  width: 44px; height: 44px; margin: 10px auto; border-radius: 50%;
  border: 4px solid var(--hint); border-top-color: var(--accent); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.code { font: 700 28px ui-monospace, Menlo, monospace; letter-spacing: 4px; word-break: break-all; }
.code-form .chat-form { margin-top: 6px; }
.code-form input { text-transform: uppercase; letter-spacing: 2px; font-family: ui-monospace, Menlo, monospace; }
.code-form .btn { width: auto; flex: none; padding: 8px 16px; }

/* duel */
.duel { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin: 14px 0; }
.side { background: var(--card); border-radius: var(--radius); padding: 14px 8px; text-align: center; min-height: 150px; }
.side.me { box-shadow: inset 0 0 0 2px var(--accent); }
.side.winner { box-shadow: inset 0 0 0 2px var(--win); }
.side .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .tag { font-size: 12px; color: var(--hint); min-height: 18px; }
.side .sum { font-size: 30px; font-weight: 800; margin-top: 4px; }
.vs { color: var(--hint); font-weight: 700; }
.dice { display: flex; justify-content: center; gap: 8px; margin-top: 10px; min-height: 46px; }
.die {
  width: 46px; height: 46px; border-radius: 10px; background: #fff; display: grid;
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); padding: 6px;
  box-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.die i { display: block; width: 8px; height: 8px; margin: auto; border-radius: 50%; background: transparent; }
.die i.on { background: #1d1d1d; }
.die.blank { background: transparent; box-shadow: inset 0 0 0 2px var(--hint); }
.die.rolling { animation: shake .18s linear infinite; }
@keyframes shake {
  0% { transform: rotate(0) translateY(0); } 25% { transform: rotate(-12deg) translateY(-3px); }
  50% { transform: rotate(8deg) translateY(1px); } 75% { transform: rotate(-6deg) translateY(-2px); }
  100% { transform: rotate(0) translateY(0); }
}
.outcome { font-size: 28px; font-weight: 800; text-align: center; margin: 6px 0 0; }
.outcome.win { color: var(--win); } .outcome.loss { color: var(--loss); }
.amount { text-align: center; font-size: 18px; font-weight: 600; margin-bottom: 10px; }

/* fairness */
details.fair { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin: 14px 0; }
details.fair summary { font-weight: 600; cursor: pointer; }
.kv { margin-top: 8px; font-size: 12px; }
.kv div { color: var(--hint); margin-top: 6px; }
.kv code { display: block; word-break: break-all; font: 12px ui-monospace, Menlo, monospace; color: var(--text); }
.fair-result { margin-top: 10px; font-weight: 600; }

/* chat */
.chat { background: var(--card); border-radius: var(--radius); padding: 10px; margin: 14px 0; }
.chat-list { max-height: 180px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 2px; }
.msg { max-width: 80%; padding: 6px 10px; border-radius: 12px; background: var(--bg); word-wrap: break-word; white-space: pre-wrap; }
.msg.mine { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.chat-form { display: flex; gap: 6px; margin-top: 8px; }
.chat-form input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 0; outline: none;
  background: var(--bg); color: var(--text); font: inherit;
}
.chat-send { width: 44px; border-radius: 12px; background: var(--accent); color: var(--accent-text); }

/* history & top */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 12px 0; }
.stat { background: var(--card); border-radius: 12px; padding: 10px 4px; text-align: center; }
.stat b { display: block; font-size: 18px; }
.stat span { font-size: 11px; color: var(--hint); }
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin: 12px 0; }
.item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 14px; }
.item + .item { border-top: 1px solid rgba(127,127,127,.15); }
.item .l { min-width: 0; }
.item .l b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .r { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item.me { background: rgba(82,136,193,.15); }
.pos { color: var(--win); } .neg { color: var(--loss); }
.seg { display: flex; background: var(--card); border-radius: 10px; padding: 3px; margin: 10px 0; }
.seg button { flex: 1; padding: 7px; border-radius: 8px; font-size: 14px; color: var(--hint); }
.seg button.active { background: var(--bg); color: var(--text); font-weight: 600; }
.empty { color: var(--hint); text-align: center; padding: 24px 0; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: var(--card);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { flex: 1; padding: 14px 4px; color: var(--hint); font-size: 14px; font-weight: 600; }
.tabs button.active { color: var(--accent); }
.tabs.locked button:not(.active) { opacity: .4; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 10;
  padding: 12px 14px; border-radius: 12px; background: #000c; color: #fff; text-align: center;
}
