:root {
  --felt: #0f2a20;
  --felt-deep: #0a1d16;
  --felt-line: rgba(255, 255, 255, 0.09);
  --ink: #f4f1e8;
  --ink-dim: rgba(244, 241, 232, 0.62);
  --ink-faint: rgba(244, 241, 232, 0.34);
  --gold: #e0b658;
  --red: #d5372f;
  --card-face: #faf7ef;
  --card-ink: #16181c;
  --card-back: #1f4d63;
  --radius: 14px;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.42);
  --tap: 44px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(120% 90% at 50% 0%, #17402f 0%, var(--felt) 46%, var(--felt-deep) 100%) fixed;
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

[x-cloak] {
  display: none !important;
}

button,
input {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

/*
 * The table is a fixed viewport: the topbar, seats and tray hold their natural
 * height and only the board in the middle scrolls. Without pinning the height
 * the tray gets flex-shrunk and clips the hand off the bottom of the screen.
 */
.screen.room {
  height: 100dvh;
  overflow: hidden;
}

.topbar,
.opponents,
.tray {
  flex: 0 0 auto;
}

/* ------------------------------------------------------------------ buttons */

.btn {
  border: 1px solid var(--felt-line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  border-radius: 999px;
  padding: 0 18px;
  min-height: var(--tap);
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.btn.primary {
  background: linear-gradient(180deg, #e8c470, var(--gold));
  border-color: transparent;
  color: #2a1d05;
}

.btn.ghost {
  background: transparent;
}

.btn.big {
  width: 100%;
  min-height: 50px;
  font-size: 1.05rem;
}

.btn.small {
  min-height: 36px;
  padding: 0 13px;
  font-size: 0.85rem;
}

/* ------------------------------------------------------------------ home */

.home {
  justify-content: center;
  align-items: center;
  padding: 28px;
  overflow-y: auto;
}

.home-inner {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.brand {
  margin: 0;
  font-size: 2rem;
  text-align: center;
  letter-spacing: -0.02em;
}

.pip {
  color: var(--gold);
}

.pip.red {
  color: var(--red);
}

.tagline {
  margin: -8px 0 12px;
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.95rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  font-size: 0.82rem;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--felt-line);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: 54px;
  outline: none;
}

input:focus {
  border-color: var(--gold);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink-faint);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--felt-line);
}

.join-row {
  display: flex;
  gap: 10px;
}

.code-input {
  /* min-width:0 or the input's intrinsic size shoves the Join button off screen. */
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
}

.join-row .btn {
  flex: 0 0 auto;
  width: auto;
  padding: 0 24px;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--felt-line);
}

.code-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0;
  background: none;
  border: 0;
  padding: 4px 6px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
}

.code-chip.copied {
  background: rgba(224, 182, 88, 0.16);
}

.code-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
}

.code-value {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--gold);
  line-height: 1.1;
}

.code-hint {
  font-size: 0.62rem;
  color: var(--ink-faint);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-chip {
  font-size: 0.78rem;
  color: var(--ink-dim);
  border: 1px solid var(--felt-line);
  border-radius: 999px;
  padding: 4px 10px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-faint);
}

.status-dot.online {
  background: #4ad07f;
}

.status-dot.connecting {
  background: var(--gold);
  animation: pulse 1s ease-in-out infinite;
}

.status-dot.offline {
  background: var(--red);
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

/* ------------------------------------------------------------------ seats */

.opponents {
  display: flex;
  gap: 8px;
  /* Extra bottom room so the ask badge hanging off a seat is not clipped. */
  padding: 8px 12px 14px;
  /* "safe" keeps the first seat reachable once the row overflows and scrolls. */
  justify-content: safe center;
  overflow-x: auto;
  scrollbar-width: none;
}

.opponents::-webkit-scrollbar {
  display: none;
}

.seat {
  position: relative;
  flex: 0 0 auto;
  min-width: 84px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--felt-line);
  background: rgba(255, 255, 255, 0.05);
  cursor: default;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.1s ease;
}

.seat.active {
  border-color: var(--gold);
  background: rgba(224, 182, 88, 0.12);
}

.seat.askable {
  border-color: #4ad07f;
  background: rgba(74, 208, 127, 0.14);
  cursor: pointer;
}

.seat.askable:active {
  transform: scale(0.96);
}

.seat.done {
  opacity: 0.45;
}

.seat.offline .avatar {
  filter: grayscale(1);
  opacity: 0.6;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #2f6b52, #1d4638);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.avatar.small {
  width: 26px;
  height: 26px;
  font-size: 0.68rem;
}

.seat-name {
  font-size: 0.82rem;
  font-weight: 600;
  max-width: 84px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-count {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--ink-dim);
}

.mini-card {
  width: 9px;
  height: 13px;
  border-radius: 2px;
  background: var(--card-back);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.seat-note {
  font-size: 0.65rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  min-height: 0.9em;
}

.ask-badge {
  position: absolute;
  bottom: -11px;
  font-size: 0.6rem;
  background: #4ad07f;
  color: #08281a;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ board */

.board {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  /*
   * "safe" matters here: with plain centring, content taller than the board
   * overflows equally in both directions and the top half becomes unreachable,
   * which hides the round counter on short screens during a war.
   */
  justify-content: safe center;
  padding: 8px 14px 12px;
  min-height: 0;
  overflow-y: auto;
}

.prompt {
  margin: 0;
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.92rem;
}

/* lobby */

.lobby {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
}

.lobby h2 {
  margin: 0;
  font-size: 1.1rem;
  text-align: center;
  color: var(--ink-dim);
  font-weight: 600;
}

.lobby-players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lobby-players li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--felt-line);
}

.tag {
  margin-left: auto;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold);
  border: 1px solid rgba(224, 182, 88, 0.4);
  border-radius: 999px;
  padding: 2px 8px;
}

.tag.you {
  color: var(--ink-dim);
  border-color: var(--felt-line);
  margin-left: 0;
}

.host-controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.choice-row {
  display: flex;
  gap: 8px;
}

.choice {
  flex: 1;
  min-height: var(--tap);
  border-radius: 12px;
  border: 1px solid var(--felt-line);
  background: rgba(255, 255, 255, 0.05);
  font-weight: 600;
  cursor: pointer;
}

.choice.small {
  min-height: 38px;
  font-size: 0.82rem;
  font-weight: 500;
}

.choice.on {
  border-color: var(--gold);
  background: rgba(224, 182, 88, 0.16);
  color: var(--gold);
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

/* ------------------------------------------------------------------ cards */

.card {
  position: relative;
  width: 58px;
  height: 82px;
  border-radius: 8px;
  background: var(--card-face);
  color: var(--card-ink);
  border: 1px solid rgba(0, 0, 0, 0.18);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
}

.card.red {
  color: var(--red);
}

.card .corner {
  position: absolute;
  top: 4px;
  left: 5px;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
}

.card .corner.bottom {
  top: auto;
  left: auto;
  bottom: 4px;
  right: 5px;
  transform: rotate(180deg);
}

.card .suit {
  font-size: 1.7rem;
  line-height: 1;
}

.card.back {
  background: repeating-linear-gradient(
      45deg,
      var(--card-back) 0 5px,
      #2a6480 5px 10px
    );
  border-color: rgba(255, 255, 255, 0.2);
}

.card.back.big {
  width: 72px;
  height: 102px;
}

.card.back.tiny {
  width: 26px;
  height: 38px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.card.slot {
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.18);
  box-shadow: none;
}

/* ------------------------------------------------------------------ war */

.war-table {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.round-line {
  display: flex;
  gap: 14px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
}

.pot {
  color: var(--gold);
}

.war-seats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

/* Five or six players only fit on one row at a narrower card. */
.war-seats.crowded {
  gap: 10px;
}

.war-seats.crowded .card {
  width: 46px;
  height: 66px;
}

.war-seats.crowded .card .suit {
  font-size: 1.35rem;
}

.war-seats.crowded .card .corner {
  font-size: 0.68rem;
}

.war-seats.crowded .war-seat {
  padding: 4px;
}

.war-seats.crowded .war-seat-name {
  font-size: 0.7rem;
  max-width: 56px;
}

.war-seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: border-color 0.25s ease, background 0.25s ease;
}

.war-seat.winner {
  border-color: var(--gold);
  background: rgba(224, 182, 88, 0.12);
}

.war-seat.atwar {
  border-color: var(--red);
  background: rgba(213, 55, 47, 0.14);
}

.burn-stack {
  display: flex;
  margin-bottom: -6px;
}

.burn-stack .card.back.tiny + .card.back.tiny {
  margin-left: -18px;
}

.card.played {
  animation: flip-in 0.24s ease-out;
}

@keyframes flip-in {
  from {
    transform: rotateY(80deg) translateY(-6px);
    opacity: 0.2;
  }
}

.war-seat-name {
  font-size: 0.78rem;
  color: var(--ink-dim);
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.war-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* ------------------------------------------------------------------ go fish */

.fish-table {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.pool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.pool-count {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

.books {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 420px;
}

.books-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

.book-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
}

.book-owner {
  color: var(--ink-dim);
  min-width: 76px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-pips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.pip-book {
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--card-face);
  color: var(--card-ink);
  font-size: 0.72rem;
  font-weight: 800;
}

.fish-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* ------------------------------------------------------------------ gin rummy */

.gin-table {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  width: 100%;
  max-width: 420px;
}

.gin-piles {
  display: flex;
  gap: 24px;
}

.pile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.pile:disabled {
  cursor: default;
}

.pile:disabled .card {
  opacity: 0.55;
}

.pile-count {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-faint);
}

.gin-reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.gin-hand-reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}

.meld-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.meld-group {
  display: flex;
  gap: 3px;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--felt-line);
}

.meld-group.deadwood-group {
  border-style: dashed;
  opacity: 0.75;
}

.card.mini {
  width: 32px;
  height: 46px;
  border-radius: 5px;
}

.card.mini .corner {
  font-size: 0.6rem;
  top: 2px;
  left: 3px;
}

.card.mini .suit {
  font-size: 1rem;
}

.deadwood-label {
  font-size: 0.78rem;
  color: var(--ink-dim);
}

.gin-status {
  display: flex;
  justify-content: center;
}

.gin-actions {
  display: flex;
  gap: 8px;
}

.gin-actions .btn {
  flex: 1;
}

/* ------------------------------------------------------------------ tray */

.tray {
  border-top: 1px solid var(--felt-line);
  background: rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
  padding: 10px 0 max(12px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tray-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
}

.tray-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 6px;
}

.count {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.72rem;
  letter-spacing: 0;
}

.tray-tools {
  display: flex;
  gap: 6px;
}

.hand-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  /* Top padding has to clear the lift on a selected card, or it gets clipped. */
  padding: 22px 14px 6px;
}

.hand-scroll::-webkit-scrollbar {
  display: none;
}

.hand {
  display: flex;
  align-items: flex-end;
  min-height: 104px;
  padding-right: 14px;
}

.hand-card {
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.hand-card + .hand-card {
  margin-left: -22px;
}

.hand-card.selected {
  transform: translateY(-18px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.55), 0 0 0 3px var(--gold);
  z-index: 2;
}

.hand-card.dim {
  opacity: 0.55;
}

.empty-hand {
  color: var(--ink-faint);
  font-size: 0.9rem;
  margin: 0;
}

.deck-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}

.deck {
  position: relative;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.deck:disabled {
  opacity: 0.5;
  cursor: default;
}

.deck-count {
  position: absolute;
  inset: auto 0 -6px 0;
  margin: 0 auto;
  width: fit-content;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.75rem;
  font-weight: 700;
}

.deck-hint {
  font-size: 0.78rem;
  color: var(--ink-faint);
}

.tray-action {
  padding: 0 14px;
}

.hint {
  margin: 0;
  text-align: center;
  font-size: 0.88rem;
  color: var(--ink-dim);
  min-height: 1.4em;
}

.red {
  color: var(--red);
}

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

.log-sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}

.log-panel {
  width: 100%;
  max-height: 62dvh;
  background: var(--felt-deep);
  border-top: 1px solid var(--felt-line);
  border-radius: 18px 18px 0 0;
  padding: 14px 16px max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
}

.log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--felt-deep);
  padding-bottom: 8px;
}

.log-head h3 {
  margin: 0;
  font-size: 0.95rem;
}

.log-panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.log-panel li {
  font-size: 0.88rem;
  color: var(--ink-dim);
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.04);
}

.log-panel li:first-child {
  color: var(--ink);
  background: rgba(224, 182, 88, 0.12);
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #2a1010;
  border: 1px solid rgba(213, 55, 47, 0.6);
  color: var(--ink);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  z-index: 40;
  max-width: min(92vw, 420px);
  text-align: center;
}

@media (min-width: 700px) {
  .card {
    width: 66px;
    height: 94px;
  }

  .hand-card + .hand-card {
    margin-left: -16px;
  }
}
