
:root {
  --green: #2e9e4f;
  --green-d: #1f6e37;
  --yellow: #e3b526;
  --yellow-d: #a97e0f;
  --blue: #2f7fd6;
  --blue-d: #1c56a3;
  --red: #d6402f;
  --red-d: #9c2a1d;
  --bg: var(--tg-theme-bg-color, #150a1e);
  --text: var(--tg-theme-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #2a1a35);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; color: var(--text);
  background:
    radial-gradient(circle at 50% -10%, #3a1f4d 0%, var(--bg) 55%),
    repeating-linear-gradient(45deg, rgba(255,255,255,.025) 0 2px, transparent 2px 34px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.02) 0 2px, transparent 2px 34px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, sans-serif;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
#app { display: flex; flex-direction: column; min-height: 100%; padding: 16px; }
.screen { display: flex; flex-direction: column; align-items: center; gap: 14px; }
h1 { margin: 8px 0 0; font-size: 28px; text-shadow: 0 2px 6px rgba(0,0,0,.4); }
.muted { opacity: 0.65; font-size: 14px; text-align: center; }
.players-list { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 8px; }
.player-row {
  display: flex; align-items: center; gap: 10px; background: var(--card);
  padding: 10px 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,.06);
}
.dot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 6px currentColor; }
.primary-btn {
  background: linear-gradient(180deg, #ffe08a, #e3b526); color: #3a2600; font-weight: 700;
  font-size: 17px; border: none; padding: 12px 28px; border-radius: 14px; box-shadow: 0 4px 0 #a5790f;
}
.primary-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #a5790f; }
.turn-banner {
  width: 100%; max-width: 420px; text-align: center; padding: 10px; border-radius: 12px;
  background: var(--card); font-weight: 600; border-right: 6px solid transparent;
  box-shadow: 0 2px 8px rgba(0,0,0,.25); transition: border-color .25s ease;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.turn-timer { font-size: 13px; opacity: .85; font-weight: 500; }
.turn-timer.urgent { color: #ff6b5e; font-weight: 700; }

.players-rail { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; width: 100%; max-width: 420px; }
.player-avatar-wrap { display: flex; flex-direction: column; align-items: center; gap: 3px; position: relative; }
.player-avatar {
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover; background: var(--card);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px;
  color: #fff; border: 3px solid transparent; box-sizing: border-box;
}
.player-avatar-wrap.active .player-avatar { box-shadow: 0 0 10px 1px #ffd76a; }
.player-avatar-name { font-size: 10px; opacity: .75; max-width: 50px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.social-bar { display: flex; gap: 10px; justify-content: center; }
.social-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 2px solid #ffd76a;
  background: var(--card); font-size: 19px; cursor: pointer;
}
.emoji-picker {
  display: flex; gap: 8px; background: var(--card); padding: 8px 12px; border-radius: 14px;
  border: 1px solid rgba(255,215,110,.3); flex-wrap: wrap; justify-content: center; max-width: 300px;
}
.emoji-picker button { font-size: 22px; background: none; border: none; cursor: pointer; padding: 2px; }

.chat-panel {
  position: fixed; left: 12px; right: 12px; bottom: 12px; max-width: 420px; margin: 0 auto;
  background: var(--card); border-radius: 14px; padding: 10px; z-index: 40;
  border: 1px solid rgba(255,215,110,.3); box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.chat-messages { max-height: 160px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; padding: 2px 4px; }
.chat-msg { font-size: 13px; line-height: 1.4; word-break: break-word; }
.chat-msg .name { font-weight: 700; margin-left: 5px; }
.chat-input-row { display: flex; gap: 6px; margin-top: 8px; }
.chat-input {
  flex: 1; min-width: 0; border-radius: 10px; border: 1px solid rgba(255,255,255,.2);
  background: #1b1023; color: #fff; padding: 8px 10px; font-size: 13px;
}
.chat-send-btn {
  border-radius: 10px; border: none; background: linear-gradient(180deg, #ffe08a, #e3b526);
  color: #3a2600; font-weight: 700; padding: 0 14px; cursor: pointer; flex-shrink: 0;
}

.reaction-float {
  position: absolute; top: -6px; left: 50%; font-size: 26px; pointer-events: none;
  animation: floatUp 1.2s ease-out forwards;
}
@keyframes floatUp {
  0% { transform: translate(-50%, 0) scale(.6); opacity: 0; }
  20% { opacity: 1; transform: translate(-50%, -6px) scale(1.15); }
  100% { transform: translate(-50%, -42px) scale(1); opacity: 0; }
}
#boardWrap {
  width: 100%; max-width: 420px; padding: 10px; border-radius: 18px;
  background: linear-gradient(145deg, #8a6236, #5a3e22);
  box-shadow: 0 10px 24px rgba(0,0,0,.45), inset 0 0 0 2px rgba(255,215,110,.3);
}
#board { width: 100%; height: auto; display: block; border-radius: 8px; }
#controls { display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 108px; justify-content: flex-end; }
.dice-hint { font-size: 13px; opacity: .8; min-height: 16px; }
.dice-badges { display: flex; gap: 8px; min-height: 42px; align-items: center; }
.die-badge {
  width: 40px; height: 40px; border-radius: 10px; border: 2px solid #ffd76a;
  background: var(--card); color: var(--text); font-size: 18px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  animation: pop .25s ease;
}
.die-badge.selected { background: linear-gradient(180deg, #ffe08a, #e3b526); color: #3a2600; transform: scale(1.08); }
.die-badge:disabled { opacity: .35; cursor: default; }
.dice-btn {
  font-size: 40px; background: radial-gradient(circle at 35% 30%, #3e2850, var(--card));
  border: 3px solid #ffd76a; border-radius: 18px; width: 84px; height: 84px; cursor: pointer;
  box-shadow: 0 4px 0 #a5790f, 0 6px 14px rgba(0,0,0,.35);
}
.dice-btn:disabled { opacity: 0.35; box-shadow: none; }
.dice-btn:active:not(:disabled) { transform: translateY(2px); }
.dice-btn.rolling { animation: roll .5s ease; }
@keyframes roll { 0% { transform: rotate(0deg) scale(1); } 50% { transform: rotate(200deg) scale(1.15); } 100% { transform: rotate(360deg) scale(1); } }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pulse-glow {
  0%, 100% { filter: drop-shadow(0 0 3px #fff) drop-shadow(0 0 2px #ffe08a); }
  50% { filter: drop-shadow(0 0 9px #fff) drop-shadow(0 0 7px #ffe08a); }
}
.token { transition: transform .35s cubic-bezier(.4,1.4,.6,1); cursor: default; }
.token.movable { cursor: pointer; animation: pulse-glow 1s ease-in-out infinite; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.75); display: flex; align-items: center; justify-content: center; z-index: 50; }
.overlay-card {
  background: var(--card); padding: 28px 24px; border-radius: 16px; text-align: center; max-width: 300px;
  border: 1px solid rgba(255,215,110,.4); box-shadow: 0 0 30px rgba(255,215,110,.25);
}
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #000; color: #fff;
  padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 60; box-shadow: 0 4px 12px rgba(0,0,0,.4);
}
