:root {
  color-scheme: light;
  --felt: #17613d;
  --felt-dark: #0d442b;
  --felt-line: rgba(235, 247, 239, 0.42);
  --ink: #17211c;
  --muted: #627069;
  --cream: #f5f1e8;
  --panel: #fffdf8;
  --accent: #e9b949;
  --accent-dark: #8c6415;
  --danger: #b3261e;
  --card-radius: clamp(4px, 0.7vw, 9px);
  --board-gap: clamp(3px, 0.75vw, 12px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--cream);
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--cream);
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  left: 0.75rem;
  top: -5rem;
  padding: 0.7rem 1rem;
  color: #111;
  background: #fff;
  border-radius: 0.5rem;
}

.skip-link:focus {
  top: 0.75rem;
}

.game-viewport {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  color: #f7fbf8;
  background:
    radial-gradient(circle at 18% 14%, rgba(255, 255, 255, 0.06), transparent 23rem),
    radial-gradient(circle at 78% 65%, rgba(0, 0, 0, 0.1), transparent 34rem),
    var(--felt);
}

.site-header {
  min-width: 0;
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem clamp(0.55rem, 2vw, 1.4rem);
  color: #f9fcfa;
  background: rgba(8, 47, 29, 0.94);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: inherit;
  font-weight: 800;
  letter-spacing: -0.025em;
  text-decoration: none;
}

.brand-mark {
  width: 1.65rem;
  height: 1.65rem;
  display: grid;
  place-items: center;
  color: #153523;
  background: var(--accent);
  border-radius: 50%;
  font-size: 1.05rem;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.game-links {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.2rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.game-links::-webkit-scrollbar,
.controls::-webkit-scrollbar {
  display: none;
}

.game-links a {
  flex: none;
  padding: 0.42rem 0.62rem;
  color: rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 650;
  text-decoration: none;
}

.game-links a:hover,
.game-links a:focus-visible,
.game-links a[aria-current="page"] {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.game-toolbar {
  min-width: 0;
  min-height: 45px;
  display: grid;
  grid-template-columns: minmax(10rem, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.32rem clamp(0.45rem, 1.4vw, 1rem);
  color: #153523;
  background: rgba(250, 247, 239, 0.97);
  box-shadow: 0 2px 9px rgba(0, 0, 0, 0.2);
}

.game-toolbar h1 {
  margin: 0;
  font-size: clamp(0.84rem, 1.35vw, 1.08rem);
  line-height: 1.1;
  letter-spacing: -0.015em;
  white-space: nowrap;
}

.controls {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.control-button {
  flex: none;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.38rem 0.62rem;
  color: #183a27;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
}

.control-button:hover,
.control-button:focus-visible {
  color: #0b2416;
  background: #eee8d9;
  border-color: #d9d0bd;
  outline: none;
}

.control-button:disabled {
  cursor: default;
  opacity: 0.38;
}

.control-icon {
  font-size: 1rem;
  line-height: 1;
}

.game-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  color: #4f5d55;
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.game-status strong {
  color: #173422;
}

.game-board {
  min-height: 0;
  position: relative;
  padding: clamp(0.45rem, 1.6vw, 1.15rem);
  overflow: hidden;
}

.board-inner {
  --columns: 7;
  width: min(100%, 930px);
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(0.45rem, 1.6vh, 0.9rem);
  margin: 0 auto;
}

[data-game="freecell"] .board-inner {
  --columns: 8;
  width: min(100%, 1040px);
}

[data-game="spider"] .board-inner {
  --columns: 10;
  width: min(100%, 1220px);
}

.top-row,
.tableau {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  gap: var(--board-gap);
}

.top-row {
  align-items: start;
}

.top-spacer {
  min-width: 0;
}

.tableau {
  min-height: 0;
  align-items: stretch;
}

.pile,
.tableau-column {
  min-width: 0;
  position: relative;
}

.top-row .pile {
  width: 100%;
  aspect-ratio: 5 / 7;
  border: 2px solid var(--felt-line);
  border-radius: var(--card-radius);
}

.tableau-column {
  height: 100%;
  border-radius: var(--card-radius);
}

.tableau-column:empty {
  min-height: 4rem;
  border: 2px solid rgba(235, 247, 239, 0.26);
}

.card {
  width: 100%;
  aspect-ratio: 5 / 7;
  display: block;
  position: absolute;
  inset: 0 auto auto 0;
  padding: 0;
  overflow: hidden;
  border-radius: var(--card-radius);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.tableau-column .card {
  top: var(--card-y, 0px);
}

.card-face {
  color: #141b17;
  background: linear-gradient(145deg, #fff 0%, #fdfcf8 62%, #ece9df 100%);
  border: 1px solid rgba(12, 22, 16, 0.45);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3), inset 0 0 0 1px rgba(255, 255, 255, 0.75);
}

.card-face.red {
  color: #bd1f2d;
}

.card-face:hover,
.card-face:focus-visible {
  outline: 2px solid rgba(255, 223, 111, 0.92);
  outline-offset: -2px;
}

.card-back {
  cursor: default;
  border: 3px solid #f2eee4;
  background-color: #175d8d;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.13) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.13) 75%),
    linear-gradient(45deg, rgba(255, 255, 255, 0.13) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.13) 75%);
  background-position: 0 0, 7px 7px;
  background-size: 14px 14px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.32), inset 0 0 0 2px #0c3f66;
}

.card-corner {
  position: absolute;
  top: clamp(2px, 0.35vw, 6px);
  left: clamp(3px, 0.45vw, 7px);
  display: grid;
  justify-items: center;
  line-height: 0.9;
  font-size: clamp(0.62rem, 1.45vw, 1.15rem);
}

.card-corner strong {
  font-size: 1em;
}

.card-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1rem, 3.5vw, 3.4rem);
  opacity: 0.94;
}

.is-selected {
  outline: 3px solid #ffd75a !important;
  outline-offset: -3px;
  filter: brightness(1.06);
}

.is-hint-source {
  animation: hint-source 0.72s ease-in-out infinite alternate;
}

.is-hint-destination {
  animation: hint-destination 0.72s ease-in-out infinite alternate;
}

@keyframes hint-source {
  to { filter: drop-shadow(0 0 8px #ffd75a); }
}

@keyframes hint-destination {
  to { box-shadow: inset 0 0 0 4px #ffd75a, 0 0 12px #ffd75a; }
}

.pile-count {
  position: absolute;
  z-index: 3;
  right: 3px;
  bottom: 3px;
  min-width: 1.25rem;
  padding: 0.13rem 0.28rem;
  color: #fff;
  background: rgba(0, 0, 0, 0.62);
  border-radius: 999px;
  font-size: 0.66rem;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

.recycle-mark,
.empty-suit,
.completed-mark,
.freecell-mark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(235, 247, 239, 0.46);
  font-family: Georgia, serif;
  font-size: clamp(1.2rem, 4vw, 3.2rem);
}

.recycle-mark {
  font-family: inherit;
  font-weight: 300;
}

.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: 1rem;
  max-width: min(90vw, 31rem);
  transform: translateX(-50%);
  padding: 0.7rem 0.95rem;
  color: #173422;
  background: #fff9e8;
  border: 1px solid #e5ce8a;
  border-radius: 0.65rem;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
}

.game-copy {
  padding: clamp(2.5rem, 6vw, 5rem) 1.2rem;
  background: var(--panel);
  border-top: 1px solid #e1dacb;
}

.game-copy-inner {
  width: min(100%, 850px);
  margin: 0 auto;
}

.game-copy h2 {
  max-width: 22ch;
  margin: 0 0 1rem;
  color: #153523;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.65rem, 4vw, 2.55rem);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.025em;
}

.game-copy h3 {
  margin: 2rem 0 0.55rem;
  color: #183a27;
  font-size: 1.08rem;
}

.game-copy p,
.game-copy li {
  color: #47564e;
  font-size: 1rem;
  line-height: 1.72;
}

.game-copy-grid {
  display: grid;
  grid-template-columns: 1.12fr 0.88fr;
  gap: clamp(1.5rem, 5vw, 4rem);
}

.quick-rules {
  margin: 0;
  padding: 1.25rem 1.25rem 1.25rem 2.4rem;
  background: #f3efe5;
  border: 1px solid #e2d9c7;
  border-radius: 0.8rem;
}

.quick-rules li + li {
  margin-top: 0.55rem;
}

.site-footer {
  padding: 1.35rem 1rem;
  color: #bec9c2;
  background: #0d2c1d;
  font-size: 0.8rem;
}

.footer-inner {
  width: min(100%, 900px);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.8rem 1.5rem;
  margin: 0 auto;
}

.site-footer p {
  margin: 0;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
}

.site-footer a {
  color: #eef4f0;
}

dialog {
  width: min(92vw, 34rem);
  max-height: min(84dvh, 46rem);
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--panel);
  border: 0;
  border-radius: 0.9rem;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

dialog::backdrop {
  background: rgba(4, 20, 12, 0.68);
  backdrop-filter: blur(2px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem;
  background: #f2ede2;
  border-bottom: 1px solid #ded4c1;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.dialog-close {
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  padding: 0;
  color: #47564e;
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.4rem;
}

.dialog-close:hover,
.dialog-close:focus-visible {
  background: #e1d8c8;
}

.dialog-body {
  max-height: calc(84dvh - 4.3rem);
  padding: 1.15rem 1.2rem 1.3rem;
  overflow-y: auto;
}

.dialog-body p,
.dialog-body li {
  color: #4a5951;
  line-height: 1.58;
}

.dialog-body h3 {
  margin: 1.25rem 0 0.4rem;
  color: #193a28;
  font-size: 1rem;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.2rem;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 0.65rem 1rem;
  border-radius: 0.55rem;
  cursor: pointer;
  font-weight: 750;
}

.primary-button {
  color: #fff;
  background: #17613d;
  border: 1px solid #17613d;
}

.secondary-button {
  color: #274435;
  background: #f4efe5;
  border: 1px solid #d9cfbd;
}

.radio-options {
  display: grid;
  gap: 0.6rem;
}

.radio-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.7rem;
  padding: 0.75rem;
  border: 1px solid #ddd3c1;
  border-radius: 0.65rem;
  cursor: pointer;
}

.radio-option input {
  grid-row: 1 / 3;
  align-self: center;
}

.radio-option strong,
.radio-option small {
  display: block;
}

.radio-option small {
  color: #66746c;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.7rem;
}

.stat-card {
  padding: 0.9rem;
  background: #f3efe6;
  border-radius: 0.65rem;
}

.stat-card span,
.stat-card strong {
  display: block;
}

.stat-card span {
  color: #657169;
  font-size: 0.76rem;
}

.stat-card strong {
  margin-top: 0.25rem;
  color: #183a27;
  font-size: 1.35rem;
}

.win-copy {
  text-align: center;
}

.win-symbol {
  margin: 0 auto 0.65rem;
  color: #9b6f13;
  font-family: Georgia, serif;
  font-size: 3.5rem;
}

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

.content-header {
  color: #fff;
  background: #0d442b;
}

.content-main {
  width: min(100% - 2rem, 760px);
  flex: 1;
  margin: 0 auto;
  padding: clamp(2.6rem, 7vw, 5rem) 0;
}

.content-main h1 {
  margin: 0 0 1.4rem;
  color: #153523;
  font-family: Georgia, serif;
  font-size: clamp(2rem, 6vw, 3.3rem);
  line-height: 1.06;
}

.content-main h2 {
  margin-top: 2rem;
  color: #183a27;
  font-size: 1.2rem;
}

.content-main p,
.content-main li {
  color: #48564f;
  line-height: 1.7;
}

.content-main a {
  color: #145b39;
}

.updated-date {
  margin-top: 2.4rem;
  font-size: 0.84rem;
}

@media (max-width: 840px) {
  .game-toolbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .game-toolbar h1 {
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

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

  .control-button {
    min-width: 34px;
    justify-content: center;
    padding-inline: 0.45rem;
  }

  .game-copy-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .site-header {
    gap: 0.35rem;
  }

  .brand-text {
    font-size: 0.9rem;
  }

  .brand-mark {
    width: 1.45rem;
    height: 1.45rem;
    font-size: 0.9rem;
  }

  .game-links a {
    padding-inline: 0.46rem;
    font-size: 0.73rem;
  }

  .game-toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.35rem;
  }

  .game-toolbar h1 {
    display: none;
  }

  .game-status {
    gap: 0.45rem;
    font-size: 0.7rem;
  }

  .status-label,
  [data-mode] {
    display: none;
  }

  .game-board {
    padding: 0.45rem 0.3rem 0.3rem;
  }

  .board-inner {
    gap: 0.45rem;
  }

  .top-row .pile {
    border-width: 1px;
  }

  .card-back {
    border-width: 2px;
    background-size: 10px 10px;
    background-position: 0 0, 5px 5px;
  }

  .card-center {
    display: none;
  }

  .card-corner {
    font-size: clamp(0.56rem, 2.5vw, 0.78rem);
  }

  [data-game="spider"] .card-corner {
    font-size: clamp(0.49rem, 2vw, 0.67rem);
  }

  .game-copy {
    padding-inline: 1rem;
  }
}

@media (max-width: 360px) {
  .brand-text {
    display: none;
  }

  .site-header {
    gap: 0.2rem;
  }

  .game-links a {
    padding-inline: 0.38rem;
  }
}

@media (max-height: 570px) and (orientation: landscape) {
  .site-header {
    min-height: 38px;
    padding-block: 0.2rem;
  }

  .game-toolbar {
    min-height: 38px;
    padding-block: 0.14rem;
  }

  .control-button {
    min-height: 30px;
  }

  .game-board {
    padding-block: 0.3rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
