:root {
  --felt: #0b6b3a;
  --felt-dark: #064927;
  --panel: #f4efe5;
  --panel-dark: #ded2bd;
  --gold: #d6a23f;
  --text: #1d1d1d;
  --muted: #666;
  --red: #b90000;
  --black: #111;
  --blue: #2554a4;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--text);
  background: #0b331f;
  overflow: hidden;
}

.screen {
  display: none;
  width: 100vw;
  height: 100vh;
}

.screen.active {
  display: block;
}

/* Setup */

#setup-screen {
  background:
    radial-gradient(circle at center, #16814a 0%, #0b5a32 55%, #062d1d 100%);
  display: none;
  align-items: center;
  justify-content: center;
}

#setup-screen.active {
  display: flex;
}

.setup-panel {
  width: min(560px, 92vw);
  background: var(--panel);
  border: 5px solid var(--gold);
  border-radius: 16px;
  padding: 32px;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.setup-panel h1 {
  margin: 0;
  font-size: 46px;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
}

.setup-group {
  margin: 24px 0;
  text-align: left;
}

.setup-group label {
  display: block;
  margin-bottom: 10px;
  font-weight: bold;
}

input {
  width: 100%;
  padding: 13px 14px;
  border: 2px solid var(--panel-dark);
  border-radius: 8px;
  font-size: 18px;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.primary-button {
  border: none;
  background: linear-gradient(#f3c35b, #bd7f19);
  color: white;
  padding: 13px 24px;
  border-radius: 10px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 4px 0 #7c4e0d;
}

.primary-button:hover {
  filter: brightness(1.05);
}

.primary-button:active {
  transform: translateY(2px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.4), 0 2px 0 #7c4e0d;
}

/* Game layout */

.top-bar {
  height: 58px;
  background: linear-gradient(#e8dbc2, #cdbb9a);
  border-bottom: 3px solid #8b641d;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 18px;
  font-family: Arial, sans-serif;
}

.status-message {
  font-weight: bold;
  color: #333;
  text-align: center;
  flex: 1;
}

.top-stats {
  display: flex;
  align-items: center;
  gap: 12px;
}

.table {
  position: relative;
  width: 100vw;
  height: calc(100vh - 58px);
  background:
    radial-gradient(ellipse at center, #16814a 0%, var(--felt) 55%, var(--felt-dark) 100%);
  border: 12px solid #5e3717;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.55);
}

/* Opponents */

.opponents-area {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.opponent {
  position: absolute;
  width: 170px;
  min-height: 90px;
  text-align: center;
  color: white;
  font-family: Arial, sans-serif;
  z-index: 2;
}


.opponent-name {
  font-weight: bold;
  text-shadow: 0 2px 2px rgba(0,0,0,0.6);
}

.opponent-meta {
  font-size: 13px;
  margin-top: 2px;
  opacity: 0.92;
}

.card-back-stack {
  margin-top: 6px;
  display: flex;
  justify-content: center;
}

.mini-card-back {
  width: 34px;
  height: 48px;
  margin-left: -20px;
  border-radius: 5px;
  border: 1px solid #eee;
  background:
    linear-gradient(45deg, #244b9b 25%, transparent 25%),
    linear-gradient(-45deg, #244b9b 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #244b9b 75%),
    linear-gradient(-45deg, transparent 75%, #244b9b 75%);
  background-color: #14306f;
  background-size: 12px 12px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.mini-card-back:first-child {
  margin-left: 0;
}

/* Centre */

.centre-area {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.action-panel {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  margin-top: 12px;
  background: rgba(244, 239, 229, 0.95);
  border: 3px solid var(--gold);
  border-radius: 14px;
  padding: 14px;
  min-width: 330px;
  text-align: center;
  font-family: Arial, sans-serif;
  pointer-events: auto;
  z-index: 10;
}

.current-trick {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.played-card-slot {
  position: absolute;
  text-align: center;
  color: white;
  font-family: Arial, sans-serif;
  font-size: 13px;
  z-index: 5;
  text-shadow: 0 2px 2px rgba(0,0,0,0.7);
}

.played-card-slot .card {
  margin: 4px auto 0;
}


.action-panel {
  margin-top: 12px;
  background: rgba(244, 239, 229, 0.95);
  border: 3px solid var(--gold);
  border-radius: 14px;
  padding: 14px;
  min-width: 330px;
  text-align: center;
  font-family: Arial, sans-serif;
}

.action-panel:empty {
  display: none;
}

.action-panel h3 {
  margin: 0 0 10px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.small-button {
  border: 2px solid #8b641d;
  background: #fff9eb;
  padding: 9px 13px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
}

.small-button:hover {
  background: #ffe9af;
}

/* Human hand */

.human-area {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18px;
  text-align: center;
}

.human-info {
  color: white;
  font-family: Arial, sans-serif;
  margin-bottom: 8px;
  font-weight: bold;
  text-shadow: 0 2px 2px rgba(0,0,0,0.7);
}

.human-hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 0;
  min-height: 130px;
  padding: 0 16px;
}

.card {
  width: 72px;
  height: 102px;
  background: #fffdf7;
  border: 2px solid #1f1f1f;
  border-radius: 9px;
  box-shadow: 0 5px 8px rgba(0,0,0,0.35);
  position: relative;
  font-family: Georgia, "Times New Roman", serif;
  user-select: none;
}

.human-hand .card {
  margin-left: -18px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.human-hand .card:first-child {
  margin-left: 0;
}

.human-hand .card.playable:hover {
  transform: translateY(-18px);
  box-shadow: 0 16px 18px rgba(0,0,0,0.45);
}

.human-hand .card.not-playable {
  opacity: 0.45;
  cursor: not-allowed;
}

.card.red {
  color: var(--red);
}

.card.black {
  color: var(--black);
}

.card-rank-top {
  position: absolute;
  left: 7px;
  top: 5px;
  font-weight: bold;
  font-size: 18px;
}

.card-suit-centre {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 38px;
}

.card-rank-bottom {
  position: absolute;
  right: 7px;
  bottom: 5px;
  font-weight: bold;
  font-size: 18px;
  transform: rotate(180deg);
}

/* Modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(760px, 94vw);
  max-height: 90vh;
  overflow: auto;
  background: var(--panel);
  border: 5px solid var(--gold);
  border-radius: 16px;
  padding: 26px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0,0,0,0.5);
  font-family: Arial, sans-serif;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 22px;
  background: white;
}

.score-table th,
.score-table td {
  border: 1px solid #c9bea8;
  padding: 9px;
}

.score-table th {
  background: #e8dbc2;
}

.winner-row {
  background: #fff1b8;
  font-weight: bold;
}

@media (max-width: 800px) {
  .card {
    width: 58px;
    height: 84px;
  }

  .card-suit-centre {
    font-size: 30px;
  }

  .human-hand .card {
    margin-left: -22px;
  }

  .opponent {
    width: 130px;
  }

  .current-trick {
    width: 320px;
  }
}

.setup-error {
  min-height: 24px;
  margin: 12px 0;
  color: #b00000;
  font-weight: bold;
  text-align: center;
  font-family: Arial, sans-serif;
}

.hand-log {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 320px;
  max-height: 330px;
  background: rgba(244, 239, 229, 0.96);
  border: 3px solid var(--gold);
  border-radius: 12px;
  box-shadow: 0 8px 18px rgba(0,0,0,0.45);
  font-family: Arial, sans-serif;
  z-index: 20;
  overflow: hidden;
}

.hand-log-header {
  background: linear-gradient(#e8dbc2, #cdbb9a);
  border-bottom: 2px solid #8b641d;
  padding: 8px 10px;
  font-weight: bold;
  text-align: center;
}

.hand-log-list {
  max-height: 285px;
  overflow-y: auto;
  padding: 8px;
  font-size: 12px;
}

.hand-log-entry {
  background: white;
  border: 1px solid #c9bea8;
  border-radius: 8px;
  padding: 7px;
  margin-bottom: 8px;
}

.hand-log-title {
  font-weight: bold;
  margin-bottom: 5px;
  color: #222;
}

.hand-log-play {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px;
  border-radius: 5px;
}

.hand-log-play.winning-play {
  background: #fff1b8;
  border: 1px solid #d6a23f;
  font-weight: bold;
}

.hand-log-player {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hand-log-card {
  font-weight: bold;
  min-width: 38px;
  text-align: right;
}

.hand-log-card.red {
  color: var(--red);
}

.hand-log-card.black {
  color: var(--black);
}

.hand-log-empty {
  color: #666;
  text-align: center;
  padding: 8px;
  font-style: italic;
}

.suit-symbol {
  font-weight: bold;
  font-size: 1.35em;
  line-height: 1;
}

.red-suit {
  color: #c00000;
}

.black-suit {
  color: #111;
}

#trump-display {
  font-size: 18px;
  font-weight: bold;
}

#trump-display .suit-symbol {
  font-size: 24px;
  vertical-align: middle;
}

.bid-trump-display {
  margin: 6px 0 10px;
  font-size: 18px;
  font-weight: bold;
}

.bid-trump-display .suit-symbol {
  font-size: 26px;
  vertical-align: middle;
}

.trump-choice-row {
  gap: 12px;
}

.trump-choice-button {
  min-width: 54px;
  min-height: 48px;
  padding: 8px 14px;
}

.trump-choice-button .suit-symbol {
  font-size: 32px;
  line-height: 1;
}

.modal-button-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.secondary-button {
  border: none;
  background: linear-gradient(#777, #444);
  color: white;
  padding: 13px 24px;
  border-radius: 10px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), 0 4px 0 #222;
}

.secondary-button:hover {
  filter: brightness(1.08);
}

.secondary-button:active {
  transform: translateY(2px);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), 0 2px 0 #222;
}

.score-sheet-card {
  width: min(980px, 96vw);
}

.score-sheet-table-wrapper {
  max-height: 65vh;
  overflow: auto;
  margin: 16px 0 22px;
  border: 1px solid #c9bea8;
  background: white;
}

.score-sheet-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

.score-sheet-table th,
.score-sheet-table td {
  border: 1px solid #c9bea8;
  padding: 9px;
  text-align: center;
}

.score-sheet-table th {
  background: #e8dbc2;
  position: sticky;
  top: 0;
  z-index: 1;
}

.score-sheet-table th:first-child,
.score-sheet-table td:first-child {
  font-weight: bold;
  background: #f7f0df;
  position: sticky;
  left: 0;
  z-index: 2;
}

.score-sheet-table th:first-child {
  z-index: 3;
}

.score-sheet-correct {
  background-color: #d9f2d9 !important;
  color: #145214;
  font-weight: bold;
}

.score-sheet-incorrect {
  background-color: #f8d7da !important;
  color: #7a1f28;
  font-weight: bold;
}

.score-sheet-round-detail {
  display: block;
  font-size: 12px;
  font-weight: normal;
  margin-top: 3px;
}

.top-score-sheet-button {
  border: 1px solid #555;
  background: linear-gradient(#f7f7f7, #d0d0d0);
  color: #222;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  font-family: Arial, sans-serif;
  box-shadow: 0 2px 0 #888;
}

.top-score-sheet-button:hover {
  background: linear-gradient(#ffffff, #dddddd);
}

.top-score-sheet-button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #777;
}

.high-card-card {
  width: min(680px, 94vw);
}

.high-card-draw-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 22px;
  background: white;
}

.high-card-draw-table th,
.high-card-draw-table td {
  border: 1px solid #c9bea8;
  padding: 9px;
  text-align: center;
}

.high-card-draw-table th {
  background: #e8dbc2;
}

.high-card-winner-row {
  background: #fff1b8;
  font-weight: bold;
}

.high-card-card-display {
  font-weight: bold;
  font-size: 22px;
}

.high-card-card-display.red {
  color: var(--red);
}

.high-card-card-display.black {
  color: var(--black);
}

.winning-played-card {
  background: #fff1a8 !important;
  border: 4px solid #ffd400 !important;
  box-shadow:
    0 0 0 3px rgba(255, 212, 0, 0.35),
    0 0 22px rgba(255, 212, 0, 0.9),
    0 8px 14px rgba(0, 0, 0, 0.45) !important;
  transform: scale(1.08);
}

.winning-played-card-slot {
  z-index: 12;
}

.winning-played-card-slot::after {
  content: "Winner";
  display: block;
  margin-top: 4px;
  color: #ffd400;
  font-weight: bold;
  font-size: 13px;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.85);
}