*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', sans-serif;
  background: #1a4a1a;
  color: #fff;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Score bar ── */
#score-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0d2e0d;
  padding: 8px 26px;
  flex-shrink: 0;
  border-bottom: 2px solid #3a6b3a;
}
.score-team { display: flex; flex-direction: column; align-items: center; min-width: 160px; }
.team-label { font-size: 15px; text-transform: uppercase; letter-spacing: 1px; color: #9fc99f; }
.team-score { font-size: 44px; font-weight: bold; color: #fff; line-height: 1; }
#score-team0 .team-score { color: #7de87d; }
#score-team1 .team-score { color: #e87d7d; }
#score-center { text-align: center; font-size: 17px; color: #c8e8c8; line-height: 1.6; }
#trump-display { font-size: 20px; font-weight: bold; }

/* ── Table layout ── */
#table {
  display: grid;
  grid-template-columns: 180px 1fr 180px;
  /* minmax(0, 1fr), not plain 1fr: a bare 1fr won't shrink below its
     content's min-content height, so a tall centre column would push the
     hand row off the bottom of the screen. */
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    ".      top     ."
    "left   center  right"
    "bottom bottom  bottom";
  flex: 1;
  gap: 6px;
  padding: 10px;
  min-height: 0;
}

#zone-top    { grid-area: top;    display: flex; flex-direction: column; align-items: center; }
#zone-left   { grid-area: left;   display: flex; flex-direction: column; align-items: center; justify-content: center; }
#zone-right  { grid-area: right;  display: flex; flex-direction: column; align-items: center; justify-content: center; }
#zone-bottom { grid-area: bottom; display: flex; flex-direction: column; align-items: center; }
#center      { grid-area: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
               min-height: 0; overflow-y: auto; }

.player-name {
  font-size: 16px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #a0d0a0;
  margin-bottom: 6px;
}

/* ── Card back (opponents) ── */
.opponent-hand { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.opponent-hand.vertical { flex-direction: column; align-items: center; }

.card-back {
  width: 48px;
  height: 70px;
  background: linear-gradient(135deg, #1a3a8a, #2a5aba);
  border: 3px solid #6888cc;
  border-radius: 7px;
  display: inline-block;
}

/* ── Playing cards ── */
.card {
  width: 86px;
  height: 124px;
  background: #fff;
  border: 3px solid #ccc;
  border-radius: 9px;
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px 7px;
  cursor: default;
  position: relative;
  user-select: none;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.card.red   { color: #c00; }
.card.black { color: #111; }
.card.purple { color: #7700cc; }

.card-rank-top  { font-size: 19px; font-weight: bold; line-height: 1; }
.card-suit-top  { font-size: 16px; line-height: 1; }
.card-center    { font-size: 32px; text-align: center; line-height: 1; }
.card-rank-bot  { font-size: 19px; font-weight: bold; line-height: 1; transform: rotate(180deg); align-self: flex-end; }

/* Human hand: clickable states */
.card.playable {
  cursor: pointer;
  border-color: #3a3;
  box-shadow: 0 0 6px rgba(50,200,50,0.6);
}
.card.playable:hover {
  transform: translateY(-8px);
  box-shadow: 0 8px 16px rgba(50,200,50,0.7);
}
.card.selected {
  border-color: #e88800;
  box-shadow: 0 0 8px rgba(220,140,0,0.8);
  transform: translateY(-10px);
}
.card.trump-highlight {
  border-color: #e8c000;
}
.card.not-legal {
  opacity: 0.5;
}

/* Small trick cards in center */
#trick-area {
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: flex-end;
  flex-wrap: wrap;
  min-height: 108px;
}
.trick-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.trick-slot .trick-label {
  font-size: 13px;
  color: #9fc99f;
  text-transform: uppercase;
}
.trick-card {
  width: 74px;
  height: 106px;
  font-size: 14px;
}
.trick-card .card-center { font-size: 25px; }
.trick-card .card-rank-top,
.trick-card .card-rank-bot { font-size: 15px; }

/* ── Phase panel (bids / actions) ── */
#phase-panel {
  background: rgba(0,0,0,0.35);
  border-radius: 12px;
  padding: 18px 26px;
  min-width: 320px;
  max-width: 420px;
  text-align: center;
}
#phase-panel h3, #result-box h3 { margin-bottom: 12px; font-size: 20px; color: #d0f0d0; }
#phase-panel p, #result-box p  { font-size: 16px; color: #ccc; margin-bottom: 12px; }

.btn {
  display: inline-block;
  padding: 10px 22px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-size: 17px;
  font-weight: bold;
  margin: 4px;
  transition: background 0.15s, transform 0.1s;
}
.btn:hover { transform: scale(1.05); }
.btn:active { transform: scale(0.97); }
.btn-green  { background: #2a9a2a; color: #fff; }
.btn-green:hover { background: #33bb33; }
.btn-red    { background: #9a2a2a; color: #fff; }
.btn-red:hover { background: #bb3333; }
.btn-blue   { background: #2a4a9a; color: #fff; }
.btn-blue:hover { background: #3355bb; }
.btn-gray   { background: #555; color: #fff; }
.btn-gray:hover { background: #666; }
.btn-suit   { font-size: 26px; width: 68px; height: 68px; padding: 0; }

#bid-input {
  width: 80px;
  font-size: 22px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 2px solid #5a9a5a;
  text-align: center;
  background: #1a3a1a;
  color: #fff;
  margin-right: 8px;
}
#bid-input:focus { outline: none; border-color: #7de87d; }

.discard-hint {
  font-size: 16px;
  color: #f0c060;
  margin-bottom: 8px;
}
.result-table { width: 100%; border-collapse: collapse; font-size: 17px; margin: 10px 0; }
.result-table td, .result-table th { padding: 6px 10px; border: 1px solid #3a6b3a; }

.undealt-note {
  font-size: 14px;
  color: #f0c060;
  background: rgba(240,192,96,0.12);
  border: 1px solid #6a5628;
  border-radius: 6px;
  padding: 8px 10px;
  margin: 8px 0;
  text-align: left;
}
.result-table th { background: #1a4a1a; color: #9fc99f; }

/* ── Widow up-card (bidding) ── */
#widow-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-height: 0;
}
#widow-area:empty { display: none; }
.widow-label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #f0c060;
}

/* ── Last trick display ── */
#last-trick-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-height: 0;
}
#last-trick-area:empty { display: none; }
.last-trick-label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7aaa7a;
}
.last-trick-cards {
  display: flex;
  gap: 7px;
  justify-content: center;
}
.last-trick-cards .trick-slot .trick-card {
  opacity: 0.72;
}
.last-trick-winner {
  font-size: 14px;
  color: #ffe060;
  font-style: italic;
}

/* ── History accordion ── */
#history-panel {
  background: #0a220a;
  border-top: 1px solid #2a5a2a;
  flex-shrink: 0;
}
#history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 18px;
  cursor: pointer;
  user-select: none;
  font-size: 15px;
  color: #7aaa7a;
}
#history-header:hover { background: #0f2e0f; }
#history-title { font-weight: bold; }
#history-summary { color: #5a8a5a; font-size: 13px; }
#history-body {
  padding: 8px 18px 10px;
  overflow-x: auto;
  white-space: nowrap;
}
#history-body.hidden { display: none; }

.history-trick {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  margin-right: 18px;
  vertical-align: top;
}
.history-trick-num {
  font-size: 13px;
  color: #5a8a5a;
  margin-bottom: 4px;
}
.history-trick-cards {
  display: flex;
  gap: 4px;
}
.history-trick-winner {
  font-size: 13px;
  color: #ffe060;
  margin-top: 4px;
  text-align: center;
}
.history-card {
  width: 56px;
  height: 80px;
  font-size: 13px;
}
.history-card .card-center { font-size: 17px; }
.history-card .card-rank-top,
.history-card .card-rank-bot { font-size: 13px; }
.history-player-label {
  font-size: 12px;
  color: #7aaa7a;
  text-align: center;
  width: 56px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Log panel ── */
#log-panel {
  background: #0d2e0d;
  border-top: 2px solid #3a6b3a;
  padding: 8px 18px;
  flex-shrink: 0;
  max-height: 76px;
  overflow-y: auto;
}
#log-title { font-size: 12px; text-transform: uppercase; color: #5a8a5a; margin-bottom: 4px; }
#log-entries { font-size: 15px; color: #a0c8a0; line-height: 1.5; }

/* ── Hand container ── */
#zone-bottom { min-height: 0; }
#hand-bottom {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 6px;
  max-width: 100%;
  overflow-y: auto;   /* safety net on very short windows */
}

/* Winning the bid hands you the whole widow - up to 14 cards. Shrink them
   so the full hand stays on screen during the discard step. */
#hand-bottom.hand-compact { gap: 5px; }
#hand-bottom.hand-compact .card {
  width: 66px;
  height: 95px;
  padding: 4px 5px;
}
#hand-bottom.hand-compact .card-center   { font-size: 23px; }
#hand-bottom.hand-compact .card-rank-top,
#hand-bottom.hand-compact .card-rank-bot { font-size: 15px; }
#hand-bottom.hand-compact .card-suit-top { font-size: 12px; }

/* ── Round/game result modal ── */
#result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 95;
  padding: 20px;
}
#result-overlay.hidden { display: none; }
#result-box {
  background: #123312;
  border: 2px solid #3a6b3a;
  border-radius: 12px;
  padding: 22px 30px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
}

/* ── Overlay ── */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#overlay.hidden { display: none; }
#overlay-box {
  background: #0d2e0d;
  border: 2px solid #3a6b3a;
  border-radius: 12px;
  padding: 48px 70px;
  text-align: center;
}
#overlay-box h1 { font-size: 54px; margin-bottom: 16px; color: #7de87d; }
#overlay-box p  { color: #a0c8a0; margin-bottom: 28px; font-size: 18px; }
#btn-new-game   { padding: 16px 44px; font-size: 20px; }

/* ── Suit colors ── */
.suit-H, .suit-D { color: #c00; }
.suit-C, .suit-S { color: #111; }
.suit-BJ, .suit-SJ { color: #7700cc; }

/* ── Turn indicator ── */
.active-player { color: #ffe060 !important; }

/* ── Dealer / trick-leader badges ── */
.player-badges {
  display: inline-flex;
  gap: 5px;
  margin-left: 8px;
  vertical-align: middle;
}
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: bold;
  color: #fff;
  border: 2px solid rgba(255,255,255,0.55);
  line-height: 1;
}
.badge-dealer { background: #8e44ad; }   /* purple */
.badge-leader { background: #c0392b; }   /* red */

/* ── Diagnostic reveal mode ── */
#btn-reveal {
  margin-top: 5px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: bold;
  border: 1px solid #5a9a5a;
  border-radius: 5px;
  background: #1a3a1a;
  color: #9fc99f;
  cursor: pointer;
}
#btn-reveal:hover { background: #245024; color: #d0f0d0; }
#btn-reveal.reveal-on {
  background: #8e44ad;
  border-color: #b06fd0;
  color: #fff;
}

/* Revealed hands wrap into a compact block so the side seats don't run
   off the bottom of the table. */
.opponent-hand.revealed,
.opponent-hand.revealed.vertical {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  max-width: 100%;
}
.revealed-card {
  width: 50px;
  height: 72px;
  font-size: 12px;
  padding: 3px 4px;
  border-width: 2px;
}
.revealed-card .card-center { font-size: 16px; }
.revealed-card .card-rank-top,
.revealed-card .card-rank-bot { font-size: 12px; }
.revealed-card .card-suit-top { font-size: 10px; }

.undealt-row {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  justify-content: center;
  max-width: 460px;
  opacity: 0.8;
}

/* ══════════════════════════════════════════════════════════════════
   Phone / narrow-screen layout
   The desktop layout is a fixed three-column table (180px side seats,
   86px cards) inside a non-scrolling 100vh box - none of which fits a
   phone. Here the seats stack, cards shrink, and the page is allowed to
   scroll normally.
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 760px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    -webkit-text-size-adjust: 100%;
  }

  /* Score bar: keep it compact so it doesn't eat the screen */
  #score-bar { padding: 6px 10px; }
  .score-team { min-width: 72px; }
  .team-label { font-size: 11px; letter-spacing: 0; }
  .team-score { font-size: 30px; }
  #score-center { font-size: 12px; line-height: 1.35; }
  #trump-display { font-size: 15px; }
  #btn-reveal { font-size: 11px; padding: 3px 8px; margin-top: 3px; }

  /* Partner across the top, the two opponents side by side, then the
     centre, then your hand. */
  #table {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "top    top"
      "left   right"
      "center center"
      "bottom bottom";
    gap: 8px;
    padding: 8px 6px;
    flex: none;
  }
  #zone-left, #zone-right { justify-content: flex-start; }
  #center { overflow: visible; }

  .player-name { font-size: 13px; margin-bottom: 3px; }
  .badge { width: 20px; height: 20px; font-size: 12px; }

  /* Opponent card backs: small, wrapping rows in every seat */
  .opponent-hand, .opponent-hand.vertical {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 3px;
  }
  .card-back { width: 26px; height: 38px; border-width: 2px; }

  /* Trick in the middle */
  #trick-area { min-height: 76px; gap: 5px; }
  .trick-slot .trick-label { font-size: 10px; }
  .trick-card { width: 50px; height: 72px; }
  .trick-card .card-center { font-size: 17px; }
  .trick-card .card-rank-top,
  .trick-card .card-rank-bot { font-size: 11px; }

  /* Your hand: six cards must fit across a phone */
  #hand-bottom { gap: 4px; padding: 2px; overflow: visible; }
  #hand-bottom .card,
  #hand-bottom.hand-compact .card {
    width: 52px;
    height: 75px;
    padding: 3px 4px;
    border-width: 2px;
  }
  #hand-bottom .card-center   { font-size: 18px; }
  #hand-bottom .card-rank-top,
  #hand-bottom .card-rank-bot { font-size: 13px; }
  #hand-bottom .card-suit-top { font-size: 11px; }
  /* Tapping, not hovering - lift the selected card clearly instead */
  .card.playable:hover { transform: none; box-shadow: 0 0 6px rgba(50,200,50,0.6); }
  .card.selected { transform: translateY(-8px); }

  /* Panels and controls sized for thumbs */
  #phase-panel { min-width: 0; max-width: 100%; padding: 12px 14px; }
  #phase-panel h3 { font-size: 17px; }
  #phase-panel p  { font-size: 14px; }
  .btn { padding: 10px 18px; font-size: 15px; }
  .btn-suit { width: 58px; height: 58px; font-size: 24px; }
  #bid-input { font-size: 20px; width: 68px; }

  #result-box { padding: 16px 16px; max-height: 84vh; }
  .result-table { font-size: 14px; }
  .result-table td, .result-table th { padding: 4px 6px; }

  .widow-label, .last-trick-label { font-size: 11px; }
  .revealed-card { width: 40px; height: 58px; }
  .revealed-card .card-center { font-size: 13px; }
  .revealed-card .card-rank-top,
  .revealed-card .card-rank-bot { font-size: 10px; }

  #log-panel { max-height: 62px; padding: 5px 10px; }
  #log-entries { font-size: 13px; }
  #history-header { font-size: 13px; padding: 6px 10px; }

  #overlay-box { padding: 28px 24px; margin: 16px; }
  #overlay-box h1 { font-size: 38px; }
  #overlay-box p  { font-size: 15px; }
}

/* Very narrow phones */
@media (max-width: 400px) {
  #hand-bottom .card,
  #hand-bottom.hand-compact .card { width: 46px; height: 67px; }
  #hand-bottom .card-center { font-size: 16px; }
  .team-score { font-size: 26px; }
  .card-back { width: 22px; height: 32px; }
}

/* ── Menu / lobby ── */
#menu-panel.hidden, #lobby-panel.hidden { display: none; }
.menu-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 18px 0 12px; color: #6a9a6a; font-size: 12px;
  text-transform: uppercase; letter-spacing: 1px;
}
.menu-divider::before, .menu-divider::after {
  content: ''; flex: 1; height: 1px; background: #2a5a2a;
}
.menu-row { display: flex; gap: 8px; justify-content: center; align-items: center; margin: 8px 0; }
#player-name, #join-code {
  padding: 9px 12px; font-size: 16px; border-radius: 6px;
  border: 2px solid #5a9a5a; background: #1a3a1a; color: #fff; text-align: center;
}
#player-name { width: 220px; }
#join-code { width: 110px; text-transform: uppercase; letter-spacing: 3px; font-weight: bold; }
#player-name:focus, #join-code:focus { outline: none; border-color: #7de87d; }
#menu-error, #lobby-error { color: #e87d7d; font-size: 13px; min-height: 18px; margin-top: 8px; }

#lobby-code {
  font-family: monospace; letter-spacing: 4px; color: #ffe060;
  background: rgba(0,0,0,0.3); padding: 2px 10px; border-radius: 6px;
}
#lobby-seats { margin: 14px 0; display: flex; flex-direction: column; gap: 7px; }
.lobby-seat {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 8px;
  background: rgba(0,0,0,0.28);
  border-left: 4px solid transparent;
  text-align: left;
}
.lobby-seat.team-A { border-left-color: #7de87d; }
.lobby-seat.team-B { border-left-color: #e87d7d; }
.lobby-seat.is-you { background: rgba(125,232,125,0.14); }
.lobby-seat-label { font-size: 12px; color: #9fc99f; text-transform: uppercase; }
.lobby-seat-who { font-size: 15px; font-weight: bold; color: #fff; }
.lobby-seat-who.open { color: #6a9a6a; font-weight: normal; font-style: italic; }
.lobby-seat-actions { display: flex; gap: 6px; }
.lobby-btn { padding: 5px 12px; font-size: 13px; margin: 0; }

/* Bot seats read differently from human ones at the table */
.pname.is-bot { color: #7fa8d0; }

@media (max-width: 760px) {
  .lobby-seat { grid-template-columns: 1fr; gap: 4px; padding: 8px 10px; }
  .lobby-seat-actions { justify-content: flex-start; }
  #player-name { width: 100%; max-width: 240px; }
  #overlay-box { max-height: 92vh; overflow-y: auto; }
}
