* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1220;
  --card: #1a1f35;
  --cell-a: #232a4a;
  --cell-b: #1c2340;
  --text: #eef0ff;
  --muted: #9aa3c7;
  --accent: #ffb84d;
  --green: #4ade80;
  --red: #fb7185;
  --blue: #60a5fa;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: radial-gradient(1200px 800px at 70% -10%, #232b55 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  touch-action: manipulation;          /* no double-tap zoom delay on mobile */
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.screen {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}

.card {
  background: var(--card);
  border: 1px solid #2b3357;
  border-radius: 16px;
  padding: 28px;
  width: min(420px, 94vw);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  text-align: center;
}
.card h1 { font-size: 1.5rem; margin-bottom: 6px; }
.accent { color: var(--accent); }
.sub { color: var(--muted); margin-bottom: 20px; }

label { display: block; text-align: left; color: var(--muted); font-size: .85rem; margin: 12px 0 4px; }
input[type=text], input[type=password] {
  width: 100%; padding: 10px 12px; margin-top: 4px;
  background: #12162a; color: var(--text);
  border: 1px solid #333c66; border-radius: 10px; font-size: 1rem;
}
input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.btn {
  cursor: pointer; border: 1px solid #3a4370; border-radius: 10px;
  background: #262e52; color: var(--text);
  padding: 10px 18px; font-size: 1rem; margin-top: 14px;
  transition: transform .08s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #26200f; font-weight: 700; }
.btn.big { font-size: 1.15rem; padding: 12px 26px; width: 100%; }
.btn.tiny { padding: 2px 8px; font-size: .7rem; margin: 0 0 0 6px; }
.btn.subtle { background: transparent; border-color: #333c66; color: var(--muted); font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; transform: none; }

.error { color: var(--red); min-height: 1.2em; margin-top: 10px; font-size: .9rem; }

/* lobby */
.lobby-block h2 { font-size: 1rem; margin-bottom: 8px; text-align: left; }
.board-choice { display: flex; gap: 10px; }
.radio {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: #12162a; border: 1px solid #333c66; border-radius: 10px;
  padding: 10px; cursor: pointer; margin: 0; color: var(--text); font-size: .95rem;
}
.radio small { color: var(--muted); }
.radio:has(input:checked) { outline: 2px solid var(--accent); }
.match-choice { margin-top: 10px; }
.hint { color: var(--muted); font-size: .78rem; margin-top: 10px; text-align: left; }
.divider { color: var(--muted); margin: 18px 0; font-size: .8rem; }
.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: .35em; text-align: center; font-weight: 700; }
.join-row .btn { margin-top: 4px; }

/* game screen */
#screen-game { flex-direction: column; justify-content: flex-start; padding: 12px; }
#game-header {
  width: 100%; max-width: 1060px; display: flex; justify-content: space-between;
  align-items: center; padding: 4px 2px 10px;
}
.room-tag { color: var(--muted); }
.room-tag strong { color: var(--accent); letter-spacing: .2em; }
#series { color: var(--muted); font-size: .85rem; }
.header-right { display: flex; align-items: center; gap: 8px; }
#mute-btn { margin: 0; }
#conn-status { font-size: .85rem; color: var(--muted); }
#conn-status.bad { color: var(--red); }

#game-layout {
  display: flex; gap: 18px; width: 100%; max-width: 1060px;
  align-items: flex-start; flex-wrap: wrap; justify-content: center;
}

#board-wrap {
  position: relative;
  width: min(620px, 94vw);
  aspect-ratio: 1;
  flex-shrink: 0;
}
#board {
  display: grid; width: 100%; height: 100%;
  border: 3px solid #3a4370; border-radius: 12px; overflow: hidden;
}
.cell {
  position: relative; display: flex; align-items: flex-start; justify-content: flex-start;
  font-size: clamp(.5rem, 1.6vw, .8rem); color: var(--muted);
}
.cell { background: var(--cell-b); }
.cell.alt { background: var(--cell-a); }
.cell .num { padding: 3px 5px; opacity: .8; }
.cell .icon {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: clamp(.9rem, 3vw, 1.5rem); pointer-events: none;
}
.cell.pu { box-shadow: inset 0 0 0 2px rgba(255,184,77,.35); }
.cell.mystery { box-shadow: inset 0 0 0 2px rgba(167,139,250,.4); }
.cell.ladder { box-shadow: inset 0 0 0 2px rgba(74,222,128,.25); cursor: pointer; }
.cell.chute { box-shadow: inset 0 0 0 2px rgba(251,113,133,.25); cursor: pointer; }
.cell.ladder .icon, .cell.chute .icon { opacity: .9; }
.cell.last { background: linear-gradient(135deg, #3f6d3f, #2b4c2b); }
.cell.last .icon { font-size: clamp(1.1rem, 3.6vw, 1.9rem); }

#board-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; border-radius: 12px;
}
#board-overlay g.transport {
  opacity: 0;
  transition: opacity .3s ease;
}
#board-overlay g.transport.show { opacity: 0.92; }
#board-overlay g.transport.blocked.show { opacity: 0.55; }

#start-zone {
  position: absolute; left: 6px; bottom: -26px;
  color: var(--muted); font-size: .7rem; letter-spacing: .2em;
}

.token {
  position: absolute; width: 9%; aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(1rem, 3.4vw, 1.7rem);
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.6));
  transition: left .35s ease, top .35s ease;
  pointer-events: none; z-index: 5;
}

/* panel */
#panel {
  width: min(380px, 94vw); background: var(--card);
  border: 1px solid #2b3357; border-radius: 14px; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
#players { display: flex; flex-direction: column; gap: 8px; }
.player-chip {
  display: flex; align-items: center; gap: 8px;
  background: #12162a; border: 1px solid #333c66; border-radius: 10px; padding: 8px 12px;
}
.player-chip.active { outline: 2px solid var(--accent); }
.player-chip .dot { font-size: 1.1rem; }
.player-chip .pname { font-weight: 600; flex: 1; text-align: left; }
.player-chip .meta { color: var(--muted); font-size: .8rem; }
.player-chip .pips { color: var(--accent); font-size: .8rem; letter-spacing: .1em; }
.player-chip .bag { opacity: .9; }
.player-chip.disconnected .pname { text-decoration: line-through; color: var(--muted); }

#controls { display: flex; flex-direction: column; gap: 12px; }

#turn-banner { text-align: center; font-weight: 700; min-height: 1.4em; }
#turn-banner.yours { color: var(--green); }

#items-bar { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.item-btn {
  margin-top: 0; font-size: .85rem; padding: 8px 12px;
  background: #221b42; border-color: #4c3a86;
}

#emote-bar { display: flex; gap: 4px; justify-content: center; }
#emote-bar .emote {
  background: transparent; border: none; font-size: 1.3rem; cursor: pointer;
  margin: 0; padding: 2px 6px; transition: transform .08s ease;
}
#emote-bar .emote:active { transform: scale(1.35); }

.emote-float {
  position: absolute; width: 9%; text-align: center;
  font-size: clamp(1.3rem, 4.5vw, 2.1rem); z-index: 6; pointer-events: none;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.6));
  animation: emote-rise 1.5s ease-out forwards;
}
@keyframes emote-rise {
  0% { opacity: 0; transform: translateY(8px) scale(.6); }
  15% { opacity: 1; transform: translateY(0) scale(1.15); }
  100% { opacity: 0; transform: translateY(-70px) scale(1); }
}

#dice-area { display: flex; align-items: center; gap: 14px; }
#die {
  font-size: 3.2rem; line-height: 1; width: 64px; text-align: center;
  user-select: none;
}
#die.rolling { animation: shake .5s infinite; }
@keyframes shake {
  0%,100% { transform: rotate(0); } 25% { transform: rotate(-14deg); } 75% { transform: rotate(14deg); }
}

#log {
  height: 180px; overflow-y: auto; background: #12162a;
  border: 1px solid #333c66; border-radius: 10px; padding: 10px;
  font-size: .85rem; display: flex; flex-direction: column-reverse; gap: 4px;
}
#log p { color: var(--muted); }
#log p.hot { color: var(--text); }

#legend { color: var(--muted); font-size: .85rem; text-align: left; }
#legend summary { cursor: pointer; }
#legend ul { list-style: none; margin: 8px 0; display: flex; flex-direction: column; gap: 4px; }
#legend p { font-size: .8rem; }

/* winner overlay */
#overlay {
  position: fixed; inset: 0; background: rgba(8,10,20,.75);
  display: flex; align-items: center; justify-content: center; z-index: 50;
  backdrop-filter: blur(3px);
}
#overlay .card { text-align: center; }
#rematch-status { color: var(--muted); margin-top: 10px; min-height: 1.2em; }

#recap { margin-top: 14px; }
#recap table { width: 100%; border-collapse: collapse; font-size: .85rem; color: var(--muted); }
#recap th, #recap td { padding: 4px 6px; border-bottom: 1px solid #2b3357; text-align: center; }
#recap th:first-child, #recap td:first-child { text-align: left; }
#recap th { color: var(--text); }
#recap .verdict { margin-top: 10px; font-size: .85rem; color: var(--text); }

/* ---------- phones ---------- */
@media (max-width: 700px) {
  #screen-game {
    /* leave room for the fixed roll bar (+ items/emotes rows) */
    padding-bottom: calc(210px + env(safe-area-inset-bottom));
    justify-content: flex-start;
  }
  #game-layout { gap: 12px; }
  #panel { width: min(620px, 94vw); background: transparent; border: none; padding: 0; }
  #log { height: 130px; }

  /* roll bar pinned to the bottom of the screen, always reachable */
  #controls {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: rgba(20, 24, 45, .96);
    border-top: 1px solid #2b3357;
    padding: 8px 16px calc(10px + env(safe-area-inset-bottom));
    gap: 4px;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
  }
  #turn-banner { font-size: .95rem; }
  #die { font-size: 2.4rem; width: 48px; }
  #dice-area { gap: 10px; }
  .btn.big { padding: 12px 20px; font-size: 1.05rem; }
  #start-zone { display: none; }
}
