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

html {
  width: 100%;
  font-size: 100%;
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Oxygen,
    Ubuntu,
    Cantarell,
    "Open Sans",
    "Helvetica Neue",
    sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #f7ede2;
  color: #011627;
  min-height: 75vh;
  overflow-x: hidden;
}
@media screen and (max-width: 992px) {
  main.content {
    width: 100vw;
  }
}

main.content {
  width: 60rem;
  max-width: 100vw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

a { color: inherit; }

/* Spades */
#spades {
  width: 100%;
  max-width: 40rem;
  margin-top: 1rem;
  text-align: center;
  box-sizing: border-box;
  padding: 0 0.5rem;
  touch-action: manipulation;
}

.spades-game {
  width: 100%;
  overflow: visible;
}

/* Menu */
.spades-menu {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}
.spades-menu-btn {
  background: #011627;
  color: #f7ede2;
  border: none;
  padding: 0.75rem 1.5rem;
  cursor: pointer;
  font-size: 1rem;
  font-family: inherit;
  border-radius: 3px;
  width: 14rem;
}
.spades-menu-btn:hover,
.spades-menu-btn:active {
  opacity: 0.85;
}
.spades-menu-label {
  font-weight: bold;
  margin: 0;
}
.spades-quickplay-timers {
  display: flex;
  gap: 0.5rem;
  width: 14rem;
}
.spades-quickplay-timers .spades-menu-btn {
  width: 100%;
  padding: 0.75rem 0;
}
.quickplay-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.queue-count {
  font-size: 0.7rem;
  color: #999;
  margin-top: 0.2rem;
}

.spades-btn {
  background: #011627;
  color: #f7ede2;
  border: none;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  border-radius: 3px;
}
.spades-btn:hover,
.spades-btn:active {
  opacity: 0.85;
}

.spades-status {
  font-style: italic;
  margin: 1rem 0;
}

.spades-scores {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 1.5rem;
}
.spades-score-team {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.spades-scores-center {
  font-style: italic;
  color: #666;
  text-align: center;
}

/* Card containers */
.card-container {
  position: relative;
  overflow: visible;
}
.hand-container {
  display: flex;
  justify-content: center;
  gap: 2px;
  padding: 4px;
  width: 100%;
  min-height: 3.5rem;
  margin: 0.5rem 0;
}
.opp-container {
  height: 50px;
  width: 100%;
  overflow: hidden;
}
.seat-west .opp-container,
.seat-east .opp-container {
  height: 50px;
  width: 100%;
}
.trick-container {
  width: 100%;
  min-height: 80px;
  font-style: normal;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  position: relative;
}

/* Base card styling */
.card {
  border-radius: 5px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-family: inherit;
  overflow: hidden;
  box-sizing: border-box;
}

/* Cards in player hand (flex children) */
.hand-container .card {
  position: relative;
  width: 46px;
  height: 64px;
  flex-shrink: 1;
  font-size: 0.8rem;
  cursor: grab;
}

/* Cards in trick area (always 4 slots: W/N/E/S) */
.trick-container .card {
  width: 46px;
  height: 64px;
  font-size: 0.8rem;
  pointer-events: none;
  flex-shrink: 0;
}

/* Empty trick slot placeholder */
.trick-container .trick-placeholder {
  background: transparent;
  border: 1px dashed rgba(255, 255, 255, 0.12);
  box-shadow: none;
}

/* Opponent cards (absolute positioned, stacked) */
.opp-container .card {
  position: absolute;
  width: 30px;
  height: 42px;
  left: calc(50% - 15px);
  top: calc(50% - 21px);
  font-size: 0.6rem;
}

/* Card colors */
.card-red { color: #c33; }
.card-black { color: #011627; }

/* Card back (face-down) */
.card-back {
  background: linear-gradient(135deg, #1a3a5c 25%, #1e4d7a 25%, #1e4d7a 50%, #1a3a5c 50%, #1a3a5c 75%, #1e4d7a 75%);
  background-size: 8px 8px;
  border: 2px solid #fff;
  box-sizing: border-box;
}

/* Drag interaction */
.card.dragging {
  position: fixed;
  z-index: 200;
  opacity: 0.85;
  cursor: grabbing;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}
.card.card-will-play {
  transform: scale(1.08);
  box-shadow: 0 0 12px rgba(42,119,42,0.5);
}
.card-placeholder {
  visibility: hidden;
}

/* Card interaction styles */
.cm-clickable {
  cursor: grab !important;
}
.cm-invalid {
  cursor: default !important;
  pointer-events: none;
}

.spades-bets {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.3rem;
  margin: 1rem 0;
  justify-content: center;
}
.spades-bet {
  flex: 1 1 0;
  min-width: 0;
  min-height: 2.5rem;
}

.spades-trick-area {
  border: 1px dashed #011627;
  border-radius: 3px;
  padding: 0.75rem;
  text-align: center;
  font-style: italic;
  color: #666;
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: 0.3rem;
  position: relative;
}

/* Table layout */
.spades-table {
  display: grid;
  grid-template-areas:
    ".     north  ."
    "west  center east"
    ".     south  .";
  grid-template-columns: minmax(0, 1fr) minmax(0, 2.5fr) minmax(0, 1fr);
  grid-template-rows: minmax(6rem, auto) 1fr minmax(7rem, auto);
  width: 100%;
  min-height: 16rem;
  margin: 1rem 0;
  overflow: visible;
}
.spades-seat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.25rem;
  overflow: visible;
  min-width: 0;
}
.spades-seat-label {
  font-weight: bold;
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  position: relative;
  z-index: 10;
}
.spades-seat-info {
  font-size: 0.75rem;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  position: relative;
  z-index: 10;
}
.conn-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  margin-right: 0.15rem;
  vertical-align: middle;
}
.conn-on { background: #2a7; }
.conn-off { background: #bbb; }
.spades-seat.active .spades-seat-label {
  color: #2a7;
}
.spades-seat.active .spades-seat-label::after {
  content: " \25C0";
}
.seat-north { grid-area: north; }
.seat-south { grid-area: south; }
.seat-west  { grid-area: west; }
.seat-east  { grid-area: east; }
.spades-table-center {
  grid-area: center;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
.spades-table-center .spades-trick-area {
  width: 100%;
  min-height: 5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Mobile: scores + table */
@media screen and (max-width: 480px) {
  .spades-scores {
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 0.75rem;
  }
  .spades-score-team {
    flex-direction: row;
    gap: 0.5rem;
    align-items: center;
  }
  .spades-table {
    grid-template-columns: minmax(0, 1fr) minmax(0, 3fr) minmax(0, 1fr);
    grid-template-rows: minmax(4.5rem, auto) 1fr minmax(5.5rem, auto);
    min-height: 10rem;
  }
  .spades-table-center .spades-trick-area {
    min-height: 4rem;
  }
  .spades-seat {
    padding: 0.15rem;
  }
  .spades-seat-label {
    font-size: 0.7rem;
  }
  .spades-seat-info {
    font-size: 0.65rem;
  }
  .opp-container {
    height: 45px;
  }
  .seat-west .opp-container,
  .seat-east .opp-container {
    height: 45px;
  }
  /* Bet buttons: single row */
  .spades-bets {
    gap: 0.2rem;
  }
  .spades-bet {
    padding: 0.45rem 0;
  }
  .spades-clock {
    font-size: 0.7rem;
    min-width: 2.5rem;
  }
  /* Menu & form containers: prevent edge overflow */
  .spades-menu-btn {
    width: 100%;
    max-width: 14rem;
  }
  .spades-quickplay-timers {
    width: 100%;
    max-width: 14rem;
  }
  .points-group,
  .seat-grid,
  .share-link {
    max-width: 100%;
  }
}

/* Ultra-small phones (iPhone SE, etc.) */
@media screen and (max-width: 375px) {
  .spades-seat-label {
    font-size: 0.65rem;
  }
  .spades-seat-info {
    font-size: 0.6rem;
  }
  .spades-bets {
    gap: 0.15rem;
  }
}

/* Landscape: compact vertical layout */
@media screen and (max-height: 500px) {
  .spades-scores {
    margin-bottom: 0.5rem;
  }
  .spades-table {
    min-height: 8rem;
    margin: 0.5rem 0;
  }
  .spades-table-center .spades-trick-area {
    min-height: 3.5rem;
  }
  .hand-container {
    min-height: 2.5rem;
    margin: 0.25rem 0;
  }
}

.spades-error {
  color: #c33;
  font-size: 0.9rem;
  margin: 0.25rem 0;
}

.spades-waiting {
  text-align: center;
}

/* Challenge form */
.challenge-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  width: 100%;
}
.form-group label {
  font-weight: bold;
  font-size: 0.9rem;
}
.points-group {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  max-width: 20rem;
}
.points-btn {
  flex: 1;
  padding: 0.6rem 0.5rem;
  border: 2px solid #011627;
  border-radius: 3px;
  background: #fff;
  color: #011627;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.points-btn:hover,
.points-btn:active {
  background: #e8ddd0;
}
.points-btn.selected {
  border-color: #2a7;
  background: #e8f5ee;
}

.form-group input,
.form-group select {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.35rem 0.5rem;
  border: 2px solid #011627;
  border-radius: 3px;
  background: #fff;
  color: #011627;
}

.seat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  width: 100%;
  max-width: 20rem;
}
.seat-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.85rem 0.6rem;
  border: 2px solid #011627;
  border-radius: 3px;
  background: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  color: #011627;
}
.seat-option:hover,
.seat-option:active {
  background: #e8ddd0;
}
.seat-option.selected {
  border-color: #2a7;
  background: #e8f5ee;
}
.seat-option.taken {
  opacity: 0.5;
  cursor: not-allowed;
  background: #eee;
}

/* Lobby */
.lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.seat-option .seat-player {
  font-size: 0.85rem;
  color: #2a7;
  font-weight: bold;
}
.seat-option .seat-you {
  font-size: 0.75rem;
  color: #666;
}
.seat-option .seat-open {
  font-size: 0.85rem;
  color: #888;
  font-style: italic;
}
.seat-option.mine {
  border-color: #2a7;
  background: #e8f5ee;
}

.share-link {
  width: 100%;
  max-width: 20rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}
.share-link label {
  font-weight: bold;
  font-size: 0.9rem;
}
.share-link-row {
  display: flex;
  gap: 0.35rem;
  width: 100%;
}
.share-link-row input {
  flex: 1;
  font-family: inherit;
  font-size: 1rem;
  padding: 0.35rem 0.5rem;
  border: 2px solid #011627;
  border-radius: 3px;
  background: #fff;
  color: #011627;
}

.spades-btn-danger {
  background: #c33;
  margin-top: 0.5rem;
}

/* Join name modal */
.join-modal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.join-modal input {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.35rem 0.5rem;
  border: 2px solid #011627;
  border-radius: 3px;
  background: #fff;
  color: #011627;
}

/* Clocks */
.spades-clock {
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  font-weight: bold;
  min-width: 3.5rem;
  display: inline-block;
  text-align: center;
}
.spades-clock.low-time {
  color: #c33;
}
.spades-clock.active-clock {
  color: #2a7;
}

/* Name editing */
.spades-name-edit {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.spades-name-edit-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0.25rem;
  color: #666;
  font-family: inherit;
}
.spades-name-edit-btn:hover,
.spades-name-edit-btn:active {
  color: #011627;
}
.spades-name-input {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.3rem 0.5rem;
  border: 2px solid #011627;
  border-radius: 3px;
  background: #fff;
  color: #011627;
  width: 8rem;
  max-width: 100%;
}
