/* ---------------------------------------------------------------------------
   The table: chrome around the game, and the coordinate system the cards live
   in. Every pile position is derived from one variable, --card-w, so the whole
   layout scales as a unit from an iPhone SE to a desktop.
   --------------------------------------------------------------------------- */

.table {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Top bar ----------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 9px) 14px 9px;
  background: color-mix(in srgb, var(--bg-sunken) 78%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--separator);
}

.topbar__back {
  flex: none;
  font-size: 16px;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.topbar__back:hover { text-decoration: none; opacity: 0.7; }

.topbar__center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-variant-numeric: tabular-nums;
}

.topbar__stat {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--label);
}

.topbar__divider {
  width: 1px;
  height: 13px;
  background: var(--separator);
}

.topbar__actions {
  flex: none;
  display: flex;
  align-items: center;
  gap: 2px;
}

.topbar__actions form { margin: 0; display: inline-flex; }

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: background-color 0.16s var(--ease-out), opacity 0.16s var(--ease-out);
}

.icon-button svg { width: 20px; height: 20px; }
.icon-button:hover { background: var(--accent-soft); }
.icon-button:active { transform: scale(0.92); }
.icon-button[disabled] { color: var(--label-tertiary); cursor: default; }
.icon-button[disabled]:hover { background: transparent; }

/* Playing surface --------------------------------------------------------- */

.board {
  --card-w: min(
    104px,
    calc((min(100vw, 1000px) - 24px) / 7.72),
    calc((100dvh - 186px) / 6.4)
  );
  --card-h: calc(var(--card-w) * 1.4);
  --gap: calc(var(--card-w) * 0.12);
  --row-gap: calc(var(--card-w) * 0.34);
  --stack: calc(var(--card-w) * 0.335);
  --stack-down: calc(var(--card-w) * 0.125);
  --fan: calc(var(--card-w) * 0.30);

  position: relative;
  flex: 1;
  padding: 16px 12px 96px;
  background:
    radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--felt) 60%, transparent), transparent 70%),
    var(--bg-sunken);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.board__form { display: none; }

.board__surface {
  position: relative;
  width: calc(7 * var(--card-w) + 6 * var(--gap));
  min-height: calc(var(--card-h) * 2 + var(--row-gap) + var(--stack) * 11);
  margin-inline: auto;
}

/* Empty pile outlines ----------------------------------------------------- */

.slot,
.card {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: calc(var(--card-w) * 0.11);
  transform: translate3d(
    calc(var(--col) * (var(--card-w) + var(--gap)) + var(--dx, 0px) + var(--drag-x, 0px)),
    calc(var(--row) * (var(--card-h) + var(--row-gap)) + var(--dy, 0px) + var(--drag-y, 0px)),
    0
  );
}

.slot {
  display: grid;
  place-items: center;
  border: 1.5px solid var(--felt-edge);
  background: color-mix(in srgb, var(--felt) 55%, transparent);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: border-color 0.2s var(--ease-out), background-color 0.2s var(--ease-out),
              box-shadow 0.2s var(--ease-out);
}

.slot--stock { cursor: pointer; }

.slot__glyph {
  font-size: calc(var(--card-w) * 0.42);
  line-height: 1;
  color: var(--label-tertiary);
  opacity: 0.5;
}

.slot__glyph--red { color: color-mix(in srgb, var(--red) 45%, transparent); }
.slot__glyph--black { color: var(--label-tertiary); }

/* Highlighted while a card is being dragged over a legal target. */
.slot.is-target,
.slot.is-hinted {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent);
}

.slot.is-hinted { animation: pulse 1.1s var(--ease-out) 2; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 26%, transparent); }
  50%      { box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 0%, transparent); }
}

/* Bottom toolbar ---------------------------------------------------------- */

.toolbar {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 14px);
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--bg-elevated) 84%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  backdrop-filter: saturate(180%) blur(24px);
  border: 1px solid var(--separator);
  box-shadow: var(--shadow-panel);
}

.toolbar form { margin: 0; }

.toolbar__button {
  border: 0;
  white-space: nowrap;
  background: transparent;
  color: var(--label);
  font-size: 15px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color 0.16s var(--ease-out);
}

.toolbar__button:hover { background: var(--bg-sunken); }
.toolbar__button:active { transform: scale(0.96); }
.toolbar__button--accent { color: var(--accent); font-weight: 600; }
.toolbar__button[disabled] { color: var(--label-tertiary); cursor: default; }
.toolbar__button[disabled]:hover { background: transparent; }

/* Win state --------------------------------------------------------------- */

.victory {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: color-mix(in srgb, var(--bg-sunken) 38%, transparent);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  animation: fade-in 0.5s var(--ease-out) 0.35s both;
}

.victory__panel {
  width: min(340px, 100%);
  display: grid;
  gap: 10px;
  padding: 28px 24px 20px;
  border-radius: 22px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow-lift);
  text-align: center;
  animation: panel-in 0.5s var(--ease-spring) 0.35s both;
}

.victory__eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--green);
}

.victory__title {
  font-family: var(--font-rounded);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.victory__meta {
  font-size: 14px;
  color: var(--label-secondary);
  margin-bottom: 8px;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

@keyframes panel-in {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}

.nudge {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 72px);
  transform: translateX(-50%);
  z-index: 24;
  width: min(260px, calc(100vw - 48px));
  animation: panel-in 0.4s var(--ease-spring) both;
}

/* Legal targets, surfaced only while a card is in the air. */
.slot.is-available {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}

.topbar__back--placeholder { width: 56px; }

.toolbar__button--quiet { color: var(--label-secondary); }

/* A surrendered game keeps its board visible — the point is to look at it —
   so the panel sits at the bottom instead of covering everything. */
.victory--quiet {
  background: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  align-items: end;
  padding-bottom: calc(var(--safe-bottom) + 78px);
  pointer-events: none;
  animation-delay: 0.15s;
}

.victory--quiet .victory__panel {
  pointer-events: auto;
  animation-delay: 0.15s;
}

.victory__eyebrow--quiet { color: var(--label-tertiary); }

.victory__note {
  font-size: 13px;
  color: var(--label-tertiary);
  margin: -4px 0 8px;
}

.victory--quiet .victory__panel {
  width: min(420px, calc(100vw - 28px));
  padding: 16px 20px 16px;
  gap: 4px;
}

.victory--quiet .victory__title { font-size: 21px; }
.victory--quiet .victory__meta { margin-bottom: 0; }

.victory__actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.victory__actions > * { flex: 1; margin: 0; }
.victory__actions .button { padding: 11px 16px; font-size: 16px; }
