/* Hearts — Classical Dutch styling for an 82-year-old gentleman (English only) */

:root {
  --delft-blue: #0D3B66;
  --delft-light: #3A6EA5;
  --gold: #C5A26F;
  --gold-dark: #8C6642;
  --cream: #F8F4EC;
  --wood: #3A2A1F;
  --wood-light: #5C4033;
  --felt: #1E4D3A;
  --red: #9C2A1F;
  --black: #1A1A1A;
  --text: #F5F0E6;
  --text-dark: #2C2118;
}

* { box-sizing: border-box; }

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--wood);
  color: var(--text);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.4;
  position: relative;
}

#app {
  width: 1280px;
  height: 720px;
  padding: 2px 6px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  background: var(--wood);
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.6);
  border: 2px solid #C5A26F;
  border-radius: 8px;
  overflow: hidden;
  position: absolute;
  top: 0;
  left: 0;
}

/* Distribute space inside the fixed 1280x720 viewport */
.header,
.score-bar,
.action-bar,
.round-preview,
footer {
  flex: 0 0 auto;
}

.game-area {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Give the table plenty of room - shrink top/bottom elements to maximize table visibility and use more of page height */
.game-area > .opponent.north {
  flex: 0 0 76px; /* name+count + small opponent hand visuals */
}
.game-area > .middle-row {
  flex: 1 1 auto;
  min-height: 0;
}
.game-area > .player-south {
  flex: 0 0 130px; /* label + 102px hand cards + paddings to fully show hand without clip */
  margin-top: 2px;
}

.header {
  background: linear-gradient(180deg, #2C2118 0%, #3A2A1F 100%);
  border-bottom: 2px solid var(--gold);
  padding: 1px 0 1px;
  margin-bottom: 1px;
  border-radius: 6px 6px 0 0;
}

.logo {
  max-height: 28px;
}

.header-actions .btn {
  font-size: 10px;
  padding: 1px 4px;
  min-height: 18px;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 12px;
}

.logo {
  max-height: 38px; /* shrunk to give more vertical to table area while keeping recognizable */
  width: auto;
  border: 2px solid var(--gold);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.header-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Buttons — large, friendly */
.btn {
  font-family: inherit;
  font-size: 17px;
  padding: 10px 22px;
  border-radius: 6px;
  border: 2px solid var(--gold);
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 48px;
  min-width: 110px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: var(--gold);
  color: var(--text-dark);
}

.btn-primary:hover { background: #d4b47f; }

.btn-secondary {
  background: #4A3728;
  color: var(--text);
  border-color: #8C6642;
}

.btn-secondary:hover { background: #5C4033; }

.btn-gold {
  background: linear-gradient(180deg, #C5A26F 0%, #A07D4A 100%);
  color: #2C2118;
  border-color: #E8D4A8;
  font-size: 18px;
  padding: 12px 28px;
  box-shadow: 0 3px 6px rgba(0,0,0,0.3);
}

.btn-gold:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-gold:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* Score bar */
.score-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  margin-bottom: 1px;
  padding: 0;
}

.player-score {
  padding: 3px 6px;
}

.player-score .name {
  font-size: 13px;
}

.player-score .total {
  font-size: 22px;
}

.player-score {
  background: #2C2118;
  border: 2px solid var(--gold);
  border-radius: 8px;
  padding: 2px 6px;
  text-align: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

.player-score.leader {
  border-color: #E8D4A8;
  box-shadow: 0 0 0 3px rgba(197, 162, 111, 0.35);
  transform: scale(1.02);
}

.player-score .name {
  font-size: 13px;
  font-weight: 700;
  display: block;
  margin-bottom: 1px;
  color: var(--gold);
}

.player-score .total {
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.player-score.you .name { color: #E8D4A8; }

/* Game area layout */
.game-area {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 4px;
}

.middle-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
  min-height: 0;
}

.opponent {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 110px;
}

.opponent.north { order: -1; }
.opponent.west, .opponent.east { width: 118px; justify-content: center; }

.opponent-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 4px;
}

.opponent-name {
  font-size: 16px;
  color: var(--gold);
  font-weight: 600;
}

.opponent-count {
  font-size: 15px;
  background: #2C2118;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid #8C6642;
}

.opponent-hand {
  min-height: 70px;
  display: flex;
  gap: 4px;
  justify-content: center;
  flex-wrap: wrap;
}

/* The beautiful table */
.table {
  flex: 1;
  min-height: 350px;
  background: #2C2118;
  border: 8px solid #4A3728;
  border-radius: 50% 50% 48% 48% / 18% 18% 22% 22%;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.6), 0 6px 20px rgba(0,0,0,0.5);
}

.table-felt {
  position: absolute;
  inset: 8px;
  background-size: cover;
  background-position: center;
  border-radius: 50% 50% 46% 46% / 16% 16% 20% 20%;
  box-shadow: inset 0 0 40px rgba(0,0,0,0.25);
  filter: saturate(1.05) contrast(1.02);
}

.played-slots {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-areas:
    ".     north  ."
    "west  center east"
    ".     south  .";
  grid-template-columns: 1fr 1.6fr 1fr;
  grid-template-rows: 96px 1fr 116px; /* balanced rows for 4 played cards to sit fully inside the table border, no bottom clip */
  padding: 6px 14px;
  pointer-events: none;
}

.slot {
  background: rgba(30, 77, 58, 0.25);
  border: 3px dashed rgba(197,162,111,0.35);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 92px;
  min-width: 78px;
  pointer-events: auto;
}

.south-slot {
  min-height: 102px;
  align-items: flex-start;
  padding-top: 1px;
}

.north-slot { grid-area: north; }
.west-slot  { grid-area: west; }
.east-slot  { grid-area: east; }
.south-slot { grid-area: south; transform: scale(1.02); align-items: flex-start; padding-top: 1px; }

.table-message {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(44, 33, 24, 0.95);
  color: var(--gold);
  padding: 8px 22px;
  border-radius: 999px;
  font-size: 17px;
  white-space: nowrap;
  border: 1px solid var(--gold);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  pointer-events: none;
  z-index: 10;
  max-width: 78%;
  text-align: center;
}

.trick-info {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: #C5A26F;
  background: rgba(0,0,0,0.3);
  padding: 1px 10px;
  border-radius: 4px;
  pointer-events: none;
}

/* Play Log — clearly visible, easy-to-read, shows plays + trick winners per hand; clears each new hand */
.play-log {
  width: 168px;
  background: #2C2118;
  border: 3px solid #4A3728;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.log-header {
  flex: 0 0 auto;
  background: #3A2A1F;
  color: var(--gold);
  font-size: 15px;
  font-weight: 700;
  padding: 4px 8px;
  text-align: center;
  border-bottom: 1px solid #8C6642;
  letter-spacing: 0.5px;
}
.log-entries {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 4px 6px;
  font-size: 14px;
  line-height: 1.28;
  color: #E8D4A8;
  background: #1f1812;
}
.log-entry {
  padding: 1px 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.log-entry.lead {
  color: var(--gold);
  font-weight: 600;
  margin-top: 3px;
  border-top: 1px dotted #5C4033;
  padding-top: 3px;
}
.log-entry.win {
  color: #C5A26F;
  font-style: italic;
  padding-bottom: 2px;
}

/* Player hand (YOU) */
.player-south {
  margin-top: 2px;
}

.player-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
  padding-left: 4px;
}

.you-label {
  font-size: 15px;
  letter-spacing: 1px;
  color: var(--gold);
  font-weight: 700;
}

.round-points {
  font-size: 14px;
  color: #E8D4A8;
}

.player-hand {
  display: flex;
  flex-wrap: nowrap;
  gap: 3px;
  padding: 3px 2px 4px;
  background: #2C2118;
  border: 3px solid #4A3728;
  border-radius: 12px;
  min-height: 96px;
  justify-content: center;
}

/* Shrink cards in hand to guarantee single row for 13 cards */
.player-hand .card {
  width: 78px;
  height: 102px;
  font-size: 12px;
  padding: 4px 5px;
}
.player-hand .card .rank {
  font-size: 17px;
}
.player-hand .card .suit {
  font-size: 20px;
}

/* CARDS — the heart of the visual */
.card {
  width: 78px;
  height: 110px;
  background: var(--cream);
  color: var(--black);
  border-radius: 8px;
  border: 2px solid #222;
  box-shadow: 0 3px 7px rgba(0,0,0,0.45), inset 0 0 0 1px #fff;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s cubic-bezier(0.2, 0, 0.2, 1), 
              box-shadow 0.12s, 
              border-color 0.12s;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 6px 7px;
  font-size: 13px;
  line-height: 1;
}

.card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 8px 16px rgba(0,0,0,0.5);
  z-index: 5;
}

.card.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 4px rgba(197, 162, 111, 0.55), 0 6px 14px rgba(0,0,0,0.4);
  transform: translateY(-6px) scale(1.03);
}

.card .rank {
  font-size: 21px;
  font-weight: 700;
  font-family: "Georgia", serif;
}

.card .suit {
  font-size: 26px;
  line-height: 0.9;
}

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

.card .top { text-align: left; }
.card .bottom {
  text-align: right;
  transform: rotate(180deg);
}

/* Card back (uses generated image) */
.card.back {
  background: #1a2a3f;
  background-image: url('../assets/card-back.jpg');
  background-size: cover;
  background-position: center;
  border: 2px solid #0D3B66;
  box-shadow: 0 3px 7px rgba(0,0,0,0.55);
}

.card.back .rank, .card.back .suit { display: none; }

/* Played cards on table (slightly larger) */
.table .card {
  width: 82px;
  height: 112px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.6);
  pointer-events: none; /* handled by parent logic */
}

/* Action bar */
.action-bar {
  background: #2C2118;
  border: 2px solid #4A3728;
  border-radius: 6px;
  padding: 1px 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  min-height: 28px;
}

.phase-info {
  font-size: 17px;
  color: var(--gold);
  font-weight: 600;
  flex: 1 1 auto;
  min-width: 180px;
}

.controls-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pass-direction {
  font-size: 15px;
  background: #3A2A1F;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid #8C6642;
  white-space: nowrap;
}

.round-info {
  margin-left: auto;
  font-size: 16px;
  color: #C5A26F;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Round preview */
.round-preview {
  font-size: 12px;
  color: #C5A26F;
  padding: 0;
  text-align: center;
  min-height: 10px;
  margin-bottom: 2px;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(26, 21, 16, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal.hidden { display: none; }

.modal-content {
  background: #F8F4EC;
  color: #2C2118;
  border-radius: 12px;
  border: 4px solid var(--gold);
  max-width: 620px;
  width: 100%;
  max-height: 86vh;
  overflow: auto;
  padding: 24px 28px;
  position: relative;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 32px;
  color: #8C6642;
  cursor: pointer;
  line-height: 1;
  width: 42px;
  height: 42px;
}

h2 { margin-top: 0; color: var(--delft-blue); font-size: 26px; }

.rules-content h3 { color: var(--delft-blue); margin: 18px 0 6px; font-size: 19px; }
.rules-content ul, .rules-content ol { padding-left: 22px; }
.rules-content li { margin: 5px 0; }
.rules-footnote { font-style: italic; color: #5C4033; margin-top: 18px; font-size: 15px; }

.settings-content .setting {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0;
  font-size: 17px;
}

.settings-content select {
  font-size: 16px;
  padding: 6px 12px;
  border-radius: 5px;
  border: 2px solid #8C6642;
}

.settings-note { font-size: 15px; color: #5C4033; margin-top: 12px; }

/* Game over */
.gameover-content { max-width: 520px; text-align: center; }
#gameover-title { font-size: 28px; }
.final-scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0;
  text-align: left;
}
.final-score-row {
  background: #3A2A1F;
  color: #F5F0E6;
  padding: 8px 14px;
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  font-size: 17px;
}
.final-score-row.winner { border: 2px solid #C5A26F; }
.winner-announce {
  font-size: 20px;
  color: var(--delft-blue);
  font-weight: 700;
  margin: 12px 0;
}

.gameover-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 8px;
}

/* Card on table during play (slightly raised) */
.table .card {
  box-shadow: 2px 5px 11px rgba(0,0,0,0.65);
}

/* Footer */
.footer {
  text-align: center;
  font-size: 12px;
  color: #8C6642;
  padding: 12px 0 18px;
  opacity: 0.85;
}

/* Intro Screen - also locked to 1280x720 viewport */
.intro {
  position: fixed;
  inset: 0;
  background: #2C2118;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #F5F0E6;
  font-family: Georgia, "Times New Roman", serif;
}

.intro-content {
  box-sizing: border-box;
  padding: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(44, 33, 24, 0.95);
  border: 4px solid #C5A26F;
  border-radius: 12px;
}
/* Intro content is now fixed inside the 1280x720 box */
.intro-content h1 {
  font-size: 48px;
  color: #C5A26F;
  margin: 0 0 8px;
  text-align: center;
}
.intro-content h2 {
  font-size: 22px;
  margin: 0 0 20px;
  color: #E8D4A8;
  text-align: center;
}
.intro-image {
  width: 620px;
  height: 320px;
  background-size: cover;
  background-position: center;
  border: 5px solid #C5A26F;
  border-radius: 12px;
  margin: 20px 0;
  box-shadow: 0 6px 25px rgba(0,0,0,0.6);
  flex-shrink: 0;
}
.gender-buttons {
  display: flex;
  gap: 40px;
  justify-content: center;
  margin-top: 10px;
}
.btn-large {
  font-size: 26px;
  padding: 18px 48px;
  min-width: 180px;
}

/* Utility */
.hidden { display: none !important; }

/* Responsive for smaller screens / tablets */
@media (max-width: 860px) {
  .middle-row { flex-direction: column; align-items: center; }
  .opponent.west, .opponent.east { flex-direction: row; width: auto; gap: 12px; }
  .player-hand .card { width: 60px; height: 84px; }
  .logo { max-height: 62px; }
  .btn { min-height: 44px; font-size: 16px; padding: 8px 16px; }
}

/* Keyboard focus */
.card:focus-visible, .btn:focus-visible {
  outline: 3px solid #E8D4A8;
  outline-offset: 2px;
}
