/* ============================================================================
 * 2048 Hub — Layout & structure
 * Shared by every variant and content page. Theme colours live in
 * theme-*.css (per-variant overrides).
 * ============================================================================ */

/* ---- Reset + iOS / Android safety ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-touch-callout: none;
}
html, body { height: 100%; }
body {
  font-family: "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  background: #faf8ef;
  color: #776e65;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  padding-top:    max(12px, env(safe-area-inset-top,    12px));
  padding-right:  max(8px,  env(safe-area-inset-right,   8px));
  padding-bottom: max(32px, env(safe-area-inset-bottom, 32px));
  padding-left:   max(8px,  env(safe-area-inset-left,    8px));
  overscroll-behavior: none;
  min-height: 100%;
}

a { color: #8f7a66; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Page container ---- */
.wrap {
  width: min(90vw, 480px);
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ---- Header ---- */
.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.title {
  font-size: 76px;
  line-height: 0.9;
  font-weight: 800;
  color: inherit;
}
.sub-title {
  font-size: 14px;
  font-weight: 700;
  color: #bbada0;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}
.scores { display: flex; gap: 8px; }
.score-box {
  background: #bbada0;
  border-radius: 4px;
  padding: 8px 16px;
  min-width: 78px;
  text-align: center;
}
.score-box .lbl {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #eee4da;
}
.score-box .val {
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  margin-top: 2px;
}

/* ---- Sub-header (instructions + actions) ---- */
.sub {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 0 14px;
  gap: 12px;
  flex-wrap: wrap;
}
.sub p { font-size: 14px; }
.sub strong { font-weight: 700; }
.sub .actions { display: flex; gap: 8px; }

/* ---- Buttons ---- */
.btn {
  background: #8f7a66;
  color: #f9f6f2;
  border: none;
  border-radius: 4px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: background 120ms ease;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.btn:hover  { background: #9f8b77; }
.btn:active { background: #7a6650; }
.btn.primary { background: #8f7a66; }
.btn.ghost   { background: transparent; color: #8f7a66; border: 2px solid #8f7a66; }
.btn.ghost:hover { background: rgba(143, 122, 102, 0.08); }

/* ---- Game container ---- */
.game {
  position: relative;
  width: 100%;
}
.grid {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #bbada0;
  border-radius: 6px;
  padding: 10px;
  touch-action: none;
  -webkit-touch-callout: none;
}
@supports not (aspect-ratio: 1 / 1) {
  .grid {
    height: 0;
    padding-top:    10px;
    padding-left:   10px;
    padding-right:  10px;
    padding-bottom: 100%;
  }
  .grid-bg { position: absolute; top: 10px; left: 10px; right: 10px; bottom: 10px; }
}
.grid-bg {
  display: grid;
  gap: 10px;
  width: 100%;
  height: 100%;
}
.cell {
  background: rgba(238, 228, 218, 0.35);
  border-radius: 4px;
}

.tiles {
  position: absolute;
  top: 10px; left: 10px; right: 10px; bottom: 10px;
  pointer-events: none;
}

/* ---- Tile base (size & font scaled per data-size in rules below) ---- */
.tile {
  position: absolute;
  background: #eee4da;
  color: #776e65;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  border-radius: 4px;
  transform: translate(var(--x), var(--y));
  transition: transform 120ms ease-in-out;
  /* width / height set by JS to match actual cell size */
}
.tile.spawn {
  animation: spawn 180ms ease-out;
}
@keyframes spawn {
  from { transform: translate(var(--x), var(--y)) scale(0); }
  to   { transform: translate(var(--x), var(--y)) scale(1); }
}
.tile.dying {
  opacity: 0;
  transform: translate(var(--x), var(--y)) scale(0.4);
  transition: transform 120ms ease-in-out, opacity 100ms ease-in;
}

/* Size-specific font sizes */
.game[data-size="3"] .tile { font-size: 64px; }
.game[data-size="3"] .tile[data-v="128"],
.game[data-size="3"] .tile[data-v="256"],
.game[data-size="3"] .tile[data-v="512"] { font-size: 50px; }
.game[data-size="3"] .tile[data-v="1024"],
.game[data-size="3"] .tile[data-v="2048"] { font-size: 38px; }

.game[data-size="4"] .tile { font-size: 55px; }
.game[data-size="4"] .tile[data-v="128"],
.game[data-size="4"] .tile[data-v="256"],
.game[data-size="4"] .tile[data-v="512"] { font-size: 45px; }
.game[data-size="4"] .tile[data-v="1024"],
.game[data-size="4"] .tile[data-v="2048"] { font-size: 35px; }
.game[data-size="4"] .tile[data-v="4096"],
.game[data-size="4"] .tile[data-v="8192"] { font-size: 30px; }

.game[data-size="5"] .tile { font-size: 44px; }
.game[data-size="5"] .tile[data-v="128"],
.game[data-size="5"] .tile[data-v="256"],
.game[data-size="5"] .tile[data-v="512"] { font-size: 36px; }
.game[data-size="5"] .tile[data-v="1024"],
.game[data-size="5"] .tile[data-v="2048"] { font-size: 28px; }
.game[data-size="5"] .tile[data-v="4096"],
.game[data-size="5"] .tile[data-v="8192"] { font-size: 24px; }

.game[data-size="6"] .tile { font-size: 36px; }
.game[data-size="6"] .tile[data-v="128"],
.game[data-size="6"] .tile[data-v="256"],
.game[data-size="6"] .tile[data-v="512"] { font-size: 30px; }
.game[data-size="6"] .tile[data-v="1024"],
.game[data-size="6"] .tile[data-v="2048"] { font-size: 24px; }
.game[data-size="6"] .tile[data-v="4096"],
.game[data-size="6"] .tile[data-v="8192"] { font-size: 20px; }

/* ---- Game-over overlay ---- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(238, 228, 218, 0.73);
  border-radius: 6px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  animation: fadeIn 250ms ease-out;
  padding: 20px;
}
.overlay.show { display: flex; }
.overlay .msg {
  font-size: 52px;
  font-weight: 800;
  color: #776e65;
  text-align: center;
  margin-bottom: 8px;
}
.overlay .sub-msg {
  font-size: 14px;
  color: #776e65;
  text-align: center;
  margin-bottom: 20px;
}
.overlay .btn { font-size: 16px; padding: 10px 24px; }
.overlay-actions { display: flex; justify-content: center; }
.share-panel {
  width: min(100%, 390px);
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(119, 110, 101, 0.25);
}
.share-summary {
  min-height: 18px;
  margin-bottom: 9px;
  color: #5f574f;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
}
.share-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.share-btn {
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid rgba(119, 110, 101, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: #5f574f;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}
.share-btn:hover { background: #fff; border-color: #8f7a66; }
.share-btn:focus-visible { outline: 3px solid rgba(143, 122, 102, 0.35); outline-offset: 2px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---- Hint footer ---- */
.hint {
  margin-top: 14px;
  font-size: 13px;
  color: #776e65;
  text-align: center;
}
.hint kbd {
  background: #bbada0;
  color: #faf8ef;
  border-radius: 3px;
  padding: 2px 6px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
}

/* ---- Related games below the home game ---- */
.related-games {
  width: 100%;
  max-width: 480px;
  margin-top: 24px;
  padding: 20px;
  border: 1px solid rgba(143, 122, 102, 0.25);
  border-radius: 10px;
  background: rgba(238, 228, 218, 0.24);
  color: #4a443c;
}
.related-games h2 {
  margin: 0;
  color: #776e65;
  font-size: 21px;
  font-weight: 800;
}
.related-games-intro {
  margin: 5px 0 14px;
  font-size: 14px;
  line-height: 1.5;
}
.related-games-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.related-game-card {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 14px;
  border: 1px solid rgba(143, 122, 102, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
  color: #4a443c;
  text-decoration: none;
  transition: transform 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}
.related-game-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin: 0 0 12px;
  overflow: hidden;
  border-radius: 6px;
  background: #eee4da;
  object-fit: cover;
}
.related-game-card:hover { transform: translateY(-2px); background: #fff; box-shadow: 0 4px 14px rgba(80, 60, 40, 0.1); }
.related-game-card:focus-visible { outline: 3px solid #8f7a66; outline-offset: 2px; }
.related-game-overlay { position: absolute; inset: 0; border-radius: 8px; }
.related-game-overlay:focus-visible { outline: 3px solid #8f7a66; outline-offset: 2px; }
.related-game-tag { color: #9a8068; font-size: 11px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.related-game-card h3 { margin: 7px 0 4px; color: #776e65; font-size: 16px; line-height: 1.3; }
.related-game-card p { margin: 0 0 12px; font-size: 13px; line-height: 1.45; }
.related-game-link { margin-top: auto; color: #776e65; font-size: 13px; font-weight: 800; }

/* ---- Site nav (footer links) ---- */
.site-nav {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid rgba(143, 122, 102, 0.25);
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  font-size: 13px;
  justify-content: center;
}
.site-nav a { color: #8f7a66; }
.site-nav-label {
  flex-basis: 100%;
  margin-bottom: 3px;
  color: #776e65;
  font-size: 14px;
  font-weight: 800;
  text-align: center;
}
.lang-switch {
  margin-top: 10px;
  font-size: 12px;
  text-align: center;
  color: #bbada0;
}
.lang-switch a { margin: 0 4px; }

/* ---- Homepage introduction ---- */
.home-content {
  margin-top: 30px;
  padding-top: 26px;
  border-top: 1px solid rgba(143, 122, 102, 0.25);
  color: #4a443c;
  font-size: 15px;
  line-height: 1.65;
}
.home-content section + section { margin-top: 30px; }
.home-content h2 {
  margin-bottom: 10px;
  color: #776e65;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.25;
}
.home-content h3 {
  color: #776e65;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.3;
}
.home-content p + p { margin-top: 12px; }
.home-content a { font-weight: 700; text-decoration: underline; }
.how-to-list { margin-left: 21px; }
.how-to-list li + li { margin-top: 8px; }
.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.feature-card {
  padding: 14px;
  border: 1px solid rgba(143, 122, 102, 0.22);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.28);
}
.feature-card p { margin-top: 5px; font-size: 13px; line-height: 1.5; }
.game-video {
  padding: 18px;
  border: 1px solid rgba(143, 122, 102, 0.2);
  border-radius: 10px;
  background: rgba(238, 228, 218, 0.26);
}
.game-video-player {
  display: block;
  width: 100%;
  margin-top: 14px;
  border-radius: 6px;
  background: #bbada0;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}
.video-credit {
  margin-top: 8px;
  color: #9a8b7c;
  font-size: 12px;
  line-height: 1.4;
}

/* ---- Content pages (how-to-play / strategy / faq / history / best-sites) ---- */
.content {
  margin-top: 8px;
  line-height: 1.65;
  font-size: 15px;
  color: #4a443c;
}
.content h1 {
  font-size: 28px;
  color: #776e65;
  margin-bottom: 12px;
  font-weight: 800;
}
.content h2 {
  font-size: 21px;
  color: #776e65;
  margin: 28px 0 10px;
  font-weight: 800;
}
.content h3 {
  font-size: 17px;
  color: #776e65;
  margin: 20px 0 8px;
  font-weight: 700;
}
.content p { margin-bottom: 14px; }
.content ul, .content ol {
  margin: 0 0 14px 22px;
}
.content li { margin-bottom: 6px; }
.content strong { font-weight: 700; color: #5e544a; }
.content code {
  background: rgba(143, 122, 102, 0.1);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.content .cta {
  background: #bbada0;
  color: #faf8ef;
  border-radius: 6px;
  padding: 18px 20px;
  margin: 24px 0;
  text-align: center;
}
.content .cta a {
  color: #fff;
  font-weight: 800;
  text-decoration: underline;
}
.game-embed {
  width: 100%;
  aspect-ratio: 16 / 10;
  margin: 16px 0 10px;
  overflow: hidden;
  border: 1px solid rgba(143, 122, 102, 0.25);
  border-radius: 8px;
  background: #eee4da;
}
.game-embed iframe { display: block; width: 100%; height: 100%; border: 0; }

/* ---- Responsive ---- */
@media (max-width: 480px) {
  .related-games { padding: 15px; }
  .related-games-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .related-game-card { padding: 12px; }
  .related-game-card h3 { font-size: 14px; }
  .related-game-thumb { margin-bottom: 10px; }
  .title { font-size: 56px; }
  .score-box { min-width: 60px; padding: 6px 10px; }
  .score-box .val { font-size: 18px; }
  .game[data-size="3"] .tile { font-size: 48px; }
  .game[data-size="3"] .tile[data-v="128"],
  .game[data-size="3"] .tile[data-v="256"],
  .game[data-size="3"] .tile[data-v="512"] { font-size: 38px; }
  .game[data-size="3"] .tile[data-v="1024"],
  .game[data-size="3"] .tile[data-v="2048"] { font-size: 30px; }
  .game[data-size="4"] .tile { font-size: 40px; }
  .game[data-size="4"] .tile[data-v="128"],
  .game[data-size="4"] .tile[data-v="256"],
  .game[data-size="4"] .tile[data-v="512"] { font-size: 32px; }
  .game[data-size="4"] .tile[data-v="1024"],
  .game[data-size="4"] .tile[data-v="2048"] { font-size: 26px; }
  .game[data-size="4"] .tile[data-v="4096"],
  .game[data-size="4"] .tile[data-v="8192"] { font-size: 22px; }
  .game[data-size="5"] .tile { font-size: 32px; }
  .game[data-size="5"] .tile[data-v="128"],
  .game[data-size="5"] .tile[data-v="256"],
  .game[data-size="5"] .tile[data-v="512"] { font-size: 26px; }
  .game[data-size="5"] .tile[data-v="1024"],
  .game[data-size="5"] .tile[data-v="2048"] { font-size: 22px; }
  .game[data-size="5"] .tile[data-v="4096"],
  .game[data-size="5"] .tile[data-v="8192"] { font-size: 18px; }
  .game[data-size="6"] .tile { font-size: 26px; }
  .game[data-size="6"] .tile[data-v="128"],
  .game[data-size="6"] .tile[data-v="256"],
  .game[data-size="6"] .tile[data-v="512"] { font-size: 22px; }
  .game[data-size="6"] .tile[data-v="1024"],
  .game[data-size="6"] .tile[data-v="2048"] { font-size: 18px; }
  .overlay .msg { font-size: 36px; }
  .overlay .sub-msg { margin-bottom: 12px; }
  .share-btn { padding: 6px 9px; font-size: 11px; }
  .feature-grid { grid-template-columns: 1fr; }
  .game-video { padding: 15px; }
}

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