:root {
  --bg: #120a24;
  --bg2: #1c1038;
  --card: #241640;
  --pink: #ff4f9a;
  --purple: #8b5cf6;
  --yellow: #ffd23f;
  --green: #35d68a;
  --red: #ff5c5c;
  --text: #f4eeff;
  --muted: #b3a6d4;
  --radius: 18px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%);
  color: var(--text);
  font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}
.screen.hidden { display: none; }

.home-wrap, .identity-wrap, .lobby-wrap, .finished-wrap {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.logo {
  font-size: 2.4rem;
  font-weight: 800;
  margin: 0 0 6px;
  letter-spacing: -0.5px;
}
.logo span { color: var(--pink); }

.tagline { color: var(--muted); margin-bottom: 32px; }

.btn {
  border: none;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
  color: var(--text);
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: linear-gradient(135deg, var(--pink), var(--purple)); }
.btn-secondary { background: var(--card); border: 1px solid #3a2a63; }
.btn-ghost { background: transparent; border: 1px solid #3a2a63; color: var(--muted); }
.btn-lg { width: 100%; padding: 16px; font-size: 1.05rem; margin-top: 10px; }
.btn-sm { padding: 8px 16px; font-size: 0.85rem; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.divider { display: flex; align-items: center; color: var(--muted); margin: 18px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: #3a2a63; }
.divider span { padding: 0 10px; font-size: 0.85rem; }

.join-code-form { display: flex; gap: 8px; }
.join-code-form input {
  flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 3px; text-align: center;
}

input[type="text"] {
  width: 100%;
  background: var(--card);
  border: 1px solid #3a2a63;
  border-radius: 12px;
  padding: 14px;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 14px;
}
input[type="text"]:focus { outline: 2px solid var(--purple); }

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

#identity-code { color: var(--yellow); }

.avatar-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 18px 0;
}
.avatar-opt {
  font-size: 1.8rem;
  background: var(--card);
  border: 2px solid #3a2a63;
  border-radius: 14px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.avatar-opt.selected { border-color: var(--pink); background: #3a1d4f; }
.avatar-opt.taken { opacity: 0.25; cursor: not-allowed; }

.share-box { margin-bottom: 24px; }
.code-pill {
  display: inline-block;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 6px;
  background: var(--card);
  border: 2px dashed var(--yellow);
  border-radius: 14px;
  padding: 10px 22px;
  margin: 10px 0;
  color: var(--yellow);
}

.player-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 20px 0;
}
.player-chip {
  background: var(--card);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 90px;
}
.player-chip .avatar { font-size: 1.6rem; }
.player-chip .pname { font-size: 0.85rem; font-weight: 600; }
.player-chip.offline { opacity: 0.45; }
.player-chip .host-tag { color: var(--yellow); font-size: 0.65rem; display: block; }

.game-wrap { width: 100%; max-width: 520px; }
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.round-badge {
  background: var(--card);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  color: var(--muted);
}
.reader-badge {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 700;
  flex: 1;
  text-align: center;
}
.btn-end-icon {
  background: var(--card);
  border: 1px solid #3a2a63;
  color: var(--muted);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn-end-icon.hidden { display: none; }

.board-wrap {
  position: relative;
  margin-bottom: 14px;
}
.board {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  grid-template-rows: repeat(9, 1fr);
  gap: 3px;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,.08) 0 2px, transparent 2px 26px),
    repeating-linear-gradient(90deg, rgba(0,0,0,.08) 0 2px, transparent 2px 26px),
    radial-gradient(ellipse at center, #a4181f 0%, #840f16 55%, #5e0a0f 100%);
  border: 3px solid #3d0608;
  border-radius: 14px;
  padding: 6px;
  aspect-ratio: 13 / 9;
  position: relative;
  transition: filter .5s ease;
}
.board.blurred { filter: blur(7px) brightness(0.7); }

.board-emblem {
  position: absolute;
  left: 7.8%;
  right: 7.8%;
  top: 11.5%;
  bottom: 11.5%;
  background-image: url('img/board-center.jpg');
  background-size: cover;
  background-position: center;
  border-radius: 10px;
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.45), 0 2px 10px rgba(0,0,0,.4);
  z-index: 0;
}

.cell {
  position: relative;
  z-index: 1;
  background: #f4efe2;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.35);
}
.cell.finish { background: linear-gradient(135deg, var(--yellow), #ffb23f); }
.cell .cell-num {
  font-size: 0.65rem;
  font-weight: 800;
  font-style: italic;
  color: #201010;
  line-height: 1;
}
.cell.finish .cell-num { color: #3d1600; }
.token {
  position: absolute;
  font-size: 0.95rem;
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.6));
  transition: left .9s cubic-bezier(.34,1.3,.64,1), top .9s cubic-bezier(.34,1.3,.64,1);
  transform: translate(-50%, -50%);
  z-index: 2;
}
.token.stayed { animation: shake .5s ease; }
@keyframes shake {
  0%, 100% { transform: translate(-50%, -50%); }
  25% { transform: translate(-60%, -50%); }
  75% { transform: translate(-40%, -50%); }
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  z-index: 5;
}
.overlay.hidden { display: none; }
.overlay-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.55);
  border: 1px solid #3a2a63;
}
.overlay-card.hidden { display: none; }

.announce-card { text-align: center; }
.announce-avatar { font-size: 3.2rem; margin-bottom: 6px; }
.announce-title { font-size: 1.4rem; margin: 0 0 4px; }

.card-face {
  position: relative;
  background-image: linear-gradient(rgba(10, 2, 4, .32), rgba(10, 2, 4, .4)), url('img/card-bomb.jpg');
  background-size: cover;
  background-position: 22% 38%;
  background-repeat: no-repeat;
  border: 2px solid #3d0608;
  border-radius: 14px;
  padding: 20px 18px;
  margin-bottom: 10px;
  min-height: 140px;
  display: flex;
  align-items: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}
.card-text {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.4;
  margin: 0;
  color: #fff;
  text-shadow: 0 2px 5px rgba(0, 0, 0, .65);
}
.card-instruction {
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--yellow);
  margin: 0 0 10px;
}

.options { display: flex; flex-direction: column; gap: 8px; }
.option-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border: 2px solid #3a2a63;
  border-radius: 12px;
  padding: 12px 14px;
  text-align: left;
  color: var(--text);
  font-size: 0.95rem;
  cursor: pointer;
}
.option-btn .letter {
  flex: 0 0 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--purple);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.85rem;
}
.option-btn.chosen { border-color: var(--pink); background: #3a1d4f; }
.option-btn:disabled { opacity: 0.55; }

.timer-box {
  display: flex;
  justify-content: center;
  margin: 12px 0 4px;
}
.timer-box.hidden { display: none; }
.timer-num {
  min-width: 64px;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 800;
  padding: 6px 16px;
  border-radius: 999px;
  background: #1c3a2a;
  color: var(--green);
  border: 2px solid var(--green);
  transition: all .3s ease;
}
.timer-num.warn { background: #3a3417; color: var(--yellow); border-color: var(--yellow); }
.timer-num.danger { background: #3a1717; color: var(--red); border-color: var(--red); animation: pulse .7s infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); } }

.vote-status { text-align: center; color: var(--muted); margin-top: 12px; font-size: 0.9rem; }

.reveal-panel { text-align: center; }
.reveal-answer {
  background: #16351f;
  border: 2px solid var(--green);
  border-radius: 12px;
  padding: 12px;
  font-weight: 700;
  margin-bottom: 14px;
}
.reveal-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.reveal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg2);
  border-radius: 10px;
  padding: 8px 12px;
  text-align: left;
}
.reveal-row.match { border: 2px solid var(--green); }
.reveal-row.nomatch { border: 2px solid var(--red); opacity: 0.85; }
.reveal-row .rname { flex: 1; font-size: 0.9rem; font-weight: 600; }
.reveal-row .rchoice { font-weight: 800; }
.reveal-row .rmove { color: var(--green); font-size: 0.85rem; }
.reveal-row .rfail { color: var(--red); font-size: 0.85rem; }

.win-title { font-size: 1.8rem; }
.win-title span { color: var(--yellow); }
#finished-win.hidden, #finished-ended.hidden { display: none; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--purple);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 50;
}
.toast.hidden { display: none; }

@media (min-width: 540px) {
  .board { max-width: 520px; margin: 0 auto 14px; }
}
