:root {
  --felt: #12372a;
  --felt-light: #1b4d3a;
  --ivory: #f4ecd8;
  --ivory-edge: #d9cdb0;
  --ink: #1d2b24;
  --gold: #d9a441;
  --tile-red: #c0392b;
  --tile-black: #23282b;
  --tile-yellow: #b8860b;
  --tile-blue: #1f6fb2;

  --pad: 8px;
  --gap: 4px;
  /* Nine columns over two rows: 18 slots for at most 15 tiles, so there are
     always gaps free to shuffle groups around. */
  --rack-cols: 9;
  --tile-w: calc((min(100vw, 560px) - 2 * var(--pad) - 2 * var(--gap) - (var(--rack-cols) - 1) * var(--gap)) / var(--rack-cols));
  --tile-h: calc(var(--tile-w) * 1.4);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: radial-gradient(circle at 50% 30%, var(--felt-light), var(--felt) 70%);
  color: var(--ivory);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  -webkit-user-select: none;
  user-select: none;
}

.hidden {
  display: none !important;
}

.muted {
  color: #b9cbc1;
}
.small {
  font-size: 13px;
}
.error {
  color: #ff9f9f;
  min-height: 18px;
  font-size: 13px;
}

/* ---------- join / lobby ---------- */

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: var(--pad);
}

.card {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 18px;
  margin-top: 12vh;
}

.card h1 {
  margin: 0 0 4px;
  font-size: 34px;
  letter-spacing: 2px;
  color: var(--gold);
}

.card h2 {
  margin: 0 0 12px;
}

label {
  display: block;
  margin: 14px 0 4px;
  font-size: 13px;
  color: #b9cbc1;
}

input {
  width: 100%;
  padding: 12px;
  font-size: 16px; /* keeps iOS from zooming on focus */
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ivory);
}

button {
  font: inherit;
  color: var(--ivory);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 10px;
  padding: 11px 14px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.4;
}

button.primary {
  width: 100%;
  margin-top: 18px;
  background: var(--gold);
  border-color: var(--gold);
  color: #2a1e06;
  font-weight: 700;
}

.seats {
  display: grid;
  gap: 8px;
}

.seats button {
  text-align: left;
  padding: 14px;
}

.seats button .who {
  display: block;
  font-size: 13px;
  color: #b9cbc1;
}

/* ---------- HUD ---------- */

.hud {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  font-size: 13px;
}

.hud .badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 999px;
  padding: 4px 10px;
}

.hud .spacer {
  flex: 1;
}

/* ---------- table ---------- */

.table {
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  grid-template-rows: auto auto auto;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.seat {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 6px;
  min-height: 62px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.seat.top {
  grid-column: 2;
  grid-row: 1;
}
.seat.left {
  grid-column: 1;
  grid-row: 2;
}
.seat.right {
  grid-column: 3;
  grid-row: 2;
}
.seat.me {
  grid-column: 2;
  grid-row: 3;
}
.center {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.seat.active {
  border-color: var(--gold);
  box-shadow: 0 0 12px rgba(217, 164, 65, 0.35);
}

.seat.offline .name {
  opacity: 0.45;
}

.seat .row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: space-between;
}

.seat .name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seat .score {
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  font-weight: 700;
  font-size: 13px;
}

.seat .meta {
  font-size: 11px;
  color: #a9bdb3;
}

.pile-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.pile-stack .count {
  font-size: 11px;
  color: #a9bdb3;
}

.takeable {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 6px;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    outline-color: rgba(217, 164, 65, 0.35);
  }
}

.facedown {
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 6px;
  background: linear-gradient(160deg, #245c45, #17402f);
  border: 1px solid rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.5);
  font-size: 11px;
}

.empty-slot {
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 6px;
  border: 1px dashed rgba(255, 255, 255, 0.18);
}

/* ---------- tiles ---------- */

.tile {
  position: relative;
  width: var(--tile-w);
  height: var(--tile-h);
  border-radius: 6px;
  background: linear-gradient(170deg, #fffaf0 0%, var(--ivory) 55%, var(--ivory-edge) 100%);
  border: 1px solid #b9ac8d;
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.16), 0 1px 2px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: calc(var(--tile-w) * 0.62);
  line-height: 1;
  color: var(--ink);
  touch-action: none;
}

.tile[data-color="0"] {
  color: var(--tile-red);
}
.tile[data-color="1"] {
  color: var(--tile-black);
}
.tile[data-color="2"] {
  color: var(--tile-yellow);
}
.tile[data-color="3"] {
  color: var(--tile-blue);
}

.tile.fake {
  color: var(--tile-black);
  font-size: calc(var(--tile-w) * 0.6);
}

.tile .wild-badge {
  position: absolute;
  top: 1px;
  right: 2px;
  font-size: calc(var(--tile-w) * 0.3);
  color: var(--gold);
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.5);
}

.tile.small {
  --tile-w: 26px;
  font-size: 16px;
}

.tile.selected {
  transform: translateY(-8px);
  box-shadow: 0 0 0 2px var(--gold), 0 6px 10px rgba(0, 0, 0, 0.45);
}

.tile.winning {
  box-shadow: 0 0 0 2px #6fdc8c, 0 4px 8px rgba(0, 0, 0, 0.4);
}

.tile.dragging {
  opacity: 0.25;
}

.drag-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}

.drag-layer .tile {
  position: absolute;
  transform: scale(1.15);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.5);
}

/* ---------- rack ---------- */

.rack {
  display: grid;
  grid-template-columns: repeat(var(--rack-cols), 1fr);
  gap: var(--gap);
  padding: var(--gap);
  background: linear-gradient(180deg, #6b4a2c, #4a3220);
  border: 1px solid #35240f;
  border-radius: 10px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.45);
}

.slot {
  height: var(--tile-h);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
}

.slot.drop-target {
  background: rgba(217, 164, 65, 0.35);
}

.slot .tile {
  width: 100%;
}

/* ---------- prompt + actions ---------- */

.prompt {
  min-height: 22px;
  text-align: center;
  font-size: 13px;
  padding: 2px 0 6px;
  color: var(--gold);
}

.prompt.waiting {
  color: #a9bdb3;
}

.actions {
  display: flex;
  gap: 6px;
  padding: 8px 0;
  flex-wrap: wrap;
}

.actions button {
  flex: 1 1 auto;
  min-width: 78px;
  font-size: 13px;
  padding: 12px 8px;
}

.actions button.go {
  background: #2e7d4f;
  border-color: #46a06c;
  font-weight: 700;
}

.actions button.win {
  background: var(--gold);
  border-color: #f0c674;
  color: #2a1e06;
  font-weight: 800;
}

/* ---------- log ---------- */

.log-panel {
  background: rgba(0, 0, 0, 0.22);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  margin-bottom: 12px;
}

.log-panel summary {
  cursor: pointer;
  color: #b9cbc1;
}

.log-panel ol {
  margin: 8px 0 0;
  padding-left: 18px;
  max-height: 30vh;
  overflow-y: auto;
}

.log-panel li {
  margin-bottom: 4px;
  color: #cfe0d7;
}

/* ---------- overlay ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 18, 12, 0.9);
  z-index: 50;
  overflow-y: auto;
  padding: 20px 12px;
}

.overlay .panel {
  max-width: 520px;
  margin: 0 auto;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  padding: 16px;
}

.overlay h2 {
  margin: 0 0 4px;
  color: var(--gold);
}

.group-row {
  display: flex;
  gap: 3px;
  margin: 6px 0;
  flex-wrap: wrap;
}

.hand-row {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  margin: 4px 0 10px;
}

.standings {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 14px;
}

.standings td {
  padding: 5px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.standings td:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  font-weight: 700;
}

/* ---------- connection banner ---------- */

.connection {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 70;
  text-align: center;
  padding: 6px;
  font-size: 13px;
  background: #8a3b2f;
  color: #fff;
}
