/*
 * game.freecellgauntlet.app — the browser game.
 *
 * Phone first (../../MOBILE_FIRST_STANDARD.md): the base rules are the phone
 * held upright, one-handed, and the only widening rule is a `min-width` query
 * on the fleet's ladder. There is no `max-width` media query in this file.
 *
 * The board's geometry is not in here. Card size, column pitch, slot
 * positions and the step come from js/play/layout.js — the app's
 * `BoardMetrics.fit`, ported — which sets them on the board as custom
 * properties and transforms, from the size of the window and nothing else.
 *
 * The palette is DESIGN.md's, literal: the table is dark in light mode too,
 * because it is a table. Everything that is not the table, a slot or a card is
 * glass, and glass carries primary and secondary text, never the cream ladder
 * (DESIGN "Two text systems"). Signal is never used: with no solver there is
 * no verdict to mark.
 */

:root {
  --bp-sm: 40rem;
  --bp-md: 48rem;
  --bp-lg: 64rem;

  --table: #0f4c4a;
  --table-low: #0a3a38;
  --table-edge: #0a3a38;
  --face: #fdfbf4;
  --red: #c0272d;
  --black: #17201f;
  --cream: #f3ead6;
  --cream-62: rgb(243 234 214 / 0.62);

  --glass: rgb(16 34 33 / 0.62);
  --glass-edge: rgb(255 255 255 / 0.14);
  --primary: rgb(255 255 255 / 0.94);
  --secondary: rgb(255 255 255 / 0.66);

  --font: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-rounded: ui-rounded, "SF Pro Rounded", var(--font);

  /* DESIGN "Motion": a snap of about 200ms with a slight overshoot. */
  --snap: 200ms;
  --snap-ease: cubic-bezier(0.3, 1.32, 0.55, 1);

  /* Set by js/play/main.js from the layout; these are only the first paint's. */
  --w: 40px;
  --h: 56px;
  --r: 4.4px;

  color-scheme: dark;
  background: var(--table-low);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  color: var(--primary);
  background: linear-gradient(180deg, var(--table) 0%, var(--table-low) 100%);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The whole window is the table, inside the safe area. Nothing scrolls. */
.table {
  position: fixed;
  inset: 0;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  min-height: 44px;
  cursor: pointer;
}

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

/* ── The pill ─────────────────────────────────────────────────────────────── */

.glass,
.pill,
.popover,
.win-panel,
.toast {
  background: var(--glass);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  backdrop-filter: blur(20px) saturate(1.5);
  border: 1px solid var(--glass-edge);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.28);
}

.pill {
  position: absolute;
  z-index: 3000;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pill-button {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
}

.pill-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#menu-button svg {
  fill: currentColor;
  stroke: none;
}

.pill-button[aria-disabled="true"] {
  color: var(--secondary);
  opacity: 0.55;
}

.pill-facts {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 0;
  min-height: 44px;
  padding: 0 6px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  overflow: hidden;
}

.fact {
  flex: none;
  text-align: center;
}

.fact[data-fact="moves"] {
  font-weight: 600;
}

.fact[data-fact="target"],
.fact[data-fact="game"],
.fact[data-fact="progress"] {
  color: var(--secondary);
}

/* On end at the trailing side, for a board with width to spare and no height. */
.rail .pill {
  flex-direction: column;
  width: 104px;
  padding: 6px 3px;
  border-radius: 28px;
}

.rail .pill-facts {
  flex-direction: column;
  gap: 6px;
  padding: 8px 4px;
  border-radius: 20px;
  white-space: normal;
}

.rail .fact {
  max-width: 96px;
  white-space: pre-line;
}

/* ── Popovers: the menu, the details, the game number ────────────────────── */

.popover {
  position: absolute;
  z-index: 3100;
  min-width: 220px;
  max-width: calc(100vw - 16px);
  padding: 6px;
  border-radius: 18px;
}

.menu button,
.menu a {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--primary);
  font-size: 16px;
  text-align: left;
  text-decoration: none;
}

.menu a {
  color: var(--secondary);
  border-top: 1px solid var(--glass-edge);
  border-radius: 0 0 12px 12px;
}

.menu button:hover,
.menu a:hover,
.menu button:focus-visible,
.menu a:focus-visible {
  background: rgb(255 255 255 / 0.1);
}

.details {
  padding: 14px 16px;
}

.details-title {
  margin: 0 0 8px;
  font-weight: 600;
}

.details dl,
.win-facts {
  display: grid;
  gap: 4px;
  margin: 0;
}

.details dl > div,
.win-facts > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.details dt,
.win-facts dt {
  color: var(--secondary);
}

.details dd,
.win-facts dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.number {
  display: grid;
  gap: 8px;
  padding: 14px;
  width: 280px;
}

.number label {
  font-weight: 600;
}

.number input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--glass-edge);
  border-radius: 12px;
  background: rgb(0 0 0 / 0.25);
  font-size: max(16px, 1rem);
  font-variant-numeric: tabular-nums;
  -webkit-user-select: text;
  user-select: text;
}

.number-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--secondary);
  font-size: 14px;
}

.number-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Buttons on glass ─────────────────────────────────────────────────────── */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
}

.button-cream {
  background: var(--cream);
  color: var(--black);
}

.button-glass {
  background: rgb(255 255 255 / 0.12);
  color: var(--primary);
  border: 1px solid var(--glass-edge);
}

.button-plain {
  background: transparent;
  color: var(--primary);
}

/* ── The board ────────────────────────────────────────────────────────────── */

.board {
  position: absolute;
  touch-action: manipulation;
}

.slot {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--w);
  height: var(--h);
  border-radius: var(--r);
  background: var(--table-edge);
  box-shadow: inset 0 1px 3px rgb(0 0 0 / 0.4);
}

.slot svg {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  translate: -50% -50%;
  fill: var(--cream);
  opacity: 0.16;
}

.card {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--w);
  height: var(--h);
  touch-action: none;
  transition: transform var(--snap) var(--snap-ease);
  will-change: transform;
  cursor: grab;
}

.card.dragging,
.card.instant {
  transition: none;
}

.card.dragging {
  cursor: grabbing;
}

.card-body {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--r);
  background: var(--face);
  /* Two shadows (DESIGN "Card stock"): the wide faint one reaches back up past
     the card's top edge and is the seam between cards in a column; the tight
     one is the outline against the table. */
  box-shadow:
    0 -1px calc(var(--w) * 0.12) rgb(0 0 0 / 0.2),
    0 1px 1.5px rgb(0 0 0 / 0.38);
  overflow: hidden;
  transition:
    transform 140ms ease-out,
    box-shadow 140ms ease-out;
}

/* A card in hand: a little larger, a deeper shadow (DESIGN "Motion → Lift"). */
.card.lifted .card-body {
  transform: scale(1.06);
  box-shadow:
    0 -1px calc(var(--w) * 0.14) rgb(0 0 0 / 0.2),
    0 calc(var(--w) * 0.12) calc(var(--w) * 0.3) rgb(0 0 0 / 0.4);
}

/* Under the top card of a foundation: no shadow to pile up. Only after the
   snap that put it there, so a card arriving home still lands with one. */
.card.under .card-body {
  box-shadow: none;
  transition: box-shadow 0s linear var(--snap);
}

.card.has-render .card-body {
  background: transparent;
}

.render {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* The minimal face, until the app's renders are in public/game/cards/. */
.face {
  position: absolute;
  inset: 0;
  color: var(--black);
  font-weight: 800;
  line-height: 1;
}

.face.red {
  color: var(--red);
}

.face svg {
  fill: currentColor;
}

.index {
  position: absolute;
  left: 6%;
  top: 0;
  height: calc(var(--h) * 0.25);
  display: flex;
  align-items: center;
  gap: 1px;
  font-size: calc(var(--h) * 0.2);
  letter-spacing: -0.03em;
}

.index svg {
  width: calc(var(--h) * 0.13);
  height: calc(var(--h) * 0.13);
}

/* A ten is two characters in one character's column: condensed, not shrunk. */
.index .ten {
  display: inline-block;
  transform: scaleX(0.78);
  transform-origin: left center;
  margin-right: -0.22em;
}

.index.foot {
  left: auto;
  top: auto;
  right: 6%;
  bottom: 0;
  rotate: 180deg;
}

.pip {
  position: absolute;
  left: 50%;
  top: 56%;
  width: 46%;
  height: 46%;
  translate: -50% -50%;
}

.court {
  position: absolute;
  left: 50%;
  top: 56%;
  translate: -50% -50%;
  display: grid;
  place-items: center;
  width: 52%;
  height: 46%;
  border: max(1px, calc(var(--w) * 0.025)) solid currentColor;
  border-radius: calc(var(--r) * 0.6);
  font-family: var(--font-rounded);
  font-size: calc(var(--w) * 0.36);
}

.back {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0;
  border: max(2px, calc(var(--w) * 0.06)) solid var(--face);
  background: repeating-linear-gradient(45deg, #0f4c4a 0 3px, #0c4240 3px 6px),
    var(--table);
  transition: opacity 120ms linear;
}

.back img {
  width: 100%;
  height: 100%;
  display: block;
}

.back.has-render {
  border: 0;
  background: transparent;
}

.card.down .back {
  opacity: 1;
}

/* The refusal: a small sideways shake (DESIGN "Motion"). */
.card.shake .card-body {
  animation: shake 280ms ease-out;
}

@keyframes shake {
  0%,
  100% {
    translate: 0 0;
  }
  20% {
    translate: -7% 0;
  }
  45% {
    translate: 6% 0;
  }
  70% {
    translate: -3% 0;
  }
}

/* A card home: one cream ring, out and gone in under half a second. */
.ring {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--w);
  height: var(--h);
  border: 2px solid var(--cream);
  border-radius: var(--r);
  pointer-events: none;
  z-index: 2500;
  animation: ring 420ms ease-out forwards;
}

.ring.flourish {
  animation: flourish 900ms ease-out forwards;
}

@keyframes ring {
  from {
    scale: 1;
    opacity: 0.9;
  }
  to {
    scale: 1.32;
    opacity: 0;
  }
}

@keyframes flourish {
  from {
    scale: 1;
    opacity: 0.95;
  }
  to {
    scale: 2.8;
    opacity: 0;
  }
}

/* ── The win ──────────────────────────────────────────────────────────────── */

.win {
  position: absolute;
  inset: 0;
  z-index: 3200;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(0 0 0 / 0.22);
  animation: rise 260ms ease-out;
}

.win-panel {
  width: 100%;
  max-width: 380px;
  max-height: 100%;
  overflow: auto;
  padding: 20px;
  border-radius: 24px;
}

.win-eyebrow {
  margin: 0;
  color: var(--secondary);
}

.win-headline {
  margin: 4px 0 16px;
  font-family: var(--font-rounded);
  font-size: 34px;
  font-weight: 700;
  line-height: 1.1;
}

.win-facts {
  padding: 12px 0;
  border-block: 1px solid var(--glass-edge);
  font-size: 17px;
}

.win-facts small {
  margin-left: 8px;
  color: var(--secondary);
  font-size: 14px;
}

.win-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.win-app {
  padding-top: 16px;
  border-top: 1px solid var(--glass-edge);
}

.win-app p {
  margin: 0 0 12px;
  color: var(--secondary);
  line-height: 1.4;
}

@keyframes rise {
  from {
    opacity: 0;
    translate: 0 12px;
  }
  to {
    opacity: 1;
    translate: 0 0;
  }
}

/* ── Odds and ends ────────────────────────────────────────────────────────── */

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 3300;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  translate: -50% 0;
  font-size: 15px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms linear;
}

.toast.shown {
  opacity: 1;
}

.noscript {
  position: absolute;
  inset: auto 16px 50% 16px;
  margin: 0;
  color: var(--cream);
  text-align: center;
  line-height: 1.5;
}

.noscript a {
  color: var(--cream);
}

/* Wider than a phone: a little more air in the pill. */
@media (min-width: 40rem) {
  .pill {
    font-size: 16px;
  }

  .pill-facts {
    gap: 16px;
  }
}

/* Reduce Motion: nothing travels. Snaps become fades, the shake a blink, and
   the win cross-fades in. Which card is in front is not motion and stays. */
@media (prefers-reduced-motion: reduce) {
  .card {
    transition: none;
  }

  .card.arrive .card-body {
    animation: fade-in 160ms linear;
  }

  .card.shake .card-body {
    animation: blink 280ms linear;
  }

  .card.lifted .card-body {
    transform: none;
  }

  .ring,
  .ring.flourish {
    animation: fade-out 300ms linear forwards;
  }

  .win {
    animation: fade-in 200ms linear;
  }
}

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

@keyframes fade-out {
  from {
    opacity: 0.8;
  }
  to {
    opacity: 0;
  }
}

@keyframes blink {
  50% {
    opacity: 0.45;
  }
}
