:root {
  --felt: #151b32;
  --felt-dark: #0c1020;
  --wood: #3a2a1c;
  --gold: #e0a36a;
  --card: #f4efe6;
  --red: #c43c4a;
  --black: #1c1a22;
  --hud: rgba(10, 12, 24, 0.82);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-width: 100%;
  overflow: hidden;
  background: var(--felt-dark);
  color: #f3eee6;
  font-family: "Avenir Next", "Segoe UI Variable Display", "Trebuchet MS", "Century Gothic", sans-serif;
  user-select: none;
  touch-action: manipulation;
}
html.web-gate,
html.web-gate body {
  overflow: auto;
  height: auto;
  min-height: 100%;
}
html.web-gate body > *:not(#web-gate) {
  display: none !important;
}
#web-gate {
  display: none;
}
html.web-gate #web-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 100dvh;
  padding: 32px 20px;
  gap: 10px;
}
.web-gate .app-mark {
  width: 88px;
  height: 88px;
  margin-bottom: 8px;
}
.web-gate h1 {
  margin: 0;
  font-size: 36px;
  font-weight: 500;
}
.web-gate p {
  max-width: 360px;
  opacity: 0.85;
  line-height: 1.45;
}
.store-btn {
  display: inline-block;
  margin-top: 12px;
  padding: 14px 22px;
  border-radius: 14px;
  background: var(--gold);
  color: #1a1408;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
}
body.in-game .table,
body.in-game .pile,
body.in-game .card {
  touch-action: none;
}
body.in-lobby {
  overflow: auto;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  padding: 0;
  min-height: 100%;
  min-height: 100dvh;
  background:
    radial-gradient(720px 420px at 50% -8%, #2a3560, transparent 58%),
    radial-gradient(420px 280px at 100% 100%, rgba(196, 120, 58, 0.18), transparent 50%),
    linear-gradient(180deg, #101628, #151b32 48%, #0c1020);
}

.hud {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  padding: max(8px, env(safe-area-inset-top, 0px)) max(10px, env(safe-area-inset-right, 0px)) 8px max(10px, env(safe-area-inset-left, 0px));
  background: var(--hud);
  border-bottom: 1px solid rgba(227, 194, 122, 0.25);
}
.title-block { min-width: 0; }
.title-block strong {
  display: block;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  font-size: 13px;
}
#status-line { font-size: 12px; opacity: 0.8; }
.stats {
  display: flex;
  gap: 12px;
  font-variant-numeric: tabular-nums;
}
.stats span { display: flex; flex-direction: column; align-items: flex-end; }
.stats small { opacity: 0.7; font-size: 10px; }
.icon-btn, .sheet button, .link-btn {
  font: inherit;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}
.icon-btn {
  width: 42px;
  height: 42px;
  background: rgba(227, 194, 122, 0.12);
  color: var(--gold);
  font-size: 20px;
}

.table {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: 8px 4px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.top-row, .tableau-row, .foundations, .cells {
  display: flex;
  gap: var(--gap, 6px);
}
.top-row {
  justify-content: space-between;
  align-items: flex-start;
  overflow: visible;
  gap: var(--gap, 6px);
  flex-shrink: 0;
}
.layout-klondike .top-row { gap: 12px; }
.layout-klondike .stock { margin-right: 6px; }
.tableau-row {
  flex: 1;
  justify-content: center;
  align-items: flex-start;
  min-height: 0;
  overflow: hidden;
}
.spacer { flex: 1; min-width: 4px; }
.waste { overflow: visible; }
.stock, .foundation, .cell { overflow: visible; }
.pile.tableau, .pile.cell, .pile.stock, .pile.waste, .pile.foundation {
  flex: 0 0 var(--card-w);
}

.pile {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  border: 1px dashed rgba(247, 241, 230, 0.28);
  background: rgba(0, 0, 0, 0.16);
}
.pile.drop-ok { outline: 2px solid var(--gold); }
.foundation::after, .stock:empty::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
  opacity: 0.35;
}
.foundation[data-suit="spades"]::after { content: "♠"; }
.foundation[data-suit="hearts"]::after { content: "♥"; color: #ffd0d0; }
.foundation[data-suit="diamonds"]::after { content: "♦"; color: #ffd0d0; }
.foundation[data-suit="clubs"]::after { content: "♣"; }

.card {
  position: absolute;
  width: var(--card-w);
  height: var(--card-h);
  border-radius: 8px;
  background: var(--card);
  color: var(--black);
  box-shadow: 0 3px 7px rgba(0, 0, 0, 0.22);
  left: 0;
  top: 0;
  overflow: hidden;
  box-sizing: border-box;
}
.card.back {
  background:
    radial-gradient(circle at 30% 18%, rgba(224, 163, 106, 0.22), transparent 36%),
    repeating-linear-gradient(32deg, #1c2748 0 7px, #141a32 7px 14px);
  color: var(--gold);
  border: 2px solid rgba(224, 163, 106, 0.75);
}
.card.red { color: var(--red); }
.card.hidden-drag { opacity: 0.15; }
.card-face {
  position: relative;
  height: 100%;
  padding: 0;
  pointer-events: none;
}
.card-face .corner {
  position: absolute;
  top: 5px;
  left: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 0.95;
  width: auto;
  white-space: nowrap;
  z-index: 1;
}
.card-face .corner b {
  display: block;
  font-size: calc(var(--card-w) * 0.2);
  font-weight: 700;
  letter-spacing: -0.04em;
}
.card-face .corner i {
  display: block;
  font-style: normal;
  font-size: calc(var(--card-w) * 0.16);
  margin-top: 1px;
}
.card-face .corner.rank-10 b {
  font-size: calc(var(--card-w) * 0.155);
  letter-spacing: -0.08em;
}
.card-face .corner.br {
  top: auto;
  left: auto;
  right: 4px;
  bottom: 5px;
  transform: rotate(180deg);
}
.card-face .pip {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--card-w) * 0.44);
  line-height: 1;
  transform: translateY(1px);
}

#drag-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}
#drag-layer .card { pointer-events: none; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 20, 0.72);
  display: grid;
  place-items: end center;
  z-index: 30;
  padding: 16px;
  touch-action: manipulation;
  pointer-events: auto;
}
.overlay[hidden] {
  display: none !important;
}
.overlay button, .ad-toolbar button {
  touch-action: manipulation;
  pointer-events: auto;
}
.sheet {
  width: min(420px, 100%);
  background: #161b30;
  border: 1px solid rgba(224, 163, 106, 0.32);
  border-radius: 20px 20px 12px 12px;
  padding: 22px;
}
.sheet h2 { margin: 0 0 12px; color: var(--gold); font-weight: 500; }
.sheet button, .link-btn {
  width: 100%;
  margin: 8px 0;
  padding: 12px;
  background: var(--gold);
  color: #23180a;
  text-align: center;
  text-decoration: none;
  display: block;
}
.sheet .secondary, .sheet .ghost { background: transparent; color: #f6f0e4; border: 1px solid rgba(246,240,228,0.25); }
.toggle { display: flex; justify-content: space-between; align-items: center; margin: 10px 0; }
.toggle input { width: 20px; height: 20px; }
.win-sheet { text-align: center; place-self: center; border-radius: 20px; }

.ad-banner {
  min-height: 50px;
  background: rgba(0,0,0,0.28);
  display: flex;
  justify-content: center;
  align-items: center;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  flex-shrink: 0;
}
.ad-banner iframe, .ad-creative {
  width: 100%;
  max-width: 728px;
  height: 58px;
  border: 0;
}
.ad-creative {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  color: inherit;
  text-decoration: none;
  background: linear-gradient(90deg, #1c2748, #12182b);
  font: inherit;
  cursor: pointer;
}
button.ad-creative {
  width: 100%;
  max-width: none;
  height: auto;
  min-height: 58px;
  border: 0;
  text-align: left;
}
.ad-smartlink {
  flex-direction: column;
  align-items: stretch;
  min-height: 200px;
  height: auto;
  padding: 0;
}
.ad-smartlink .video-stage,
.ad-smartlink-fill {
  flex: 1;
  width: 100%;
  min-height: 0;
  height: 100%;
  border-radius: 0;
}
.ad-mrec .ad-smartlink,
.ad-native .ad-smartlink {
  min-height: 0;
  height: 100%;
  max-width: none;
}
.ad-mrec, .ad-native {
  display: flex;
  margin: 0;
  width: 100%;
  min-height: 0;
  background: rgba(0,0,0,0.28);
  border-radius: 18px;
  overflow: hidden;
}
.ad-mrec iframe, .ad-mrec img, .ad-native iframe, .ad-native img,
.ad-mrec button, .ad-native button {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.ad-creative img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  background: #234;
}
.ad-fallback {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #1c2748;
  color: var(--gold);
}
.ad-overlay {
  place-items: stretch;
  padding: max(8px, env(safe-area-inset-top, 0px)) 8px max(8px, env(safe-area-inset-bottom, 0px));
  z-index: 40;
  background: rgba(0, 0, 0, 0.86);
}
#ad-video { z-index: 50; }
.ad-sheet {
  width: 100%;
  height: 100%;
  max-width: none;
  display: flex;
  flex-direction: column;
  background: #12182b;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(227, 194, 122, 0.3);
}
.ad-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: #1a2038;
  flex-shrink: 0;
}
.ad-toolbar button {
  width: auto;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: var(--gold);
}
.ad-toolbar button:disabled { opacity: 0.45; pointer-events: none; }
#ad-interstitial-body,
#ad-video-body,
#ad-rewarded-body,
#ad-offerwall-body,
#ad-appopen-body {
  flex: 1;
  min-height: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  background: #05080c;
}
#ad-video-body video {
  width: 100%;
  height: 100%;
  max-height: none;
  background: #000;
  object-fit: contain;
}
.ad-frame-wrap,
.ad-frame {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: #05080c;
}
.offer-card {
  width: 100%;
  height: 100%;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 6px;
  padding: 18px;
  border: 1px solid rgba(227, 194, 122, 0.28);
  border-radius: 18px;
  background:
    radial-gradient(160px 100px at 90% 0%, rgba(227, 194, 122, 0.2), transparent 55%),
    linear-gradient(180deg, #243056, #141a2c);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.offer-kicker {
  color: var(--gold);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11px;
}
.offer-card strong { font-size: 22px; font-weight: 500; }
.offer-card small { opacity: 0.8; }
.lobby-offer {
  display: block;
  width: 100%;
  margin: 0;
  padding: 12px;
  background: transparent;
  color: var(--gold);
  border: 1px solid rgba(224, 163, 106, 0.35);
  border-radius: 12px;
  flex-shrink: 0;
}
.ad-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 80;
  background: #1a2038;
  border: 1px solid var(--gold);
  padding: 10px 14px;
  border-radius: 10px;
  color: #f6f0e4;
}
.ad-image { justify-content: center; }
.ad-image img { width: 100%; height: auto; object-fit: contain; }
#ad-offerwall-body iframe, #ad-appopen-body iframe,
#ad-interstitial-body iframe, #ad-rewarded-body iframe, #ad-video-body iframe {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: #05080c;
}
.video-test {
  min-height: 220px;
  border-radius: 10px;
  overflow: hidden;
  background: #05080c;
  text-align: center;
  color: #f6f0e4;
}
.video-stage {
  height: 100%;
  min-height: 160px;
  background:
    linear-gradient(120deg, #243056, #7a1c3a, #c4783a, #243056);
  background-size: 300% 300%;
  animation: videoWash 4s linear infinite;
}
.video-test p { margin: 10px 12px 14px; }
@keyframes videoWash {
  0% { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}

.card.selected {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

#game-screen:not([hidden]) {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.lobby[hidden],
#game-screen[hidden] {
  display: none !important;
}
.lobby {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: max(18px, env(safe-area-inset-top, 0px)) 16px 12px;
  touch-action: manipulation;
}
.lobby-ads {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
.lobby-ads .ad-mrec {
  flex: 1 1 auto;
  min-height: 160px;
}
.lobby-ads .ad-mrec iframe,
.lobby-ads .ad-mrec .ad-frame-wrap,
.lobby-ads .ad-mrec .ad-frame {
  height: 100%;
  min-height: 160px;
}
.lobby-ads .ad-native {
  flex: 0 0 auto;
  min-height: 0;
  height: auto;
}
.lobby-ads .ad-native .ad-creative {
  min-height: 64px;
  height: auto;
}
.lobby-hero { margin-bottom: 18px; position: relative; padding-right: 48px; flex-shrink: 0; }
.app-mark {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: block;
  margin: 0 0 14px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}
.lobby-settings { position: absolute; top: 0; right: 0; }
.lobby-hero .brand {
  color: var(--gold);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 12px;
  margin: 0 0 6px;
}
.lobby-hero h1 {
  margin: 0 0 6px;
  font-weight: 500;
  font-size: 34px;
}
.lang-pick {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0;
  font-size: 14px;
}
.lang-pick select {
  font: inherit;
  color: var(--gold);
  background: #161b30;
  border: 1px solid rgba(227, 194, 122, 0.35);
  border-radius: 10px;
  padding: 8px 10px;
  width: auto;
  min-width: 140px;
  touch-action: manipulation;
}
.game-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  flex-shrink: 0;
}
.game-tile {
  font: inherit;
  color: inherit;
  text-align: left;
  border: 1px solid rgba(227, 194, 122, 0.28);
  border-radius: 18px;
  min-height: 148px;
  padding: 16px;
  background:
    radial-gradient(120px 80px at 90% 0%, rgba(224, 163, 106, 0.2), transparent 55%),
    linear-gradient(180deg, #222a48, #141a2c);
  touch-action: manipulation;
}
.game-tile.spider { background: linear-gradient(180deg, #3a2238, #1a121c); }
.game-tile.freecell { background: linear-gradient(180deg, #1a3348, #101824); }
.game-tile.pyramid { background: linear-gradient(180deg, #3a2a18, #1a140c); }
.game-tile strong { display: block; font-size: 20px; margin: 8px 0 4px; }
.game-tile small { opacity: 0.75; }
.tile-suits { color: var(--gold); font-size: 22px; letter-spacing: 0.15em; }

.card.peek .pip,
.card.peek .corner.br {
  display: none;
}
.card.peek .corner {
  top: 2px;
  left: 2px;
}
.table.compact .card-face .corner b {
  font-size: calc(var(--card-w) * 0.26);
}
.table.compact .card-face .corner i {
  font-size: calc(var(--card-w) * 0.2);
}
.table.compact .card-face .pip {
  font-size: calc(var(--card-w) * 0.42);
}
.table.compact .card.back {
  border-width: 1px;
}

.cells, .foundations {
  display: flex;
  gap: var(--gap, 6px);
  flex-shrink: 0;
}
.layout-spider .spacer {
  display: block;
  flex: 1;
  min-width: 6px;
}
.layout-spider .foundations {
  margin-left: 0;
  gap: 3px;
  max-width: none;
}
.layout-spider .top-row {
  gap: 6px;
  min-height: var(--card-h);
  align-items: center;
}
.layout-spider .foundation {
  width: calc(var(--card-w) * 0.8);
  flex: 0 0 calc(var(--card-w) * 0.8);
  height: calc(var(--card-h) * 0.8);
  border: 1px dashed rgba(247, 241, 230, 0.38);
  background: rgba(0, 0, 0, 0.16);
  overflow: visible;
}
.layout-spider .foundation::after {
  font-size: 14px;
}
.layout-spider .foundation .card {
  width: calc(var(--card-w) * 0.8);
  height: calc(var(--card-h) * 0.8);
}
.layout-freecell .top-row { gap: var(--gap, 6px); }
.pyramid-board {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  overflow: auto;
  padding-top: 6px;
}
.pyramid-row {
  display: flex;
  justify-content: center;
  margin-top: calc(var(--card-h) * -0.58);
}
.pyramid-row:first-child { margin-top: 0; }
.pyramid-board .pile {
  margin: 0 1px;
  border-color: transparent;
  background: transparent;
}

@media (max-width: 420px) {
  .stats span:first-child { display: none; }
}
