/* ---------------------------------------------------------------------
   FreeCell — style.css
   Dark-felt theme, iPhone-first fixed layout, CSS-drawn playing cards.
   --------------------------------------------------------------------- */

:root {
  --felt-top: #0f5132;
  --felt-bottom: #073622;
  --felt-line: rgba(255, 255, 255, 0.08);
  --toolbar-bg: #0b2417;
  --toolbar-fg: #eaf6ee;
  --toolbar-fg-dim: #9fc2ac;
  --accent: #ffd166;
  --danger: #ff6b6b;
  --card-bg: #fbfbf8;
  --card-border: #d9d5c9;
  --card-red: #c62828;
  --card-black: #16181d;
  --slot-border: rgba(255, 255, 255, 0.28);
  --slot-bg: rgba(0, 0, 0, 0.14);
  --selected-glow: #ffd166;
  /* Drop feedback while dragging: orange = this is where the card lands. */
  --drop-ok: #ff9f1c;
  --drop-ok-wash: rgba(255, 159, 28, 0.16);

  /* Populated at runtime by render.js via JS custom properties */
  --card-w: 44px;
  --card-h: 62px;
  --fan-y: 18px;
  --col-gap: 4px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  background: var(--felt-bottom);
  color: var(--toolbar-fg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  background: radial-gradient(ellipse at top, var(--felt-top), var(--felt-bottom));
}

/* ---------------------------------- Toolbar --------------------------- */

#toolbar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px 4px;
  background: var(--toolbar-bg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  z-index: 50;
}

.tb-row {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tb-row::-webkit-scrollbar {
  display: none;
}

.tb-btn {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 46px;
  padding: 4px 6px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--toolbar-fg);
  font-size: 9px;
  line-height: 1.1;
  -webkit-tap-highlight-color: transparent;
}
.tb-btn:active {
  background: rgba(255, 255, 255, 0.12);
}
.tb-btn .icon {
  font-size: 18px;
}
.tb-btn:disabled {
  opacity: 0.35;
}

.tb-spacer {
  flex: 1 1 auto;
}

.tb-stats {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 2px 6px;
  font-size: 12px;
  color: var(--toolbar-fg-dim);
  white-space: nowrap;
}
.tb-stats b {
  color: var(--toolbar-fg);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------- Board ------------------------------ */

#board {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  padding: 6px 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#top-row {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: var(--col-gap);
}

.slot-group {
  display: flex;
  gap: var(--col-gap);
}

.slot {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border: 2px solid var(--slot-border);
  border-radius: 8px;
  background: var(--slot-bg);
}

.slot.foundation::after {
  content: attr(data-suit-symbol);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w) * 0.55);
  color: rgba(255, 255, 255, 0.18);
}
.slot.foundation.red::after {
  color: rgba(198, 40, 40, 0.25);
}

/* Top-row slots are exactly card-sized, so the ghost lands flush on them and
   the slot only needs the wash. */
.slot.dropzone-active {
  background: var(--drop-ok-wash);
}
.slot.dropzone-invalid {
  background: rgba(255, 107, 107, 0.12);
}

#tableau {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: var(--col-gap);
}

.column {
  position: relative;
  flex: 1 1 0;
  height: 100%;
  border-radius: 8px;
}
/* Lane focus is a soft wash only — the crisp edge belongs to .drop-ghost,
   which sits exactly where the card will land. A hard ring around the full
   column height reads as misaligned, because a column is much taller than
   the cards stacked in it. */
/* Fades out well before the bottom of the lane: a column is far taller than
   its stack, and a wash running to the screen edge reads as a stray band. */
.column.dropzone-active {
  background: linear-gradient(rgba(255, 159, 28, 0.16), rgba(255, 159, 28, 0) 65%);
  border-radius: 10px;
}
.column.dropzone-invalid {
  background: linear-gradient(rgba(255, 107, 107, 0.14), rgba(255, 107, 107, 0) 65%);
  border-radius: 10px;
}
.column-empty-outline {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--card-w);
  height: var(--card-h);
  border: 2px dashed var(--felt-line);
  border-radius: 8px;
  pointer-events: none;
}

/* ---------------------------------- Cards ------------------------------ */

#cards-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Card-shaped landing indicator. Same box model and radius as .card so its
   edge sits exactly where the dropped card's edge will be. */
.drop-ghost {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: calc(var(--card-w) * 0.11);
  border: 2px solid var(--drop-ok);
  /* The landing slot overlaps the card above it in the fan, so the fill stays
     barely-there — the outline carries the meaning, and the card underneath
     must remain readable. */
  background: rgba(255, 159, 28, 0.06);
  box-shadow: 0 0 12px rgba(255, 159, 28, 0.45);
  opacity: 0;
  z-index: 8500;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.drop-ghost.visible {
  opacity: 1;
}
.drop-ghost.invalid {
  border-color: var(--danger);
  background: rgba(255, 107, 107, 0.12);
  box-shadow: 0 0 12px rgba(255, 107, 107, 0.4);
}

.card {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: calc(var(--card-w) * 0.11);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  will-change: transform;
  transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.3, 1), box-shadow 0.15s ease;
  touch-action: none;
  /* iOS shows a selection/share callout on long-press, which would fight the
     hold-to-peek gesture and interrupt it. */
  -webkit-touch-callout: none;
  z-index: 1;
}

.card.dragging {
  transition: none;
  /* Must clear every other card, including a .selected one (z-index 100) and
     the cards of whatever column is being dragged over. */
  z-index: 9000;
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.5);
  border-color: var(--drop-ok);
}

/* While a drag is in flight, drop targets are found with elementFromPoint().
   Cards sit in #cards-layer, outside the zone elements, so any card left
   hit-testable would mask the column underneath and the drop would resolve
   to nothing. The pointer is captured, so the drag still tracks normally. */
.is-dragging .card {
  pointer-events: none;
}

/* Hold-to-look: the card lifts clear of the fan so its whole face is visible.
   z-index is set inline by render.js; the scale and glow are what make it read
   as "temporarily raised" rather than moved. */
.card.peeking {
  transform-origin: center center;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.55), 0 0 0 2px var(--accent);
  filter: brightness(1.06);
}

.card.selected {
  box-shadow: 0 0 0 3px var(--selected-glow), 0 4px 8px rgba(0, 0, 0, 0.4);
  z-index: 100;
}

.card.autoplaying {
  z-index: 400;
}

.shake {
  animation: card-shake 0.3s ease;
}

@keyframes card-shake {
  0%, 100% { margin-left: 0; }
  20% { margin-left: -6px; }
  40% { margin-left: 5px; }
  60% { margin-left: -4px; }
  80% { margin-left: 3px; }
}

.card .pip {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
  font-weight: 700;
  font-family: -apple-system, 'Helvetica Neue', Arial, sans-serif;
}
.card .pip.tl {
  top: 4%;
  left: 6%;
}
.card .pip.br {
  bottom: 4%;
  right: 6%;
  transform: rotate(180deg);
}
.card .rank {
  font-size: calc(var(--card-w) * 0.30);
}
.card .suit-small {
  font-size: calc(var(--card-w) * 0.24);
  margin-top: -8%;
}
.card .suit-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w) * 0.5);
  opacity: 0.9;
}

.card.red .rank,
.card.red .suit-small,
.card.red .suit-center {
  color: var(--card-red);
}
.card.black .rank,
.card.black .suit-small,
.card.black .suit-center {
  color: var(--card-black);
}

/* ---------------------------------- Win overlay ------------------------ */

#win-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(3, 20, 12, 0.82);
  backdrop-filter: blur(2px);
}
#win-overlay.visible {
  display: flex;
}
.win-card {
  background: var(--toolbar-bg);
  border-radius: 16px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  max-width: 86vw;
}
.win-card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  color: var(--accent);
}
.win-card p {
  margin: 4px 0;
  color: var(--toolbar-fg-dim);
  font-size: 14px;
}
.win-card button {
  margin-top: 18px;
  padding: 10px 22px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #2a1e00;
  font-weight: 700;
  font-size: 15px;
}

.confetti-piece {
  position: fixed;
  top: -10px;
  width: 8px;
  height: 14px;
  z-index: 999;
  pointer-events: none;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to {
    transform: translateY(115vh) rotate(540deg);
    opacity: 0.9;
  }
}

/* ---------------------------------- Settings panel ---------------------- */

#settings-panel {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
#settings-panel.visible {
  display: flex;
}
.settings-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--toolbar-bg);
  border-radius: 16px 16px 0 0;
  padding: 18px 20px calc(20px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.5);
}
.settings-sheet h2 {
  margin: 0 0 12px;
  font-size: 16px;
  color: var(--accent);
}
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 14px;
}
.settings-row:last-of-type {
  border-bottom: none;
}
.switch {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  border: none;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
.switch.on {
  background: var(--accent);
}
.switch.on::after {
  transform: translateX(20px);
}
.settings-close {
  margin-top: 14px;
  width: 100%;
  padding: 10px;
  border-radius: 10px;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: var(--toolbar-fg);
  font-size: 14px;
}

/* ---------------------------------- Landscape tweak --------------------- */

@media (orientation: landscape) {
  #toolbar {
    padding: 4px 8px;
  }
  #board {
    padding: 4px 8px 8px;
  }
}
