:root {
  --table-green: #0b5e3b;
  --table-dark: #063824;
  --accent-gold: #f7c948;
  --text-light: #f8f9fa;
  --card-shadow: rgba(0, 0, 0, 0.35);
  --card-w: 128px;
  --card-h: 184px;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1d734a 0%, #063824 60%, #021c12 100%);
  color: var(--text-light);
  font-size: clamp(16px, 1.2vw, 19px);
  overflow: hidden;
}

body.showing-start #stage-sizer {
  filter: blur(6px);
  opacity: 0.45;
  transition: filter 0.3s ease, opacity 0.3s ease;
}

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, rgba(3, 34, 22, 0.92), rgba(2, 20, 12, 0.95));
  z-index: 200;
  padding: 32px;
}

.screen[hidden] {
  display: none;
}

.screen-content {
  background: rgba(6, 56, 36, 0.95);
  border-radius: 24px;
  padding: 48px min(8vw, 72px);
  width: min(560px, 100%);
  text-align: center;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.6);
}

.screen-content h1 {
  font-size: clamp(48px, 5vw, 62px);
  margin: 0 0 12px;
  letter-spacing: 2px;
}

.tagline {
  margin: 0 0 32px;
  font-size: clamp(18px, 1.6vw, 22px);
  opacity: 0.85;
}

#start-form {
  display: grid;
  gap: 24px;
}

.field-group {
  display: grid;
  gap: 10px;
  text-align: left;
}

.field-group label {
  font-weight: 600;
  letter-spacing: 0.5px;
}

.field-group select,
.field-group input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: none;
  font-size: 18px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-light);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

#start-button {
  margin-top: 12px;
  padding: 16px 24px;
  border-radius: 999px;
  border: none;
  font-size: 20px;
  font-weight: 700;
  background: var(--accent-gold);
  color: #2b2200;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

#start-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.45);
}

#stage-sizer {
  width: min(100vw, 100vh * 2.4);
  height: min(100vh, 100vw / 2.4);
  position: fixed;
  inset: 0;
  margin: 0 auto;
  display: grid;
  place-items: center;
  pointer-events: none;
  transition: filter 0.3s ease, opacity 0.3s ease;
}

#stage-scaler {
  position: absolute;
  transform-origin: top left;
  pointer-events: none;
}

#stage {
  position: relative;
  width: 2400px;
  height: 1000px;
  transform-origin: top left;
  pointer-events: none;
}

#game,
#game * {
  pointer-events: auto;
}

#game {
  width: 100%;
  height: 100%;
  background: rgba(3, 34, 22, 0.94);
  border-radius: 24px;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.65);
  padding: 40px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

header {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(0, 1.4fr) minmax(220px, 1fr);
  align-items: start;
  gap: 32px;
}

.title-block h1 {
  font-size: clamp(48px, 3.6vw, 60px);
  letter-spacing: 2px;
  margin: 0 0 10px;
}

.title-block {
  justify-self: start;
}

.header-computer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.header-computer h2 {
  margin-bottom: 12px;
}

.header-computer .hand {
  min-height: calc(var(--card-h) + 24px);
  flex-wrap: nowrap;
  gap: 14px;
}

#settings-display {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: clamp(18px, 1.4vw, 22px);
  opacity: 0.9;
}

#settings-display .divider {
  opacity: 0.5;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 28px;
  justify-self: end;
}

#scores {
  display: flex;
  gap: 20px;
  font-weight: 600;
  font-size: clamp(18px, 1.4vw, 22px);
}

.score {
  padding: 8px 18px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
}

#new-game-button {
  padding: 12px 26px;
  border-radius: 999px;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: var(--text-light);
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

#new-game-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
  background: rgba(255, 255, 255, 0.25);
}

#message {
  font-size: clamp(20px, 1.6vw, 24px);
  min-height: 1.8em;
  text-align: center;
  margin: 10px auto 0;
}

.hand-area h2 {
  margin: 0 0 16px;
  font-size: clamp(26px, 2vw, 32px);
  letter-spacing: 1.4px;
}

.hand {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  flex-wrap: wrap;
  min-height: 220px;
  padding: 16px;
  gap: 18px;
}

.card {
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  box-shadow: 0 14px 34px var(--card-shadow);
  position: relative;
  transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease, opacity 0.18s ease;
  cursor: grab;
}

.card:active {
  cursor: grabbing;
}

.card:hover {
  transform: translateY(-10px);
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.6);
}

.card.back {
  background-image: url('Card_Faces/card_back.png');
  cursor: pointer;
}

.card.placeholder {
  background: rgba(255, 255, 255, 0.12);
  border: 3px dashed rgba(255, 255, 255, 0.25);
  box-shadow: none;
}

.card.selected {
  outline: 6px solid var(--accent-gold);
  outline-offset: 4px;
  filter: saturate(1.25);
}

.card.unpaired::after {
  content: attr(data-value);
  position: absolute;
  bottom: -26px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 16px;
  background: rgba(0, 0, 0, 0.7);
  padding: 4px 10px;
  border-radius: 12px;
}

.card.dragging {
  opacity: 0.65;
  transform: translateY(-12px) scale(1.02);
}

.card.incoming {
  animation: cardFadeIn 0.45s ease-out both;
}

@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(-30px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.card.ai-pickup {
  animation: cardPickup 0.4s ease forwards;
}

@keyframes cardPickup {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-40px) scale(0.94);
  }
}

#table {
  display: flex;
  justify-content: center;
  gap: 60px;
  align-items: center;
  margin: 12px 0 8px;
  flex-wrap: wrap;
}

.pile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 18px 28px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.pile.disabled {
  opacity: 0.45;
  pointer-events: none;
  filter: grayscale(0.3);
}

.pile:focus,
.pile:hover {
  transform: translateY(-6px);
  box-shadow: 0 18px 32px rgba(0, 0, 0, 0.55);
  background: rgba(0, 0, 0, 0.45);
}

.pile .card {
  pointer-events: none;
}

.pile .card.ai-pickup {
  pointer-events: none;
}

.pile-label {
  font-weight: 700;
  letter-spacing: 1.2px;
  font-size: 18px;
}

.pile-count {
  font-size: 16px;
  opacity: 0.85;
}

#controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 28px;
  margin: 6px auto 0;
}

.sort-controls {
  display: flex;
  gap: 18px;
}

#controls button,
#continue-button {
  padding: 12px 28px;
  border-radius: 999px;
  border: none;
  font-weight: 700;
  cursor: pointer;
  font-size: 18px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

#controls button:hover,
#continue-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.45);
}

#discard-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

#discard-button {
  background: var(--accent-gold);
  color: #2b2200;
}

#sort-rank-button,
#sort-suit-button {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-light);
}

#round-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  place-items: center;
  z-index: 150;
}

#round-overlay:not([hidden]) {
  display: grid;
}

.overlay-content {
  background: rgba(6, 56, 36, 0.95);
  border-radius: 24px;
  padding: 36px 44px;
  text-align: center;
  width: min(520px, 90%);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.58);
}

.overlay-content h2 {
  font-size: clamp(32px, 2.6vw, 40px);
  margin-bottom: 14px;
}

.overlay-content p {
  font-size: clamp(20px, 1.6vw, 24px);
  margin-bottom: 20px;
}

#continue-button {
  background: var(--accent-gold);
  color: #2b2200;
}

.back-to-games {
  position: fixed;
  left: 24px;
  bottom: 24px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: 999px;
  background: rgba(6, 56, 36, 0.85);
  color: var(--text-light);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: 0.6px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.5);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  z-index: 250;
}

.back-to-games:hover {
  transform: translateY(-3px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.55);
  background: rgba(6, 56, 36, 0.95);
}

.back-to-games span[aria-hidden="true"] {
  font-size: 1.2em;
  line-height: 1;
}

.back-to-games .label {
  text-transform: uppercase;
  font-size: 0.8em;
  letter-spacing: 1px;
}

@media (max-width: 900px) {
  .screen-content {
    padding: 36px 28px;
  }

  .back-to-games {
    left: 16px;
    bottom: 16px;
    padding: 10px 16px;
    gap: 8px;
  }

  header {
    grid-template-columns: 1fr;
    justify-items: stretch;
    gap: 24px;
  }

  .header-controls {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-computer {
    width: 100%;
  }

  .header-computer .hand {
    flex-wrap: wrap;
  }

  #scores {
    flex-wrap: wrap;
  }
}