/* ── TABLE ───────────────────────────────────────────────────────
   Card size is measured from this element by the script, which writes
   --ks-w / --ks-h back so the type inside the cards can scale with it. */
#ksTable {
  --ks-w: 72px;
  --ks-h: 104px;
  --ks-gap: 10px;

  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  touch-action: none;           /* dragging a card must not scroll the page */
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: filter .25s;
}

#ksTable.blurred { filter: blur(8px); pointer-events: none; }

.ks-row {
  display: flex;
  gap: var(--ks-gap);
  align-items: flex-start;
}

.ks-spacer { flex: 1; min-width: 0; }

/* ── SLOTS ───────────────────────────────────────────────────── */
.ks-slot {
  position: relative;
  flex-shrink: 0;
  border-radius: 7px;
  box-sizing: border-box;
}

/* An empty slot is just an outline, drawn one card tall: the tableau slots
   are as tall as the longest column so the space below a short pile is
   still a drop target, and a full-height dashed box there would be wrong. */
.ks-slot::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: var(--ks-h);
  border: 2px dashed rgba(100, 130, 170, .4);
  border-radius: 7px;
}
[data-theme="dark"] .ks-slot::before { border-color: rgba(140, 170, 220, .28); }

.ks-found::after {
  content: attr(data-suit);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--ks-w) * .5);
  color: rgba(100, 130, 170, .35);
  pointer-events: none;
}
.ks-found.ks-red-slot::after { color: rgba(200, 70, 70, .3); }

.ks-recycle {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--ks-w) * .42);
  color: var(--muted);
  cursor: pointer;
}

.ks-slot.ks-over::before {
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 3px rgba(42, 111, 189, .25);
}

.ks-slot.ks-hint::before {
  border: 2px solid #f59e0b;
  box-shadow: 0 0 14px rgba(245, 158, 11, .6);
}

/* ── CARDS ───────────────────────────────────────────────────── */
.ks-card {
  position: absolute;
  left: 0;
  top: 0;
  box-sizing: border-box;
  border-radius: 7px;
  background: #fffdf8;
  border: 1px solid #c3cedd;
  box-shadow: 0 1px 2px rgba(20, 35, 60, .28);
  cursor: pointer;
  overflow: hidden;
  font-family: 'Segoe UI', Arial, sans-serif;
  line-height: 1;
}

.ks-black { color: #1b2535; }
.ks-red   { color: #c62828; }

.ks-corner {
  position: absolute;
  top: 4%;
  left: 7%;
  font-size: calc(var(--ks-w) * .3);
  font-weight: 800;
  text-align: center;
  line-height: 1.05;
}

.ks-pip {
  position: absolute;
  right: 6%;
  bottom: 2%;
  font-size: calc(var(--ks-w) * .58);
  opacity: .9;
}

/* the back of a card */
.ks-card.ks-down {
  background:
    repeating-linear-gradient(45deg, #2a6fbd 0 6px, #255f9f 6px 12px);
  border-color: #1d5296;
  box-shadow: inset 0 0 0 3px #fdfdfd, 0 1px 2px rgba(20, 35, 60, .3);
}
[data-theme="dark"] .ks-card.ks-down {
  background: repeating-linear-gradient(45deg, #1d4273 0 6px, #18365e 6px 12px);
  box-shadow: inset 0 0 0 3px #0f1e30, 0 1px 2px rgba(0, 0, 0, .5);
}

.ks-card.ks-sel {
  outline: 3px solid var(--primary);
  outline-offset: -1px;
  box-shadow: 0 0 14px rgba(42, 111, 189, .5);
}

.ks-card.ks-dragging { opacity: .32; }

@keyframes ks-flip {
  from { transform: rotateY(90deg); }
  to   { transform: rotateY(0deg); }
}
.ks-card.ks-flip { animation: ks-flip .18s ease-out; }

/* the stack being carried by the pointer */
.ks-drag {
  position: fixed;
  z-index: 800;
  pointer-events: none;
  filter: drop-shadow(0 10px 14px rgba(10, 20, 50, .45));
}
.ks-drag .ks-card { cursor: grabbing; }

/* ── READOUTS ────────────────────────────────────────────────── */
.best-info {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.best-info b {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
}

.ks-count {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--muted);
}
.ks-count b {
  font-size: 20px;
  font-weight: 800;
  color: var(--primary);
}

/* ── MESSAGE ─────────────────────────────────────────────────── */
#ksMsg {
  display: none;
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #fde047;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  margin: 12px auto 0;
  width: fit-content;
  max-width: 100%;
}
#ksMsg.show { display: block; }
[data-theme="dark"] #ksMsg {
  background: #422006;
  color: #fde047;
  border-color: #854d0e;
}

/* ── ACTIONS ─────────────────────────────────────────────────── */
.ks-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.act-btn.ks-btn-off { opacity: .45; cursor: not-allowed; }
.act-btn.ks-btn-off:hover {
  border-color: var(--btn-border);
  color: var(--btn-text);
  background: var(--card-bg);
}

/* the difficulty pills carry longer labels here */
#diffGroup .diff-btn { padding: 6px 14px; font-size: 12.5px; }

/* ── HINT AD MODAL ───────────────────────────────────────────── */
#hintModal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 15, 45, .72);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
#hintModal.show { display: flex; }

.hint-card {
  background: var(--card-bg);
  border-radius: 20px;
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 24px 72px rgba(0, 0, 40, .32);
  animation: pop .38s cubic-bezier(.34, 1.56, .64, 1);
  width: 360px;
  max-width: 90vw;
  position: relative;
}

#hintPhase1, #hintPhase2, #hintPhase3 { display: none; }
#hintPhase1.active, #hintPhase2.active, #hintPhase3.active { display: block; }

.hint-icon  { font-size: 50px; line-height: 1.15; }
.hint-title { font-size: 1.25em; font-weight: 800; color: var(--primary); margin: 10px 0 6px; }
.hint-sub   { font-size: 14px; color: var(--muted); line-height: 1.55; }

.hint-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }

.hint-btn-primary {
  padding: 11px 24px; border: none; border-radius: 26px;
  background: var(--primary); color: white;
  font-size: 14px; font-weight: 700; cursor: pointer; transition: .16s;
}
.hint-btn-primary:hover { background: var(--primary-dk); transform: translateY(-1px); }

.hint-btn-ghost {
  padding: 9px 24px; border: 2px solid var(--btn-border); border-radius: 26px;
  background: transparent; color: var(--btn-text);
  font-size: 14px; font-weight: 600; cursor: pointer; transition: .16s;
}
.hint-btn-ghost:hover { border-color: var(--primary); color: var(--primary); }

#hintPhase2 { position: relative; }
.hint-close-btn {
  position: absolute; top: -8px; right: -8px;
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid var(--btn-border); background: var(--card-bg);
  cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center; transition: .14s;
}
.hint-close-btn:hover { border-color: var(--err-color); color: var(--err-color); }

#hintAdSlot { margin: 0 auto; }

.hint-progress-label { font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.hint-progress-wrap  { height: 8px; background: var(--border-light); border-radius: 4px; overflow: hidden; }
.hint-progress-bar   { height: 100%; width: 0%; background: var(--primary); border-radius: 4px; transition: width 1s linear; }

/* ── SIDE PANEL ADS (hidden by default) ─────────────────────── */
.side-panel-ad     { display: none; }
.side-panel-mid-ad { display: none; }
.game-mid-ad       { display: none; margin: 0 auto 14px; }

@media (max-width: 775px) {
  .hdr-nav .ad-leaderboard { display: none; }
  .game-mid-ad { display: flex; }
}
@media (max-width: 1100px) {
  .content-row { grid-template-columns: 1fr; }
}
@media (min-width: 775px) and (max-width: 1100px) {
  .right-sidebar { display: none; }
  .side-panel-ad { display: flex; }
}
@media (max-width: 650px) {
  .side-panel-mid-ad { display: flex; margin: 0 auto; }
}
