:root {
  --bg: #100d20;
  --bg-2: #17132b;
  --text: #f3f0ff;
  --muted: #9d97c2;
  --accent: #8f7bff;
  --accent-2: #ffb35c;
  --accent-dark: #6b57e8;
  --card: rgba(255, 255, 255, 0.045);
  --card-border: rgba(255, 255, 255, 0.09);
  --board: rgba(255, 255, 255, 0.06);
  --cell: rgba(255, 255, 255, 0.055);
  --green: #47d18b;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 17px;
  overflow-x: hidden;
}

/* Ambient background */
.mesh {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(42rem 42rem at 82% -8%, rgba(143, 123, 255, 0.22), transparent 62%),
    radial-gradient(34rem 34rem at -12% 28%, rgba(255, 179, 92, 0.12), transparent 60%),
    radial-gradient(30rem 30rem at 50% 118%, rgba(107, 87, 232, 0.18), transparent 65%),
    var(--bg);
}
.mesh::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.035;
  background-image: radial-gradient(rgba(255,255,255,0.9) 1px, transparent 1px);
  background-size: 26px 26px;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 20px;
  background: rgba(16, 13, 32, 0.72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.4px;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(140deg, #a995ff, #6b57e8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 900;
  color: #fff;
  box-shadow: 0 0 18px rgba(143, 123, 255, 0.55);
}
.topbar .top-actions { display: flex; align-items: center; gap: 14px; }
.link-quiet {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px dashed rgba(157, 151, 194, 0.4);
  padding-bottom: 1px;
  cursor: pointer;
  background: none;
  font-family: inherit;
}
.link-quiet:hover { color: var(--text); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  background: linear-gradient(180deg, #a493ff, #7a63f2);
  color: #120f24;
  font-weight: 800;
  font-size: 16px;
  padding: 12px 32px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  box-shadow: 0 8px 28px rgba(122, 99, 242, 0.4), inset 0 1px 0 rgba(255,255,255,0.35);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
  font-family: inherit;
  letter-spacing: 0.3px;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 12px 34px rgba(122, 99, 242, 0.5), inset 0 1px 0 rgba(255,255,255,0.35); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn.small { padding: 8px 18px; font-size: 13px; }
.btn.ghost {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.12);
}
.btn.ghost:hover { background: rgba(255, 255, 255, 0.11); box-shadow: inset 0 0 0 1px rgba(255,255,255,0.2); }

/* Hero */
.hero {
  max-width: 640px;
  margin: 0 auto;
  padding: 46px 20px 10px;
  text-align: center;
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 2.2px;
  text-transform: uppercase;
  color: var(--accent-2);
  background: rgba(255, 179, 92, 0.08);
  border: 1px solid rgba(255, 179, 92, 0.25);
  border-radius: 999px;
  padding: 6px 14px;
  margin-bottom: 20px;
}
.hero h1 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(34px, 7vw, 52px);
  line-height: 1.08;
  letter-spacing: -1.2px;
  margin-bottom: 14px;
}
.hero h1 em { font-style: italic; color: var(--accent-2); }
.hero .sub {
  color: var(--muted);
  font-size: 17px;
  max-width: 430px;
  margin: 0 auto 24px;
}
.hero-cta { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

/* Game stage */
.stage {
  max-width: 480px;
  margin: 26px auto 0;
  padding: 0 20px;
  scroll-margin-top: 84px;
}
.board-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}
.game-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.score-boxes { display: flex; gap: 8px; }
.score-box {
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid var(--card-border);
  border-radius: 11px;
  padding: 6px 15px;
  text-align: center;
}
.score-box .label { font-size: 9.5px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); }
.score-box .val { font-size: 18px; font-weight: 800; color: var(--text); }

.board {
  position: relative;
  background: var(--board);
  border-radius: 16px;
  aspect-ratio: 1 / 1;
  width: 100%;
  touch-action: none;
  overflow: hidden;
  user-select: none;
}
.cell-grid {
  position: absolute;
  inset: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
}
.cell-grid .cell { background: var(--cell); border-radius: 9px; }

.tile-layer { position: absolute; inset: 10px; }
.tile {
  position: absolute;
  width: calc((100% - 30px) / 4);
  height: calc((100% - 30px) / 4);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 26px;
  transition: transform 0.12s ease;
  will-change: transform;
  z-index: 2;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.25);
}
.tile.pop { animation: pop 0.15s ease; }
.tile.merging { opacity: 0; transition: transform 0.12s ease, opacity 0.18s ease; z-index: 1; }
@keyframes pop { from { scale: 0.6; } to { scale: 1; } }
.tile.v2 { background: linear-gradient(180deg, #4a4270, #3a345c); color: #cfc9f2; }
.tile.v4 { background: linear-gradient(180deg, #5c4f95, #483d78); color: #e8e2ff; }
.tile.v8 { background: linear-gradient(180deg, #7a63f2, #6450d4); color: #fff; }
.tile.v16 { background: linear-gradient(180deg, #8f7bff, #7663ea); color: #fff; }
.tile.v32 { background: linear-gradient(180deg, #a995ff, #8a74f6); color: #fff; }
.tile.v64 { background: linear-gradient(180deg, #ffc37a, #f5a63f); color: #3a2503; }
.tile.v128 { background: linear-gradient(180deg, #ffb35c, #ef8f23); color: #3a2503; font-size: 22px; }
.tile.v256 { background: linear-gradient(180deg, #ff9f3d, #e77c12); color: #fff; font-size: 22px; }
.tile.v512 { background: linear-gradient(180deg, #ff8a2b, #d96607); color: #fff; font-size: 22px; }
.tile.v1024 { background: linear-gradient(180deg, #ff6b6b, #e04a4a); color: #fff; font-size: 18px; }
.tile.v2048 { background: linear-gradient(180deg, #ff5c8a, #d6336c); color: #fff; font-size: 18px; }
.tile.v4096, .tile.v8192 { background: linear-gradient(180deg, #47d18b, #22a866); color: #fff; font-size: 16px; }

/* Cover */
.cover {
  position: absolute;
  inset: 0;
  z-index: 6;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 24px;
  background:
    radial-gradient(26rem 20rem at 50% 8%, rgba(143, 123, 255, 0.22), transparent 60%),
    linear-gradient(180deg, rgba(23, 19, 43, 0.92), rgba(16, 13, 32, 0.96));
  backdrop-filter: blur(6px);
  transition: opacity 0.3s ease, visibility 0.3s;
}
.cover.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.cover .cover-mark {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(140deg, #a995ff, #6b57e8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 900;
  color: #fff;
  box-shadow: 0 0 44px rgba(143, 123, 255, 0.55);
  animation: float 3.4s ease-in-out infinite;
}
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
.cover .cover-title { font-family: Georgia, serif; font-style: italic; font-size: 23px; letter-spacing: -0.4px; }
.cover .cover-hint { font-size: 12px; color: var(--muted); letter-spacing: 0.8px; text-transform: uppercase; }

.game-over {
  position: absolute;
  inset: 0;
  background: rgba(16, 13, 32, 0.86);
  backdrop-filter: blur(6px);
  border-radius: 16px;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  z-index: 7;
  text-align: center;
  padding: 20px;
}
.game-over.show { display: flex; }
.game-over .go-title { font-family: Georgia, serif; font-style: italic; font-size: 25px; }
.game-over .go-score { color: var(--muted); font-weight: 600; }
.game-hint { text-align: center; font-size: 12.5px; color: var(--muted); margin-top: 12px; }

/* Standalone game page card */
.game-wrap {
  max-width: 480px;
  margin: 22px auto 0;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
}

/* Sections */
.wrap { max-width: 660px; margin: 0 auto; padding: 0 20px; }
section.block { margin-top: 72px; }
h2 {
  font-family: Georgia, serif;
  font-size: clamp(25px, 4.6vw, 32px);
  letter-spacing: -0.6px;
  line-height: 1.15;
  margin-bottom: 10px;
}
h2 em { font-style: italic; color: var(--accent-2); }
.lead { color: var(--muted); margin-bottom: 22px; max-width: 480px; }
h3 { font-size: 17px; margin: 20px 0 8px; }
p { margin-bottom: 14px; color: #d9d4f2; }
ul, ol { margin: 0 0 16px 22px; color: #d9d4f2; }
li { margin-bottom: 7px; }

.steps { display: grid; gap: 12px; grid-template-columns: repeat(3, 1fr); }
@media (max-width: 560px) { .steps { grid-template-columns: 1fr; } }
.step {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 18px;
}
.step .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: rgba(143, 123, 255, 0.16);
  color: var(--accent);
  font-weight: 900;
  font-size: 14px;
  margin-bottom: 12px;
}
.step strong { display: block; margin-bottom: 5px; font-size: 15.5px; }
.step span { color: var(--muted); font-size: 14px; line-height: 1.5; }

.quote {
  border-left: 2px solid var(--accent-2);
  padding: 4px 0 4px 18px;
  margin: 16px 0;
  color: #e6e1fb;
  font-family: Georgia, serif;
  font-style: italic;
  font-size: 17.5px;
}
.quote cite { display: block; font-family: -apple-system, sans-serif; font-style: normal; font-size: 13px; color: var(--muted); margin-top: 6px; }

details.faq {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 0 18px;
  margin-bottom: 10px;
}
details.faq summary {
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  font-size: 15.5px;
  padding: 15px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary::after {
  content: "+";
  color: var(--accent);
  font-size: 20px;
  font-weight: 400;
  transition: transform 0.15s;
}
details.faq[open] summary::after { transform: rotate(45deg); }
details.faq p { font-size: 15px; color: var(--muted); padding: 0 0 15px; margin: 0; }

.about-teaser {
  background: linear-gradient(160deg, rgba(143, 123, 255, 0.12), rgba(255, 179, 92, 0.07));
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 26px;
}
.about-teaser h2 { margin-bottom: 8px; }
.about-teaser p { margin-bottom: 0; color: var(--muted); }
.about-teaser a { color: var(--accent-2); }

/* Footer */
.site-footer {
  margin-top: 80px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  padding: 30px 20px 40px;
  font-size: 13px;
  color: var(--muted);
}
.site-footer .inner { max-width: 660px; margin: 0 auto; }
.site-footer .footer-nav { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-bottom: 12px; }
.site-footer a { color: #cfc9ec; text-decoration: none; font-weight: 600; }
.site-footer a:hover { color: var(--accent-2); }

/* Modal */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(8, 6, 18, 0.66);
  backdrop-filter: blur(4px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 80;
}
.modal-back.show { display: flex; }
.modal {
  background: #1b1633;
  border: 1px solid var(--card-border);
  border-radius: 20px 20px 0 0;
  padding: 24px 22px calc(24px + env(safe-area-inset-bottom));
  max-width: 460px;
  width: 100%;
}
.modal h3 { margin: 0 0 8px; font-size: 19px; }
.modal p { font-size: 14.5px; color: var(--muted); margin-bottom: 8px; }
.modal ol { font-size: 14.5px; margin: 0 0 16px 20px; color: var(--muted); }
.modal .btn { width: 100%; }
@media (min-width: 641px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 20px; }
}

/* Sub pages */
.container { max-width: 640px; margin: 0 auto; padding: 44px 20px 60px; }
.page-title { font-family: Georgia, serif; font-size: clamp(30px, 5.5vw, 40px); letter-spacing: -0.8px; margin-bottom: 20px; line-height: 1.1; }
.site-nav {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 24px;
  padding: 14px 16px;
  font-size: 13.5px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.site-nav a { color: var(--muted); text-decoration: none; text-transform: uppercase; letter-spacing: 1.2px; }
.site-nav a:hover, .site-nav a.active { color: var(--text); }
.container a { color: var(--accent-2); }
.container .muted { color: var(--muted); }
