:root {
  color-scheme: light dark;
  --game-card-ratio: 0.7;
  --column-gap: 8px;
  --dock-gap: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --z-board: 1;
  --z-cards: 2;
  --z-drag: 20;
}

.game-shell,
.game-stage,
.table-wrap {
  min-width: 0;
}

.game-play-grid {
  align-items: start;
}

.table-wrap {
  overflow: visible;
}

.felt {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-content: start;
  column-gap: 8px;
  row-gap: 8px;
  width: 100%;
  height: auto;
  min-height: 0;
  max-height: none;
  overflow: visible;
  padding: 12px 14px 16px;
  --card-w: 32px;
  --card-h: calc(var(--card-w) / var(--game-card-ratio));
  color-scheme: only light;
  forced-color-adjust: none;
}

.table-meta {
  display: contents;
}

.difficulty {
  grid-column: 1;
  grid-row: 1;
  align-self: start;
  z-index: 3;
  min-width: 0;
}

.game-mode {
  display: none;
}

.stock-row {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  display: flex;
  align-items: center;
  width: max-content;
  min-height: 0;
  gap: 5px;
  margin: 0;
  z-index: 3;
}

.foundation-area {
  position: relative;
  margin-left: 0;
}

.stock,
.stock-outline {
  flex: none;
  width: calc(var(--card-w) * 0.72);
  height: calc(var(--card-h) * 0.72);
}

.stock {
  position: relative;
  right: auto;
  bottom: auto;
  z-index: 2;
}

.stock-outline {
  display: block;
  border-width: 1px;
}

.finish-zone {
  grid-template-columns: repeat(var(--finish-count, 4), calc(var(--card-w) * 0.68));
  gap: 4px;
}

.finish-pair {
  width: calc(var(--card-w) * 0.68);
  height: calc(var(--card-h) * 0.68);
}

.finish-pair:before {
  font-size: calc(var(--card-w) * 0.42);
}

.finish-pair span {
  font-size: calc(var(--card-w) * 0.24);
}

.foundation-area > #sets {
  right: 0;
  bottom: -15px;
  font-size: 10px;
}

.columns {
  grid-column: 1 / -1;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  align-items: start;
  gap: var(--column-gap);
  width: 100%;
  min-width: 0;
  margin: 0;
  z-index: var(--z-board);
}

.column {
  position: relative;
  width: auto;
  min-width: 0;
  min-height: var(--card-h);
  overflow: visible;
}

.card {
  width: var(--card-w);
  height: var(--card-h);
  touch-action: manipulation;
  transition: none;
  z-index: var(--z-cards);
}

.card:not(.face-down) {
  border: 1px solid #c9c4b6;
  background: #fffdf6;
  box-shadow: 0 2px 5px #00120fe0, inset 0 0 0 1px #fff;
  opacity: 1;
  filter: none;
  mix-blend-mode: normal;
  color-scheme: only light;
  forced-color-adjust: none;
}

.card-face {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background-color: #fffdf6;
  object-fit: contain;
  opacity: 1;
  filter: none;
  mix-blend-mode: normal;
  color-scheme: only light;
  forced-color-adjust: none;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
  }

  .card:not(.face-down),
  .card-face {
    background-color: #fffdf6;
    opacity: 1;
    filter: none;
    mix-blend-mode: normal;
    color-scheme: only light;
    forced-color-adjust: none;
  }
}

.card.movable {
  touch-action: none;
}

.card.dragging {
  opacity: 1;
  visibility: hidden;
}

.column.drop-target {
  outline: 2px solid #ffe28b;
  outline-offset: 2px;
  background: #c9f9c21a;
}

.drag-layer {
  z-index: var(--z-drag);
  pointer-events: none;
  overflow: visible;
}

.drag-stack {
  width: var(--card-w);
  filter: none;
  pointer-events: none;
  will-change: transform;
}

.drag-stack .card {
  transition: none;
}

.deal-fly-card {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 15;
  flex: none;
  pointer-events: none;
  border-radius: 7%;
  background: #fff7e0 url('/assets/reference/back.webp') center / 100% 100%;
  border: 1px solid #fff2ce;
  box-shadow: 0 5px 10px #001a1455;
  transform-origin: top left;
  will-change: transform;
}

.card.dealing {
  opacity: 1;
  visibility: hidden;
}

.control-dock {
  margin-top: var(--dock-gap);
  margin-bottom: var(--safe-bottom);
}

.game-stage:fullscreen {
  box-sizing: border-box;
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-width: none;
  margin: 0;
  padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  overflow: auto;
  background: #064d39;
}

.game-stage:fullscreen .table-wrap {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  align-self: stretch;
  width: 100%;
  max-width: none;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.game-stage:fullscreen .felt {
  box-sizing: border-box;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  max-height: 100%;
}

.game-stage:fullscreen .control-dock {
  flex: 0 0 auto;
  margin: 0;
}

.game-stage:fullscreen #gameFullscreenBtn {
  display: flex;
}

/* The felt is a viewport-sized game surface; only an extreme tableau may pan. */
.site-header {
  min-height: 56px;
  margin-top: max(8px, env(safe-area-inset-top));
  padding-block: 6px;
  border-radius: 13px;
}

.brand {
  font-size: 28px;
  gap: 8px;
}

.brand-spade {
  font-size: 40px;
}

.top-nav a {
  min-height: 36px;
  padding: 7px 11px;
}

.header-actions button {
  min-width: 38px;
  height: 38px;
  border-radius: 9px;
}

#soundBtn[aria-pressed="false"] {
  position: relative;
}

#soundBtn[aria-pressed="false"]::after {
  position: absolute;
  width: 19px;
  height: 2px;
  content: "";
  background: currentColor;
  transform: rotate(45deg);
  border-radius: 2px;
}

.game-shell {
  margin-top: 8px;
}

.felt {
  grid-template-rows: auto minmax(0, 1fr);
  align-content: stretch;
  row-gap: 5px;
  padding: 8px 12px 7px;
}

.table-meta {
  margin: 0;
}

.difficulty {
  width: max-content;
  max-width: 100%;
}

.stock-row {
  gap: 4px;
}

.status-cluster {
  align-items: center;
  gap: 9px;
  padding: 5px 7px;
  border: 1px solid #d4e8cc55;
  border-radius: 9px;
  background: #042e2588;
}

.stock-control {
  display: flex;
  align-items: center;
  gap: 4px;
}

.stock,
.stock-outline {
  width: clamp(27px, calc(var(--card-w) * 0.48), 39px);
  aspect-ratio: var(--game-card-ratio);
  height: auto;
}

.stock {
  box-shadow: 1px 2px 0 #f1e7cf, 2px 3px 0 #dfd4b8, 0 4px 7px #001a1466;
}

.stock-outline {
  display: none;
}

.stock-badge {
  display: grid;
  justify-items: center;
  min-width: 30px;
  color: #f7efdc;
  font-variant-numeric: tabular-nums;
}

.stock-badge > span {
  color: #f3cf79;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.05;
}

.stock-badge small {
  font-size: 8px;
  line-height: 1.1;
  text-transform: uppercase;
}

.finish-zone {
  display: grid;
  grid-template-columns: repeat(4, 7px);
  gap: 3px 2px;
}

.finish-mark {
  width: 7px;
  height: 5px;
  border: 1px solid #a7d1b080;
  border-radius: 2px;
  background: #0d543c;
}

.finish-mark.complete {
  border-color: #f4d27d;
  background: #e6bd58;
  box-shadow: 0 0 5px #f1ce7455;
}

.foundation-area {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-width: 42px;
  padding-left: 8px;
  border-left: 1px solid #d4e8cc44;
}

.foundation-area > #sets {
  position: static;
  color: #f5e9ca;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.stock span {
  top: -4px;
  right: -5px;
  width: 16px;
  height: 16px;
  font-size: 10px;
}

.columns {
  align-self: stretch;
  align-items: start;
  grid-template-columns: repeat(10, var(--card-w));
  justify-content: center;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #d5bd8066 transparent;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.columns::-webkit-scrollbar {
  width: 5px;
}

.columns::-webkit-scrollbar-thumb {
  border-radius: 5px;
  background: #d5bd8066;
}

.column {
  min-height: var(--card-h);
}

.card {
  overflow: hidden;
  border-radius: 5%;
  box-shadow: 0 2px 4px #001c1977;
}

.corner {
  left: 6%;
  top: 3%;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 2px;
  line-height: 1;
}

.corner-bottom {
  left: auto;
  top: auto;
  right: 6%;
  bottom: 4%;
}

.rank {
  font-size: max(10px, calc(var(--card-w) * 0.25));
  font-weight: 700;
}

.suit {
  font-size: max(7.5px, calc(var(--card-w) * 0.17));
  line-height: 1.1;
}

.rank {
  font-size: max(10px, calc(var(--card-w) * 0.25));
}

.suit {
  font-size: max(7.5px, calc(var(--card-w) * 0.17));
}

.finish-zone {
  grid-template-columns: repeat(4, 7px);
  gap: 3px 2px;
}

.control-dock {
  min-height: 58px;
  gap: 8px;
  margin-top: 7px;
  padding: 6px 9px;
  border-radius: 12px;
}

.control-dock > .primary-action {
  min-height: 40px;
  padding: 7px 11px;
  font-size: 13px;
}

.dock-tools > button,
.dock-tools > a {
  min-height: 40px;
}

.score-strip .icon {
  width: 21px;
  height: 21px;
}

.score-strip > div {
  padding-inline: 6px;
}

.score-strip strong {
  font-size: 15px;
}

.run-clearing {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  transition: opacity 170ms ease-out, transform 170ms ease-out;
}

.run-cleared {
  opacity: 0;
  transform: scale(0.96);
}

@media (max-width: 960px) {
  .site-header,
  .game-shell,
  .site-footer {
    width: calc(100% - 24px);
  }

  .site-header {
    margin-top: max(8px, env(safe-area-inset-top));
  }

  .game-play-grid {
    display: block;
  }

  .felt {
    padding: 7px 8px 6px;
    column-gap: 4px;
    row-gap: 4px;
    border-radius: 11px;
  }

  .table-wrap {
    padding: 3px;
  }

  .side-widgets {
    margin-top: 14px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .site-header,
  .game-shell,
  .site-footer {
    width: calc(100% - 16px);
  }

  .site-header {
    min-height: 46px;
    padding: 4px 8px;
    border-radius: 11px;
  }

  .brand {
    font-size: 20px;
  }

  .header-actions {
    gap: 4px;
  }

  .header-actions button#soundBtn {
    display: flex;
    width: 36px;
    min-width: 36px;
    height: 36px;
  }

  .brand-spade {
    font-size: 29px;
  }

  .top-nav a[href="/guides/"] {
    display: flex;
    width: auto;
    height: 32px;
    min-height: 32px;
    padding: 4px 7px;
  }

  .top-nav a[href="/guides/"] span {
    display: inline;
    font-size: 10px;
  }

  .game-shell {
    margin-top: 5px;
  }

  .table-wrap {
    padding: 3px;
    border-radius: 12px;
  }

  .felt {
    padding: 5px 5px 4px;
    column-gap: 3px;
    row-gap: 3px;
  }

  .difficulty label > span {
    gap: 3px;
    padding: 3px 5px;
    font-size: 10px;
  }

  .difficulty small {
    display: none;
  }

  .stock-row {
    gap: 3px;
  }

  .status-cluster {
    gap: 6px;
    padding: 4px 5px;
  }

  .stock-badge {
    min-width: 26px;
  }

  .stock-badge > span {
    font-size: 12px;
  }

  .stock-badge small {
    font-size: 7px;
  }

  .stock {
    border-width: 1px;
    box-shadow: 1px 2px 0 #f1e7cf, 2px 4px 0 #dfd4b8, 0 5px 8px #001a1466;
  }

  .finish-zone {
    gap: 3px;
  }

  .finish-pair {
    border-width: 1px;
    border-radius: 4px;
  }

  .finish-pair:before {
    font-size: calc(var(--card-w) * 0.4);
  }

  .finish-pair span {
    font-size: calc(var(--card-w) * 0.22);
  }

  .stock span {
    display: none;
  }

  .card {
    border-radius: 5%;
    box-shadow: 0 2px 4px #001c1977;
  }

  .rank {
    font-size: max(7px, calc(var(--card-w) * 0.29));
  }

  .suit {
    font-size: max(6px, calc(var(--card-w) * 0.21));
  }

  .control-dock {
    flex-wrap: wrap;
    gap: 6px;
    padding: 5px;
    border-radius: 10px;
    gap: 4px;
  }

  .control-dock > .primary-action {
    min-height: 34px;
    min-width: 0;
    padding: 5px 7px;
    gap: 4px;
    font-size: 10px;
  }

  .control-dock > .primary-action .icon {
    width: 18px;
  }

  .dock-tools {
    gap: 2px;
    padding-left: 4px;
  }

  .dock-tools > button,
  .dock-tools > a {
    min-width: 30px;
    min-height: 34px;
    gap: 1px;
    padding: 1px;
    font-size: 9px;
  }

  .dock-tools .icon {
    width: 17px;
    height: 17px;
  }

  .dock-tools a,
  .dock-tools > button:first-child {
    display: none;
  }

  .score-strip {
    width: 100%;
    justify-content: center;
    padding-top: 3px;
    border-top: 1px solid #d2e4d833;
  }

  .score-strip > div {
    min-width: 0;
    padding-inline: clamp(5px, 2vw, 9px);
  }

  .score-strip .icon {
    width: 20px;
    height: 20px;
  }

  .score-strip strong {
    font-size: 12px;
  }

  .side-widgets {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 960px) and (orientation: landscape) {
  :root {
    --dock-gap: 6px;
  }

  .site-header {
    min-height: 36px;
    margin-top: max(3px, env(safe-area-inset-top));
    padding-block: 2px;
  }

  .header-actions button {
    min-width: 32px;
    height: 32px;
  }

  .top-nav a {
    min-height: 32px;
    padding: 4px 7px;
  }

  .top-nav a[href="/guides/"] {
    display: flex;
    width: auto;
    height: 32px;
    padding-inline: 7px;
  }

  .top-nav a[href="/guides/"] span {
    display: inline;
    font-size: 10px;
  }

  .brand {
    font-size: 20px;
  }

  .brand-spade {
    font-size: 29px;
  }

  .game-shell {
    margin-top: 3px;
  }

  .felt {
    padding-block: 3px;
    row-gap: 2px;
  }

  .table-wrap {
    padding: 2px;
  }

  .control-dock {
    margin-top: 2px;
    padding: 3px 5px;
    min-height: 38px;
    flex-wrap: nowrap;
  }

  .control-dock > .primary-action {
    min-height: 31px;
    padding: 4px 7px;
    font-size: 9px;
  }

  .dock-tools > button,
  .dock-tools > a {
    min-height: 30px;
    font-size: 7px;
  }

  .dock-tools .icon {
    width: 16px;
    height: 16px;
  }

  .score-strip .icon {
    width: 18px;
    height: 18px;
  }

  .score-strip strong {
    font-size: 13px;
  }

  .score-strip {
    flex: 0 1 auto;
    width: auto;
    min-width: 0;
    justify-content: flex-end;
    padding-top: 0;
    border-top: 0;
  }

  .score-strip > div {
    min-width: 0;
    gap: 3px;
    padding-inline: 4px;
  }
}

@media (min-width: 961px) and (max-height: 650px) {
  .felt {
    padding-block: 8px 10px;
    row-gap: 4px;
  }

  .stock,
  .stock-outline {
    width: calc(var(--card-w) * 0.5);
    height: calc(var(--card-h) * 0.5);
  }

  .finish-zone {
    grid-template-columns: repeat(var(--finish-count, 4), calc(var(--card-w) * 0.5));
    gap: 4px;
  }

  .finish-pair {
    width: calc(var(--card-w) * 0.5);
    height: calc(var(--card-h) * 0.5);
  }

  .finish-pair:before {
    font-size: calc(var(--card-w) * 0.3);
  }

  .finish-pair span {
    font-size: calc(var(--card-w) * 0.16);
  }

  .control-dock {
    min-height: 56px;
    margin-top: 8px;
    padding-block: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  .drag-stack,
  .deal-fly-card {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

@media (max-width: 700px) {
  .difficulty label > span {
    gap: 2px;
    padding: 3px 5px;
  }

  .difficulty b {
    font-size: 13px;
  }
}

.finish-zone {
  grid-template-columns: repeat(4, 7px);
  gap: 3px 2px;
}

.stock {
  padding: 0;
  min-height: 0;
}
