:root {
  --p0: #1e3a8a;
  --p1: #9a3412;
  --p2: #14532d;
  --p3: #581c87;

  --active-color: #1e3a8a;
  --active-tint: #dbeafe;
  --ink: #0f172a;
  --ink-soft: #334155;
  --surface: #ffffff;
  --bg: #e2e8f0;
  --border: #94a3b8;
  --border-strong: #334155;

  /* Light space tints (always paired with dark ink) plus a bold strip per group */
  --sip-bg: #fef3c7;
  --sip-band: #f59e0b;
  --sip-ink: #451a03;

  --sweet-bg: #ffe4e6;
  --sweet-band: #e11d48;
  --sweet-ink: #4c0519;

  --trade-bg: #dcfce7;
  --trade-band: #16a34a;
  --trade-ink: #052e16;

  --job-bg: #f3e8ff;
  --job-band: #9333ea;
  --job-ink: #3b0764;

  --shortcut-bg: #e0f2fe;
  --shortcut-band: #0284c7;

  --special-bg: #f8fafc;
  --special-band: #64748b;

  /* The board fills the window height and everything on it scales with --u */
  --bar-h: 58px;
  --board-h: max(540px, calc(100vh - var(--bar-h) - 20px));
  --board-w: min(calc(100vw - 392px), calc(var(--board-h) * 1.45));
  --u: calc(min(var(--board-h), var(--board-w) / 1.25) / 58);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  background-image: radial-gradient(rgba(15, 23, 42, 0.09) 1.5px, transparent 1.6px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.35;
}

.hidden {
  display: none !important;
}

.p0-fill { background-color: var(--p0); color: #ffffff; }
.p1-fill { background-color: var(--p1); color: #ffffff; }
.p2-fill { background-color: var(--p2); color: #ffffff; }
.p3-fill { background-color: var(--p3); color: #ffffff; }

.shape-svg {
  width: 18px;
  height: 18px;
  fill: #ffffff;
  stroke: #000000;
  stroke-width: 1.5;
  flex-shrink: 0;
}

/* Logo made of letter tiles in the four player colors */
.logo-tiles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.14em;
  margin: 0;
  line-height: 1;
}

.logo-tiles span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15em;
  height: 1.3em;
  border: 2px solid var(--ink);
  border-radius: 0.2em;
  box-shadow: 0 0.1em 0 var(--ink);
  color: #ffffff;
  font-weight: 900;
}

.logo-tiles span:nth-child(4n + 1) { background: var(--p0); transform: rotate(-4deg); }
.logo-tiles span:nth-child(4n + 2) { background: var(--p1); transform: rotate(3deg); }
.logo-tiles span:nth-child(4n + 3) { background: var(--p2); transform: rotate(-2deg); }
.logo-tiles span:nth-child(4n + 4) { background: var(--p3); transform: rotate(4deg); }

/* ==================== START SCREEN ==================== */
.start-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.start-card {
  width: 100%;
  max-width: 680px;
  background: var(--surface);
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
}

.brand-header h1 {
  margin: 0 0 10px;
  font-size: 2.4rem;
}

.subtitle {
  margin: 4px 0 16px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.play-mode-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 14px;
}

.play-mode-btn {
  min-height: 46px;
  padding: 7px 9px;
  background: #ffffff;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 10px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 900;
  cursor: pointer;
}

.play-mode-btn:hover {
  background: #f1f5f9;
}

.play-mode-btn.active {
  background: var(--ink);
  color: #ffffff;
  box-shadow: 0 4px 0 #64748b;
}

.quick-rules {
  background: #f1f5f9;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 0.96rem;
  color: var(--ink);
}

.quick-rules p {
  margin: 0;
}

.player-setup h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.count-picker-wrap {
  margin-bottom: 14px;
}

.count-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.count-btn {
  background: #ffffff;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
}

.count-btn:hover {
  background: #f1f5f9;
}

.count-btn.active {
  background: var(--ink);
  color: #ffffff;
}

.setup-hint {
  margin: 7px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.game-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: #fef3c7;
  border: 2px solid #92400e;
  border-radius: 12px;
}

.game-options label {
  display: flex;
  flex-direction: column;
  color: #451a03;
}

.game-options label span {
  font-size: 0.8rem;
  color: #78350f;
}

.cash-input-wrap {
  display: flex;
  align-items: center;
  flex: none;
  overflow: hidden;
  background: #ffffff;
  border: 2px solid #451a03;
  border-radius: 10px;
  box-shadow: 0 3px 0 #451a03;
}

.cash-input-wrap > span {
  padding-left: 10px;
  font-size: 1.25rem;
  font-weight: 900;
  color: #14532d;
}

.cash-input-wrap input {
  width: 76px;
  padding: 6px 8px 6px 3px;
  background: transparent;
  color: #14532d;
  border: 0;
  outline: 0;
  font: inherit;
  font-size: 1.2rem;
  font-weight: 900;
}

.cash-input-wrap:focus-within {
  outline: 3px solid #14532d;
  outline-offset: 2px;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.setup-player {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border: 2px solid var(--border-strong);
  border-radius: 12px;
  background: #f8fafc;
}

.setup-player.slot-off {
  background: #e2e8f0;
  border-style: dashed;
  border-color: #64748b;
}

.setup-player.slot-remote {
  background: #ecfeff;
  border-color: #0e7490;
  border-style: dashed;
}

.setup-player.slot-off input {
  background: #cbd5e1;
  color: #334155;
}

.setup-player.slot-remote input {
  background: #cffafe;
  color: #155e75;
}

.setup-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mode-select {
  padding: 4px 8px;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ink);
  background: #ffffff;
  border: 2px solid var(--ink);
  border-radius: 8px;
  cursor: pointer;
}

.setup-player.p0 { border-color: var(--p0); }
.setup-player.p1 { border-color: var(--p1); }
.setup-player.p2 { border-color: var(--p2); }
.setup-player.p3 { border-color: var(--p3); }

.badge-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 700;
}

.setup-label-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
}

.setup-player input {
  padding: 8px 10px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  background: #ffffff;
  border: 2px solid #64748b;
  border-radius: 8px;
}

.setup-player input:focus {
  outline: 3px solid var(--ink);
  outline-offset: 1px;
}

.start-btn {
  width: 100%;
  font-size: 1.15rem;
  padding: 13px 20px;
}

/* ---------- Online room setup and lobby ---------- */
.online-join {
  display: grid;
  gap: 9px;
  max-width: 410px;
  margin: 0 auto;
  padding: 18px;
  background: #eff6ff;
  border: 3px solid var(--p0);
  border-radius: 14px;
}

.online-join h2,
.online-join p {
  margin: 0;
}

.online-join label,
.add-phone-player label {
  font-size: 0.88rem;
  font-weight: 800;
}

.online-join input,
.add-phone-player input {
  width: 100%;
  padding: 10px 12px;
  color: var(--ink);
  background: #ffffff;
  border: 2px solid #64748b;
  border-radius: 9px;
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
}

#join-code {
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  font-size: 1.4rem;
  font-weight: 900;
}

.online-lobby {
  padding: 18px;
  background:
    radial-gradient(circle at top right, #dbeafe, transparent 42%),
    #ffffff;
  border: 3px solid var(--p0);
  border-radius: 15px;
  box-shadow: 0 7px 0 #0f172a;
}

.lobby-eyebrow {
  display: inline-block;
  margin: 0;
  padding: 3px 10px;
  background: var(--p0);
  color: #ffffff;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.online-lobby h2 {
  margin: 7px 0 3px;
  font-size: 1.8rem;
}

#room-code {
  display: inline-block;
  padding: 2px 9px;
  background: #fef3c7;
  border: 2px solid #92400e;
  border-radius: 8px;
  color: #451a03;
  letter-spacing: 0.12em;
}

.lobby-status {
  margin: 0 0 12px;
  font-weight: 700;
  color: var(--ink-soft);
}

.lobby-seats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.lobby-seat {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 9px;
  background: #f8fafc;
  border: 2px solid #64748b;
  border-left-width: 8px;
  border-radius: 10px;
}

.lobby-seat.p0 { border-left-color: var(--p0); }
.lobby-seat.p1 { border-left-color: var(--p1); }
.lobby-seat.p2 { border-left-color: var(--p2); }
.lobby-seat.p3 { border-left-color: var(--p3); }

.lobby-seat.waiting {
  border-style: dashed;
  background: #fefce8;
}

.lobby-seat.off {
  color: #475569;
  background: #e2e8f0;
}

.lobby-seat .shape-svg {
  width: 22px;
  height: 22px;
}

.lobby-seat-copy {
  min-width: 0;
}

.lobby-seat-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 900;
}

.lobby-seat-note {
  font-size: 0.75rem;
  font-weight: 700;
  color: #475569;
}

.lobby-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 13px;
}

.add-phone-player {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 2px dashed #94a3b8;
}

.add-phone-player > div {
  display: flex;
  gap: 8px;
  margin-top: 5px;
}

.add-phone-player .secondary-btn {
  flex: none;
}

.online-error {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: #991b1b;
  font-size: 0.86rem;
  font-weight: 800;
}

.lobby-leave-btn {
  margin-top: 8px;
  padding: 4px 0;
  background: none;
  color: #475569;
  border: 0;
  text-decoration: underline;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

/* ==================== SHARED BUTTONS ==================== */
.primary-btn {
  background: var(--active-color);
  color: #ffffff;
  border: 2px solid #0f172a;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  flex: 1 1 auto;
  text-align: center;
  box-shadow: 0 4px 0 #0f172a;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}

.primary-btn:hover:not(:disabled) {
  filter: brightness(1.12);
}

.primary-btn:active:not(:disabled),
.secondary-btn:active:not(:disabled) {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #0f172a;
}

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secondary-btn {
  background: #ffffff;
  color: #0f172a;
  border: 2px solid #0f172a;
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 0.95rem;
  font-weight: 800;
  cursor: pointer;
  flex: 1 1 auto;
  box-shadow: 0 4px 0 #0f172a;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}

.secondary-btn:hover:not(:disabled) {
  background: #f1f5f9;
}

.secondary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary-btn:focus-visible,
.secondary-btn:focus-visible,
.helper-btn:focus-visible,
.sell-item-btn:focus-visible,
.count-btn:focus-visible,
.bar-reset-btn:focus-visible {
  outline: 3px solid #0f172a;
  outline-offset: 2px;
}

/* ==================== GAME SCREEN ==================== */
.game-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* The whole table takes a light tint of the current player's color */
  background-color: var(--active-tint);
  background-image: radial-gradient(rgba(15, 23, 42, 0.09) 1.5px, transparent 1.6px);
  background-size: 22px 22px;
  transition: background-color 0.3s ease;
}

.turn-bar {
  min-height: var(--bar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 16px;
  border-bottom: 3px solid #0f172a;
  color: #ffffff;
  transition: background-color 0.25s ease;
}

.turn-bar-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.turn-shape {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  background: rgba(255, 255, 255, 0.16);
  border: 2px solid #ffffff;
  border-radius: 8px;
}

.turn-shape::after,
.pc-badge::after {
  content: attr(data-number);
  position: absolute;
  right: -7px;
  bottom: -6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: #ffffff;
  color: #0f172a;
  border: 2px solid #0f172a;
  border-radius: 50%;
  font-size: 0.68rem;
  line-height: 1;
  font-weight: 900;
}

.turn-shape .shape-svg {
  width: 22px;
  height: 22px;
}

.turn-title {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.turn-bar-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}

.turn-cash {
  font-size: 1.1rem;
  font-weight: 800;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.6);
}

.room-chip {
  padding: 4px 9px;
  background: #fef3c7;
  color: #451a03;
  border: 1px solid #ffffff;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.05em;
}

.bar-reset-btn {
  background: #ffffff;
  color: #0f172a;
  border: 2px solid #0f172a;
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.bar-reset-btn:hover {
  background: #f1f5f9;
}

/* ==================== MAIN LAYOUT ==================== */
.play-layout {
  flex: 1;
  display: grid;
  grid-template-columns: var(--board-w) 340px;
  gap: 12px;
  padding: 10px;
  justify-content: center;
  align-items: start;
}

/* ==================== BOARD ==================== */
.board-wrap {
  position: relative;
  width: var(--board-w);
  height: var(--board-h);
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.08) 0 2px, transparent 2px 18px),
    linear-gradient(135deg, #92400e, #713f12 50%, #a16207);
  border: 5px solid #451a03;
  border-radius: 20px;
  padding: 10px;
  box-shadow:
    inset 0 0 0 4px var(--active-color),
    inset 0 0 0 7px rgba(255, 255, 255, 0.7),
    0 0 0 3px #ffffff,
    0 14px 0 #3f250b,
    0 22px 34px rgba(15, 23, 42, 0.35);
  transition: box-shadow 0.25s ease;
}

.board-grid {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: #475569;
  box-shadow: inset 0 0 12px rgba(15, 23, 42, 0.8);
  /* Every size on the board is in em, so the whole board scales together */
  font-size: clamp(8.5px, var(--u), 17px);
}

/* ---------- Board center: logo, dice, turn controls, drawn card ---------- */
.board-center {
  grid-column: 2 / 6;
  grid-row: 2 / 6;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  position: relative;
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.9) 0 3%, transparent 3.2%),
    radial-gradient(circle at 82% 75%, rgba(255, 255, 255, 0.55) 0 2%, transparent 2.2%),
    repeating-linear-gradient(135deg, transparent 0 12px, rgba(15, 23, 42, 0.025) 12px 14px),
    radial-gradient(circle at 50% 25%, #ffffff 0%, var(--active-tint) 100%);
  border: 3px solid rgba(15, 23, 42, 0.65);
  border-radius: 1em;
  padding: 0.8em 1em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7em;
  text-align: center;
  box-shadow:
    inset 0 0 0 0.35em rgba(255, 255, 255, 0.55),
    inset 0 0 2em rgba(15, 23, 42, 0.12);
  transition: background 0.3s ease;
}

/* Auto margins keep the stack centered but still scrollable if it overflows */
.board-center > :first-child { margin-top: auto; }
.board-center > :last-child { margin-bottom: auto; }

/* While selling, drop the logo and the empty card so the sell list fits */
.board-center:has(.sell-panel:not(.hidden)) .center-title,
.board-center:has(.sell-panel:not(.hidden)) .card-banner.is-empty {
  display: none;
}

.board-center:has(.sell-panel:not(.hidden)) .dice-stage { margin-top: auto; }
.board-center:has(.sell-panel:not(.hidden)) .action-panel { margin-bottom: auto; }

.center-title {
  font-size: 2.3em;
  justify-content: center;
  flex: none;
}

.dice-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55em;
  flex: none;
}

.dice-pair {
  display: flex;
  gap: 1.1em;
  /* It is a button: hold to shake the dice, let go to throw */
  background: linear-gradient(#f8fafc, #cbd5e1);
  border: 2px solid #64748b;
  padding: 0.5em 0.6em 0.7em;
  border-radius: 1.3em;
  box-shadow:
    inset 0 0.2em 0 rgba(255, 255, 255, 0.9),
    0 0.35em 0 #475569,
    0 0.55em 0.8em rgba(15, 23, 42, 0.25);
  font: inherit;
  cursor: default;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.dice-pair:focus-visible {
  outline: 3px solid var(--active-color);
  outline-offset: 2px;
}

.dice-pair.can-roll {
  cursor: grab;
  background: linear-gradient(#ffffff, var(--active-tint));
  border-color: var(--active-color);
}

.dice-pair.can-roll:active {
  cursor: grabbing;
}

/* Dice bob up and down in the player's color when they are ready to be picked up */
.dice-pair.can-roll .die {
  border-color: var(--active-color);
  box-shadow: 0 0.35em 0 var(--active-color);
  animation: diceInvite 0.6s ease-in-out infinite alternate;
}

.dice-pair.can-roll #die-2 {
  animation-delay: 0.3s;
}

.dice-pair.can-pass {
  cursor: pointer;
  background: linear-gradient(135deg, var(--active-color), #0f172a);
  border-color: #ffffff;
  animation: handoffGlow 0.8s ease-in-out infinite alternate;
}

.dice-pair.can-pass .die {
  animation: handoffDice 0.8s ease-in-out infinite alternate;
}

.dice-pair.can-pass #die-2 {
  animation-delay: 0.15s;
}

.dice-pair.can-pass + .dice-caption {
  color: var(--active-color);
  background: #ffffff;
  border: 2px solid var(--active-color);
  border-radius: 999px;
  padding: 0.25em 0.75em;
  box-shadow: 0 0.2em 0 rgba(15, 23, 42, 0.18);
}

@keyframes diceInvite {
  from { transform: translateY(0) rotate(0deg); }
  to { transform: translateY(-0.45em) rotate(-5deg); }
}

@keyframes handoffGlow {
  from { box-shadow: 0 0.35em 0 #0f172a, 0 0 0 0 var(--active-color); }
  to { box-shadow: 0 0.35em 0 #0f172a, 0 0 0 0.45em rgba(255, 255, 255, 0.85); }
}

@keyframes handoffDice {
  from { transform: translateX(-0.25em) rotate(-4deg); }
  to { transform: translateX(0.25em) rotate(4deg); }
}

.die {
  width: 4.6em;
  height: 4.6em;
  background: #ffffff;
  color: var(--ink);
  border: 0.28em solid var(--ink);
  border-radius: 0.9em;
  box-shadow: 0 0.35em 0 var(--ink);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 0.2em;
  padding: 0.5em;
}

.pip {
  border-radius: 50%;
}

.pip.on {
  background: var(--ink);
}

.die-blank {
  grid-area: 1 / 1 / -1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.3em;
  font-weight: 900;
  line-height: 1;
}

.die.rolling {
  animation: dieShake 0.17s linear infinite;
}

#die-2.rolling {
  animation-direction: reverse;
}

@keyframes dieShake {
  0% { transform: translate(0, 0) rotate(0deg); }
  25% { transform: translate(-0.2em, -0.55em) rotate(-14deg); }
  50% { transform: translate(0.2em, 0) rotate(10deg); }
  75% { transform: translate(0.1em, -0.35em) rotate(-6deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

.dice-caption {
  margin: 0;
  font-size: max(11px, 1.15em);
  font-weight: 800;
  color: var(--ink);
}

/* Turn controls sit on the board, framed in the current player's color */
.action-panel {
  width: 100%;
  max-width: 31em;
  flex: none;
  position: relative;
  background:
    linear-gradient(90deg, transparent 0 2.2em, rgba(239, 68, 68, 0.18) 2.2em 2.35em, transparent 2.35em),
    repeating-linear-gradient(#ffffff 0 1.65em, #dbeafe 1.65em 1.72em);
  border: 3px solid var(--active-color);
  border-radius: 0.9em;
  padding: 1.15em 0.8em 0.85em;
  box-shadow:
    0 0.35em 0 var(--active-color),
    0 0.8em 1.2em rgba(15, 23, 42, 0.18);
  transition: border-color 0.25s ease;
}

.action-kind {
  position: absolute;
  top: -0.75em;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--active-color);
  color: #ffffff;
  border: 2px solid #ffffff;
  border-radius: 999px;
  padding: 0.16em 0.9em;
  font-size: max(10px, 1.05em);
  line-height: 1.2;
  font-weight: 900;
  letter-spacing: 0.08em;
  box-shadow: 0 0.2em 0 #0f172a;
}

.phase-card .action-kind,
.phase-cardread .action-kind {
  background: #134e4a;
}

.phase-pay .action-kind {
  background: #9a3412;
}

.phase-done .action-kind {
  background: #14532d;
}

.status-prompt {
  margin: 0 0 0.6em;
  min-height: 2.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: max(15px, 1.4em);
  line-height: 1.25;
  font-weight: 800;
  color: var(--ink);
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6em;
}

.action-panel .primary-btn,
.action-panel .secondary-btn {
  font-size: max(14px, 1.55em);
  padding: 0.42em 0.8em;
}

.helper-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.helper-actions:empty {
  display: none;
}

.helper-btn {
  background: #f8fafc;
  color: #0f172a;
  border: 2px dashed #0f172a;
  border-radius: 8px;
  padding: 0.4em 0.6em;
  font-size: max(12px, 1.25em);
  font-weight: 800;
  cursor: pointer;
}

.helper-btn:hover:not(:disabled) {
  background: #e2e8f0;
}

.helper-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sell-panel {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 2px solid #cbd5e1;
}

.sell-heading {
  margin: 0 0 6px;
  font-size: max(12px, 1.2em);
  font-weight: 800;
  color: var(--ink);
}

.sell-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 7.5rem;
  overflow-y: auto;
}

.sell-item-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex: none;
  background: #fff7ed;
  color: #0f172a;
  border: 2px solid #9a3412;
  border-radius: 8px;
  padding: 0.35em 0.6em;
  font-size: max(12px, 1.2em);
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.sell-item-btn:hover:not(:disabled) {
  background: #ffedd5;
}

.sell-item-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* The drawn card keeps its place when empty so the buttons never jump */
.card-banner {
  position: relative;
  width: 100%;
  max-width: 31em;
  flex: none;
  background: #ffffff;
  border: 2px solid var(--ink);
  border-radius: 0.8em;
  padding: 0.45em 0.8em 0.55em;
  box-shadow: 0 0.3em 0 var(--ink);
  text-align: left;
}

.card-banner.is-empty {
  visibility: hidden;
}

.card-banner.card-flip {
  animation: cardFlip 0.45s ease-out;
}

@keyframes cardFlip {
  0% { transform: rotateX(90deg) scale(0.85); opacity: 0; }
  100% { transform: rotateX(0deg) scale(1); opacity: 1; }
}

.card-deck-tag {
  display: inline-block;
  background: #7c2d12;
  color: #ffffff;
  font-size: max(10px, 0.95em);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1em 0.7em;
  border-radius: 999px;
  margin-bottom: 0.25em;
}

.card-banner.deck-hall .card-deck-tag {
  background: #134e4a;
}

.card-text {
  margin: 0;
  min-height: 2.5em;
  font-size: max(15px, 1.25em);
  line-height: 1.25;
  font-weight: 700;
  color: var(--ink);
}

/* A drawn card waits face down until the player flips it */
.card-banner.face-down {
  background: #7c2d12;
  text-align: center;
  padding: 0.9em 0.8em 1.1em;
  animation: cardWiggle 0.8s ease-in-out infinite;
}

.card-banner.face-down.deck-hall {
  background: #134e4a;
}

.card-banner.face-down.is-tappable {
  cursor: pointer;
}

.card-banner.face-down:focus-visible {
  outline: 3px solid var(--active-color);
  outline-offset: 3px;
}

.card-banner.face-down .card-deck-tag {
  background: #ffffff;
  color: var(--ink);
}

.card-banner.face-down .card-text {
  min-height: 0;
  font-size: max(14px, 1.6em);
  font-weight: 900;
  color: #ffffff;
}

.card-banner.read-card.is-tappable {
  cursor: pointer;
  padding-bottom: 2.25em;
  border-width: 3px;
  box-shadow:
    0 0.35em 0 var(--ink),
    0 0 0 0.35em rgba(255, 255, 255, 0.8),
    0 0 0 0.6em var(--active-color);
}

.card-banner.read-card.is-tappable::after {
  content: "TAP WHEN YOU ARE FINISHED READING";
  position: absolute;
  left: 0.75em;
  right: 0.75em;
  bottom: 0.45em;
  background: var(--active-color);
  color: #ffffff;
  border-radius: 999px;
  padding: 0.18em 0.55em;
  font-size: max(10px, 0.95em);
  font-weight: 900;
  letter-spacing: 0.03em;
  text-align: center;
}

.card-banner.read-card.is-tappable:hover {
  transform: translateY(-0.15em) rotate(-0.5deg);
}

@keyframes cardWiggle {
  0%, 100% { transform: rotate(-1.5deg); }
  50% { transform: rotate(1.5deg) scale(1.04); }
}

/* ---------- Board spaces ---------- */
.space {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--border-strong);
  border-radius: 0.7em;
  background: var(--special-bg);
  color: var(--ink);
  overflow: hidden;
  box-shadow:
    inset 0 0.18em 0 rgba(255, 255, 255, 0.85),
    0 0.28em 0 #1e293b;
  transform: translateY(-0.12em);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.space:hover {
  transform: translateY(-0.28em);
  box-shadow:
    inset 0 0.18em 0 rgba(255, 255, 255, 0.95),
    0 0.42em 0 #1e293b,
    0 0.65em 0.75em rgba(15, 23, 42, 0.25);
  z-index: 5;
}

/* Bold color strip across the top, like a property card */
.space-band {
  flex: none;
  height: 0.9em;
  background: var(--special-band);
  border-bottom: 2px solid var(--border-strong);
}

.space.pair-sip { background: var(--sip-bg); }
.space.pair-sweet { background: var(--sweet-bg); }
.space.pair-trade { background: var(--trade-bg); }
.space.pair-job { background: var(--job-bg); }
.space.type-shortcut,
.space.type-fountain { background: var(--shortcut-bg); }
.space.deck-hallpass { background: #f0fdfa; }
.space.deck-backpack { background: #fff7ed; }

.pair-sip .space-band { background: var(--sip-band); }
.pair-sweet .space-band { background: var(--sweet-band); }
.pair-trade .space-band { background: var(--trade-band); }
.pair-job .space-band { background: var(--job-band); }
.type-shortcut .space-band,
.type-fountain .space-band { background: var(--shortcut-band); }
.deck-hallpass .space-band { background: #0f766e; }
.deck-backpack .space-band { background: #c2410c; }

.space.type-corner {
  background: #ffffff;
  border-width: 3px;
  border-color: var(--ink);
}

.type-corner .space-band {
  background: var(--ink);
  border-bottom-color: var(--ink);
}

/* Owned spaces are framed in the owner's color */
.space.owned {
  border-color: var(--owner-color, var(--ink));
  border-width: max(3px, 0.32em);
}

/* The space the current player is standing on */
.space.active-space {
  outline: max(3px, 0.3em) solid var(--active-color);
  outline-offset: 0.12em;
  z-index: 3;
  filter: saturate(1.15);
}

/* A spot the current player can buy: tap the spot itself */
.space.buyable {
  cursor: pointer;
  z-index: 4;
  animation: buyPulse 0.7s ease-in-out infinite alternate;
}

.space.buyable::after {
  content: "TAP TO BUY";
  position: absolute;
  right: 0.3em;
  bottom: 0.3em;
  background: var(--active-color);
  color: #ffffff;
  font-size: max(10px, 1.1em);
  font-weight: 900;
  letter-spacing: 0.03em;
  padding: 0.15em 0.55em;
  border-radius: 999px;
  border: 2px solid #ffffff;
}

.space.buyable:focus-visible {
  outline-style: dashed;
}

@keyframes buyPulse {
  from { transform: scale(1); box-shadow: 0 0 0 0 var(--active-color); }
  to { transform: scale(1.07); box-shadow: 0 0 0 0.45em var(--active-color); }
}

/* Stamp effect right after a spot is bought */
.space.just-bought {
  z-index: 4;
  animation: stampPop 0.5s ease-out;
}

@keyframes stampPop {
  0% { transform: scale(1.3) rotate(-6deg); }
  60% { transform: scale(0.95) rotate(2deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.space-body {
  flex: 1;
  min-height: 0;
  padding: 0.25em 0.4em 2.35em;
}

.space-icon {
  float: right;
  width: 2.4em;
  height: 2.4em;
  margin: 0 0 0.1em 0.2em;
}

.space-icon svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: #ffffff;
  stroke: var(--ink);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.space-icon svg .ln { fill: none; }
.space-icon svg .ink { fill: var(--ink); stroke: none; }

.space-name {
  font-size: 1.2em;
  line-height: 1.12;
  font-weight: 800;
  color: var(--ink);
}

.space-meta {
  clear: both;
  margin-top: 0.1em;
  font-size: 1.05em;
  line-height: 1.2;
  font-weight: 700;
  color: var(--ink-soft);
}

.owner-slot {
  clear: both;
}

.owner-pill {
  display: flex;
  align-items: center;
  gap: 0.3em;
  margin-top: 0.15em;
  padding: 0.12em 0.45em;
  border-radius: 999px;
  font-size: 1em;
  line-height: 1.25;
  font-weight: 800;
  color: #ffffff;
}

.owner-pill .shape-svg {
  width: 1em;
  height: 1em;
}

.owner-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.owner-fee {
  flex: none;
  margin-left: auto;
  white-space: nowrap;
}

.helper-tag {
  position: absolute;
  top: 0.1em;
  right: 0.25em;
  z-index: 1;
  background: #0f172a;
  color: #ffffff;
  border: 1px solid #ffffff;
  border-radius: 0.4em;
  padding: 0 0.35em;
  font-size: max(8px, 0.85em);
  line-height: 1.3;
  font-weight: 800;
  letter-spacing: 0.03em;
}

/* ---------- Tokens ---------- */
.token-tray {
  position: absolute;
  left: 0.35em;
  bottom: 0.3em;
  display: flex;
  align-items: center;
  gap: 0.2em;
}

.token {
  position: relative;
  flex: none;
  width: 2.65em;
  height: 2.65em;
  border-radius: 50%;
  border: 0.25em solid #ffffff;
  outline: 0.16em solid var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    inset 0 0.25em 0 rgba(255, 255, 255, 0.9),
    0 0.18em 0 #0f172a,
    0 0.32em 0.4em rgba(0, 0, 0, 0.4);
}

.token .token-svg {
  width: 68%;
  height: 68%;
  fill: #ffffff !important;
  stroke: #000000;
  stroke-width: 2.5;
}

.token.p0-token { background: var(--p0); }
.token.p1-token { background: var(--p1); }
.token.p2-token { background: var(--p2); }
.token.p3-token { background: var(--p3); }

.token::before {
  content: attr(data-number);
  position: absolute;
  top: -0.65em;
  right: -0.65em;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.35em;
  height: 1.35em;
  background: #ffffff;
  color: #0f172a;
  border: 0.15em solid #0f172a;
  border-radius: 50%;
  font-size: max(9px, 0.85em);
  line-height: 1;
  font-weight: 900;
}

.token.active-token {
  z-index: 2;
  box-shadow:
    inset 0 0.25em 0 rgba(255, 255, 255, 0.9),
    0 0 0 0.2em #ffffff,
    0 0 0 0.38em var(--active-color),
    0 0.42em 0.5em rgba(0, 0, 0, 0.45);
  animation: tokenPulse 1.2s ease-in-out infinite;
}

.token.hop {
  animation: tokenHop 0.23s ease-out;
}

.token.in-timeout::after {
  content: "T";
  position: absolute;
  bottom: -0.3em;
  right: -0.65em;
  width: 1.2em;
  height: 1.2em;
  background: #0f172a;
  color: #ffffff;
  font-size: 0.75em;
  font-weight: 900;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

@keyframes tokenPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.14); }
}

@keyframes tokenHop {
  0% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-55%) scale(1.2); }
  100% { transform: translateY(0) scale(1); }
}

/* ==================== SIDE PANEL ==================== */
.side-panel {
  height: var(--board-h);
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.players-section {
  flex: none;
}

.player-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 3px;
}

/* Cards never fade: every player's cash stays easy to read */
.player-card {
  background: #f1f5f9;
  border: 2px solid #64748b;
  border-left-width: 10px;
  border-radius: 10px;
  padding: 8px 10px;
}

.player-card.p0-card { border-left-color: var(--p0); }
.player-card.p1-card { border-left-color: var(--p1); }
.player-card.p2-card { border-left-color: var(--p2); }
.player-card.p3-card { border-left-color: var(--p3); }

.player-card.active-card {
  background: #ffffff;
  border-width: 3px;
  border-left-width: 10px;
  box-shadow: 0 0 0 3px #ffffff, 0 6px 14px rgba(15, 23, 42, 0.28);
}

.player-card.p0-card.active-card { border-color: var(--p0); }
.player-card.p1-card.active-card { border-color: var(--p1); }
.player-card.p2-card.active-card { border-color: var(--p2); }
.player-card.p3-card.active-card { border-color: var(--p3); }

.player-card.out-card {
  background: #e2e8f0;
  border-style: dashed;
}

.player-card.out-card .pc-name {
  text-decoration: line-through;
}

.pc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pc-identity {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.pc-badge {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  flex-shrink: 0;
}

.pc-name {
  font-weight: 800;
  font-size: 1rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pc-bot-tag {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 6px;
  background: #e2e8f0;
  color: #0f172a;
  border: 1px solid #475569;
}

.pc-turn-tag {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
}

.pc-cash {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--ink);
}

.pc-status {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-top: 3px;
}

.pc-props {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.pc-prop-chip {
  font-size: 0.72rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 5px;
  border: 1px solid #475569;
  color: var(--ink);
  background: #ffffff;
}

.pc-prop-chip.sip { background: var(--sip-bg); color: var(--sip-ink); }
.pc-prop-chip.sweet { background: var(--sweet-bg); color: var(--sweet-ink); }
.pc-prop-chip.trade { background: var(--trade-bg); color: var(--trade-ink); }
.pc-prop-chip.job { background: var(--job-bg); color: var(--job-ink); }
.pc-prop-chip.shortcut,
.pc-prop-chip.fountain { background: var(--shortcut-bg); color: var(--ink); }

/* Money gained or lost pops up beside the player's cash */
.cash-pop {
  position: fixed;
  z-index: 60;
  padding: 2px 9px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  font-size: 1.05rem;
  font-weight: 900;
  color: #ffffff;
  pointer-events: none;
  animation: cashPop 1.3s ease-out forwards;
}

.cash-pop.gain { background: #14532d; }
.cash-pop.loss { background: #991b1b; }

@keyframes cashPop {
  0% { transform: translateY(8px) scale(0.6); opacity: 0; }
  15% { transform: translateY(0) scale(1.15); opacity: 1; }
  70% { transform: translateY(-16px) scale(1); opacity: 1; }
  100% { transform: translateY(-28px) scale(1); opacity: 0; }
}

/* ==================== GAME LOG ==================== */
.log-section {
  flex: 1;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 2px solid #64748b;
  border-radius: 10px;
  padding: 8px 12px;
}

.log-heading {
  margin: 0 0 6px;
  flex: none;
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}

.game-log {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.game-log li {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink);
  padding-bottom: 4px;
  border-bottom: 1px solid #e2e8f0;
}

.game-log li:first-child {
  font-weight: 800;
}

/* ==================== WINNER MODAL ==================== */
.winner-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.winner-card {
  position: relative;
  z-index: 1;
  background: #ffffff;
  border: 4px solid #0f172a;
  border-radius: 16px;
  padding: 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.35);
}

.winner-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.95rem;
  margin-bottom: 12px;
}

.winner-card h2 {
  margin: 0 0 8px;
  font-size: 2rem;
  color: var(--ink);
}

.winner-message {
  margin: 0 0 20px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.confetti i {
  position: absolute;
  top: -24px;
  width: 10px;
  height: 16px;
  border: 1px solid #ffffff;
  border-radius: 2px;
  animation: confettiFall 3s linear infinite;
}

@keyframes confettiFall {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(110vh) rotate(720deg); }
}

/* ==================== SMALLER WINDOWS ==================== */
/* Board on top, players and log underneath */
@media (max-width: 980px) {
  :root {
    --board-w: calc(100vw - 40px);
    --board-h: max(540px, min(calc(var(--board-w) * 0.95), calc(100vh - var(--bar-h) - 20px)));
  }

  .play-layout {
    grid-template-columns: var(--board-w);
  }

  .side-panel {
    height: auto;
    overflow-y: visible;
  }

  .player-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-log {
    max-height: 170px;
  }
}

@media (max-width: 700px) {
  :root {
    --bar-h: 86px;
  }

  .turn-bar {
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    padding: 6px 10px;
  }

  .turn-bar-main,
  .turn-bar-meta {
    width: 100%;
    justify-content: center;
  }

  .turn-title {
    font-size: 1rem;
    white-space: nowrap;
  }

  .turn-bar-meta {
    gap: 6px;
  }

  .turn-cash,
  .bar-reset-btn {
    font-size: 0.78rem;
    padding: 3px 8px;
  }

  .turn-shape {
    width: 28px;
    height: 28px;
  }

  .token-tray {
    gap: 0;
  }

  .token + .token {
    margin-left: -0.35em;
  }

  /* Narrow spaces: the owner's shape and color are enough, drop the name */
  .owner-name {
    display: none;
  }

  .space.buyable::after {
    content: "BUY";
  }
}

/* Spaces get too narrow for a picture beside the name */
@media (max-width: 620px) {
  .space-icon {
    display: none;
  }
}

/* Phones: keep the board readable and let it scroll sideways */
@media (max-width: 560px) {
  :root {
    --board-w: 520px;
    --board-h: 540px;
  }

  .setup-grid {
    grid-template-columns: 1fr;
  }

  .count-picker {
    grid-template-columns: repeat(2, 1fr);
  }

  .play-mode-picker {
    grid-template-columns: 1fr;
  }

  .play-mode-btn {
    min-height: 38px;
  }

  .lobby-seats {
    grid-template-columns: 1fr;
  }

  .add-phone-player > div {
    flex-direction: column;
  }

  .add-phone-player .secondary-btn {
    width: 100%;
  }

  .play-layout {
    display: block;
    overflow-x: auto;
  }

  .side-panel {
    width: var(--board-w);
    margin-top: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
}
