/* FreeCell on an oxblood games-table top with gilt tooling. The table is the
   one loud thing; the cards stay crisp and quiet so they read at any size. */

:root {
  --leather: #36131a;
  --leather-deep: #210a0f;
  --gilt: #c8a25a;
  --gilt-bright: #ecca86;
  --gilt-dim: rgba(200, 162, 90, 0.46);
  --gilt-faint: rgba(200, 162, 90, 0.2);
  --vellum: #f0e4c8;
  --vellum-dim: rgba(240, 228, 200, 0.72);
  --stock: #fdfaf3;
  --stock-edge: #d9cdb4;
  --ink-red: #ad1d29;
  --ink-black: #1a2031;
  --serif: "Bodoni Moda", "Bodoni 72", Didot, "Libre Bodoni", Georgia, serif;
  --ease-out: cubic-bezier(0.2, 0.75, 0.25, 1);
  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.45;
  color: var(--vellum);
  background-color: var(--leather);
  background-image:
    radial-gradient(110% 70% at 50% 30%, rgba(255, 214, 170, 0.08), transparent 62%),
    radial-gradient(140% 110% at 50% 45%, transparent 52%, rgba(0, 0, 0, 0.5)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.12 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-attachment: fixed;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

button {
  font: inherit;
  color: inherit;
}

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

/* Header ---------------------------------------------------------------- */

.bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 22px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 10px 16px 4px;
}

.wordmark {
  margin: 0;
  font-size: 1.75rem;
  font-style: italic;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--gilt);
  font-variation-settings: "opsz" 72;
}

.status {
  display: flex;
  align-items: baseline;
  gap: 18px;
  color: var(--vellum-dim);
  font-size: 0.95rem;
}

.figure {
  color: var(--vellum);
  font-weight: 600;
  font-variant-numeric: lining-nums tabular-nums;
}

.deal-button {
  padding: 2px 0;
  border: 0;
  border-bottom: 1px solid var(--gilt-dim);
  background: none;
  color: var(--vellum-dim);
  cursor: pointer;
}

.deal-button span {
  color: var(--vellum);
  font-weight: 600;
  font-variant-numeric: lining-nums tabular-nums;
}

.deal-button:hover {
  border-bottom-color: var(--gilt-bright);
}

.actions {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

.action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 10px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--vellum-dim);
  font-size: 0.95rem;
  cursor: pointer;
}

.action svg {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.action:hover:not(:disabled) {
  color: var(--gilt-bright);
}

.action:disabled {
  opacity: 0.38;
  cursor: default;
}

.action.armed {
  color: var(--gilt-bright);
  box-shadow: inset 0 0 0 1px var(--gilt-dim);
}

.action.busy svg {
  animation: think 1s ease-in-out infinite;
}

@keyframes think {
  50% {
    opacity: 0.35;
  }
}

@media (max-width: 860px) {
  .action span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .action {
    padding: 6px 9px;
  }
}

@media (max-width: 600px) {
  .bar {
    padding: 8px 12px 0;
  }
  .wordmark {
    font-size: 1.45rem;
  }
  .status {
    margin-left: auto;
    gap: 12px;
    font-size: 0.88rem;
  }
  .actions {
    width: 100%;
    justify-content: space-between;
    margin-left: 0;
  }
  .action {
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
  }
}

/* Table ----------------------------------------------------------------- */

.table {
  position: relative;
  max-width: 1240px;
  margin: 0 auto 14px;
  padding: clamp(8px, 1.6vw, 22px);
}

/* Gilt tooling: two fine rules pressed into the leather. */
.table::before,
.table::after {
  content: "";
  position: absolute;
  pointer-events: none;
  border-radius: 10px;
}

.table::before {
  inset: 3px;
  border: 1px solid var(--gilt-dim);
}

.table::after {
  inset: 7px;
  border: 1px solid var(--gilt-faint);
  border-radius: 7px;
}

.board {
  position: relative;
  width: 100%;
  min-height: 60vh;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  --cw: 100px;
  --ch: 140px;
  --radius: 7px;
  --idx: 22px;
}

.board:focus {
  outline: none;
}

.slot {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw);
  height: var(--ch);
  border-radius: var(--radius);
  pointer-events: auto;
}

.slot-cell,
.slot-found {
  border: 1px solid var(--gilt-dim);
  background: rgba(0, 0, 0, 0.14);
  box-shadow:
    inset 0 0 0 3px rgba(33, 10, 15, 0.55),
    inset 0 0 0 4px var(--gilt-faint),
    inset 0 2px 8px rgba(0, 0, 0, 0.4);
}

.slot-found .slot-suit {
  position: absolute;
  left: 30%;
  top: 50%;
  width: 40%;
  height: 40%;
  transform: translateY(-50%);
  fill: var(--gilt-faint);
}

.slot-col {
  border: 1px solid var(--gilt-faint);
}

.slot.drop-ok {
  border-color: var(--gilt-bright);
  box-shadow: 0 0 0 1px var(--gilt-bright), 0 0 18px rgba(236, 202, 134, 0.35);
}

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

.card {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw);
  height: var(--ch);
  border: 1px solid var(--stock-edge);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0) 40%),
    var(--stock);
  color: var(--ink);
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
  transform-origin: 50% 100%;
  transition: transform var(--move-ms, 200ms) var(--ease-out), box-shadow 160ms ease;
  will-change: transform;
  touch-action: none;
  cursor: grab;
  overflow: hidden;
}

.card.red {
  --ink: var(--ink-red);
}

.card.black {
  --ink: var(--ink-black);
}

.card svg {
  fill: currentColor;
}

.board.no-anim .card {
  transition: none !important;
}

.card.fixed {
  cursor: default;
}

.card.dragging {
  transition: none;
  cursor: grabbing;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.45), 0 3px 8px rgba(0, 0, 0, 0.3);
}

.card.selected {
  box-shadow: 0 0 0 2px var(--gilt-bright), 0 0 16px 3px rgba(236, 202, 134, 0.55);
}

.card.drop-ok {
  box-shadow: 0 0 0 2px var(--gilt-bright), 0 2px 6px rgba(0, 0, 0, 0.2);
}

.card.hint,
.slot.hint {
  animation: hint 0.85s ease-in-out 3;
}

@keyframes hint {
  50% {
    box-shadow: 0 0 0 3px var(--gilt-bright), 0 0 24px 8px rgba(236, 202, 134, 0.7);
  }
}

.index {
  position: absolute;
  top: calc(var(--ch) * 0.04);
  left: calc(var(--cw) * 0.08);
  display: flex;
  align-items: center;
  gap: 0.06em;
  font-size: var(--idx);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  font-variant-numeric: lining-nums;
}

.index-suit {
  width: 0.74em;
  height: 0.74em;
  margin-top: 0.04em;
}

.face {
  position: absolute;
  inset: 0;
}

.pips {
  position: absolute;
  left: 28%;
  right: 28%;
  top: 34%;
  bottom: 12%;
}

.pip {
  position: absolute;
  left: calc(var(--x) * 100%);
  top: calc(var(--y) * 100%);
  width: calc(var(--cw) * 0.19);
  height: calc(var(--cw) * 0.19);
  transform: translate(-50%, -50%);
}

.pip.flip {
  transform: translate(-50%, -50%) rotate(180deg);
}

.solo {
  display: none;
}

.ace {
  position: absolute;
  left: 24%;
  top: 36%;
  width: 52%;
  height: auto;
  aspect-ratio: 1;
}

.court {
  position: absolute;
  left: 13%;
  right: 13%;
  top: 30%;
  bottom: 7%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10%;
  border: 1px solid currentColor;
  border-radius: 3px;
  background: color-mix(in srgb, currentColor 5%, transparent);
  box-shadow: inset 0 0 0 2px var(--stock), inset 0 0 0 2.6px currentColor;
}

/* A text optical size keeps the hairlines sturdy; the display cut's K arm
   all but disappears at card sizes. */
.court-letter {
  font-size: calc(var(--cw) * 0.5);
  font-style: italic;
  font-weight: 600;
  line-height: 0.85;
  font-variation-settings: "opsz" 14;
}

.court-suit {
  width: calc(var(--cw) * 0.17);
  height: calc(var(--cw) * 0.17);
}

/* Small cards: one large suit instead of pips. */
.board.compact .pips {
  display: none;
}

.board.compact .solo {
  display: block;
  position: absolute;
  left: 25%;
  top: 46%;
  width: 50%;
  height: auto;
  aspect-ratio: 1;
}

.board.compact .ace {
  left: 22%;
  top: 46%;
  width: 56%;
}

.board.compact .court {
  left: 10%;
  right: 10%;
  top: 48%;
  bottom: 6%;
  box-shadow: none;
  gap: 0;
}

.board.compact .court-letter {
  font-size: calc(var(--cw) * 0.42);
}

.board.compact .court-suit {
  display: none;
}

/* Toast ----------------------------------------------------------------- */

.toast {
  position: absolute;
  left: 50%;
  top: clamp(14px, 3vw, 30px);
  z-index: 2000;
  max-width: min(32rem, calc(100% - 32px));
  margin: 0;
  padding: 0.55em 1.05em;
  border-radius: 4px;
  background: var(--stock);
  color: var(--ink-black);
  font-size: 0.95rem;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  transform: translate(-50%, -6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms var(--ease-out);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Sheets ---------------------------------------------------------------- */

.sheet {
  width: min(27rem, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 26px 28px 24px;
  border: 1px solid var(--stock-edge);
  border-radius: 6px;
  background: var(--stock);
  color: var(--ink-black);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.55);
}

.sheet.wide {
  width: min(36rem, calc(100% - 32px));
}

.sheet::backdrop {
  background: rgba(22, 6, 10, 0.62);
}

.sheet[open] {
  animation: sheet-in 220ms var(--ease-out);
}

@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

.sheet h2 {
  margin: 0 0 8px;
  font-size: 2.1rem;
  font-style: italic;
  font-weight: 600;
  line-height: 1.05;
  color: var(--leather);
  font-variation-settings: "opsz" 96;
}

.sheet h3 {
  margin: 22px 0 8px;
  font-size: 1.1rem;
  font-weight: 700;
}

.lede {
  margin: 0 0 6px;
  font-size: 1.15rem;
}

.small {
  margin: 0 0 14px;
  font-size: 0.92rem;
  color: #4a4f5e;
}

.prose p {
  margin: 0 0 10px;
  max-width: 62ch;
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

.btn {
  min-height: 42px;
  padding: 8px 16px;
  border: 1px solid #8f8571;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-black);
  cursor: pointer;
}

.btn:hover {
  border-color: var(--ink-black);
}

.btn.primary {
  border-color: var(--leather);
  background: var(--leather);
  color: var(--vellum);
}

.btn.primary:hover {
  background: #4a1b23;
}

.btn.quiet {
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
  color: #4a4f5e;
}

.sheet :focus-visible {
  outline-color: var(--leather);
}

.field {
  display: grid;
  gap: 4px;
  font-size: 0.92rem;
}

.field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #8f8571;
  border-radius: 4px;
  background: #fff;
  color: var(--ink-black);
  font: inherit;
  font-size: 1.3rem;
  font-variant-numeric: lining-nums tabular-nums;
}

.error {
  margin: 8px 0 0;
  color: var(--ink-red);
  font-size: 0.92rem;
}

.record {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 18px;
  margin: 14px 0 0;
}

.record div {
  border-top: 1px solid #e2d8c3;
  padding-top: 8px;
}

.record dt {
  font-size: 0.88rem;
  color: #4a4f5e;
}

.record dd {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.15;
  font-variant-numeric: lining-nums tabular-nums;
}

.keys {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.92rem;
}

.keys li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0;
  border-top: 1px solid #e8dfcd;
}

.keys li span:last-child {
  text-align: right;
  color: #4a4f5e;
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 0.35em;
  border: 1px solid #b9ae98;
  border-bottom-width: 2px;
  border-radius: 3px;
  font-family: var(--serif);
  font-size: 0.85em;
  text-align: center;
  color: var(--ink-black);
}

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 0;
  font-size: 0.95rem;
  cursor: pointer;
}

.toggle input {
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  accent-color: var(--leather);
  flex: none;
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .toast {
    transition-duration: 0ms !important;
    transition-delay: 0ms !important;
  }
  .card.hint,
  .slot.hint,
  .sheet[open],
  .action.busy svg {
    animation: none;
  }
  .card.hint,
  .slot.hint {
    box-shadow: 0 0 0 3px var(--gilt-bright);
  }
}
