:root {
  --bg-top: #040611;
  --bg-bottom: #0a1230;
  --text: #eaf2ff;
  --card-bg-panel: #e7edf6;
  --card-text: #0f172a;
  --card-line: #c9d5e6;
  --table-bg: #14513b;
  --table-bg-deep: #08291f;
  --table-felt-a: #1b6a4e;
  --table-felt-b: #0f4733;
  --gold: #ffe45c;
  --gold-2: #d79a1f;
  --red: #d92d2d;
  --black: #18212f;
  --font-ui: "Noto Sans TC", "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, var(--bg-bottom), var(--bg-top));
  color: var(--text);
  font-family: var(--font-ui);
}

.page-wrap {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding-inline: 24px;
}

.top-strip {
  position: sticky;
  top: 0;
  z-index: 200;
  background: rgba(8, 10, 23, 0.92);
  border-bottom: 1px solid rgba(126, 153, 255, 0.24);
  backdrop-filter: blur(8px);
}

.top-strip-inner {
  overflow-x: auto;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  min-height: 58px;
  width: max-content;
  min-width: 100%;
  padding: 0.5rem 0;
}

.icon-button {
  width: auto;
  height: auto;
  background: none;
  border: none;
  padding: 0;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  transition: filter 0.2s, transform 0.2s;
}

.icon-button img {
  width: clamp(168px, 26vw, 280px);
  height: auto;
  pointer-events: none;
}

.icon-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.top-nav-links {
  display: inline-flex;
  align-items: center;
  gap: 0.58rem;
  flex-shrink: 0;
  min-width: max-content;
  white-space: nowrap;
}

.top-nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0.7rem 1.02rem;
  border-radius: 999px;
  border: 1px solid rgba(164, 191, 255, 0.2);
  background: rgba(14, 20, 38, 0.72);
  color: #e6eeff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.01em;
  transition:
    transform 0.2s ease,
    background-color 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    box-shadow 0.2s ease;
}

.top-nav-link:hover {
  transform: translateY(-1px);
  background: rgba(31, 47, 84, 0.96);
  border-color: rgba(141, 176, 255, 0.5);
  box-shadow: 0 10px 24px rgba(5, 10, 24, 0.32);
}

.top-nav-link.is-active {
  background: linear-gradient(135deg, rgba(74, 117, 255, 0.92), rgba(42, 80, 186, 0.92));
  border-color: rgba(198, 217, 255, 0.74);
  color: #fff;
  box-shadow: 0 12px 28px rgba(43, 77, 179, 0.28);
}

.game-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 1rem;
  padding: 1.2rem 0 2rem;
}

.game-panel {
  background: var(--card-bg-panel);
  border: 1px solid var(--card-line);
  border-radius: 8px;
  color: var(--card-text);
  padding: 1rem 1.05rem;
  box-shadow: 0 10px 24px rgba(9, 20, 36, 0.08);
}

.game-stage {
  --game-frame-height: 900px;
  --game-frame-sidebar-width: 280px;
  --game-frame-gap: 14px;
  --game-frame-padding: 16px;
  --game-frame-surface-padding: 10px;
  padding: 12px;
}

.game-info h2 {
  margin: 0 0 0.5rem;
}

.game-info p {
  margin: 0.35rem 0;
  line-height: 1.7;
}

.game-info h3 {
  margin-top: 1.2rem;
  margin-bottom: 0.5rem;
}

.game-shell-freecell .game-shell__toolbar {
  align-items: center;
}

.game-shell-freecell .game-shell__toolbar-group {
  gap: 10px;
}

.game-shell-freecell .game-shell__button {
  font-size: 1.25rem;
  min-height: 46px;
  padding: 0.72rem 1.18rem;
}

.freecell-audio-toggle {
  min-width: 74px;
  padding-inline: 0.92rem;
}

.freecell-audio-toggle.is-muted {
  background: rgba(21, 32, 58, 0.92);
  border-color: rgba(164, 191, 255, 0.24);
  color: #eef4ff;
  opacity: 0.88;
}

.freecell-viewport {
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 14px;
  border: 1px solid rgba(152, 192, 255, 0.48);
  background:
    radial-gradient(circle at 50% -15%, rgba(245, 255, 250, 0.12), transparent 42%),
    linear-gradient(160deg, var(--table-bg), var(--table-bg-deep));
  overflow: hidden;
  user-select: none;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.08),
    inset 0 28px 54px rgba(255, 255, 255, 0.03),
    0 18px 34px rgba(3, 10, 8, 0.28);
}

.freecell-board {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  height: 100%;
  min-height: 0;
  padding: 14px 16px;
}

.fs-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.82);
  color: #fff;
  padding: 1.4rem 3rem;
  border-radius: 60px;
  font-size: 1.5rem;
  font-weight: 700;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
  backdrop-filter: blur(8px);
  letter-spacing: 1px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

.fs-hint.show {
  opacity: 1;
  visibility: visible;
}

.freecell-fs-controls {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 10001;
  display: none;
  gap: 10px;
}

.freecell-fs-stats {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 10001;
  display: none;
  gap: 10px;
  justify-items: end;
}

.freecell-fs-stat {
  min-width: 132px;
  display: grid;
  gap: 6px;
  padding: 12px 16px;
  border-radius: 18px;
  color: #f4f8ff;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent),
    rgba(7, 12, 26, 0.82);
  border: 1px solid rgba(164, 191, 255, 0.24);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.24);
  text-align: right;
}

.freecell-fs-stat__label {
  color: #9bb5e6;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.freecell-fs-stat__value {
  color: #ffffff;
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.1;
}

.freecell-top-zone {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}

.freecell-zone-block {
  display: grid;
  gap: 6px;
}

.freecell-zone-block h2 {
  margin: 0;
  color: #f8fafc;
  font-size: 1rem;
  letter-spacing: 0.035em;
}

.freecell-slots {
  display: grid;
  grid-template-columns: repeat(4, minmax(80px, 1fr));
  gap: 8px;
}

.freecell-slot,
.freecell-column {
  border: 2px dashed rgba(255, 255, 255, 0.32);
  background: rgba(0, 0, 0, 0.14);
  color: rgba(255, 255, 255, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.freecell-slot {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 5 / 6.8;
  min-height: 92px;
  border-radius: 12px;
  font-weight: 900;
}

.freecell-slot.is-drop-target,
.freecell-column.is-drop-target {
  border-color: var(--gold);
  background: rgba(255, 228, 92, 0.18);
  box-shadow:
    0 0 0 3px rgba(255, 228, 92, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.freecell-slot.is-available-target,
.freecell-column.is-available-target {
  border-color: rgba(255, 245, 166, 0.62);
  background: rgba(255, 245, 166, 0.08);
  box-shadow:
    0 0 0 2px rgba(255, 245, 166, 0.1),
    0 0 18px rgba(255, 228, 92, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.freecell-slot.is-drop-target,
.freecell-column.is-drop-target {
  border-color: #fff1a8;
  background: rgba(255, 228, 92, 0.2);
  box-shadow:
    0 0 0 3px rgba(255, 228, 92, 0.18),
    0 0 28px rgba(255, 228, 92, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.freecell-slot-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0.44;
  pointer-events: none;
}

.foundation-heart,
.foundation-diamond {
  color: #fecaca;
}

.foundation-spade,
.foundation-club {
  color: #e5e7eb;
}

.freecell-tableau {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
  min-height: 0;
}

.freecell-column {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  padding: 8px 7px 10px;
  border-radius: 12px;
  overflow: visible;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
}

.freecell-column-label {
  color: rgba(255, 255, 255, 0.74);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
  margin-bottom: 8px;
}

.freecell-card {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 100%;
  height: auto;
  aspect-ratio: 5 / 7;
  margin-top: -115%;
  border: 1px solid #bfc8d6;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff, #f4f7fb);
  color: var(--black);
  cursor: grab;
  touch-action: none;
  box-shadow:
    0 8px 16px rgba(0, 0, 0, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.86);
  transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

/* 修復首張牌被上推裁切：標題後的第一張牌保持 0 偏移 */
.freecell-column > .freecell-column-label + .freecell-card {
  margin-top: 0;
}

.freecell-slot .freecell-card {
  margin: 0;
  width: auto;
  height: 100%;
  max-width: 100%;
  min-height: 0;
  max-height: 100%;
  aspect-ratio: 5 / 7;
  filter: none;
  align-self: center;
  justify-self: center;
}

.freecell-card:hover {
  transform: translateY(-2px);
}

.freecell-card.is-selected {
  box-shadow:
    0 0 0 4px var(--gold),
    0 16px 28px rgba(0, 0, 0, 0.34);
  z-index: 20;
}

.freecell-card.is-dragging {
  opacity: 0.32;
}

.freecell-card.is-locked {
  filter: brightness(0.72) saturate(0.85);
}

.freecell-card.is-hint {
  animation: hintPulse 0.65s ease-in-out 0s 3 alternate;
}

.freecell-card.red {
  color: var(--red);
}

.freecell-card.black {
  color: var(--black);
}

.freecell-card__top,
.freecell-card__bottom {
  display: flex;
  gap: 0.14em;
  align-items: center;
  padding: 0.24rem 0.34rem;
  font-size: clamp(0.9rem, 1.15vw, 1.08rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.freecell-card__center {
  display: grid;
  place-items: center;
  font-size: clamp(1.54rem, 2.6vw, 2.2rem);
  font-weight: 900;
  opacity: 0.5;
}

.freecell-card__bottom {
  justify-content: flex-end;
  transform: rotate(180deg);
}

.freecell-drag-ghost {
  position: fixed;
  z-index: 2147483647;
  pointer-events: none;
  transform: translate(-50%, -35%);
  filter: none;
}

.freecell-drag-ghost .freecell-card {
  width: 100%;
  height: auto;
  aspect-ratio: 5 / 7;
  margin-top: -82%;
  opacity: 1;
  filter: none;
  box-shadow:
    0 24px 44px rgba(0, 0, 0, 0.5),
    0 0 0 3px rgba(255, 228, 92, 0.34),
    0 0 26px rgba(255, 228, 92, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.9);
}

.freecell-drag-ghost .freecell-card:first-child {
  margin-top: 0;
}

.freecell-toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 40px));
  padding: 0.68rem 1rem;
  border-radius: 999px;
  background: rgba(5, 10, 24, 0.86);
  color: #fff;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 40;
}

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

.freecell-win {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 50;
  background: rgba(3, 7, 18, 0.72);
  backdrop-filter: blur(4px);
}

.freecell-win[hidden] {
  display: none;
}

.freecell-win__panel {
  width: min(420px, calc(100% - 32px));
  padding: 1.5rem;
  border-radius: 22px;
  border: 1px solid rgba(255, 228, 92, 0.38);
  background: linear-gradient(180deg, rgba(19, 31, 63, 0.96), rgba(8, 14, 33, 0.98));
  color: #eef4ff;
  text-align: center;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.38);
}

.freecell-win__kicker {
  margin: 0 0 0.3rem;
  color: var(--gold);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.freecell-win__panel h2 {
  margin: 0 0 0.6rem;
  color: #fff;
}

.freecell-win__panel button {
  border: 0;
  border-radius: 999px;
  padding: 0.78rem 1.25rem;
  font: inherit;
  font-weight: 900;
  background: linear-gradient(135deg, var(--gold), var(--gold-2));
  color: #241707;
  cursor: pointer;
}

@keyframes hintPulse {
  from {
    transform: translateY(0);
    box-shadow: 0 0 0 0 rgba(255, 228, 92, 0);
  }

  to {
    transform: translateY(-5px);
    box-shadow: 0 0 0 5px rgba(255, 228, 92, 0.42);
  }
}

.game-shell-freecell .game-shell__sidebar {
  align-content: start;
  gap: 12px;
  padding: 14px;
}

.freecell-side-panel {
  display: grid;
  gap: 12px;
  width: 100%;
}

.freecell-side-title {
  margin: 0;
  color: #eef4ff;
  font-size: 1.22rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.freecell-side-stats {
  display: grid;
  gap: 10px;
}

.freecell-side-stat {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 228, 92, 0.22);
  background: rgba(7, 12, 26, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.freecell-side-stat__label {
  color: #f6d66c;
  font-size: 1rem;
  font-weight: 800;
}

.freecell-side-stat__value {
  color: #ffffff;
  font-size: 1.38rem;
  font-weight: 900;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.freecell-side-note {
  margin: 0;
  color: #b9c8ea;
  font-size: 0.92rem;
  line-height: 1.5;
}

.site-footer {
  border-top: 1px solid rgba(177, 198, 233, 0.28);
  padding: 1rem 0 1.5rem;
  color: #d5e2ff;
}

#gameViewport:fullscreen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  margin: 0;
  border-radius: 0;
  border: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% -15%, rgba(245, 255, 250, 0.12), transparent 42%),
    linear-gradient(160deg, var(--table-bg), var(--table-bg-deep));
}

#gameViewport:fullscreen::backdrop {
  background: #12331e;
}

#gameViewport:fullscreen .freecell-board {
  width: min(calc(100vw - 520px), calc((100vh - 40px) * 1.2));
  max-height: calc(100vh - 40px);
  min-width: 620px;
  aspect-ratio: 6 / 5;
  height: auto;
  min-height: 0;
  margin: 0 auto;
}

#gameViewport:fullscreen .freecell-fs-controls {
  display: grid;
  position: fixed;
  left: clamp(12px, 2.2vw, 34px);
  top: 50%;
  transform: translateY(-50%);
  align-content: start;
  grid-auto-flow: row;
}

#gameViewport:fullscreen .freecell-fs-stats {
  display: grid;
  position: fixed;
  right: clamp(12px, 2.2vw, 34px);
  top: 50%;
  transform: translateY(-50%);
}

#gameViewport:fullscreen .freecell-fs-controls .game-shell__button {
  min-width: 120px;
  justify-content: flex-start;
  padding-inline: 1rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

@media (max-width: 1180px) {
  #gameViewport:fullscreen .freecell-board {
    width: min(calc(100vw - 32px), calc((100vh - 32px) * 1.14));
    min-width: 0;
  }
}

@media (max-width: 980px) {
  .game-stage {
    --game-frame-height: 900px;
    --game-frame-sidebar-width: 0px;
  }

  .freecell-top-zone {
    grid-template-columns: 1fr;
  }

  .freecell-tableau {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .game-shell-freecell .game-shell__sidebar {
    display: none;
  }
}

@media (max-width: 768px) {
  .page-wrap {
    padding-inline: 16px;
  }

  .top-nav-link {
    min-height: 40px;
    padding: 0.52rem 0.82rem;
    font-size: 0.95rem;
  }

  .game-shell-freecell .game-shell__button {
    font-size: 1rem;
    min-height: 40px;
    padding: 0.55rem 0.85rem;
  }

  .game-stage {
    --game-frame-height: 960px;
    --game-frame-padding: 12px;
    --game-frame-surface-padding: 8px;
  }

  .freecell-board {
    padding: 12px;
    gap: 12px;
  }

  .freecell-slots {
    gap: 8px;
  }

  .freecell-slot {
    min-height: 82px;
    font-size: 0.82rem;
  }

  .freecell-tableau {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .freecell-column {
    min-height: 0;
  }

  .freecell-card {
    margin-top: -94%;
  }

  .freecell-column > .freecell-column-label + .freecell-card {
    margin-top: 0;
  }

  .freecell-slot .freecell-card {
    height: 100%;
    min-height: 0;
    max-height: 100%;
    width: auto;
  }
}
