:root {
  --bg: #1c2f3c;
  --card-bg: #ffffff;
  --card-back: linear-gradient(135deg, #b23a48 0%, #861b28 100%);
  --text: #f7f7f7;
  --accent: #f3c677;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #9cb6ca, #73afd6 55%);
  color: var(--text);
}

body {
  display: flex;
  justify-content: center;
  padding: 24px;
  min-height: 100vh;
}

.app-shell {
  width: min(1200px, 100%);
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 48px);
  height: calc(100vh - 48px);
}

header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 12px;
}

.header-top {
  text-align: center;
  width: 100%;
}

.header-top h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.8rem);
}

.header-bottom {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  width: 100%;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

button {
  border: none;
  border-radius: 999px;
  padding: 8px 5px;
  background: var(--accent);
  color: #1c2f3c;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, filter 0.2s ease;
}

#undoMove {
  border: 1px solid #1c2f3c;
  font-weight: 700;
  cursor: pointer;
  background: none;
  padding: 3px 3px;
}

#undoMove:disabled {
    background-color: #cccccc; /* Light gray */
    color: #666666;            /* Darker gray text */
    cursor: not-allowed;       /* Show "not allowed" cursor */
    opacity: 0.6;              /* Slightly faded look */
    border: 1px solid #999999; /* Optional border for clarity */
}

#makeNoise {
  border: 1px solid #1c2f3c;
  font-weight: 700;
  cursor: pointer;
  background: none;
  padding: 3px 3px;
}

#makeNoise[silent='true'] {
    background-color: #cccccc; /* Light gray */
    color: #666666;            /* Darker gray text */
    opacity: 0.6;                /* Slightly faded look */
    border: 1px solid #999999; /* Optional border for clarity */
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

main {
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
}

.pile,
.tableau-pile {
  min-height: 122px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 12px;
  position: relative;
}

.pile {
  display: flex;
  justify-content: center;
  align-items: center;
}

.tableau-headers {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  justify-items: center;
  place-items: center;
  gap: 26px;
}

.tableau {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 26px;
  flex: 1 1 auto;
  min-height: 0;
}

.tableau-pile {
  min-height: 0;
  overflow: hidden;
}

.cardsXXX-remaining {
  position: relative;
  top: 50%;
  z-index:9999;
}

.deal-cards {
  position: relative;
  top: 45%;
}

.card {
  width: 100px;
  min-height: 140px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(0, 0, 0, 0.12);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-bg);
  color: #1b1b1b;
  cursor: pointer;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 12px;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.card.back {
  background: var(--card-back);
  border: none;
}

.card.selected {
  outline: 3px solid rgba(243, 198, 119, 0.9);
  outline-offset: 4px;
}

.card-content {
  display: grid;
  grid-template-columns: auto auto;
  align-items: start;
  gap: 4px;
}

.card-value,
.card-suit {
  font-size: 1.5rem;
  line-height: 1.1;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.header.header-red {
  color: #c12d35;
}

.header.header-black {
  color: #0a1c2a;
}

.card.suit-red {
  color: #c12d35;
}

.card.suit-black {
  color: #0a1c2a;
}

.card .large-suit {
  place-self: center;
  font-size: 3rem;
}

.card[draggable="true"] {
  cursor: grab;
}

.card.dragging {
  opacity: 0.65;
}

.card * {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.tableau-headers-section {
  display: grid;
  place-items: center;
  justify-items: center;
  margin-bottom: 4px;
}

.tableau-headers .large-suit {
  font-size: 3rem;
}

.tableau-headers .large-suit.header-red.suit-matched {
  color: #c12d35;
    display: inline-block;           /* Shrinks to fit content */
    padding-left: 14px;                   /* Space between text and border */
    padding-right: 14px;                  /* Space between text and border */
    padding-top: 0px;
    padding-bottom: 0px;
    border: 2px solid #3498db;       /* Border color and thickness */
    border-radius: 100%;              /* Makes the border circular */
    text-align: center;              /* Centers text inside */
}

.tableau-headers .large-suit.header-black.suit-matched {
  color: #0a1c2a;
    display: inline-block;           /* Shrinks to fit content */
    padding-left: 14px;                   /* Space between text and border */
    padding-right: 14px;                  /* Space between text and border */
    padding-top: 0px;
    padding-bottom: 0px;
    border: 2px solid #3498db;       /* Border color and thickness */
    border-radius: 100%;              /* Makes the border circular */
    text-align: center;              /* Centers text inside */
}
.tableau-headers .header-red {
  color: #c12d35;
}

.tableau-headers .header-black {
  color: #0a1c2a;
}

.tableau-pile.drag-over,
.foundation-slot.drag-over {
  border-color: var(--accent);
  background: rgba(243, 198, 119, 0.16);
}

.card-label {
  font-size: 0.8rem;
  color: rgba(0, 0, 0, 0.45);
  justify-self: end;
}

#fireworks-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 9998;
}

.firework-piece {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--color);
  box-shadow: 0 0 14px var(--color), 0 0 24px color-mix(in srgb, var(--color) 70%, transparent);
  transform: translate(-50%, -50%) scale(0.2);
  opacity: 0;
  animation: firework-burst 1.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: var(--delay, 0s);
}

@keyframes firework-burst {
  0% {
    transform: translate(-50%, -50%) scale(0.2);
    opacity: 1;
  }
  20% {
    opacity: 1;
  }
  70% {
    transform: translate(calc(-50% + var(--dx) * 0.55), calc(-50% + var(--dy) * 0.55)) scale(calc(var(--scale, 1) * 0.95));
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(calc(var(--scale, 1) * 0.35));
    opacity: 0;
  }
}

footer {
  margin-top: 5px;
  margin-bottom: 5px;
  color: rgba(255, 255, 255, 0.84);
  font-size: 0.95rem;
}

@media (max-width: 960px) {
  .top-row {
    grid-template-columns: 1fr 1fr;
  }
  .foundations {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 720px) {
  body {
    padding: 12px;
  }
  .top-row {
    grid-template-columns: 1fr 1fr;
  }
  .pile,
  .foundation-slot,
  .tableau-pile {
    min-height: 130px;
  }
  .card {
    width: 90px;
  }
}
