:root {
  --red: #e8403a;
  --green: #2eaa55;
  --yellow: #f4bd1f;
  --blue: #2c7be0;
  --ink: #1d1840;
  --muted: #6f6a96;
  --line: #dcd8ee;
  --bg: #120c33;
  --rot: 0deg;
  --bs: 360px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'Baloo 2', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: #fff;
  background: radial-gradient(1100px 700px at 50% -15%, #3d2d95 0%, #221766 40%, var(--bg) 80%) fixed, var(--bg);
  min-height: 100svh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; }
.hidden { display: none !important; }

.screen {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
}

/* ---------- brand ---------- */
.brand { text-align: center; margin-bottom: 18px; }
.brand h1 { margin: 8px 0 0; font-size: 44px; line-height: 1; font-weight: 800; letter-spacing: -.5px; }
.brand h1 em { font-style: normal; color: var(--yellow); }
.brand p { margin: 6px 0 0; opacity: .7; }
.logo {
  display: inline-grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 7px;
  background: #fff; border-radius: 18px; transform: rotate(-8deg);
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
}
.logo span { width: 24px; height: 24px; border-radius: 7px; background: var(--c); }

/* ---------- cards / controls ---------- */
.card {
  width: 100%; max-width: 380px;
  background: #fff; color: var(--ink);
  border-radius: 22px; padding: 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,.4);
  display: flex; flex-direction: column; gap: 12px;
}
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input {
  width: 100%; border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px;
  font-size: 17px; color: var(--ink); outline: none; background: #faf9ff;
}
input:focus { border-color: #7b6cf0; background: #fff; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: #efedf9; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 8px; border-radius: 9px; font-weight: 700; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(29,24,64,.15); }

.btn {
  border: 0; border-radius: 14px; padding: 11px 16px; font-weight: 700; font-size: 16px;
  background: #efedf9; color: var(--ink); cursor: pointer; text-decoration: none; text-align: center;
  transition: transform .08s, filter .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #ff5a4e, #e0342d); color: #fff; box-shadow: 0 5px 0 #a8201b, 0 10px 20px rgba(232,64,58,.35); }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 2px 0 #a8201b; }
.btn.big { font-size: 19px; padding: 13px 16px; }
.btn.small { font-size: 14px; padding: 8px 12px; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.wa { background: #25d366; color: #fff; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.join { display: flex; gap: 8px; }
.join input { text-transform: uppercase; letter-spacing: 3px; font-weight: 700; text-align: center; }
.join .btn { flex: none; }
.invite { background: #fff7dc; border: 2px dashed var(--yellow); border-radius: 12px; padding: 8px 12px; font-size: 15px; }
.conn { margin-top: 14px; font-size: 13px; opacity: .6; }
.conn.ok::before { content: '● '; color: #4ade80; }
.conn.bad::before { content: '● '; color: #f87171; }

/* ---------- lobby ---------- */
.lobby-card { max-width: 420px; }
.lobby-card h2 { margin: 0; font-size: 26px; line-height: 1.1; }
.sub { margin: -4px 0 0; color: var(--muted); }
.code-box { background: #f5f3ff; border-radius: 16px; padding: 12px; text-align: center; }
.code-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.code { font-size: 40px; font-weight: 800; letter-spacing: 8px; line-height: 1.1; margin: 2px 0 8px; }
.share { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.seats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seat {
  position: relative; border-radius: 14px; padding: 12px 8px; text-align: center; min-height: 104px;
  background: #faf9ff; border: 2px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.seat.filled { border-color: var(--c); background: color-mix(in srgb, var(--c) 8%, #fff); }
.seat .avatar { width: 44px; height: 44px; font-size: 20px; }
.seat .sname { font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .stag { font-size: 12px; color: var(--muted); min-height: 16px; }
.seat.empty { border-style: dashed; color: var(--muted); }
.seat .x { position: absolute; top: 4px; right: 4px; border: 0; background: transparent; font-size: 14px; cursor: pointer; color: var(--muted); padding: 4px 6px; }
.seat .addbot { border: 0; background: #efedf9; color: var(--ink); border-radius: 10px; padding: 6px 10px; font-weight: 700; cursor: pointer; }
.waiting-dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.lobby-actions { display: flex; flex-direction: column; gap: 6px; }

/* ---------- game layout ---------- */
.screen.game { justify-content: flex-start; padding: 8px 12px 12px; gap: 8px; }
.screen.game .table { margin-block: auto; }
.topbar { width: 100%; max-width: 640px; display: flex; align-items: center; justify-content: space-between; }
.icon { width: 40px; height: 40px; border-radius: 12px; border: 0; background: rgba(255,255,255,.1); color: #fff; font-size: 18px; cursor: pointer; }
.room-tag { font-weight: 700; opacity: .8; letter-spacing: .5px; }
.table {
  --bs: max(260px, min(calc(100vw - 24px), calc(100svh - 300px), 600px));
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.panels { width: var(--bs); display: flex; justify-content: space-between; gap: 10px; }

/* ---------- board ---------- */
.board {
  position: relative; width: var(--bs); height: var(--bs);
  transform: rotate(var(--rot)); transition: transform .6s ease;
  border-radius: 16px; background: #fff;
  box-shadow: 0 0 0 5px rgba(255,255,255,.12), 0 24px 60px rgba(0,0,0,.5);
}
.cells {
  position: absolute; inset: 0; display: grid;
  grid-template-columns: repeat(15, 1fr); grid-template-rows: repeat(15, 1fr);
  border-radius: 16px; overflow: hidden;
}
.cell {
  border: .5px solid var(--line); background: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--bs) / 15 * .6); line-height: 1; color: #c6c1e0;
}
.cell.red { background: var(--red); } .cell.green { background: var(--green); }
.cell.yellow { background: var(--yellow); } .cell.blue { background: var(--blue); }
.cell.star::after { content: '★'; }
.cell.start::after { content: '★'; color: rgba(255,255,255,.85); }
.base { background: var(--c); position: relative; }
.base-inner { position: absolute; inset: 16.66%; background: #fff; border-radius: 20%; box-shadow: inset 0 2px 8px rgba(0,0,0,.12); }
.spot {
  position: absolute; width: 16%; height: 16%; border-radius: 50%;
  background: var(--c); opacity: .28; transform: translate(-50%, -50%);
}
.center { background: conic-gradient(from -45deg, var(--green) 0 90deg, var(--yellow) 90deg 180deg, var(--blue) 180deg 270deg, var(--red) 270deg 360deg); }

/* ---------- tokens ---------- */
.tokens { position: absolute; inset: 0; pointer-events: none; }
.token {
  --s: 1;
  position: absolute; left: 0; top: 0;
  width: calc(var(--bs) / 15 * .76); height: calc(var(--bs) / 15 * .76);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,.75) 0 14%, transparent 15%), var(--c);
  border: 2.5px solid #fff;
  box-shadow: 0 3px 5px rgba(0,0,0,.4), inset 0 -3px 0 rgba(0,0,0,.2);
  transform: translate(-50%, -50%) rotate(calc(-1 * var(--rot))) scale(var(--s));
  transition: left .14s ease-out, top .14s ease-out, transform .2s, opacity .3s;
  z-index: 2; pointer-events: auto;
}
.token::before { content: ''; position: absolute; inset: 20%; border-radius: 50%; border: 2px solid rgba(255,255,255,.6); }
.token::after { content: ''; position: absolute; inset: -40%; border-radius: 50%; }
.token.fly { transition: left .4s ease-in-out, top .4s ease-in-out, transform .2s; }
.token.gone { opacity: 0; pointer-events: none; }
.token.can {
  z-index: 8; cursor: pointer;
  animation: hop .45s ease-in-out infinite alternate;
  box-shadow: 0 0 0 3px #fff, 0 0 16px 5px var(--c), 0 3px 5px rgba(0,0,0,.4);
}
.token.mine-top { z-index: 4; }
@keyframes hop {
  from { transform: translate(-50%, -50%) rotate(calc(-1 * var(--rot))) scale(var(--s)); }
  to   { transform: translate(-50%, -50%) rotate(calc(-1 * var(--rot))) translateY(-22%) scale(var(--s)); }
}

/* ---------- player panels ---------- */
.panel {
  flex: 1; min-width: 0; max-width: 50%;
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: 16px; min-height: 66px;
  background: rgba(255,255,255,.06); border: 2px solid transparent;
  position: relative; visibility: hidden; transition: background .2s, border-color .2s, box-shadow .2s;
}
.panel.used { visibility: visible; }
.panel.right { flex-direction: row-reverse; text-align: right; }
.panel.active { border-color: var(--c); background: rgba(255,255,255,.14); box-shadow: 0 0 22px -6px var(--c); }
.panel.gone { opacity: .45; }
.avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%; background: var(--c);
  display: grid; place-items: center; font-weight: 800; font-size: 18px; color: #fff;
  border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3);
}
.pinfo { flex: 1; min-width: 0; }
.pname { font-weight: 700; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pstat { font-size: 12px; opacity: .75; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer { height: 4px; margin-top: 5px; border-radius: 3px; background: rgba(255,255,255,.12); overflow: hidden; }
.timer i { display: block; height: 100%; width: 0; background: var(--c); border-radius: 3px; }
.panel.right .timer i { margin-left: auto; }

/* ---------- dice ---------- */
.die {
  flex: none; width: 46px; height: 46px; border-radius: 11px; background: #fff; padding: 7px;
  display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  box-shadow: inset 0 -4px 0 #d9d4f0, 0 4px 10px rgba(0,0,0,.3);
  opacity: .3; transition: opacity .2s; position: relative;
}
.panel.active .die { opacity: 1; }
.die span { width: 72%; height: 72%; margin: auto; border-radius: 50%; background: var(--ink); opacity: 0; }
.die[data-v="1"] span:nth-child(5),
.die[data-v="2"] span:nth-child(3), .die[data-v="2"] span:nth-child(7),
.die[data-v="3"] span:nth-child(3), .die[data-v="3"] span:nth-child(5), .die[data-v="3"] span:nth-child(7),
.die[data-v="4"] span:nth-child(1), .die[data-v="4"] span:nth-child(3), .die[data-v="4"] span:nth-child(7), .die[data-v="4"] span:nth-child(9),
.die[data-v="5"] span:nth-child(1), .die[data-v="5"] span:nth-child(3), .die[data-v="5"] span:nth-child(5), .die[data-v="5"] span:nth-child(7), .die[data-v="5"] span:nth-child(9),
.die[data-v="6"] span:nth-child(1), .die[data-v="6"] span:nth-child(3), .die[data-v="6"] span:nth-child(4), .die[data-v="6"] span:nth-child(6), .die[data-v="6"] span:nth-child(7), .die[data-v="6"] span:nth-child(9) { opacity: 1; }
.die[data-v="6"] span { background: var(--red); }
.die.can { cursor: pointer; animation: pulse 1s ease-in-out infinite; }
.die.can::after {
  content: 'TAP'; position: absolute; left: 50%; bottom: -15px; transform: translateX(-50%);
  font-size: 10px; font-weight: 800; letter-spacing: 1px; color: #fff; opacity: .85;
}
.die.rolling { animation: shake .35s linear infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); box-shadow: inset 0 -4px 0 #d9d4f0, 0 0 0 0 rgba(255,255,255,.7); } 50% { transform: scale(1.08); box-shadow: inset 0 -4px 0 #d9d4f0, 0 0 0 8px rgba(255,255,255,0); } }
@keyframes shake { 0% { transform: rotate(0) } 25% { transform: rotate(18deg) translateY(-3px) } 50% { transform: rotate(-12deg) } 75% { transform: rotate(10deg) translateY(-2px) } 100% { transform: rotate(0) } }

/* ---------- emoji ---------- */
.emojis { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.emojis button { border: 0; background: rgba(255,255,255,.08); border-radius: 12px; font-size: 20px; width: 42px; height: 38px; cursor: pointer; }
.emojis button:active { transform: scale(.9); }
.bubble {
  position: absolute; top: -18px; left: 50%; font-size: 30px; pointer-events: none;
  animation: floatUp 1.8s ease-out forwards; z-index: 20;
}
@keyframes floatUp { 0% { transform: translate(-50%, 10px) scale(.4); opacity: 0; } 15% { transform: translate(-50%, 0) scale(1.2); opacity: 1; } 80% { opacity: 1; } 100% { transform: translate(-50%, -40px) scale(1); opacity: 0; } }

/* ---------- overlay ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10,6,30,.72); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50;
  animation: fade .3s;
}
@keyframes fade { from { opacity: 0; } }
.over-card { text-align: center; }
.trophy { font-size: 56px; line-height: 1; }
.over-card h2 { margin: 4px 0 0; font-size: 30px; line-height: 1.1; }
.ranks { list-style: none; margin: 4px 0; padding: 0; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.ranks li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: #f5f3ff; }
.ranks .medal { width: 28px; text-align: center; font-size: 20px; }
.ranks .avatar { width: 30px; height: 30px; font-size: 14px; border-width: 2px; }
.ranks .rn { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranks .rt { font-size: 12px; color: var(--muted); }
.confetti { position: fixed; top: -12px; width: 9px; height: 14px; z-index: 60; pointer-events: none; animation: drop linear forwards; }
@keyframes drop { to { transform: translateY(110vh) rotate(720deg); } }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; top: 12px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 100; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: rgba(20,14,50,.94); border: 1px solid rgba(255,255,255,.15); color: #fff; padding: 8px 14px; border-radius: 12px; font-weight: 600; box-shadow: 0 8px 20px rgba(0,0,0,.35); animation: toastIn .25s; text-align: center; }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } }

@media (max-width: 420px) {
  .panel { padding: 6px; gap: 6px; min-height: 58px; }
  .avatar { width: 32px; height: 32px; font-size: 15px; border-width: 2px; }
  .die { width: 40px; height: 40px; padding: 6px; }
  .pname { font-size: 14px; }
  .pstat { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  .token.can, .die.can { animation: none; }
}
