:root {
  --bg-0: #03070d;
  --bg-1: #07111f;
  --bg-2: #10233b;
  --felt: #0c3a3f;
  --felt-dark: #08272c;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f6f8fb;
  --muted: #aab8c8;
  --accent: #5ed1c4;
  --gold: #e7bd65;
  --danger: #e05f70;
  --card-w: clamp(30px, calc((100vw - 34px) / 10), 86px);
  --card-gap: 22px;
  --hidden-gap: 10px;
  --radius: 8px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

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

body {
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 12%, rgba(94, 209, 196, 0.18), transparent 26%),
    linear-gradient(145deg, var(--bg-2), var(--bg-0) 68%);
}

button {
  color: inherit;
  font: inherit;
}

.game-shell {
  display: grid;
  grid-template-rows: auto minmax(0, auto) 1fr auto;
  height: 100dvh;
  padding:
    max(10px, env(safe-area-inset-top))
    max(8px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(8px, env(safe-area-inset-left));
  gap: 8px;
}

.top-bar,
.bottom-bar {
  background: rgba(3, 9, 18, 0.72);
  border: 1px solid var(--line);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(16px);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 62px;
  padding: 8px 10px;
  border-radius: var(--radius);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
  color: #07111f;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent), var(--gold));
}

h1 {
  margin: 0;
  font-size: clamp(1rem, 4vw, 1.55rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(45px, auto));
  gap: 6px;
  flex: 0 0 auto;
}

.stat {
  min-width: 45px;
  padding: 5px 7px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
  text-align: center;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.58rem;
  letter-spacing: 0.08em;
}

.stat strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(0.78rem, 2.8vw, 1rem);
  white-space: nowrap;
}

.message {
  min-height: 22px;
  color: #d7fff9;
  font-size: 0.84rem;
  text-align: center;
}

.message:empty {
  visibility: hidden;
}

.board {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 3px;
  min-height: 0;
  padding: 5px 0 10px;
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(0, 0, 0, 0.08)),
    linear-gradient(145deg, var(--felt), var(--felt-dark));
  background-size: 18px 18px, auto, auto;
  overflow: hidden;
  touch-action: none;
}

.column {
  position: relative;
  min-width: 0;
  height: 100%;
  border-radius: 8px;
}

.column::before {
  content: "";
  position: absolute;
  inset: 0 1px auto;
  height: calc(var(--card-w) * 1.38);
  border: 1px dashed rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.08);
}

.card {
  position: absolute;
  left: 50%;
  width: min(100%, var(--card-w));
  aspect-ratio: 0.715;
  transform: translateX(-50%);
  border-radius: var(--radius);
  border: 1px solid rgba(9, 23, 38, 0.24);
  user-select: none;
  touch-action: none;
  cursor: grab;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.18);
  transition: filter 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

.card.face-up {
  background-color: #fff;
  background-image: url("../assets/cards-sprite.webp");
  color: #0d1927;
  background-size: 1300% 400%;
  background-repeat: no-repeat;
  padding: 0;
}

.card.face-down {
  background:
    linear-gradient(135deg, rgba(19, 45, 75, 0.96), rgba(7, 17, 31, 0.98));
  border-color: rgba(255, 255, 255, 0.16);
}

.card.face-down::after {
  content: "";
  position: absolute;
  inset: 17%;
  border: 1px solid rgba(94, 209, 196, 0.46);
  border-radius: 6px;
  background:
    repeating-linear-gradient(45deg, rgba(94, 209, 196, 0.18) 0 3px, transparent 3px 8px);
}

.card-rank {
  position: absolute;
  top: 5px;
  left: 5px;
  font-size: clamp(0.58rem, 2.6vw, 1rem);
  font-weight: 850;
  line-height: 1;
}

.card-suit {
  position: absolute;
  right: 5px;
  bottom: 4px;
  color: #131d2a;
  font-size: clamp(0.7rem, 3vw, 1.1rem);
  line-height: 1;
}

.card.selected,
.card.hint {
  filter: drop-shadow(0 0 10px rgba(94, 209, 196, 0.86));
  box-shadow: 0 0 0 2px var(--accent), 0 8px 16px rgba(0, 0, 0, 0.2);
}

.card.dragging {
  transition: none;
  will-change: transform;
  z-index: 1000;
  cursor: grabbing;
  pointer-events: none;
  filter: drop-shadow(0 13px 20px rgba(0, 0, 0, 0.34));
}

.card.drag-ghost {
  opacity: 0.96;
}

.completion-badge {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255, 255, 255, 0.14);
  font-size: clamp(1.8rem, 7vw, 4.4rem);
  font-weight: 900;
}

.bottom-bar {
  display: grid;
  grid-template-columns: 1.35fr 1fr 1fr 1fr;
  gap: 8px;
  padding: 8px;
  border-radius: var(--radius);
}

.tool-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 48px;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.tool-button:disabled {
  color: rgba(255, 255, 255, 0.35);
  cursor: not-allowed;
}

.tool-button:not(:disabled):active {
  transform: translateY(1px);
}

.stock-button {
  justify-content: space-evenly;
}

.stock-stack {
  width: 34px;
  height: 42px;
  border: 1px solid rgba(94, 209, 196, 0.52);
  border-radius: 7px;
  background:
    linear-gradient(135deg, rgba(94, 209, 196, 0.18), transparent),
    #10233b;
  box-shadow: 4px 0 0 rgba(255, 255, 255, 0.1), 8px 0 0 rgba(255, 255, 255, 0.06);
}

.win-dialog {
  width: min(320px, calc(100vw - 32px));
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  color: var(--text);
  background: #07111f;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.win-dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.win-dialog form {
  display: grid;
  gap: 12px;
}

.win-dialog h2,
.win-dialog p {
  margin: 0;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  color: #07111f;
  background: var(--accent);
  font-weight: 800;
}

.secondary-button {
  background: rgba(255, 255, 255, 0.1);
}

@media (min-width: 720px) {
  :root {
    --card-w: clamp(58px, calc((100vw - 82px) / 10), 96px);
  }

  .game-shell {
    max-width: 1120px;
    margin: 0 auto;
    padding-inline: 16px;
  }

  .board {
    gap: 6px;
    padding-inline: 8px;
  }

  .bottom-bar {
    max-width: 640px;
    justify-self: center;
    width: 100%;
  }
}

@media (max-width: 460px) {
  .top-bar {
    min-height: 58px;
    padding: 7px;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
  }

  .brand p {
    display: none;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(40px, auto));
  }

  .stat {
    padding-inline: 4px;
  }

  .tool-button {
    font-size: 0.82rem;
    padding-inline: 4px;
  }
}
