/* ==========================================================================
   Game: NumFusion  (sliding number-fusion puzzle)
   Self-contained — every class is prefixed .nf-. The game panel is a dark
   "stage" in both site themes. Uses site tokens from common.css.
   ========================================================================== */

.nf {
  --nf-bg: #13152b;
  --nf-card: rgba(255, 255, 255, .06);
  --nf-card-hover: rgba(255, 255, 255, .11);
  --nf-line: rgba(255, 255, 255, .12);
  --nf-text: #fff;
  --nf-sub: rgba(255, 255, 255, .72);
  --nf-good: #19c28f;
  --nf-bad: #ff5c8a;
  --nf-accent: var(--hot);
  --nf-gap: 10px;

  position: relative;
  margin: 10px 0 40px;
  padding: 36px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(110% 80% at 100% 0%, rgba(255, 140, 66, .26), transparent 55%),
    radial-gradient(90% 80% at 0% 100%, rgba(91, 61, 245, .42), transparent 60%),
    var(--nf-bg);
  color: var(--nf-text);
  isolation: isolate;
  min-height: 520px;
}
:root[data-theme="dark"] .nf { border: 1px solid var(--line); }

/* Decorative floating tiles */
.nf::before {
  content: "";
  position: absolute;
  right: -40px;
  bottom: -40px;
  z-index: -1;
  width: 260px;
  height: 260px;
  border-radius: 34px;
  background:
    linear-gradient(135deg, rgba(255, 216, 77, .22), rgba(232, 68, 122, .18));
  transform: rotate(18deg);
  opacity: .5;
}

.nf-screen[hidden] { display: none !important; }
.nf-screen { animation: nf-fade .35s var(--ease); }
@keyframes nf-fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.nf-ico {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Buttons ---------- */
.nf-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 8px 18px;
  border: 1px solid var(--nf-line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--nf-text);
  font: 600 .875rem/1.2 var(--font);
  cursor: pointer;
  transition: background-color .2s var(--ease), border-color .2s var(--ease), opacity .2s var(--ease);
}
.nf-ghost:hover:not(:disabled) { background: var(--nf-card-hover); }
.nf-ghost:disabled { opacity: .4; cursor: not-allowed; }
.nf-ghost--danger { color: var(--nf-sub); }
.nf-ghost.is-confirm { border-color: var(--nf-bad); color: var(--nf-bad); }
.nf-ghost .nf-ico--off { display: none; }
.nf-ghost.is-off .nf-ico--on { display: none; }
.nf-ghost.is-off .nf-ico--off { display: block; }

.nf-badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 11px;
  background: rgba(255, 216, 77, .18);
  color: var(--nf-accent);
  font-size: .75rem;
}

.nf-icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  padding: 0;
  border: 1px solid var(--nf-line);
  border-radius: 50%;
  background: var(--nf-card);
  color: var(--nf-text);
  cursor: pointer;
  transition: background-color .2s var(--ease);
}
.nf-icon-btn:hover { background: var(--nf-card-hover); }

.nf .btn-pill { min-height: 46px; padding: 11px 24px; }
.nf .btn-pill:not(.btn-pill--hot) { background: var(--brand-soft); color: var(--night); }
.nf button:focus-visible,
.nf-board:focus-visible { outline: 3px solid var(--nf-accent); outline-offset: 3px; }

/* ==========================================================================
   Home
   ========================================================================== */
.nf-home__head { display: flex; align-items: flex-start; gap: 22px; max-width: 760px; }

.nf-logo {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
  flex: none;
  width: 76px;
  height: 76px;
  padding: 7px;
  border-radius: 20px;
  background: rgba(255, 255, 255, .1);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .3);
}
.nf-logo span {
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-size: .82rem;
  font-weight: 800;
  color: #fff;
}
.nf-logo span:nth-child(1) { background: #ece7ff; color: #3b2c99; }
.nf-logo span:nth-child(2) { background: #c9bdff; color: #2c1f80; }
.nf-logo span:nth-child(3) { background: #ff9d5c; }
.nf-logo span:nth-child(4) { background: #ff6b6b; animation: nf-bob 2.4s ease-in-out infinite; }
@keyframes nf-bob { 50% { transform: scale(1.1); } }

.nf-kicker {
  display: inline-block;
  margin-bottom: 8px;
  padding: 4px 12px;
  border-radius: var(--radius-pill);
  background: rgba(255, 216, 77, .14);
  color: var(--nf-accent);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.nf-title { margin: 0 0 8px; font-size: clamp(2rem, 4.4vw, 3rem); letter-spacing: -.035em; line-height: 1.05; }
.nf-lead { margin: 0; color: var(--nf-sub); }

.nf-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 28px 0 26px;
}
.nf-chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 0; padding: 0; list-style: none; }
.nf-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--nf-line);
  border-radius: var(--radius-pill);
  background: var(--nf-card);
}
.nf-chip__label { color: var(--nf-sub); font-size: .78rem; font-weight: 500; }
.nf-chip strong { color: var(--nf-accent); font-size: 1rem; }
.nf-toolbar__actions { display: flex; flex-wrap: wrap; gap: 10px; }

.nf-subtitle { margin: 0 0 14px; font-size: 1rem; letter-spacing: .06em; text-transform: uppercase; color: var(--nf-sub); }

.nf-stages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.nf-stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  height: 100%;
  padding: 18px;
  border: 1px solid var(--nf-line);
  border-radius: var(--radius-md);
  background: var(--nf-card);
  color: var(--nf-text);
  font-family: var(--font);
  text-align: left;
  cursor: pointer;
  transition: transform .2s var(--ease), background-color .2s var(--ease), border-color .2s var(--ease);
}
.nf-stage:hover:not(:disabled) { transform: translateY(-3px); border-color: rgba(255, 216, 77, .55); background: var(--nf-card-hover); }
.nf-stage.is-cleared { border-color: rgba(25, 194, 143, .45); }
.nf-stage.is-locked { cursor: not-allowed; opacity: .5; }
.nf-stage__top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.nf-stage__num {
  display: grid;
  place-items: center;
  min-width: 52px;
  height: 44px;
  padding: 0 8px;
  border-radius: 12px;
  background: #ffd84d;
  color: var(--night);
  font-size: 1.05rem;
  font-weight: 800;
}
.nf-stage.is-locked .nf-stage__num { background: rgba(255, 255, 255, .14); color: var(--nf-text); }
.nf-stage__size {
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, .08);
  color: var(--nf-sub);
  font-size: .75rem;
  font-weight: 700;
}
.nf-stage__body { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nf-stage__name { font-size: 1rem; font-weight: 700; line-height: 1.3; }
.nf-stage__blurb { color: var(--nf-sub); font-size: .82rem; line-height: 1.45; }
.nf-stage__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--nf-line);
}
.nf-stage__best { color: var(--nf-sub); font-size: .78rem; font-weight: 600; }

.nf-star { color: rgba(255, 255, 255, .22); font-size: 1.05rem; line-height: 1; }
.nf-star.is-on { color: var(--nf-accent); text-shadow: 0 0 12px rgba(255, 216, 77, .5); }

.nf-noscript { margin: 16px 0 0; padding: 14px 18px; border-radius: var(--radius-sm); background: rgba(255, 92, 138, .15); }

/* ==========================================================================
   Play
   ========================================================================== */
.nf-play { position: relative; }

.nf-hud { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-bottom: 20px; }
.nf-hud__stage {
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: rgba(255, 216, 77, .14);
  color: var(--nf-accent);
  font-size: .8rem;
  font-weight: 700;
}
.nf-hud__stats { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-left: auto; }
.nf-stat { display: flex; flex-direction: column; line-height: 1.2; }
.nf-stat__label { color: var(--nf-sub); font-size: .68rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.nf-stat strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.nf-arena {
  display: grid;
  grid-template-columns: minmax(0, 480px) minmax(220px, 280px);
  justify-content: center;
  align-items: start;
  gap: 28px;
}

.nf-boardwrap { position: relative; width: 100%; }

.nf-board {
  --nf-n: 4;
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  padding: var(--nf-gap);
  border-radius: 18px;
  background: rgba(8, 9, 24, .55);
  box-shadow: inset 0 0 0 1px var(--nf-line), 0 18px 40px rgba(0, 0, 0, .35);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  container-type: inline-size;
  cursor: grab;
}
.nf-board.is-nudge-left { animation: nf-nudge-l .18s ease; }
.nf-board.is-nudge-right { animation: nf-nudge-r .18s ease; }
.nf-board.is-nudge-up { animation: nf-nudge-u .18s ease; }
.nf-board.is-nudge-down { animation: nf-nudge-d .18s ease; }
@keyframes nf-nudge-l { 50% { transform: translateX(-5px); } }
@keyframes nf-nudge-r { 50% { transform: translateX(5px); } }
@keyframes nf-nudge-u { 50% { transform: translateY(-5px); } }
@keyframes nf-nudge-d { 50% { transform: translateY(5px); } }

.nf-cells {
  display: grid;
  grid-template-columns: repeat(var(--nf-n), 1fr);
  gap: var(--nf-gap);
  width: 100%;
  height: 100%;
}
.nf-cell { border-radius: 10px; background: rgba(255, 255, 255, .06); }

.nf-tiles { position: absolute; inset: var(--nf-gap); pointer-events: none; }

.nf-tile {
  --r: 0;
  --c: 0;
  --nf-tbg: #ece7ff;
  --nf-tfg: #2c1f80;
  position: absolute;
  top: 0;
  left: 0;
  width: calc((100% - (var(--nf-n) - 1) * var(--nf-gap)) / var(--nf-n));
  height: calc((100% - (var(--nf-n) - 1) * var(--nf-gap)) / var(--nf-n));
  transform: translate(calc(var(--c) * (100% + var(--nf-gap))), calc(var(--r) * (100% + var(--nf-gap))));
  transition: transform .11s ease-out;
  will-change: transform;
}
.nf-tile__inner {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  background: var(--nf-tbg);
  color: var(--nf-tfg);
  font-weight: 800;
  font-size: calc(36cqw / var(--nf-n));
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .18);
}
.nf-tile.is-long .nf-tile__inner { font-size: calc(28cqw / var(--nf-n)); }
.nf-tile.is-xlong .nf-tile__inner { font-size: calc(22cqw / var(--nf-n)); }
.nf-tile.is-new .nf-tile__inner { animation: nf-appear .2s ease-out .06s backwards; }
.nf-tile.is-merged { z-index: 2; }
.nf-tile.is-merged .nf-tile__inner { animation: nf-pop .2s ease-out; }
@keyframes nf-appear { from { transform: scale(0); opacity: 0; } }
@keyframes nf-pop { 50% { transform: scale(1.16); } }

/* Tile palette (2 → 8192+) */
.nf-tile[data-v="2"] { --nf-tbg: #ece7ff; --nf-tfg: #2c1f80; }
.nf-tile[data-v="4"] { --nf-tbg: #d6ccff; --nf-tfg: #2c1f80; }
.nf-tile[data-v="8"] { --nf-tbg: #ffc27a; --nf-tfg: #4a2300; }
.nf-tile[data-v="16"] { --nf-tbg: #ff9d5c; --nf-tfg: #fff; }
.nf-tile[data-v="32"] { --nf-tbg: #ff7a59; --nf-tfg: #fff; }
.nf-tile[data-v="64"] { --nf-tbg: #ff5257; --nf-tfg: #fff; }
.nf-tile[data-v="128"] { --nf-tbg: #ffd84d; --nf-tfg: #3a2c00; }
.nf-tile[data-v="256"] { --nf-tbg: #ffcc1f; --nf-tfg: #3a2c00; }
.nf-tile[data-v="512"] { --nf-tbg: #3ddc97; --nf-tfg: #053321; }
.nf-tile[data-v="1024"] { --nf-tbg: #19c2b8; --nf-tfg: #fff; }
.nf-tile[data-v="2048"] { --nf-tbg: #e8447a; --nf-tfg: #fff; }
.nf-tile[data-v="4096"] { --nf-tbg: #8e44ad; --nf-tfg: #fff; }
.nf-tile[data-v="8192"] { --nf-tbg: #5b3df5; --nf-tfg: #fff; }
.nf-tile[data-v="big"] { --nf-tbg: #0b0c1b; --nf-tfg: #ffd84d; }
.nf-tile[data-v="128"] .nf-tile__inner,
.nf-tile[data-v="256"] .nf-tile__inner,
.nf-tile[data-v="2048"] .nf-tile__inner,
.nf-tile[data-v="4096"] .nf-tile__inner { box-shadow: 0 3px 0 rgba(0, 0, 0, .18), 0 0 22px rgba(255, 216, 77, .35); }

/* Side panel */
.nf-side { display: flex; flex-direction: column; gap: 18px; }

.nf-progress {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px 12px;
  padding: 16px;
  border: 1px solid var(--nf-line);
  border-radius: var(--radius-md);
  background: var(--nf-card);
}
.nf-progress__label { color: var(--nf-sub); font-size: .75rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.nf-progress__tile { font-size: 1.6rem; line-height: 1; color: var(--nf-accent); font-variant-numeric: tabular-nums; }
.nf-progress__bar { grid-column: 1 / -1; height: 8px; overflow: hidden; border-radius: 8px; background: rgba(255, 255, 255, .1); }
.nf-progress__bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff9d5c, var(--nf-accent));
  transition: width .3s var(--ease);
}

.nf-pad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(2, 56px);
  grid-template-areas: ". up ." "left down right";
  justify-content: center;
  gap: 8px;
}
.nf-pad__btn {
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--nf-line);
  border-radius: 14px;
  background: var(--nf-card);
  color: var(--nf-text);
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color .15s var(--ease), transform .1s var(--ease);
}
.nf-pad__btn:hover { background: var(--nf-card-hover); }
.nf-pad__btn:active { transform: scale(.94); background: rgba(255, 216, 77, .2); }
.nf-pad__btn .nf-ico { width: 24px; height: 24px; }
.nf-pad__btn--up { grid-area: up; }
.nf-pad__btn--left { grid-area: left; }
.nf-pad__btn--down { grid-area: down; }
.nf-pad__btn--right { grid-area: right; }

.nf-actions { display: flex; gap: 10px; }
.nf-actions .nf-ghost { flex: 1; }

.nf-tip { margin: 0; color: var(--nf-sub); font-size: .82rem; line-height: 1.5; }

/* Overlays (win / game over, pause) */
.nf-over,
.nf-paused {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
}
.nf-over { border-radius: 18px; background: rgba(10, 11, 26, .62); backdrop-filter: blur(3px); animation: nf-fade .3s var(--ease); }
.nf-over.is-win { background: rgba(60, 40, 0, .45); }
.nf-over[hidden],
.nf-paused[hidden] { display: none; }

.nf-over__card,
.nf-paused__card {
  max-width: 360px;
  padding: 26px;
  border: 1px solid var(--nf-line);
  border-radius: var(--radius-md);
  background: rgba(21, 23, 46, .95);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .45);
  text-align: center;
}
.nf-over__title,
.nf-paused__title { margin: 0 0 6px; font-size: 1.6rem; }
.nf-over.is-win .nf-over__title { color: var(--nf-accent); }
.nf-over__card p,
.nf-paused__card p { margin: 0 0 18px; color: var(--nf-sub); font-size: .9rem; }
.nf-over__actions,
.nf-paused__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.nf-over__actions [hidden] { display: none; }

.nf-play.is-paused .nf-arena { filter: blur(12px); pointer-events: none; user-select: none; }

/* ==========================================================================
   Results
   ========================================================================== */
.nf-result { max-width: 640px; margin: 0 auto; padding: 10px 0; text-align: center; }
.nf-result__stars { display: flex; justify-content: center; gap: 10px; margin-bottom: 8px; }
.nf-star--big { font-size: clamp(3rem, 9vw, 4.25rem); opacity: 0; animation: nf-star-in .5s var(--ease) forwards; }
@keyframes nf-star-in {
  from { opacity: 0; transform: scale(.3) rotate(-30deg); }
  to { opacity: 1; transform: none; }
}
.nf-result__title { margin: 0 0 6px; font-size: clamp(1.8rem, 4vw, 2.5rem); }
.nf-result__new {
  display: inline-block;
  margin: 0 0 10px;
  padding: 4px 14px;
  border-radius: var(--radius-pill);
  background: var(--nf-accent);
  color: var(--night);
  font-size: .8rem;
  font-weight: 700;
}
.nf-result__new[hidden] { display: none; }
.nf-result__text { margin: 0 auto 24px; max-width: 460px; color: var(--nf-sub); }
.nf-result__stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 0 0 26px; }
.nf-result__stats div { padding: 14px 8px; border: 1px solid var(--nf-line); border-radius: var(--radius-sm); background: var(--nf-card); }
.nf-result__stats dt { color: var(--nf-sub); font-size: .68rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.nf-result__stats dd { margin: 2px 0 0; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.nf-result__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.nf-result__actions [hidden] { display: none; }

/* ==========================================================================
   How to play
   ========================================================================== */
.nf-guide { margin: 0 0 56px; }
.nf-guide .section-head__title { margin-bottom: 22px; }
.nf-guide__item {
  height: 100%;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.nf-guide__item h3 { margin: 12px 0 6px; font-size: 1.05rem; }
.nf-guide__item p { margin: 0; color: var(--sub); font-size: .9rem; }
.nf-guide__num {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--brand);
  color: var(--onbrand);
  font-weight: 700;
}
.nf-guide__back { margin: 24px 0 0; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 991.98px) {
  .nf-arena { grid-template-columns: minmax(0, 480px); }
  .nf-side { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 14px 18px; }
  .nf-progress { grid-column: 1 / -1; }
  .nf-actions { flex-direction: column; }
  .nf-tip { grid-column: 1 / -1; }
}

@media (max-width: 767.98px) {
  .nf { padding: 24px 20px; min-height: 0; }
  .nf-result__stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nf-hud__stats { margin-left: 0; order: 3; width: 100%; justify-content: space-between; }
  .nf-hud .nf-icon-btn { margin-left: auto; }
}

@media (max-width: 575.98px) {
  .nf { --nf-gap: 7px; margin-left: -4px; margin-right: -4px; padding: 20px 14px; border-radius: var(--radius-md); }
  .nf-home__head { flex-direction: column; gap: 16px; }
  .nf-logo { width: 62px; height: 62px; }
  .nf-toolbar { flex-direction: column; align-items: stretch; }
  .nf-toolbar__actions .nf-ghost { flex: 1; }
  .nf-stages { grid-template-columns: 1fr; }
  .nf-hud { margin-bottom: 14px; }
  .nf-arena { gap: 16px; }
  .nf-board { border-radius: 14px; }
  .nf-cell, .nf-tile__inner { border-radius: 8px; }
  .nf-side { grid-template-columns: 1fr; }
  .nf-pad { grid-template-columns: repeat(4, 1fr); grid-template-rows: 50px; grid-template-areas: "left up down right"; }
  .nf-actions { flex-direction: row; }
  .nf-progress { padding: 12px 14px; }
  .nf-over__card, .nf-paused__card { padding: 20px; }
  .nf::before { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .nf-logo span, .nf-screen { animation: none; }
  .nf-tile { transition: none; }
  .nf-tile .nf-tile__inner { animation: none !important; }
  .nf-star--big { opacity: 1; animation: none; }
}

@media (min-width: 992px) {
  .nf-stages { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
