:root {
  --card-w: 82px;
  --card-h: 115px;
  --surface: #0d5c3a;
  --surface-dark: #063620;
  --slot-radius: calc(var(--card-w) * 0.095);
  --text: #eef8f0;
  --muted: rgba(238, 248, 240, 0.72);
  --line: rgba(255, 255, 255, 0.2);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--surface-dark);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button,
select {
  font: inherit;
}

#app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding:
    calc(0.64rem + env(safe-area-inset-top))
    calc(0.84rem + env(safe-area-inset-right))
    0.64rem
    calc(0.84rem + env(safe-area-inset-left));
  background: rgba(5, 24, 16, 0.82);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
}

.title-block {
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1rem, 2.6vw, 1.35rem);
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.topbar p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: clamp(0.72rem, 1.8vw, 0.92rem);
  line-height: 1.24;
  max-width: 74rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex: 0 0 auto;
}

.difficulty-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.86rem;
}

select,
button {
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  min-height: 2.25rem;
}

select {
  padding: 0.42rem 1.85rem 0.42rem 0.72rem;
}

select option {
  color: #111;
  background: #fff;
}

button {
  padding: 0.48rem 0.78rem;
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

#table {
  position: relative;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.095), transparent 54%),
    linear-gradient(135deg, #126d44, #063620);
}

.felt-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 25% 18%, rgba(255, 255, 255, 0.05), transparent 24%),
    radial-gradient(circle at 78% 80%, rgba(0, 0, 0, 0.18), transparent 38%);
}

.pile-slot {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 1;
  width: var(--card-w);
  height: var(--card-h);
  border: 2px dashed rgba(255, 255, 255, 0.28);
  border-radius: var(--slot-radius);
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  padding: calc(var(--card-w) * 0.07);
  color: rgba(255, 255, 255, 0.62);
  font-size: clamp(0.58rem, 1.3vw, 0.76rem);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.055em;
  pointer-events: none;
  user-select: none;
  background: rgba(255, 255, 255, 0.035);
}

.pile-slot.is-drop-target {
  border-color: rgba(255, 255, 255, 0.92);
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08) inset;
}

.pile-slot.is-inactive {
  opacity: 0.28;
}

.foundation-slot {
  border-style: solid;
  grid-template-rows: 1fr;
  padding: 0;
}

.tomb-slot {
  border-color: rgba(255, 222, 125, 0.46);
  background: rgba(255, 222, 125, 0.055);
}

.foundation-marker {
  align-self: center;
  color: rgba(255, 255, 255, 0.17);
  font-family: Georgia, "Times New Roman", serif;
  font-size: calc(var(--card-w) * 0.9);
  font-weight: 700;
  line-height: 1;
  text-transform: none;
}

.tomb-marker {
  align-self: center;
  color: rgba(255, 222, 125, 0.34);
  font-family: Georgia, "Times New Roman", serif;
  font-size: calc(var(--card-w) * 0.9);
  font-weight: 700;
  line-height: 1;
  text-transform: none;
}

.slot-title,
.tomb-marker,
.slot-count {
  pointer-events: none;
}

.slot-count {
  opacity: 0.82;
  font-size: 0.82em;
}

.card {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: var(--slot-radius);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transform-origin: 50% 50%;
  will-change: transform;
}

.card-svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: drop-shadow(0 0.28rem 0.42rem rgba(0, 0, 0, 0.33));
}

.card.can-drag {
  cursor: grab;
}

.card.can-deal-stock {
  cursor: pointer;
}

.card.locked {
  cursor: default;
}

.card.dragging {
  cursor: grabbing;
}

.card.dragging .card-svg,
.card.in-drag-group .card-svg {
  filter: drop-shadow(0 0.75rem 1.1rem rgba(0, 0, 0, 0.48));
}

.card.face-down .card-svg {
  filter: drop-shadow(0 0.2rem 0.33rem rgba(0, 0, 0, 0.36));
}

.card.stock-under-card .card-svg {
  filter: none;
}

.card.stock-top-card.face-down .card-svg {
  filter: drop-shadow(0 0.18rem 0.24rem rgba(0, 0, 0, 0.24));
}

@media (max-width: 720px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 0.5rem;
  }

  .controls {
    justify-content: space-between;
    gap: 0.42rem;
  }

  .difficulty-label {
    flex: 1 1 auto;
  }

  .difficulty-label select {
    width: 100%;
  }

  button {
    padding-inline: 0.64rem;
  }
}

@media (max-width: 420px) {
  .controls {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
  }

  .difficulty-label span {
    display: none;
  }

  .topbar p {
    white-space: normal;
  }
}
