:root {
  --card-w: clamp(46px, 19vw, 82px);
  /* Proporcao real da arte do baralho (viewBox 167 x 242.7). */
  --card-h: calc(var(--card-w) * 1.452);
  --felt: #17603f;
  --felt-dark: #0e4530;
  --ink: #16241d;
  --paper: #fdfdf8;
  --accent: #ffd166;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  /* Altura travada (não min-height): é o que obriga as colunas a comprimirem o
     leque em vez de esticarem a página. dvh acompanha a barra do navegador. */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: radial-gradient(circle at 50% 0%, var(--felt) 0%, var(--felt-dark) 100%);
  color: #f2f7f4;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.controls {
  display: flex;
  gap: 6px;
}

button {
  font: inherit;
  cursor: pointer;
}

.ghost,
.primary {
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  padding: 8px 14px;
  min-height: 40px;
}

.ghost:disabled {
  opacity: 0.4;
  cursor: default;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink);
  font-weight: 600;
}

.primary:disabled {
  opacity: 0.45;
  cursor: default;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.hint {
  margin: 0;
  min-height: 2.4em;
  font-size: 0.85rem;
  line-height: 1.35;
  color: #d8ebe1;
}

.hint.won {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.05rem;
}

.board {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

/* Monte */

.stock {
  display: flex;
  align-items: center;
  gap: 12px;
}

.pile {
  position: relative;
  border: 2px dashed rgba(255, 255, 255, 0.3);
  border-radius: var(--radius);
  background: none;
  padding: 6px;
  display: flex;
}

.pile.droppable {
  border-color: var(--accent);
  border-style: solid;
  background: rgba(255, 209, 102, 0.15);
}

.pile:disabled {
  opacity: 0.5;
  cursor: default;
}

.facedown {
  position: absolute;
  inset: 10px;
  border-radius: var(--radius);
  background: repeating-linear-gradient(45deg, #2b4f7a 0 6px, #1e3a5c 6px 12px);
  transform: translate(-5px, -5px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.counter {
  margin: 0;
  font-size: 0.85rem;
}

.counter strong {
  font-size: 1.3rem;
}

/* Colunas */

.columns {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  /* A linha precisa ser limitada: com altura automática ela cresce junto com a
     pilha, e aí o leque nunca comprime — a coluna é que estica a tela. */
  grid-template-rows: minmax(0, 1fr);
  gap: 6px;
  min-height: 0;
}

.column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 0;
  overflow: hidden;
  padding: 6px 4px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.16);
  color: inherit;
}

.column.droppable {
  border-color: var(--accent);
  background: rgba(255, 209, 102, 0.14);
}

.column-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  min-height: 0;
  overflow: hidden;
  transform: scale(var(--fit, 1));
  transform-origin: top center;
  --step: 28px;
}

.column-body .card + .card {
  margin-top: calc(var(--step) - var(--card-h));
}

.column-foot {
  font-size: 0.75rem;
  opacity: 0.85;
}

/* Cartas */

.card {
  position: relative;
  flex: 0 0 auto;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 6px;
  background: var(--paper);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  display: block;
  object-fit: fill;
  user-select: none;
}

.card.empty {
  background: none;
  border: 2px dashed rgba(255, 255, 255, 0.25);
  box-shadow: none;
}

.card.in-hand {
  opacity: 0.4;
  outline: 2px dashed var(--accent);
}





/* Painel de escolha */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  z-index: 10;
}

/* O atributo hidden perde para o display: flex acima sem esta regra. */
.overlay[hidden] {
  display: none;
}

.sheet {
  width: min(620px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--paper);
  color: var(--ink);
  border-radius: 14px 14px 0 0;
  padding: 16px;
}

.sheet h2 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.sheet-hint {
  margin: 0 0 12px;
  font-size: 0.82rem;
  color: #55635b;
}

.pick-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 6px;
}

.pick,
.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 58px;
  padding: 6px 2px;
  border: 2px solid #ccccc0;
  border-radius: 8px;
  background: #fff;
}

.chip {
  flex: 0 0 auto;
  width: 54px;
}

.chip.held {
  opacity: 0.45;
  border-style: dashed;
}

.pick.on {
  border-color: #16603f;
  background: #e4f4ec;
  box-shadow: inset 0 0 0 2px #16603f;
}

.mini {
  display: block;
  width: 44px;
  height: 64px;
  border-radius: 4px;
  background: #fff;
  object-fit: fill;
  user-select: none;
}

.pick-pos {
  font-size: 0.65rem;
  color: #6a776f;
}

/* A coluna de destino aberta: cartas à vista, espaços entre elas clicáveis. */
.drop-row {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 2px 0;
}

.slot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  min-height: 58px;
  padding: 0;
  border: 2px dashed #16603f;
  border-radius: 8px;
  background: #eef7f2;
  color: #16603f;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
}

.slot:hover,
.slot:focus-visible {
  background: #16603f;
  color: #fff;
  border-style: solid;
}

.slot:disabled {
  opacity: 0.25;
  cursor: default;
  background: none;
}

.slot.inline {
  display: inline-flex;
  width: 18px;
  min-height: 18px;
  vertical-align: -3px;
  font-size: 0.8rem;
  border-width: 1px;
}

.carried {
  display: inline-block;
  width: 26px;
  height: 38px;
  margin-right: 3px;
  vertical-align: -12px;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  object-fit: fill;
}

.sheet-actions {
  position: sticky;
  bottom: -16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 14px;
  padding: 10px 0 2px;
  background: var(--paper);
}

.sheet-actions .ghost {
  border-color: #b9b9ad;
  background: #fff;
  color: var(--ink);
}

/* Vitória e avisos */

.board.won .stock .pile {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 209, 102, 0.35);
}

.file-warning {
  background: #fff3cd;
  color: #4a3a05;
  border: 1px solid #e0c86a;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.85rem;
  line-height: 1.4;
}

@media (min-width: 720px) {
  :root {
    /* Na tela grande a coluna sobra espaço; a carta cresce junto. */
    --card-w: clamp(76px, 8vw, 112px);
  }

  body {
    padding: 16px 20px;
  }

  h1 {
    font-size: 1.35rem;
  }

  .hint {
    font-size: 0.95rem;
  }

  .overlay {
    align-items: center;
    padding: 20px;
  }

  .sheet {
    border-radius: 14px;
  }
}
