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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #111827, #020617);
  color: #e5e7eb;
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 1.5rem;
}

.app-shell {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}

.app-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.app-header h1 {
  font-size: 2.5rem;
  letter-spacing: 0.08em;
}

.tagline {
  margin-top: 0.4rem;
  font-size: 0.95rem;
  color: #9ca3af;
}

.card {
  background: rgba(15, 23, 42, 0.9);
  border-radius: 16px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(148, 163, 184, 0.4);
}

.hidden {
  display: none !important;
}

/* Lobby */

#lobby {
  max-width: 540px;
  margin: 0 auto;
}

#lobby h2 {
  font-size: 1.4rem;
  margin-bottom: 1rem;
}

.lobby-highscores {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(148, 163, 184, 0.25);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.highscores-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.highscores-header h3 {
  font-size: 1.1rem;
}

.highscores-subtitle {
  font-size: 0.8rem;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.highscores-empty {
  font-size: 0.9rem;
  color: #9ca3af;
}

.highscores-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-left: 0;
}

.high-score-row {
  display: grid;
  grid-template-columns: 0.6fr 1.6fr 0.8fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(2, 6, 23, 0.6);
}

.high-score-rank {
  font-weight: 700;
  color: #38bdf8;
}

.high-score-name {
  font-weight: 600;
}

.high-score-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.form-row label {
  font-size: 0.85rem;
  color: #9ca3af;
}

.form-row input,
.form-row select {
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  border: 1px solid #4b5563;
  background: rgba(15, 23, 42, 0.9);
  color: #e5e7eb;
  outline: none;
}

.form-row input:focus,
.form-row select:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.45);
}

.button-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.button-row-centered {
  justify-content: center;
}

button {
  cursor: pointer;
  border-radius: 999px;
  border: none;
  padding: 0.6rem 1.2rem;
  font-weight: 600;
  font-size: 0.95rem;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
}

button.primary {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #052e16;
  box-shadow: 0 10px 20px rgba(22, 163, 74, 0.5);
}

button.primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(22, 163, 74, 0.65);
}

button.secondary {
  background: rgba(15, 23, 42, 0.95);
  color: #e5e7eb;
  border: 1px solid #4b5563;
}

button.secondary:hover {
  background: rgba(31, 41, 55, 0.95);
}

.icon-button {
  padding: 0.3rem 0.65rem;
  font-size: 1rem;
  line-height: 1;
}

button:active {
  transform: translateY(0);
  box-shadow: none;
}

.error-msg {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: #f97373;
}

/* Game layout */

.game-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.top-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.pot-card {
  flex: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.status-card {
  flex: 1.5;
}

.share-card {
  flex: 1;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.share-text {
  font-size: 0.9rem;
  color: #cbd5f5;
}

.share-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.share-actions button {
  width: 100%;
}

.share-status {
  min-height: 1.2rem;
  font-size: 0.85rem;
  color: #9ca3af;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.card-title {
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.8rem;
  color: #9ca3af;
}

/* Pot & phase visuals */

.pot-value {
  font-size: 3.2rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: center;
  margin-bottom: 0.75rem;
}

.phase-badge {
  text-align: center;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  display: inline-block;
  margin: 0 auto;
}

/* Phase styles */
.phase-safe {
  background: rgba(22, 163, 74, 0.18);
  border: 1px solid rgba(34, 197, 94, 0.9);
  color: #bbf7d0;
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.4);
}

.phase-danger {
  background: rgba(220, 38, 38, 0.18);
  border: 1px solid rgba(248, 113, 113, 0.9);
  color: #fecaca;
  box-shadow: 0 0 16px rgba(248, 113, 113, 0.55);
}

.pot-bust {
  border-color: rgba(248, 113, 113, 0.9);
  box-shadow: 0 0 30px rgba(248, 113, 113, 0.5);
  animation: pot-bust-pulse 0.5s ease-in-out 4;
}

.pot-bust .pot-value {
  color: #fecaca;
}

@keyframes pot-bust-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
}

/* Status card */

.status-line {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
}

.status-line .label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #9ca3af;
}

/* Mid row */

.mid-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1.5fr);
  gap: 1rem;
}

.players-card {
  max-height: 320px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.players-list {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.player-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr 0.8fr;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid transparent;
  font-size: 0.9rem;
}

.player-name {
  font-weight: 600;
}

.player-score {
  text-align: right;
}

.player-banked-tag {
  justify-self: end;
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.45);
}

.player-current {
  border-color: #22c55e;
  box-shadow: 0 0 12px rgba(34, 197, 94, 0.55);
}

/* Dice */

.dice-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.dice-display {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin: 0.75rem 0;
}

.dice {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  border: 2px solid #4b5563;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  background: radial-gradient(circle at 20% 20%, #1f2937, #020617);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.45);
}

.dice-card.dice-rolling {
  border-color: rgba(148, 163, 184, 0.75);
  box-shadow: 0 0 24px rgba(148, 163, 184, 0.4), 0 18px 40px rgba(0, 0, 0, 0.4);
}

.dice-card.dice-rolling .dice {
  animation: dice-roll 0.6s ease-in-out infinite;
  border-color: rgba(148, 163, 184, 0.9);
}

.roll-summary {
  font-size: 0.9rem;
  color: #e5e7eb;
  text-align: center;
}

.dice-card.double-flash {
  animation: doubleFlash 2.6s ease-in-out;
  border-color: rgba(34, 197, 94, 0.9);
  box-shadow: 0 0 30px rgba(34, 197, 94, 0.6), 0 18px 40px rgba(0, 0, 0, 0.4);
}

.dice-card.double-flash .dice {
  border-color: rgba(34, 197, 94, 0.9);
  box-shadow: 0 0 18px rgba(34, 197, 94, 0.7);
}

.roll-summary.double-text {
  color: #bbf7d0;
  text-shadow: 0 0 12px rgba(34, 197, 94, 0.85);
  font-weight: 700;
}

@keyframes doubleFlash {
  0% {
    background: rgba(22, 163, 74, 0.15);
  }
  20% {
    background: rgba(34, 197, 94, 0.45);
  }
  40% {
    background: rgba(22, 163, 74, 0.2);
  }
  60% {
    background: rgba(34, 197, 94, 0.45);
  }
  80% {
    background: rgba(22, 163, 74, 0.2);
  }
  100% {
    background: rgba(15, 23, 42, 0.9);
  }
}

@keyframes dice-roll {
  0% {
    transform: rotate(0deg) scale(1);
  }
  25% {
    transform: rotate(8deg) scale(1.04);
  }
  50% {
    transform: rotate(-8deg) scale(0.98);
  }
  75% {
    transform: rotate(6deg) scale(1.03);
  }
  100% {
    transform: rotate(0deg) scale(1);
  }
}

/* Bottom row */

.bottom-row {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.bank-btn {
  min-width: 180px;
  font-size: 1.05rem;
}

.voice-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.voice-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.push-to-talk {
  min-width: 160px;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

.floating-ptt {
  position: fixed;
  right: calc(1.5rem + env(safe-area-inset-right));
  bottom: calc(1.5rem + env(safe-area-inset-bottom));
  z-index: 20;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.35);
}

.push-to-talk.ptt-active {
  background: linear-gradient(135deg, #38bdf8, #0ea5e9);
  color: #0c4a6e;
  border: none;
  box-shadow: 0 10px 20px rgba(14, 165, 233, 0.4);
}

.push-to-talk:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.voice-status {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.9rem;
  color: #e5e7eb;
}

.voice-hint {
  font-size: 0.8rem;
  color: #9ca3af;
}

.remote-audio {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.game-message {
  margin-top: 0.75rem;
  text-align: center;
  font-size: 0.9rem;
  color: #facc15;
}

/* Game over highlight */

.game-over {
  color: #fbbf24;
  font-weight: 600;
}

/* QR modal */

.qr-modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 50;
}

.qr-dialog {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  text-align: center;
}

.qr-dialog .card-header {
  width: 100%;
}

.qr-image {
  width: 220px;
  height: 220px;
  align-self: center;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: #fff;
  padding: 0.5rem;
}

/* How to play modal */

.how-to-modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 55;
}

.how-to-dialog {
  width: min(520px, 100%);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.how-to-content {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  font-size: 0.95rem;
  color: #e2e8f0;
}

.how-to-content ul {
  padding-left: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  color: #cbd5f5;
}

.how-to-content strong {
  color: #e5e7eb;
}

@media (min-width: 720px) {
  .share-actions {
    flex-direction: row;
  }

  .share-actions button {
    width: auto;
    flex: 1;
  }
}

/* Responsive tweaks */

@media (max-width: 800px) {
  body {
    padding: 0.75rem;
  }

  .app-header h1 {
    font-size: 2rem;
  }

  .top-row,
  .mid-row {
    display: contents;
  }

  .pot-card {
    order: 1;
  }

  .dice-card {
    order: 2;
  }

  .bottom-row {
    order: 3;
  }

  .status-card {
    order: 4;
  }

  .players-card {
    order: 5;
  }

  .share-card {
    order: 6;
  }

  .voice-card {
    order: 7;
  }

  .game-message {
    order: 8;
  }

  .players-card {
    max-height: 260px;
  }

  .pot-value {
    font-size: 2.6rem;
  }
}
