:root {
  color-scheme: light;
  --felt: #0f6f5d;
  --felt-deep: #08483f;
  --paper: #fff8ea;
  --paper-dim: #eadfc8;
  --ink: #1c2520;
  --muted: #62706a;
  --gold: #d5a73d;
  --red: #b42d36;
  --black-card: #1b2420;
  --shadow: 0 24px 70px rgba(8, 38, 32, 0.32);
  --card-stack-step: 1.2rem;
  --card-width-padding: 1rem;
  --card-base-width: 5.6rem;
  --card-base-height: 7.8rem;
  --card-width: 5.1rem;
  --card-height: 7.1rem;
  --card-face-scale: 1;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 248, 234, 0.18), transparent 24rem),
    linear-gradient(135deg, var(--felt), var(--felt-deep));
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.menu-screen {
  display: grid;
  grid-template-columns: minmax(18rem, 0.9fr) minmax(18rem, 28rem);
  gap: clamp(2rem, 6vw, 5rem);
  align-items: center;
  min-height: 100vh;
  padding: clamp(1.5rem, 5vw, 5rem);
}

#menu-title {
    color: var(--gold);
}

.menu-copy {
  color: var(--paper);
  max-width: 40rem;
}

.eyebrow {
  margin: 0 0 0.65rem;
  color: var(--paper);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 1rem;
  font-size: clamp(3rem, 9vw, 7.5rem);
  line-height: 1.2;
}

.intro {
  max-width: 32rem;
  color: rgba(255, 248, 234, 0.82);
  font-size: clamp(1rem, 2vw, 1.25rem);
  line-height: 1.55;
}

.settings-panel {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  background: rgba(255, 248, 234, 0.93);
  border: 1px solid rgba(255, 248, 234, 0.65);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings-panel label {
  display: grid;
  grid-template-columns: 1fr 6rem;
  gap: 1rem;
  align-items: center;
  color: var(--muted);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
}

input {
  width: 100%;
  padding: 0.65rem 0.7rem;
  color: var(--ink);
  background: #fffdf6;
  border: 1px solid var(--paper-dim);
  border-radius: 6px;
}

.settings-error {
  min-height: 1.25rem;
  margin: 0;
  color: var(--red);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.35;
}

button {
  padding: 0.72rem 1rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid rgba(28, 37, 32, 0.18);
  border-radius: 6px;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 800;
}

.game-actions button:hover:not(:disabled),
.settings-panel button:hover:not(:disabled),
.end-actions button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.primary-action {
  color: #1c1608;
  background: linear-gradient(180deg, #f7d56d, var(--gold));
  border-color: #a77b1b;
}

.game-screen {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0.45rem;
  padding: 0.45rem;
}

.game-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.55rem;
  background: rgba(3, 39, 32, 0.34);
  border: 1px solid rgba(255, 248, 234, 0.12);
  border-radius: 8px;
  color: var(--paper);
}

.game-title-wrap {
  display: flex;
  align-items: center;
  margin-left: 0.5rem;
}

.game-title {
  margin: 0;
  color: var(--gold);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: 1.2rem;
  font-weight: normal;
}

.game-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: flex-end;
}

.score-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  color: var(--paper);
  font-family: "Trebuchet MS", Verdana, sans-serif;
}

.score-strip span {
  padding: 0.28rem 0.55rem;
  background: rgba(3, 39, 32, 0.42);
  border: 1px solid rgba(255, 248, 234, 0.16);
  border-radius: 999px;
  font-size: 0.84rem;
}

.game-metrics {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  align-items: flex-end;
  justify-content: flex-end;
  margin-right: 2rem;
  color: var(--paper);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: 0.84rem;
}

.game-metrics span {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0;
  background: transparent;
  border: 0;
  border-radius: 0;
  white-space: nowrap;
}

.game-metrics strong {
  font-size: 0.96rem;
}

.stock-chip {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 3.7rem;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 8px;
  appearance: none;
  overflow: visible;
}

.stock-chip.is-empty {
  opacity: 0.65;
}

.stock-chip:hover:not(:disabled),
.stock-chip:focus-visible:not(:disabled) {
  transform: none;
}

.stock-chip:hover:not(:disabled) .stock-card-back,
.stock-chip:focus-visible:not(:disabled) .stock-card-back {
  box-shadow:
    0 0.7rem 1.2rem rgba(0, 0, 0, 0.24),
    0 0 0 2px rgba(255, 248, 234, 0.35) inset;
  filter: brightness(1.08) saturate(1.05);
}

.stock-chip::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  top: calc(100% + 0.35rem);
  transform: translateX(-50%) translateY(-0.15rem);
  padding: 0.2rem 0.45rem;
  color: var(--paper);
  background: rgba(7, 25, 21, 0.9);
  border: 1px solid rgba(255, 248, 234, 0.18);
  border-radius: 999px;
  box-shadow: 0 0.35rem 0.8rem rgba(0, 0, 0, 0.24);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  white-space: nowrap;
}

.stock-chip:hover:not(:disabled)::after,
.stock-chip:focus-visible:not(:disabled)::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.symbol-chip {
  position: relative;
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  color: var(--paper);
  background: rgba(3, 39, 32, 0.42);
  border: 1px solid rgba(255, 248, 234, 0.16);
  border-radius: 999px;
  box-shadow: none;
  appearance: none;
  overflow: visible;
}

.symbol-chip span {
  font-size: 1.15rem;
  line-height: 1;
}

.symbol-chip svg {
  display: block;
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.symbol-chip:hover:not(:disabled),
.symbol-chip:focus-visible:not(:disabled) {
  transform: none;
}

.game-actions .symbol-chip:hover:not(:disabled),
.game-actions .symbol-chip:focus-visible:not(:disabled) {
  transform: none;
}

.symbol-chip:hover:not(:disabled),
.symbol-chip:focus-visible:not(:disabled) {
  background: rgba(9, 58, 49, 0.65);
  box-shadow:
    0 0 0 2px rgba(255, 248, 234, 0.32) inset,
    0 0 0 1px rgba(0, 0, 0, 0.12);
}

.symbol-chip:disabled {
  opacity: 0.42;
  color: rgba(255, 248, 234, 0.72);
  background: rgba(3, 39, 32, 0.22);
  box-shadow: none;
  cursor: not-allowed;
  filter: saturate(0.65);
}

.symbol-chip::after {
  content: attr(data-tooltip);
  position: absolute;
  left: auto;
  right: 0;
  top: calc(100% + 0.35rem);
  transform: translateY(-0.15rem);
  padding: 0.2rem 0.45rem;
  color: var(--paper);
  background: rgba(7, 25, 21, 0.9);
  border: 1px solid rgba(255, 248, 234, 0.18);
  border-radius: 999px;
  box-shadow: 0 0.35rem 0.8rem rgba(0, 0, 0, 0.24);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  white-space: nowrap;
}

.symbol-chip:hover:not(:disabled)::after,
.symbol-chip:focus-visible:not(:disabled)::after {
  opacity: 1;
  transform: translateY(0);
}

#undo-button::after {
  left: 50%;
  right: auto;
  transform: translateX(-50%) translateY(-0.15rem);
}

#undo-button:hover:not(:disabled)::after,
#undo-button:focus-visible:not(:disabled)::after {
  transform: translateX(-50%) translateY(0);
}

.stock-card-back {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--paper);
  background: repeating-linear-gradient(135deg, #123b61, #123b61 7px, #174a78 7px, #174a78 14px);
  border: 1px solid rgba(0, 0, 0, 0.28);
  border-radius: 8px;
  box-shadow: 0 0.45rem 0.9rem rgba(0, 0, 0, 0.2);
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: 0.88rem;
  font-weight: 900;
  line-height: 1;
}

.stock-card-back strong {
  display: block;
  font-size: 1.08rem;
  line-height: 1;
  transform: none;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--column-count), minmax(4.6rem, 1fr));
  gap: 0.42rem;
  align-items: start;
  justify-content: center;
  min-height: 0;
  overflow-x: auto;
}

.column {
  position: relative;
  display: block;
  min-width: 4.6rem;
  min-height: 30rem;
  padding: 0;
  background: rgba(3, 39, 32, 0.23);
  border: 1px solid rgba(255, 248, 234, 0.15);
  border-radius: 8px;
}

.column.drop-target {
  box-shadow: inset 0 0 0 2px var(--gold);
  background: rgba(9, 58, 49, 0.34);
}

.empty-slot {
  position: absolute;
  inset: 0.55rem;
  display: grid;
  place-items: center;
  min-height: 6.4rem;
  color: rgba(255, 248, 234, 0.45);
  border: 1px dashed rgba(255, 248, 234, 0.35);
  border-radius: 8px;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.card {
  position: absolute;
  top: calc(0.5rem + var(--card-index) * var(--card-stack-step));
  left: 50%;
  display: block;
  width: var(--card-width);
  height: var(--card-height);
  padding: 0;
  background: repeating-linear-gradient(135deg, #123b61, #123b61 7px, #174a78 7px, #174a78 14px);
  border: 1px solid rgba(0, 0, 0, 0.28);
  border-radius: 8px;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.2);
  overflow: hidden;
  transform: translateX(-50%);
  transition: transform 160ms ease, box-shadow 160ms ease;
  user-select: none;
  touch-action: none;
  cursor: grab;
}

.card.face-up {
  background:
    linear-gradient(145deg, rgba(213, 167, 61, 0.16), transparent 42%),
    linear-gradient(180deg, #fffef9, #f5ecdb);
}

.card-content {
  position: absolute;
  inset: 0;
  width: var(--card-base-width);
  height: var(--card-base-height);
  transform-origin: top left;
  transform: scale(var(--card-face-scale));
}

.card.dragging-source {
  opacity: 0;
  cursor: grabbing;
}

.selected-group-frame {
  position: absolute;
  left: 50%;
  top: calc(0.6rem + var(--selected-start) * var(--card-stack-step));
  width: var(--card-width);
  height: calc(var(--card-height) + (var(--selected-count) - 1) * var(--card-stack-step));
  transform: translateX(-50%);
  border: 2px solid var(--gold);
  border-radius: 8px;
  box-shadow: 0 0 0 1px rgba(255, 248, 234, 0.2) inset;
  pointer-events: none;
  z-index: 3;
}

.card-index {
  position: absolute;
  top: 0;
  right: 0.22rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.14rem;
  min-height: 1rem;
  padding: 0 0.02rem;
  text-align: right;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-weight: 900;
  line-height: 1;
}

.index-rank {
  font-size: 0.76rem;
}

.index-suit {
  transform: translateY(-0.1rem);
}

.card-center {
  position: absolute;
  inset: 1rem 0.64rem 0.34rem;
  display: grid;
  overflow: hidden;
}

.drag-ghost {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  perspective: 900px;
  filter: drop-shadow(0 0.8rem 1rem rgba(0, 0, 0, 0.28));
}

.deal-ghost {
  position: fixed;
  z-index: 45;
  pointer-events: none;
  perspective: 900px;
  transform-style: preserve-3d;
  will-change: left, top, width, height;
}

.deal-ghost-inner {
  position: absolute;
  inset: 0;
  transform-origin: center center;
  transform-style: preserve-3d;
  will-change: transform;
}

.deal-ghost-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 8px;
  overflow: hidden;
  will-change: transform;
}

.deal-ghost-back {
  display: grid;
  place-items: center;
  color: var(--paper);
  background: repeating-linear-gradient(135deg, #123b61, #123b61 7px, #174a78 7px, #174a78 14px);
  border: 1px solid rgba(0, 0, 0, 0.28);
  box-shadow: 0 0.45rem 0.9rem rgba(0, 0, 0, 0.2);
}

.deal-ghost-backmark {
  width: 38%;
  height: 38%;
  border-radius: 999px;
  border: 1px solid rgba(255, 248, 234, 0.58);
  box-shadow: 0 0 0 0.22rem rgba(255, 248, 234, 0.08) inset;
}

.deal-ghost-front {
  transform: rotateY(180deg);
}

.deal-ghost-card.card {
  position: absolute;
  inset: 0;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  transform: none;
}

.deal-ghost-card.card.face-up {
  box-shadow: none;
}

.deal-ghost-card.card .card-index {
  top: 0.14rem;
  right: 0.16rem;
}

.deal-ghost-card.card .card-center {
  inset: 0.9rem 0.55rem 0.3rem;
}

.drag-ghost .card {
  width: var(--card-width);
  height: var(--card-height);
  left: 0;
  transform: none;
  top: calc(var(--card-index) * var(--card-stack-step));
}

.drag-ghost .card-content,
.deal-ghost-card.card .card-content {
  transform: scale(var(--card-face-scale));
}

.drag-ghost.is-invalid {
  opacity: 0.6;
  filter: drop-shadow(0 0.8rem 1rem rgba(0, 0, 0, 0.28)) saturate(0.7);
}

.pip-layout {
  display: grid;
  width: 69%;
  justify-self: center;
  justify-items: stretch;
  align-content: space-evenly;
  gap: 0;
}

.pip-row {
  display: grid;
  align-items: center;
  justify-items: center;
  width: 100%;
}

.pip-row-1 {
  grid-template-columns: 1fr;
}

.pip-row-2 {
  display: flex;
  justify-content: space-between;
  width: 82%;
  justify-self: center;
  padding: 0;
}

.pip-row-3 {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.pip {
  display: grid;
  place-items: center;
  font-size: 1.8rem;
  line-height: 1;
}

.pip-layout-1 .pip-row-1 .pip {
  position: relative;
  top: -0.3rem;
  font-size: 3.5rem;
}

.pip-layout-2 .pip, .pip-layout-3 .pip {
  font-size: 1.8rem;
}

.pip-layout-4 .pip {
  font-size: 1.5rem;
}

.pip-layout-5 .pip {
  font-size: 1.2rem;
}

.pip-layout-6 .pip {
  font-size: 0.9rem;
}

.court-center {
  align-content: center;
  justify-items: center;
  gap: 0;
  transform: translateY(-0.2rem);
}

.court-letter {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.3rem;
  font-weight: 700;
  line-height: 1;
}

.court-suit {
  margin-top: -0.1rem;
  font-size: 2.8rem;
  line-height: 1;
}

.game-statusbar {
  padding: 0.28rem 0.55rem 0.42rem;
  color: var(--paper);
  background: rgba(3, 39, 32, 0.34);
  border: 1px solid rgba(255, 248, 234, 0.12);
  border-radius: 8px;
}

.game-statusbar p {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}

.red {
  color: var(--red);
}

.black {
  color: var(--black-card);
}

.end-menu {
  width: min(90vw, 26rem);
  padding: 1.5rem;
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.end-menu::backdrop {
  background: rgba(3, 28, 24, 0.72);
}

.end-menu h2 {
  margin-bottom: 0.4rem;
  font-size: 2.2rem;
}

.end-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.2rem;
}

@media (max-width: 780px) {
  .game-screen {
    gap: 0.4rem;
    padding: 0.4rem;
  }

  .menu-screen {
    grid-template-columns: 1fr;
    align-content: center;
  }

  .game-header {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .settings-panel label {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }

  .game-actions {
    justify-content: flex-start;
  }

  .score-strip {
    justify-content: flex-start;
  }

  .board {
    grid-template-columns: repeat(var(--column-count), minmax(4.2rem, 1fr));
  }

  .column {
    min-height: 26rem;
  }
}
