:root {
  --page-bg: linear-gradient(160deg, #fff8f1 0%, #f7e8d7 52%, #f1d8bc 100%);
  --panel-bg: rgba(255, 251, 245, 0.88);
  --panel-border: rgba(175, 129, 90, 0.14);
  --board-bg: #caa27a;
  --cell-bg: rgba(255, 246, 236, 0.26);
  --text-main: #5a3924;
  --text-muted: #8d6d56;
  --button-main: #e08a4e;
  --button-main-hover: #c96f37;
  --button-secondary: rgba(255, 249, 241, 0.96);
  --shadow-soft: 0 20px 45px rgba(140, 95, 56, 0.16);
  --shadow-card: 0 10px 24px rgba(124, 81, 44, 0.16);
  --board-size: min(88vw, 460px);
  --gap: 12px;
  --tile-radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Avenir Next", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.72), transparent 28%),
    radial-gradient(circle at bottom right, rgba(255, 205, 156, 0.2), transparent 22%),
    var(--page-bg);
}

button,
.back-link {
  border: none;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

button:hover,
.back-link:hover {
  transform: translateY(-1px);
}

button:active,
.back-link:active {
  transform: translateY(1px);
}

.game-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 18px 32px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 14px;
}

.site-nav {
  position: sticky;
  top: 14px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 24px;
  background: rgba(255, 251, 245, 0.9);
  border: 1px solid rgba(175, 129, 90, 0.16);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.site-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text-main);
  background: rgba(255, 247, 238, 0.98);
  border: 1px solid rgba(195, 152, 114, 0.18);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
  white-space: nowrap;
}

.site-nav-links {
  display: flex;
  gap: 10px;
  flex: 1;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.site-nav-links::-webkit-scrollbar {
  display: none;
}

.site-nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255, 249, 241, 0.96);
  border: 1px solid rgba(195, 152, 114, 0.18);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
  white-space: nowrap;
  flex: 0 0 auto;
  transition: transform 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
}

.site-nav-link:hover,
.site-brand:hover {
  transform: translateY(-1px);
}

.site-nav-link:active,
.site-brand:active {
  transform: translateY(1px);
}

.site-nav-link.is-active {
  color: #fff8f0;
  background: var(--button-main);
  border-color: transparent;
  box-shadow: 0 12px 24px rgba(224, 138, 78, 0.24);
}

.topbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  width: 100vw;
  margin: 0 calc(50% - 50vw);
  padding: 0 32px;
}

.topbar > :first-child {
  width: 100%;
  max-width: min(100%, 1440px);
  text-align: center;
}

.topbar > :last-child {
  flex: none;
}

.theme-label {
  margin: 0 0 6px;
  color: #c4753c;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.95rem, 3.4vw, 3.35rem);
  line-height: 0.94;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.subtitle {
  margin: 8px auto 0;
  max-width: min(100%, 88rem);
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: nowrap;
}

.scoreboard {
  display: flex;
  gap: 12px;
  align-items: stretch;
  justify-content: center;
  align-self: center;
}

.score-card {
  min-width: 104px;
  padding: 10px 16px 12px;
  border-radius: 20px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  backdrop-filter: blur(8px);
}

.score-card .label {
  display: block;
  width: 100%;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 0.74rem;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.score-card strong {
  display: block;
  width: 100%;
  font-size: 1.6rem;
  line-height: 1;
}

.board-wrap {
  display: flex;
  justify-content: center;
}

.board-frame {
  position: relative;
  padding: 14px;
  border-radius: 28px;
  background: rgba(255, 249, 241, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.56);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.board {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  padding: var(--gap);
  border-radius: 24px;
  background: var(--board-bg);
  box-shadow:
    inset 0 4px 16px rgba(122, 79, 47, 0.14),
    0 0 0 1px rgba(255, 255, 255, 0.14);
  touch-action: none;
}

.cell,
.tile {
  position: absolute;
  width: calc((100% - (var(--gap) * 5)) / 4);
  height: calc((100% - (var(--gap) * 5)) / 4);
  border-radius: var(--tile-radius);
}

.cell {
  background: var(--cell-bg);
}

.tile {
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-card);
  will-change: left, top, transform;
  transition:
    left 0.175s cubic-bezier(0.22, 0.9, 0.24, 1),
    top 0.175s cubic-bezier(0.22, 0.9, 0.24, 1),
    transform 0.16s ease,
    opacity 0.16s ease;
}

.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tile.level-missing {
  background: linear-gradient(160deg, #fff1d8, #f0b35e);
  color: #5d3512;
  font-size: clamp(1.3rem, 5vw, 2rem);
  font-weight: 800;
}

.tile.new {
  animation: tile-pop 0.18s ease-out;
}

.tile.merged {
  animation: tile-merge 0.2s ease-out;
}

.overlay {
  position: absolute;
  inset: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  border-radius: 24px;
  background: rgba(96, 60, 33, 0.42);
  backdrop-filter: blur(8px);
  z-index: 20;
}

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

.overlay-card {
  width: min(100%, 320px);
  padding: 28px 22px;
  border-radius: 24px;
  background: rgba(255, 250, 243, 0.96);
  text-align: center;
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(189, 144, 102, 0.16);
}

.overlay-card h2 {
  margin: 0 0 10px;
  font-size: 2rem;
}

.overlay-card p {
  margin: 0 0 18px;
  color: var(--text-muted);
  line-height: 1.5;
}

.overlay-actions,
.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.primary,
#overlay-restart-btn {
  padding: 12px 24px;
  color: #fff8f0;
  background: var(--button-main);
  box-shadow: 0 12px 24px rgba(224, 138, 78, 0.28);
}

.primary:hover,
#overlay-restart-btn:hover {
  background: var(--button-main-hover);
}

.secondary,
.back-link {
  padding: 12px 22px;
  color: var(--text-main);
  background: var(--button-secondary);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  text-decoration: none;
}

@keyframes tile-pop {
  0% {
    opacity: 0;
    transform: scale(0.35);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes tile-merge {
  0% {
    transform: scale(1);
  }

  40% {
    transform: scale(1.16);
  }

  100% {
    transform: scale(1);
  }
}

@media (max-width: 640px) {
  :root {
    --gap: 10px;
    --tile-radius: 15px;
  }

  .game-shell {
    padding-top: 0;
    padding-bottom: 24px;
  }

  .topbar > :first-child {
    flex-basis: auto;
    min-width: 0;
  }

  .site-nav {
    top: 10px;
    padding: 12px;
    border-radius: 20px;
    gap: 10px;
  }

  .site-brand {
    padding: 10px 14px;
    font-size: 0.95rem;
  }

  .topbar {
    margin: 0 calc(50% - 50vw);
    padding: 0 18px;
    align-items: stretch;
  }

  h1 {
    font-size: clamp(1.75rem, 8.5vw, 2.2rem);
    white-space: normal;
  }

  .subtitle {
    font-size: 0.86rem;
    white-space: normal;
  }

  .scoreboard {
    width: 100%;
  }

  .score-card {
    flex: 1;
  }

  .board-frame {
    padding: 10px;
    border-radius: 22px;
  }

  .overlay {
    inset: 10px;
    padding: 16px;
  }
}

/* SEO Content Styles */
.seo-content {
  margin-top: 48px;
  padding: 40px 32px;
  border-radius: 28px;
  background: rgba(255, 251, 245, 0.88);
  border: 1px solid rgba(175, 129, 90, 0.14);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(8px);
}

.seo-content h2 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  margin: 40px 0 16px;
  color: var(--text-main);
}

.seo-content h2:first-child {
  margin-top: 0;
}

.seo-content h3 {
  font-size: clamp(1.2rem, 3vw, 1.5rem);
  margin: 28px 0 12px;
  color: var(--text-main);
}

.seo-content p {
  margin: 12px 0;
  line-height: 1.7;
  color: var(--text-muted);
}

.variant-comparison {
  width: 100%;
  margin: 20px 0;
  border-collapse: collapse;
  border-radius: 18px;
  overflow: hidden;
  background: rgba(255, 251, 246, 0.96);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.08);
}

.variant-comparison thead {
  background: linear-gradient(180deg, rgba(224, 138, 78, 0.12), rgba(224, 138, 78, 0.06));
}

.variant-comparison th {
  padding: 16px;
  text-align: left;
  font-weight: 700;
  color: var(--text-main);
  border-bottom: 2px solid rgba(175, 129, 90, 0.14);
}

.variant-comparison td {
  padding: 14px 16px;
  color: var(--text-muted);
  border-bottom: 1px solid rgba(175, 129, 90, 0.08);
}

.variant-comparison tbody tr:last-child td {
  border-bottom: none;
}

.variant-comparison tbody tr:hover {
  background: rgba(255, 248, 240, 0.6);
}

.faq-section {
  margin: 24px 0;
}

.faq-section h3 {
  font-size: 1.2rem;
  margin: 24px 0 8px;
  color: var(--text-main);
}

.faq-section p {
  margin: 8px 0;
  line-height: 1.7;
  color: var(--text-muted);
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin: 24px 0;
}

.theme-card {
  display: flex;
  flex-direction: column;
  padding: 24px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 251, 246, 0.96), rgba(250, 238, 225, 0.92));
  border: 1px solid rgba(195, 152, 114, 0.12);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.theme-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.16);
}

.theme-card h3 {
  font-size: 1.4rem;
  margin: 0 0 8px;
  color: var(--text-main);
}

.theme-card p {
  margin: 0;
  line-height: 1.6;
  color: var(--text-muted);
}

.seo-content a {
  color: var(--button-main);
  text-decoration: underline;
  transition: color 0.2s ease;
}

.seo-content a:hover {
  color: var(--button-main-hover);
}

@media (max-width: 720px) {
  .seo-content {
    padding: 28px 20px;
  }

  .theme-grid {
    grid-template-columns: 1fr;
  }

  .variant-comparison {
    font-size: 0.9rem;
  }

  .variant-comparison th,
  .variant-comparison td {
    padding: 12px;
  }
}
