* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, Arial, sans-serif;
  background: #ffffff;
  color: #0b1324;
}

.game-wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
}

.hero {
  text-align: center;
  margin-bottom: 24px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(2rem, 5vw, 3.5rem);
  color: #2f6efb;
}

.hero p {
  margin: 0;
  color: #56607a;
}

.mode-panel {
  margin-bottom: 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.mode-field {
  display: grid;
  gap: 6px;
}

.mode-field span {
  font-size: 0.84rem;
  color: #56607a;
}

.mode-field select {
  border: 1px solid #d6def0;
  border-radius: 10px;
  padding: 8px 10px;
  background: #ffffff;
  color: #0b1324;
}

.toggle-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: #56607a;
  font-size: 0.92rem;
}

.toggle-field input {
  width: 16px;
  height: 16px;
}

.name-panel {
  margin-bottom: 18px;
}

.online-box {
  margin-bottom: 18px;
}

.online-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  flex-wrap: wrap;
}

.online-head h2 {
  margin: 0;
}

.online-subtitle {
  margin: 8px 0 0;
  color: #56607a;
  max-width: 620px;
}

.online-status {
  margin: 0;
  font-size: 0.92rem;
  color: #1e4fbe;
  font-weight: 700;
}

.online-status.error {
  color: #b42318;
}

.online-grid {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) auto minmax(180px, 240px) auto;
  gap: 12px;
  align-items: end;
  margin-top: 14px;
}

.online-grid-secondary {
  grid-template-columns: minmax(240px, 1fr) auto;
}

.online-grid input {
  border: 1px solid #d6def0;
  border-radius: 10px;
  padding: 9px 10px;
  background: #ffffff;
  color: #0b1324;
}

.online-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

#onlineStartRoomBtn[hidden] {
  display: none;
}

.online-room-meta {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 16px;
  color: #56607a;
}

.online-room-players {
  margin-top: 14px;
}

.online-room-players strong {
  display: block;
  margin-bottom: 8px;
}

.online-players-list {
  margin: 0;
  padding-left: 18px;
  color: #0b1324;
}

.online-players-list li {
  margin: 4px 0;
}

.online-host-badge,
.online-self-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
}

.online-host-badge {
  background: #edf3ff;
  color: #1e4fbe;
}

.online-self-badge {
  background: #ecfdf5;
  color: #047857;
}

.leaderboard-box {
  margin-bottom: 18px;
}

.leaderboard-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.leaderboard-head h2 {
  margin: 0;
}

.leaderboard-tabs {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.lb-tab {
  border: 1px solid #d6def0;
  background: #ffffff;
  color: #0b1324;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
}

.lb-tab.active {
  background: #edf3ff;
  border-color: #2f6efb;
  color: #1e4fbe;
}

.leaderboard-status {
  margin: 0;
  color: #56607a;
  font-size: 0.92rem;
}

.leaderboard-wrap {
  margin-top: 12px;
  overflow-x: auto;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  border: 1px solid #e6e8ee;
  border-radius: 12px;
  overflow: hidden;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 10px 10px;
  text-align: left;
  border-bottom: 1px solid #eef1f6;
  white-space: nowrap;
}

.leaderboard-table th {
  color: #56607a;
  font-weight: 700;
  font-size: 0.9rem;
  background: #f8fafc;
}

.leaderboard-table tbody tr:last-child td {
  border-bottom: none;
}

.leaderboard-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-start;
}

.leaderboard-row-new td {
  background: #edf3ff;
  font-weight: 700;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 19, 36, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  background: #ffffff;
  border-radius: 16px;
  padding: 28px 32px;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(11, 19, 36, 0.18);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-box h3 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-box p {
  margin: 0;
  color: #56607a;
  font-size: 0.95rem;
}

.modal-box input[type="text"] {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d6def0;
  border-radius: 8px;
  font-size: 1rem;
  box-sizing: border-box;
}

.modal-box input[type="text"]:focus {
  outline: none;
  border-color: #2f6efb;
  box-shadow: 0 0 0 3px rgba(47, 110, 251, 0.15);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

.player-names {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.player-name-field {
  display: grid;
  gap: 6px;
}

.player-name-field label {
  font-size: 0.84rem;
  color: #56607a;
}

.player-name-field input {
  border: 1px solid #d6def0;
  border-radius: 10px;
  padding: 9px 10px;
  background: #ffffff;
  color: #0b1324;
}

.score-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.player-chip {
  background: #ffffff;
  border: 1px solid #e6e8ee;
  border-radius: 16px;
  padding: 14px;
  text-align: center;
}

.player-chip strong {
  font-size: 1.8rem;
}

.player-chip span {
  display: block;
  font-size: 0.85rem;
  color: #56607a;
}

.player-chip.active {
  border-color: #2f6efb;
  box-shadow: 0 0 0 3px rgba(47, 110, 251, 0.12);
}

.player-chip-tokens {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: #d97706;
  font-weight: 700;
  margin-top: 4px;
}

.token-btn {
  background: #fffbeb;
  border: 1.5px solid #f59e0b;
  color: #92400e;
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s;
}

.token-btn:hover:not(:disabled) {
  background: #fef3c7;
}

.token-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.dice-zones {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 18px;
}

.dice-zone {
  border: 1px solid #e6e8ee;
  border-radius: 12px;
  padding: 10px;
  background: #f8fafc;
}

.dice-zone h3 {
  margin: 0 0 8px;
  font-size: 0.86rem;
  color: #56607a;
  font-weight: 700;
}

.dice-area {
  display: grid;
  grid-template-columns: repeat(var(--dice-columns, 6), minmax(56px, 1fr));
  gap: 12px;
}

.dice-placeholder {
  grid-column: 1 / -1;
  border: 1px dashed #cbd5ea;
  border-radius: 10px;
  padding: 12px;
  color: #56607a;
  background: #ffffff;
  text-align: center;
  font-size: 0.92rem;
}

.die {
  aspect-ratio: 1;
  border-radius: 12px;
  border: none;
  background: transparent;
  font-size: 2rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s;
  user-select: none;
}

.die:hover {
  transform: none;
}

.die-svg {
  width: 100%;
  height: 100%;
  max-width: 56px;
  max-height: 56px;
}

@keyframes diceRoll {
  0% {
    transform: rotateX(0deg) rotateY(0deg);
  }
  100% {
    transform: rotateX(720deg) rotateY(720deg);
  }
}

.die-svg.rolling {
  animation: diceRoll 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.dice-preview-row {
  display: contents;
}

.die-preview {
  cursor: default;
  opacity: 0.6;
}

.die-preview .die-shape {
  fill: #f2f5fb;
  stroke: #cfd8ea;
}

.die-preview .pip {
  fill: #6f7f9c;
}

.die-shape {
  fill: #ffffff;
  stroke: #c7ceda;
  stroke-width: 2;
}

.die .pip {
  fill: #1f2937;
}

.die.held .die-shape {
  fill: #edf3ff;
  stroke: #2f6efb;
  stroke-width: 2.5;
}

.die.held .die-svg {
  filter: drop-shadow(0 2px 8px rgba(47, 110, 251, 0.28));
}

button {
  border: 1px solid #e6e8ee;
  border-radius: 999px;
  padding: 13px 22px;
  font-weight: 800;
  cursor: pointer;
  background: #ffffff;
  color: #0b1324;
}

button:hover:not(:disabled) {
  filter: brightness(0.98);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#rollBtn {
  background: #2f6efb;
  border-color: #2f6efb;
  color: #ffffff;
}

button.secondary {
  background: #ffffff;
}

#scorecard-container {
  margin-top: 18px;
}

.scorecard {
  width: 100%;
  border-collapse: collapse;
  background: #ffffff;
  border: 1px solid #e6e8ee;
  border-radius: 12px;
  overflow: hidden;
}

.scorecard th,
.scorecard td {
  border-bottom: 1px solid #eef1f6;
  padding: 10px;
  text-align: left;
}

.scorecard th {
  color: #56607a;
  font-weight: 700;
  font-size: 0.9rem;
  background: #f8fafc;
}

.scorecard .filled {
  background: #edf3ff;
  font-weight: 700;
}

.scorecard .preview {

  .bonus-row td {
    background: #fffbeb;
    color: #92400e;
    font-size: 0.88rem;
    border-top: 2px solid #f59e0b;
    border-bottom: 2px solid #f59e0b;
  }

  .bonus-row.bonus-achieved td {
    background: #ecfdf5;
    color: #065f46;
    border-color: #34d399;
    font-weight: 700;
  }

  .bonus-status {
    font-size: 0.82rem;
    color: inherit;
  }

  .bonus-toast {
    position: fixed;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    animation: toast-in 0.35s ease;
  }

  .bonus-toast[hidden] {
    display: none;
  }

  .bonus-toast-inner {
    display: flex;
    align-items: center;
    gap: 14px;
    background: #ffffff;
    border: 1.5px solid #34d399;
    border-radius: 16px;
    padding: 16px 22px;
    box-shadow: 0 8px 32px rgba(11, 19, 36, 0.16);
    min-width: 260px;
    max-width: 90vw;
  }

  .bonus-toast-emoji {
    font-size: 2rem;
    line-height: 1;
  }

  .bonus-toast-inner strong {
    display: block;
    font-size: 1rem;
    color: #065f46;
  }

  .bonus-toast-inner p {
    margin: 2px 0 0;
    font-size: 0.88rem;
    color: #56607a;
  }

  @keyframes toast-in {
    from { opacity: 0; transform: translateX(-50%) translateY(16px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
  }
  color: #56607a;
}

.score-action {
  padding: 8px 14px;
  font-size: 14px;
}

.totals {
  margin-top: 12px;
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.totals span {
  background: #f8fafc;
  border: 1px solid #e6e8ee;
  border-radius: 999px;
  padding: 8px 12px;
  color: #56607a;
  font-weight: 700;
}

.table {
  background: #ffffff;
  border: 1px solid #e6e8ee;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 6px 30px rgba(7, 14, 30, 0.06);
}

.message {
  background: #f8fafc;
  border: 1px solid #e6e8ee;
  border-radius: 14px;
  padding: 14px;
  text-align: center;
  margin-bottom: 20px;
  font-weight: 700;
}

.controls {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.rules-box {
  margin-top: 24px;
  background: #ffffff;
  border-radius: 18px;
  padding: 20px;
  border: 1px solid #e6e8ee;
}

.rules-box h2 {
  margin-top: 0;
}

@media (max-width: 760px) {
  .game-wrap {
    padding: 16px;
  }

  #dice-container {
    grid-template-columns: repeat(3, minmax(56px, 1fr));
    gap: 10px;
  }

  #held-dice-container {
    grid-template-columns: repeat(3, minmax(56px, 1fr));
    gap: 10px;
  }

  .die {
    width: 56px;
    height: 56px;
    font-size: 1.4rem;
  }

  .table {
    padding: 16px;
  }

  .online-grid,
  .online-grid-secondary {
    grid-template-columns: 1fr;
  }

  .controls {
    gap: 8px;
  }

  button {
    padding: 10px 16px;
    font-size: 0.9rem;
  }

  .scorecard th,
  .scorecard td {
    padding: 8px 10px;
    font-size: 0.88rem;
  }

  .leaderboard-table th,
  .leaderboard-table td {
    padding: 8px 10px;
    font-size: 0.88rem;
  }

  .rules-box {
    margin-top: 16px;
    padding: 16px;
  }
}

.player-chip-lastmove {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
  color: #1e4fbe;
  font-weight: 700;
}

.scorecard tr.recent-choice td {
  background: #fff8e6;
}