:root {
  --bg: #fff8fb;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-strong: #ffffff;
  --ink: #4d2f3a;
  --muted: #846778;
  --brand: #e85b8b;
  --brand-dark: #b43f68;
  --brand-soft: #ffe1eb;
  --accent: #f6b95e;
  --accent-soft: #fff0d4;
  --board: #bda79d;
  --cell: rgba(255, 249, 245, 0.38);
  --shadow: 0 24px 80px rgba(125, 64, 84, 0.16);
  --small-shadow: 0 12px 35px rgba(125, 64, 84, 0.14);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --gap: clamp(8px, 2.2vw, 14px);
  --tile-size: calc((min(88vw, 520px) - var(--gap) * 5) / 4);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 206, 223, 0.86), transparent 34rem),
    radial-gradient(circle at 88% 20%, rgba(255, 239, 198, 0.9), transparent 30rem),
    linear-gradient(180deg, #fff8fb 0%, #fffaf4 100%);
}

button, input, select { font: inherit; }

button { border: 0; cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }

a { color: inherit; text-decoration: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  left: 1rem;
  top: 1rem;
  padding: .75rem 1rem;
  border-radius: 999px;
  background: #ffffff;
  box-shadow: var(--small-shadow);
  transform: translateY(-160%);
  transition: transform .2s ease;
}

.skip-link:focus { transform: translateY(0); }

.page-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
}

.site-header,
.site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-header {
  padding: 22px 0 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  min-width: max-content;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: linear-gradient(135deg, #fff, #ffdce7);
  box-shadow: var(--small-shadow);
  font-size: 1.75rem;
}

.brand strong { display: block; font-size: 1.05rem; letter-spacing: -.02em; }
.brand small { display: block; color: var(--muted); font-size: .78rem; margin-top: .1rem; }

.site-nav,
.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: .5rem;
}

.site-nav a,
.site-footer a {
  padding: .65rem .85rem;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, .54);
  transition: background .2s ease, color .2s ease, transform .2s ease;
}

.site-nav a:hover,
.site-footer a:hover {
  background: #fff;
  color: var(--brand-dark);
  transform: translateY(-1px);
}

a:focus-visible,
button:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(232, 91, 139, .28);
  outline-offset: 3px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(330px, .72fr);
  gap: clamp(22px, 5vw, 64px);
  align-items: center;
  padding: clamp(26px, 6vw, 76px) 0 clamp(22px, 4vw, 42px);
}

.eyebrow {
  margin: 0 0 .5rem;
  color: var(--brand-dark);
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-size: .76rem;
}

h1, h2, h3, p { margin-top: 0; }

h1 {
  font-size: clamp(2.4rem, 8vw, 5.7rem);
  line-height: .92;
  letter-spacing: -.07em;
  margin-bottom: 1.1rem;
}

.hero-text {
  font-size: clamp(1.02rem, 2.2vw, 1.3rem);
  line-height: 1.65;
  max-width: 60ch;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.hero-actions,
.overlay-actions,
.action-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: .75rem 1.05rem;
  border-radius: 999px;
  font-weight: 850;
  letter-spacing: -.015em;
  border: 1px solid transparent;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}

.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(1px) scale(.99); }

.button.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--brand), #ff7aa7);
  box-shadow: 0 12px 26px rgba(232, 91, 139, .27);
}

.button.secondary {
  color: var(--ink);
  background: var(--surface-strong);
  border-color: rgba(125, 64, 84, .08);
  box-shadow: 0 8px 20px rgba(125, 64, 84, .08);
}

.button.ghost {
  color: var(--brand-dark);
  background: var(--brand-soft);
}

.hero-card {
  position: relative;
  border-radius: var(--radius-xl);
  padding: 20px;
  background: rgba(255,255,255,.5);
  box-shadow: var(--shadow);
  transform: rotate(2deg);
}

.hero-card::before {
  content: "";
  position: absolute;
  inset: -14px;
  z-index: -1;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255,255,255,.82), rgba(255, 207, 224, .5));
  transform: rotate(-4deg);
}

.mini-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  aspect-ratio: 1 / 1;
  padding: 12px;
  border-radius: 26px;
  background: #bda79d;
}

.mini-board span {
  display: grid;
  place-items: center;
  min-width: 0;
  border-radius: 18px;
  background: rgba(255, 250, 245, .34);
  color: #75495d;
  font-size: clamp(.55rem, 1.4vw, .82rem);
  font-weight: 900;
  text-align: center;
  overflow: hidden;
}

.mini-board span:not(:empty) {
  background: linear-gradient(135deg, #fff6fb, #ffd9e6);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 620px) minmax(290px, 1fr);
  gap: clamp(18px, 4vw, 34px);
  align-items: start;
  padding: 10px 0 52px;
}

.game-panel,
.side-panel > section,
.content-section,
.site-footer {
  border: 1px solid rgba(125, 64, 84, .08);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.game-panel {
  border-radius: var(--radius-xl);
  padding: clamp(14px, 3vw, 22px);
}

.game-toolbar {
  display: flex;
  justify-content: space-between;
  gap: .8rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: .9rem;
}

.mode-group {
  display: inline-flex;
  gap: .35rem;
  padding: .35rem;
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(125, 64, 84, .08);
}

.mode-button {
  min-height: 38px;
  padding: .55rem .8rem;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-weight: 850;
}

.mode-button.active {
  color: #fff;
  background: var(--ink);
  box-shadow: 0 8px 18px rgba(77, 47, 58, .16);
}

.theme-picker {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  color: var(--muted);
  font-weight: 800;
}

.theme-picker select {
  min-height: 40px;
  border: 1px solid rgba(125, 64, 84, .1);
  border-radius: 999px;
  padding: .45rem 2rem .45rem .8rem;
  color: var(--ink);
  background: #fff;
}

.score-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .65rem;
  margin-bottom: .75rem;
}

.stat-card {
  min-height: 70px;
  padding: .7rem;
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff, rgba(255,255,255,.66));
  border: 1px solid rgba(125, 64, 84, .08);
  text-align: center;
}

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  font-weight: 850;
}

.stat-card strong {
  display: block;
  margin-top: .15rem;
  font-size: clamp(1.15rem, 4vw, 1.9rem);
  line-height: 1;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 800;
  margin: .5rem 0 .85rem;
}

.status-strip span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: .28rem .65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, .52);
}

.board-wrap {
  position: relative;
  width: min(100%, 560px);
  margin: 0 auto;
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 560px;
  padding: var(--gap);
  border-radius: clamp(18px, 4vw, 28px);
  background:
    linear-gradient(145deg, rgba(255,255,255,.08), rgba(255,255,255,0)),
    var(--board);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.2), 0 20px 50px rgba(86, 57, 48, .18);
  touch-action: none;
  user-select: none;
  outline: none;
}

.board:focus-visible {
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.2), 0 0 0 4px rgba(232, 91, 139, .25), 0 20px 50px rgba(86, 57, 48, .18);
}

.tile {
  --tile-bg-a: #fff;
  --tile-bg-b: #f7eee9;
  --tile-ink: #6e5060;
  --tile-shadow: rgba(112, 65, 78, .16);
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  border-radius: clamp(12px, 2.5vw, 20px);
  color: var(--tile-ink);
  background: linear-gradient(145deg, var(--tile-bg-a), var(--tile-bg-b));
  box-shadow: 0 10px 18px var(--tile-shadow), inset 0 1px rgba(255,255,255,.8);
  overflow: hidden;
  will-change: transform;
}

.tile-empty {
  background: var(--cell);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18);
}

.tile-inner {
  display: grid;
  place-items: center;
  gap: .16rem;
  width: 100%;
  padding: .25rem;
  text-align: center;
}

.tile-emoji {
  display: block;
  font-size: clamp(1.25rem, 7vw, 2.55rem);
  line-height: 1;
  filter: drop-shadow(0 3px 2px rgba(98, 54, 68, .12));
}

.tile-label {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(.56rem, 2.1vw, .9rem);
  font-weight: 950;
  letter-spacing: -.04em;
  line-height: 1.05;
}

.tile-value {
  display: block;
  opacity: .72;
  font-size: clamp(.52rem, 1.7vw, .72rem);
  font-weight: 900;
  line-height: 1;
}

.tile-new { animation: pop-in .22s cubic-bezier(.2, 1.35, .36, 1) both; }
.tile-merged { animation: merge-pop .28s cubic-bezier(.2, 1.45, .36, 1) both; }

@keyframes pop-in {
  0% { transform: scale(.35); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes merge-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  border-radius: clamp(18px, 4vw, 28px);
  background: rgba(79, 47, 58, .62);
  backdrop-filter: blur(8px);
}

.overlay-card {
  width: min(92%, 380px);
  padding: 1.25rem;
  border-radius: 26px;
  background: #fffaf7;
  box-shadow: var(--shadow);
  text-align: center;
}

.overlay-kicker {
  margin: 0 0 .35rem;
  color: var(--brand-dark);
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .76rem;
}

.overlay-card h2 {
  margin: 0 0 .45rem;
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  letter-spacing: -.05em;
}

.overlay-card p { color: var(--muted); line-height: 1.55; }
.overlay-actions { justify-content: center; }

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 1rem;
}

.action-grid .button { width: 100%; }

.control-help {
  color: var(--muted);
  line-height: 1.55;
  font-size: .9rem;
  margin: .9rem 0 0;
}

.side-panel {
  display: grid;
  gap: 1rem;
}

.side-panel > section,
.content-section,
.site-footer {
  border-radius: var(--radius-lg);
  padding: clamp(16px, 3vw, 24px);
}

.section-heading h2 {
  margin: 0 0 .8rem;
  font-size: clamp(1.2rem, 3vw, 1.7rem);
  letter-spacing: -.04em;
}

.progress-track {
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(125, 64, 84, .11);
}

.progress-track span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width .28s ease;
}

#questProgressText {
  margin: .55rem 0 0;
  color: var(--muted);
  font-weight: 800;
}

.tile-ladder {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .5rem;
}

.ladder-item,
.achievement-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem;
  border-radius: 16px;
  background: rgba(255,255,255,.66);
  border: 1px solid rgba(125, 64, 84, .07);
}

.ladder-item.locked { opacity: .42; filter: grayscale(.2); }
.ladder-emoji { font-size: 1.35rem; }
.ladder-copy { min-width: 0; }
.ladder-copy strong,
.ladder-copy span { display: block; }
.ladder-copy strong { font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ladder-copy span { color: var(--muted); font-size: .72rem; font-weight: 800; }

.achievements {
  display: grid;
  gap: .55rem;
}

.achievement-item { align-items: flex-start; }
.achievement-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: var(--brand-soft);
}

.achievement-item.locked .achievement-icon { background: rgba(125, 64, 84, .08); }
.achievement-item.locked { opacity: .58; }
.achievement-copy strong { display: block; font-size: .9rem; }
.achievement-copy span { display: block; color: var(--muted); font-size: .8rem; line-height: 1.45; }

.content-section {
  margin: 0 0 52px;
}

.content-section h2 {
  font-size: clamp(1.8rem, 4.8vw, 3rem);
  line-height: 1;
  letter-spacing: -.055em;
  margin-bottom: 1rem;
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.content-grid article {
  padding: 1rem;
  border-radius: 18px;
  background: rgba(255,255,255,.6);
}

.content-grid h3 { margin-bottom: .45rem; letter-spacing: -.025em; }
.content-grid p { color: var(--muted); line-height: 1.65; margin-bottom: 0; }

.site-footer {
  margin-bottom: 26px;
  color: var(--muted);
  line-height: 1.55;
}

.site-footer p { max-width: 68ch; margin: 0; }

.toast-stack {
  position: fixed;
  z-index: 50;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  display: grid;
  gap: .6rem;
  width: min(360px, calc(100vw - 2rem));
}

.toast {
  padding: .85rem 1rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, .94);
  border: 1px solid rgba(125, 64, 84, .08);
  box-shadow: var(--small-shadow);
  color: var(--ink);
  font-weight: 800;
  line-height: 1.45;
  animation: toast-in .22s ease both;
}

@keyframes toast-in {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.confetti-piece {
  position: fixed;
  z-index: 70;
  top: -20px;
  font-size: 1.5rem;
  pointer-events: none;
  animation: confetti-fall 1.9s linear forwards;
}

@keyframes confetti-fall {
  to { transform: translateY(110vh) rotate(540deg); opacity: 0; }
}

/* Tile palettes */
.tile-value-2 { --tile-bg-a: #fff6fb; --tile-bg-b: #ffdce8; --tile-ink: #7d4054; }
.tile-value-4 { --tile-bg-a: #fff6eb; --tile-bg-b: #ffe0bd; --tile-ink: #765035; }
.tile-value-8 { --tile-bg-a: #fffcec; --tile-bg-b: #ffe898; --tile-ink: #7b5f1b; }
.tile-value-16 { --tile-bg-a: #eefced; --tile-bg-b: #c8efc4; --tile-ink: #3c6b3c; }
.tile-value-32 { --tile-bg-a: #edf8ff; --tile-bg-b: #c6e6ff; --tile-ink: #345d7e; }
.tile-value-64 { --tile-bg-a: #f7edff; --tile-bg-b: #e1c6ff; --tile-ink: #65428c; }
.tile-value-128 { --tile-bg-a: #fff0e6; --tile-bg-b: #ffc9a9; --tile-ink: #81513a; }
.tile-value-256 { --tile-bg-a: #fff0fa; --tile-bg-b: #ffbfe8; --tile-ink: #8c3d72; }
.tile-value-512 { --tile-bg-a: #eafffb; --tile-bg-b: #b6eee5; --tile-ink: #357268; }
.tile-value-1024 { --tile-bg-a: #fff7d1; --tile-bg-b: #ffc966; --tile-ink: #7e570c; }
.tile-value-2048 { --tile-bg-a: #fff; --tile-bg-b: #ff8fb0; --tile-ink: #fff; text-shadow: 0 2px 10px rgba(100, 26, 51, .32); }
.tile-value-super { --tile-bg-a: #2e2030; --tile-bg-b: #895eff; --tile-ink: #fff; }

.info-page main {
  padding: 34px 0 60px;
}

.info-card {
  max-width: 920px;
  margin: 0 auto;
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 1px solid rgba(125, 64, 84, .08);
  padding: clamp(22px, 5vw, 44px);
}

.info-card h1 {
  font-size: clamp(2.2rem, 7vw, 4.6rem);
}

.info-card h2 {
  margin-top: 2rem;
  letter-spacing: -.04em;
}

.info-card p,
.info-card li {
  color: var(--muted);
  line-height: 1.75;
  font-size: 1.02rem;
}

.info-card a { color: var(--brand-dark); font-weight: 850; }

.tile-table {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .75rem;
  margin-top: 1rem;
}

.tile-table .ladder-item { min-height: 74px; }

@media (max-width: 980px) {
  .hero,
  .game-layout {
    grid-template-columns: 1fr;
  }
  .hero-card { max-width: 430px; justify-self: center; }
  .side-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .achievements-card { grid-column: 1 / -1; }
  .content-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .page-shell { width: min(100% - 18px, 1180px); }
  .site-header { align-items: flex-start; }
  .site-nav { justify-content: flex-start; font-size: .9rem; }
  .hero { padding-top: 22px; }
  .score-row { grid-template-columns: repeat(3, 1fr); }
  .timer-stat { grid-column: span 3; }
  .side-panel { grid-template-columns: 1fr; }
  .action-grid { grid-template-columns: repeat(2, 1fr); }
  .site-footer { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 460px) {
  :root { --gap: 8px; }
  .site-header { flex-direction: column; }
  .site-nav a { padding: .5rem .65rem; }
  .game-panel { padding: 10px; border-radius: 24px; }
  .mode-group { width: 100%; justify-content: space-between; }
  .mode-button { flex: 1 1 auto; padding-inline: .5rem; }
  .theme-picker { width: 100%; justify-content: space-between; }
  .theme-picker select { flex: 1 1 auto; }
  .score-row { gap: .45rem; }
  .stat-card { min-height: 62px; padding: .55rem .35rem; }
  .action-grid { grid-template-columns: 1fr; }
  .tile-label { display: none; }
  .tile-emoji { font-size: clamp(1.6rem, 10vw, 2.6rem); }
}

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

.tile-move-left { animation: slide-from-right .16s ease both; }
.tile-move-right { animation: slide-from-left .16s ease both; }
.tile-move-up { animation: slide-from-down .16s ease both; }
.tile-move-down { animation: slide-from-up .16s ease both; }
.tile-shuffle { animation: shuffle-jiggle .28s ease both; }

@keyframes slide-from-right { from { transform: translateX(12px) scale(.985); } to { transform: translateX(0) scale(1); } }
@keyframes slide-from-left { from { transform: translateX(-12px) scale(.985); } to { transform: translateX(0) scale(1); } }
@keyframes slide-from-down { from { transform: translateY(12px) scale(.985); } to { transform: translateY(0) scale(1); } }
@keyframes slide-from-up { from { transform: translateY(-12px) scale(.985); } to { transform: translateY(0) scale(1); } }
@keyframes shuffle-jiggle {
  0% { transform: rotate(0deg) scale(.96); }
  35% { transform: rotate(-2deg) scale(1.03); }
  70% { transform: rotate(2deg) scale(1.01); }
  100% { transform: rotate(0deg) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .tile-move-left,
  .tile-move-right,
  .tile-move-up,
  .tile-move-down,
  .tile-shuffle,
  .tile-new,
  .tile-merged,
  .toast,
  .confetti-piece {
    animation: none !important;
  }
}
