* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: #1a5c38;
  color: #f0f0f0;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  /* Card geometry, scaled by the card-size setting. */
  --card-w: 78px;
  --card-h: 108px;
  --strip: 44px; /* visible width of each overlapped card */
  --rank-size: 32px;
  --suit-size: 29px;
  --pip-size: 32px;
  --side-card-h: 72px;
}
.app.size-small {
  --card-w: 64px; --card-h: 90px; --strip: 36px;
  --rank-size: 26px; --suit-size: 24px; --pip-size: 26px; --side-card-h: 60px;
}
.app.size-large {
  --card-w: 94px; --card-h: 130px; --strip: 54px;
  --rank-size: 40px; --suit-size: 36px; --pip-size: 40px; --side-card-h: 88px;
}

/* ---- mode tabs ---- */

.mode-tabs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 1rem;
  background: #0d2f1c;
}
.mode-tabs .brand {
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-right: 0.8rem;
  color: #ffd76a;
}
.mode-tabs button {
  background: none;
  border: none;
  color: #cfe8d8;
  padding: 0.3rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
.mode-tabs button.active {
  background: #2d7a4f;
  color: #fff;
  font-weight: 600;
}
.mode-tabs .sound-btn {
  margin-left: auto;
  font-size: 1rem;
  padding: 0.3rem 0.5rem;
}

/* ---- online lobby ---- */

.online-lobby {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.8rem;
  padding: 3rem 1rem;
}
.online-lobby h2 { margin: 0; }
.online-lobby .conn { opacity: 0.7; margin: 0; }
.online-lobby .conn.ok { color: #7fdc9f; opacity: 1; }
.online-lobby .identity { margin: 0; }
.online-lobby input, .online-lobby select {
  background: #123f26;
  color: #fff;
  border: 1px solid #3f9a67;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.95rem;
}
.lobby-actions { display: flex; flex-direction: column; gap: 0.8rem; align-items: center; }
.join-row { display: flex; gap: 0.4rem; }
.online-lobby .hint { opacity: 0.6; font-size: 0.85rem; }
.error { color: #ff9d9d; text-align: center; margin: 0.3rem 0; }
button.link {
  background: none;
  border: none;
  color: #7fdc9f;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
  font-size: inherit;
}

/* ---- status bar ---- */

.status-bar {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  padding: 0.6rem 1rem;
  background: #123f26;
  font-size: 0.9rem;
}

.status-bar .contract { font-weight: 700; }
.status-bar .spacer { flex: 1; }
.show-all { display: flex; align-items: center; gap: 0.35rem; cursor: pointer; }

.suit-order { display: flex; align-items: center; gap: 0.4rem; }
.suit-order select {
  background: #2d7a4f;
  color: #fff;
  border: 1px solid #3f9a67;
  border-radius: 6px;
  padding: 0.25rem 0.4rem;
  font-size: 0.85rem;
}

.btn {
  background: #2d7a4f;
  color: #fff;
  border: 1px solid #3f9a67;
  border-radius: 6px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.btn:hover { background: #37905e; }
.btn.primary { font-size: 1rem; padding: 0.5rem 1.4rem; }

/* ---- layout ---- */

.layout {
  flex: 1;
  display: flex;
  gap: 1rem;
  padding: 1rem;
}

.table {
  position: relative;
  flex: 1;
  display: grid;
  grid-template-areas:
    '. north .'
    'west center east'
    '. south .';
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto 1fr auto;
  gap: 0.5rem;
  background: radial-gradient(ellipse at center, #237a49 0%, #1a5c38 75%);
  border-radius: 16px;
  padding: 1rem;
  min-height: 70vh;
}

.seat-north { grid-area: north; justify-self: center; }
.seat-south { grid-area: south; justify-self: center; }
.seat-west { grid-area: west; align-self: center; justify-self: start; }
.seat-east { grid-area: east; align-self: center; justify-self: end; }
.table-center { grid-area: center; align-self: center; justify-self: center; }

.sidebar {
  width: 260px;
  background: #123f26;
  border-radius: 12px;
  padding: 1rem;
}
.sidebar h3 { margin: 0 0 0.5rem; font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.8; }

/* ---- hands ---- */

.hand { text-align: center; }
.hand-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.7;
  margin-bottom: 0.3rem;
}
.hand.active .hand-label { opacity: 1; color: #ffd76a; font-weight: 700; }

.hand-cards {
  display: flex;
  padding-left: calc(var(--card-w) - var(--strip));
}

.hand-W .hand-cards, .hand-E .hand-cards { max-width: 300px; flex-wrap: wrap; row-gap: 5px; }

/* Side seats face up: one row per suit. */
.hand-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.hand-rows .hand-row { flex-wrap: nowrap; max-width: none; min-height: 24px; }
.hand-rows .card { height: var(--side-card-h); }
.hand-rows .card-pip { display: none; }

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

/*
 * Cards use whole-pixel sizes to avoid subpixel blur, and BBO-style faces:
 * a large rank with the suit symbol directly beneath, filling the visible
 * strip of each overlapped card. High contrast for readability.
 */
.card {
  width: var(--card-w);
  height: var(--card-h);
  margin-left: calc(var(--strip) - var(--card-w));
  border-radius: 6px;
  border: 1px solid #777;
  background: #ffffff;
  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
  font-family: Arial, Helvetica, sans-serif;
  padding: 0;
  cursor: default;
  position: relative;
}
.card.red { color: #d40000; }
.card.black { color: #000000; }

.card.playable { cursor: pointer; }
.card.playable:hover { transform: translateY(-10px); z-index: 5; }

/*
 * Dim only cards that are illegal to play right now, and only during play.
 * Dim the ink and paper, never the card's opacity: in the overlapped fan a
 * translucent card lets the covered corner pip of the card beneath bleed
 * through, painting a ghost "second suit" on the face above it.
 */
.phase-play .hand-cards .card:disabled { background: #e3e5e1; }
.phase-play .hand-cards .card:disabled .card-corner,
.phase-play .hand-cards .card:disabled .card-pip { opacity: 0.45; }

/* Rank + suit fill the visible strip so they read at a glance. */
.card-corner {
  position: absolute;
  top: 6px;
  left: 0;
  width: var(--strip);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.card-rank {
  font-size: var(--rank-size);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -1px;
}
.card-suit {
  font-size: var(--suit-size);
  line-height: 1;
  margin-top: 1px;
}
.card-pip {
  position: absolute;
  bottom: 6px;
  right: 7px;
  font-size: var(--pip-size);
  line-height: 1;
}

.card-back {
  background: repeating-linear-gradient(45deg, #2b4d8f, #2b4d8f 4px, #35619f 4px, #35619f 8px);
  border-color: #1e3766;
}

/* ---- trick area ---- */

.trick-area {
  position: relative;
  width: calc(var(--card-h) * 2.4);
  height: calc(var(--card-h) * 2.4);
}

.last-trick {
  text-align: center;
  font-size: 0.85rem;
  opacity: 0.75;
  margin-top: 0.4rem;
}

/* ---- review mode ---- */

.review-bar {
  margin-top: 0.6rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: center;
}
.review-controls { display: flex; gap: 4px; align-items: center; }
.review-pos { min-width: 3.4rem; font-weight: 700; }
.review-dd { font-size: 0.85rem; opacity: 0.85; }
.review-note {
  font-size: 0.9rem;
  padding: 0.25rem 0.7rem;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
}
.review-note.declarer-error { background: #7a2d2d; }
.review-note.defence-error { background: #7a5b2d; }

.result-actions { display: flex; gap: 0.6rem; }
.trick-card { position: absolute; }
.trick-card .card { margin-left: 0; opacity: 1 !important; }
.trick-N { top: 0; left: 50%; transform: translateX(-50%); }
.trick-S { bottom: 0; left: 50%; transform: translateX(-50%); }
.trick-W { left: 0; top: 50%; transform: translateY(-50%); }
.trick-E { right: 0; top: 50%; transform: translateY(-50%); }

/* ---- auction ---- */

.auction {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.auction th {
  padding: 0.25rem;
  border-bottom: 1px solid #2d7a4f;
  font-weight: 600;
  opacity: 0.8;
}
.auction td {
  padding: 0.3rem 0.25rem;
  text-align: center;
  min-height: 1.4rem;
}
.auction td.to-call { color: #ffd76a; font-weight: 700; }
.auction td.explained {
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  cursor: help;
}

/* ---- bidding box ---- */

.bidding-box { margin-top: 0.5rem; }
.bid-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}
.bid-btn {
  padding: 0.4rem 0;
  border-radius: 5px;
  border: 1px solid #3f9a67;
  background: #f5f5ef;
  color: #1a1a1a;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}
.bid-btn.red { color: #c8102e; }
.bid-btn:disabled { opacity: 0.25; cursor: default; }
.bid-btn:not(:disabled):hover { background: #ffd76a; }

.call-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 4px;
  margin-top: 4px;
}
.call-row .pass { background: #2e8b57; color: #fff; }
.call-row .double { background: #b03030; color: #fff; }
.call-row .redouble { background: #2b4d8f; color: #fff; }

/* ---- score sheet ---- */

.score-sheet { margin-top: 1.2rem; }
.score-sheet table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.score-sheet th {
  padding: 0.25rem;
  border-bottom: 1px solid #2d7a4f;
  font-weight: 600;
  opacity: 0.8;
  text-align: left;
}
.score-sheet td { padding: 0.25rem; }
.score-sheet td:nth-child(4), .score-sheet td:nth-child(5),
.score-sheet th:nth-child(4), .score-sheet th:nth-child(5) { text-align: right; }
.score-sheet tfoot td {
  border-top: 1px solid #2d7a4f;
  font-weight: 700;
  color: #ffd76a;
}

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

/* ---- chat ---- */

.chat { margin-top: 1.2rem; display: flex; flex-direction: column; }
.chat h3 { margin: 0 0 0.4rem; font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.8; }
.chat-log {
  height: 11rem;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  padding: 0.5rem;
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.chat-item.system { opacity: 0.55; font-style: italic; }
.chat-from { color: #ffd76a; font-weight: 600; margin-right: 0.3rem; }
.chat-input { display: flex; gap: 4px; margin-top: 0.4rem; }
.chat-input input {
  flex: 1;
  background: #0d2f1c;
  color: #fff;
  border: 1px solid #3f9a67;
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
}

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

.board-result {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: rgba(10, 30, 18, 0.82);
  border-radius: 16px;
  z-index: 10;
}
.board-result h2 { margin: 0; font-size: 1.6rem; }
.board-result .score { margin: 0 0 0.4rem; font-size: 1.2rem; color: #ffd76a; }

/* ---- analysis ---- */

.analysis { text-align: center; margin-bottom: 0.6rem; }
.analysis .par { margin: 0.2rem 0; font-size: 1rem; }
.analysis .dd-compare { margin: 0.2rem 0 0.6rem; font-size: 0.95rem; opacity: 0.9; }
.analysis-loading { opacity: 0.7; font-size: 0.9rem; }

.dd-table {
  margin: 0 auto;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
}
.dd-table th, .dd-table td {
  padding: 0.25rem 0.55rem;
  text-align: center;
}
.dd-table thead th { border-bottom: 1px solid #2d7a4f; }
.dd-table th.red { color: #ff8080; }
.dd-caption { font-size: 0.75rem; opacity: 0.6; margin: 0.3rem 0 0; }
