:root {
  color-scheme: light;
  --felt: #0b6e4f;
  --felt-dark: #095a40;
  --panel: #ffffff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--felt), var(--felt-dark));
  color: #f8fafc;
}

header {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  padding: 0.4rem 1rem;
  background: rgba(0, 0, 0, 0.25);
}

header h1 {
  font-size: 1.25rem;
  margin: 0;
  margin-right: auto;
}

/* The button row lives in a hamburger dropdown at every screen size, not
   just phones - keeps the header (and the vertical space it takes while
   scrolling) consistent between mobile and desktop. */
.menu-toggle {
  display: inline-flex;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.3rem 0.6rem;
}

header nav {
  display: none;
  flex-direction: column;
  gap: 0.35rem;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--felt-dark);
  padding: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
  z-index: 20;
}
header nav.open {
  display: flex;
}

button {
  font: inherit;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  cursor: pointer;
}
button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
button.primary {
  background: #2563eb;
  border-color: #1d4ed8;
}

#status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  padding: 0.25rem 1rem;
  font-size: 0.8rem;
  opacity: 0.9;
}

#board {
  padding: 0.6rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#rank-piles {
  display: grid;
  grid-template-columns: repeat(7, minmax(96px, 1fr));
  gap: 0.4rem 0.6rem;
}

.rank-pile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.rank-label {
  font-size: 0.7rem;
  text-align: center;
  opacity: 0.85;
}
.rank-label .count {
  opacity: 0.7;
}

.card-svg {
  width: 96px;
  height: 134px;
  display: block;
}

.pile-card,
.spread-card,
.foundation {
  cursor: pointer;
  border-radius: 8px;
  transition: transform 0.1s ease;
}
.pile-card,
.spread-card {
  /* Let our own pointer-drag code handle vertical finger movement instead of
     the browser scrolling the page underneath a card being dragged. */
  touch-action: none;
  /* Without this, dragging the mouse across a card's text/svg content
     starts a native text-selection instead of (or alongside) our drag. */
  user-select: none;
  -webkit-user-select: none;
}
.pile-card:hover,
.spread-card:hover {
  transform: translateY(-4px);
}
.pile-card.selected .card-svg,
.spread-card.selected .card-svg {
  outline: 3px solid #facc15;
  outline-offset: 2px;
  border-radius: 8px;
}
.pile-card.empty {
  cursor: default;
  touch-action: auto;
}
.pile-card.empty:hover {
  transform: none;
}
.pile-card.dragging-source,
.spread-card.dragging-source {
  opacity: 0.35;
}

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.05);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.4));
}

.foundation.drag-target {
  outline: 3px solid #facc15;
  outline-offset: 2px;
  border-radius: 8px;
}

#foundations {
  display: flex;
  justify-content: center;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.foundation-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1.4rem 1rem;
}

.foundation-pair {
  display: flex;
  gap: 0.35rem;
}

.foundation-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
}

.foundation-label {
  font-size: 0.7rem;
  text-align: center;
  opacity: 0.85;
  white-space: nowrap;
}

.foundation.invalid .card-svg {
  animation: shake 0.3s;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.foundation-done {
  position: relative;
}
.done-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #16a34a;
  color: #fff;
  border-radius: 999px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}

.stock-pile {
  /* Double-clicking the card-back to draw shouldn't select nearby text
     (e.g. the "Draw" button's label). */
  user-select: none;
  -webkit-user-select: none;
}
.stock-pile button {
  margin-top: 0.15rem;
}

/* The mobile sticky stock bar (see _renderMobileStockBar) is hidden by
   default - only shown, in place of the in-grid .stock-pile, on phones. */
#mobile-stock-bar {
  display: none;
}

/* Piles-vs-spread view toggle - phones only (see .mobile-hide below). */
.mobile-view-toggle {
  display: none;
}

#spread-tray {
  min-height: 110px;
  background: rgba(0, 0, 0, 0.15);
  border-radius: 10px;
  padding: 0.75rem 1rem;
}
.spread-title {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  opacity: 0.85;
}
.spread-hint {
  margin: 0;
  opacity: 0.7;
  font-size: 0.9rem;
}
.spread-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

dialog {
  border: none;
  border-radius: 10px;
  padding: 1.25rem 1.5rem;
  width: min(420px, 92vw);
  max-height: 85vh;
  overflow-y: auto;
  color: #111827;
  box-sizing: border-box;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}
.dialog-form h2 {
  margin-top: 0;
}
.dialog-form label,
.dialog-form fieldset {
  display: block;
  margin: 0.5rem 0;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}
.scores-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.scores-table th,
.scores-table td {
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
}

@media (max-width: 900px) {
  #rank-piles {
    grid-template-columns: repeat(4, minmax(80px, 1fr));
  }
  .card-svg {
    width: 80px;
    height: 112px;
  }
  /* On the narrower mobile grid, keep the stock in its old spot (the very
     end) rather than wherever the middle-of-desktop-row DOM position falls. */
  .stock-pile {
    order: 999;
  }
}

@media (max-width: 520px) {
  header h1 {
    font-size: 1.05rem;
  }
  button {
    padding: 0.35rem 0.6rem;
    font-size: 0.85rem;
  }
  #status-bar {
    font-size: 0.7rem;
    gap: 0.3rem 0.8rem;
    padding: 0.2rem 0.6rem;
  }
  #board {
    padding: 0.5rem 0.6rem 0.75rem;
    gap: 0.5rem;
  }
  #rank-piles {
    grid-template-columns: repeat(4, minmax(68px, 1fr));
    gap: 0.3rem 0.4rem;
  }
  .card-svg {
    width: 68px;
    height: 95px;
  }
  .rank-label,
  .foundation-label {
    font-size: 0.62rem;
  }
  .foundation-row {
    gap: 0.9rem 0.6rem;
  }
  .foundation-pair {
    gap: 0.25rem;
  }
  #spread-tray {
    padding: 0.5rem 0.6rem;
    min-height: 90px;
  }

  /* The in-grid stock cell is hidden on phones - the draw control instead
     lives directly under the spread cards, as part of the Draw Pile tab
     (shown/hidden together with #spread-tray, see _applyMobileView). */
  .stock-pile {
    display: none;
  }
  #mobile-stock-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    padding: 0.6rem;
    margin-top: 0.5rem;
  }
  #mobile-stock-bar .card-svg {
    width: 48px;
    height: 67px;
  }
  #mobile-stock-bar .rank-label {
    font-size: 0.75rem;
  }

  /* There isn't room on a phone to show the full pile grid and a fully
     revealed pile at once, so a toggle switches between them instead. */
  .mobile-view-toggle {
    display: flex;
    gap: 0.4rem;
  }
  .mobile-view-toggle .view-tab {
    flex: 1;
    padding: 0.45rem 0.4rem;
    font-size: 0.8rem;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.08);
    color: inherit;
  }
  .mobile-view-toggle .view-tab.active {
    background: #2563eb;
    border-color: #1d4ed8;
  }
  /* #rank-piles/#spread-tray/#mobile-stock-bar specificity beats a plain
     .mobile-hide rule, so this needs the id+class combined selector to
     actually win. */
  #rank-piles.mobile-hide,
  #spread-tray.mobile-hide,
  #mobile-stock-bar.mobile-hide {
    display: none;
  }
  /* "A-6" / "7-K" tabs: only render the half of the grid that's active. */
  #rank-piles.view-low .rank-pile[data-group="high"],
  #rank-piles.view-high .rank-pile[data-group="low"] {
    display: none;
  }
}
