@font-face {
  font-family: "Obvia Wide Thin";
  src: url("../fonts/Obvia_Wide_Thin.otf") format("opentype");
  font-weight: 200;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #f4ead6;
  --muted: rgba(244, 234, 214, 0.68);
  --orange: #f76f24;
  --gold: #b38227;
  --panel: #16141f;
  --card: #1d1a28;
  --black: #07070d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Obvia Wide Thin", "SF Pro Display", system-ui, sans-serif;
  color: var(--ink);
  background: var(--black);
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  position: relative;
}

.scene {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: #07070d center / cover no-repeat;
  opacity: 0.7;
  transform: translateZ(0);
}

.play {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: min(98vw, calc(100dvh - 160px));
  margin: 0 auto;
  padding: 18px 16px 28px;
  padding-top: max(18px, env(safe-area-inset-top, 0px));
  padding-bottom: max(48px, calc(env(safe-area-inset-bottom, 0px) + 28px));
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.logo {
  width: min(42vw, 180px);
  height: auto;
  margin: 8px 0 20px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,.55));
}

.progress-wrap {
  width: 100%;
  height: 8px;
  border-radius: 99px;
  background: rgba(255,255,255,.12);
  overflow: hidden;
  margin: 20px 0 12px;
}

.progress-wrap[hidden] { display: none; }

.progress-wrap[hidden] + .moves {
  margin-top: 16px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold), var(--orange));
  border-radius: inherit;
  transition: width 0.35s ease;
}

.moves {
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  margin: 0 0 8px;
  min-height: 1.4em;
}

.board-wrap {
  width: 100%;
  aspect-ratio: 1;
  touch-action: none;
  overscroll-behavior: none;
  margin: 0;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.board.is-busy .block.is-pulse {
  animation: none;
}

.block {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  left: 0;
  top: 0;
  touch-action: none;
  cursor: grab;
  contain: layout style;
}

.block.is-drag {
  z-index: 20;
  cursor: grabbing;
}

.block img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: block;
}

.block .state {
  z-index: 1;
}

.block.is-pulse {
  animation: stateAPulse 2.4s ease-in-out infinite;
}

@keyframes stateAPulse {
  0%, 100% { transform: scale(0.95); }
  50% { transform: scale(1.05); }
}

.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 18px 0 22px;
  width: 100%;
}

.util-btn {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  width: 52px;
  height: 52px;
  position: relative;
  cursor: pointer;
}

.util-btn img {
  width: 100%;
  height: 100%;
  display: block;
}

.shuffle-count {
  position: absolute;
  top: -4px;
  right: -6px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 99px;
  background: #777;
  color: #111;
  font: 700 12px/22px system-ui, sans-serif;
  text-align: center;
  border: 1px solid #000;
}

.shuffle-count.has-free { background: #f76f24; }
.shuffle-count.too-many { background: #3dce4a; }

.app-store {
  margin: 8px 0 16px;
}

.app-store img {
  width: 120px;
  height: 40px;
}

.share-puzzle, .share-buttons {
  margin: 8px 0 16px;
  text-align: center;
}

.game-promo {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  margin: 4px 0 10px;
  padding: 10px 12px;
  border-radius: 14px;
  text-decoration: none;
  color: var(--ink);
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.1);
  text-align: left;
}

.game-promo img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  object-fit: cover;
}

.game-promo strong {
  display: block;
  font-weight: 500;
  font-style: normal;
}

.game-promo em {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-style: normal;
  line-height: 1.35;
}

.share-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.share-row {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.share-btn, .share-btn-small {
  appearance: none;
  border: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255,255,255,.1);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.share-btn-small {
  width: 36px;
  height: 36px;
}

.site-footer {
  margin-top: 16px;
  padding: 4px 4px 8px;
  color: var(--muted);
  font-size: 0.95rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 4px;
}

.site-footer a, .footer-btn {
  color: var(--ink);
  background: none;
  border: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  padding: 12px 14px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(7, 7, 13, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 12px;
  overflow: auto;
}

.overlay.hidden,
.hidden { display: none !important; }

.card {
  background: var(--card);
  color: var(--ink);
  border-radius: 20px;
  padding: 22px 20px 18px;
  width: min(520px, 100%);
  max-height: min(92vh, 92dvh);
  overflow: auto;
  box-shadow: 0 16px 40px rgba(0,0,0,.45);
  border: 1px solid rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
}

.card .stack {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent, var(--card) 28%);
  padding-top: 12px;
  margin-top: auto;
}

.card.narrow { width: min(380px, 100%); }

.card-logo {
  display: block;
  width: min(46%, 140px);
  height: auto;
  margin: 0 auto 12px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,.45));
}

.card h1, .card h2 {
  margin: 0 0 10px;
  font-weight: 400;
  letter-spacing: 0.02em;
  text-align: center;
}

.card p, .card li {
  line-height: 1.45;
}

.help-list {
  margin: 8px 0 12px;
  padding-left: 1.2em;
}

.settings-card {
  background: rgba(255,255,255,.05);
  border-radius: 14px;
  padding: 8px 12px;
  margin: 0 0 12px;
}

.toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.toggle:last-child { border-bottom: 0; }

.toggle input {
  width: 44px;
  height: 24px;
  accent-color: var(--orange);
}

.field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.field:last-child { border-bottom: 0; }

.field select {
  font: inherit;
  color: var(--ink);
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  padding: 6px 8px;
  max-width: 60%;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.play-btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  background: var(--orange);
  color: #111;
  font: inherit;
  font-weight: 600;
  padding: 12px 16px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}

.play-btn.ghost {
  background: rgba(255,255,255,.1);
  color: var(--ink);
}

.scores-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.scores-table th, .scores-table td {
  text-align: left;
  padding: 8px 4px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.toast {
  position: fixed;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  z-index: 40;
  background: rgba(20, 18, 28, .92);
  border: 1px solid rgba(255,255,255,.16);
  color: #fff;
  padding: 14px 22px;
  border-radius: 14px;
  font-size: 1.15rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.toast.show { opacity: 1; }

.loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #07070d center / cover no-repeat;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.loading.hidden { display: none; }

.loading img {
  width: min(70vw, 280px);
}

.loading p {
  margin: 0;
  color: var(--muted);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255,255,255,.2);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hp { position: absolute; left: -9999px; }

.form-error { color: #ff8a70; }

label { display: block; margin: 10px 0 6px; }

input[type="text"], input[type="email"], textarea, select.full {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px;
  padding: 10px 12px;
}

.optional { color: var(--muted); font-weight: 400; }

.page-static .play {
  max-width: 640px;
  align-items: stretch;
  justify-content: center;
}

@media (max-width: 420px) {
  .util-btn { width: 46px; height: 46px; }
  .controls { gap: 8px; }
}
