:root {
  --paper: #e9f0f5;
  --ink: #15202b;
  --muted: #5a6b7c;
  --line: #c5d4e0;
  --accent: #1f6feb;
  --accent-deep: #1554b8;
  --calc-shell: #4aa8e8;
  --calc-face: #5eb6f0;
  --calc-key: #7ec8f5;
  --calc-key-hover: #97d4f8;
  --calc-fn: #6bbef2;
  --calc-op: #2b8fd4;
  --calc-eq: #1a7fc0;
  --display: #0c3d5c;
  --shadow: 0 24px 48px rgba(42, 140, 200, 0.28);
  --radius: 18px;
  --font-display: "Bricolage Grotesque", sans-serif;
  --font-body: "Source Serif 4", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.65;
  background: var(--paper);
}

.page-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(31, 111, 235, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 20%, rgba(43, 182, 115, 0.12), transparent 50%),
    linear-gradient(180deg, #dce7ef 0%, var(--paper) 42%, #eef4f8 100%);
}

.page-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(21, 32, 43, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 32, 43, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(180deg, #000 0%, transparent 70%);
}

a {
  color: inherit;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.nav {
  display: flex;
  gap: 1.25rem;
}

.nav a {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--muted);
  transition: color 0.2s ease;
}

.nav a:hover,
.nav a:focus-visible {
  color: var(--ink);
}

.hero {
  max-width: 960px;
  margin: 0 auto;
  padding: clamp(3rem, 12vh, 6.5rem) 1.5rem 4rem;
  animation: rise 0.7s ease both;
}

.hero-brand {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: clamp(3.5rem, 12vw, 6.5rem);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.06em;
  color: var(--ink);
}

.hero-title {
  margin: 0 0 1rem;
  max-width: 16ch;
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 3.5vw, 2.35rem);
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.03em;
}

.hero-lead {
  margin: 0 0 1.75rem;
  max-width: 36ch;
  color: var(--muted);
  font-size: 1.125rem;
}

.hero-cta {
  display: inline-flex;
  align-items: center;
  padding: 0.85rem 1.35rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.98rem;
  text-decoration: none;
  transition: background 0.2s ease, transform 0.2s ease;
}

.hero-cta:hover {
  background: var(--accent-deep);
  transform: translateY(-1px);
}

.hero-cta:focus-visible {
  outline: 3px solid rgba(31, 111, 235, 0.35);
  outline-offset: 3px;
}

.about,
.tools-section {
  max-width: 960px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 1rem;
}

.about {
  animation: rise 0.7s ease 0.12s both;
}

.about h2,
.tool-panel h2 {
  margin: 0 0 0.75rem;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.about p,
.tool-intro {
  margin: 0;
  max-width: 42ch;
  color: var(--muted);
}

.tools-section {
  padding-bottom: 4rem;
  animation: rise 0.7s ease 0.22s both;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2rem 2.5rem;
  align-items: start;
}

.tool-intro {
  margin-bottom: 1.75rem;
}

.calculator {
  width: 100%;
  max-width: 360px;
  padding: 1rem;
  border-radius: calc(var(--radius) + 6px);
  background: linear-gradient(160deg, #6ec0f5 0%, var(--calc-shell) 55%, #3a9adb 100%);
  box-shadow: var(--shadow);
}

.calc-display {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: flex-end;
  gap: 0.35rem;
  min-height: 6.5rem;
  margin-bottom: 0.85rem;
  padding: 1rem 1.1rem;
  border-radius: var(--radius);
  background: linear-gradient(180deg, #dff1fb 0%, #c8e7f8 100%);
  color: var(--display);
  font-family: var(--font-mono);
  overflow: hidden;
}

.calc-expression {
  min-height: 1.2em;
  color: rgba(12, 61, 92, 0.5);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.calc-result {
  font-size: clamp(1.85rem, 7vw, 2.4rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1.1;
  word-break: break-all;
  text-align: right;
}

.calc-keys {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
}

.key {
  appearance: none;
  border: 0;
  border-radius: 14px;
  min-height: 3.35rem;
  padding: 0;
  background: var(--calc-key);
  color: #0c3d5c;
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.key:hover {
  background: var(--calc-key-hover);
}

.key:active {
  transform: scale(0.96);
}

.key:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.key-fn {
  background: var(--calc-fn);
  color: #0a3550;
  font-size: 1rem;
}

.key-op {
  background: var(--calc-op);
  color: #fff;
}

.key-op:hover {
  background: #1f7ab8;
}

.key-eq {
  background: var(--calc-eq);
  color: #fff;
}

.key-eq:hover {
  background: #156aa8;
}

.key-zero {
  grid-column: span 2;
}

.game-2468 {
  position: relative;
  width: 100%;
  max-width: 360px;
  padding: 1rem;
  border-radius: calc(var(--radius) + 6px);
  background: linear-gradient(160deg, #7ed0a8 0%, #4fbf86 55%, #2f9f6a 100%);
  box-shadow: 0 24px 48px rgba(47, 159, 106, 0.28);
  outline: none;
}

.game-2468:focus-visible {
  box-shadow:
    0 24px 48px rgba(47, 159, 106, 0.28),
    0 0 0 3px rgba(255, 255, 255, 0.7);
}

.game-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.game-score-box {
  display: flex;
  flex-direction: column;
  min-width: 5.5rem;
  padding: 0.45rem 0.75rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.28);
  color: #0a3d28;
  font-family: var(--font-mono);
}

.game-score-label {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  opacity: 0.75;
}

.game-score-value {
  font-size: 1.25rem;
  font-weight: 500;
  line-height: 1.2;
}

.game-restart {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  background: #0f6b45;
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.game-restart:hover {
  background: #0b5537;
}

.game-restart:active {
  transform: scale(0.96);
}

.game-restart:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.game-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  padding: 0.55rem;
  border-radius: var(--radius);
  background: rgba(10, 61, 40, 0.22);
  touch-action: none;
  user-select: none;
}

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.18);
  color: #0a3d28;
  font-family: var(--font-mono);
  font-size: clamp(1rem, 3.6vw, 1.35rem);
  font-weight: 500;
  transition: transform 0.12s ease;
}

.tile-2 { background: #e8f7ef; }
.tile-4 { background: #d4f0e1; }
.tile-6 { background: #bfe8d3; }
.tile-8 { background: #9edcbb; color: #064028; }
.tile-16 { background: #7dcea3; color: #fff; }
.tile-32 { background: #5bbc87; color: #fff; }
.tile-64 { background: #3da56c; color: #fff; }
.tile-128 { background: #2f9f6a; color: #fff; font-size: clamp(0.9rem, 3vw, 1.15rem); }
.tile-256 { background: #248557; color: #fff; font-size: clamp(0.9rem, 3vw, 1.15rem); }
.tile-512 { background: #1b6b46; color: #fff; font-size: clamp(0.85rem, 2.8vw, 1.05rem); }
.tile-1024 { background: #145338; color: #fff; font-size: clamp(0.75rem, 2.4vw, 0.95rem); }
.tile-2048,
.tile-2468,
.tile-4096,
.tile-8192 { background: #0f3f2b; color: #fff; font-size: clamp(0.7rem, 2.2vw, 0.9rem); }

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

.tile-merged {
  animation: merge-pop 0.18s ease;
}

.game-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin-top: 0.85rem;
  max-width: 180px;
  margin-inline: auto;
}

.pad-btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  min-height: 2.6rem;
  background: rgba(255, 255, 255, 0.28);
  color: #0a3d28;
  font-family: var(--font-mono);
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.pad-btn[data-dir="up"] { grid-column: 2; grid-row: 1; }
.pad-btn[data-dir="left"] { grid-column: 1; grid-row: 2; }
.pad-btn[data-dir="down"] { grid-column: 2; grid-row: 2; }
.pad-btn[data-dir="right"] { grid-column: 3; grid-row: 2; }

.pad-btn:hover {
  background: rgba(255, 255, 255, 0.42);
}

.pad-btn:active {
  transform: scale(0.96);
}

.pad-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.game-hint {
  margin: 0.75rem 0 0;
  text-align: center;
  color: rgba(10, 61, 40, 0.72);
  font-size: 0.82rem;
}

.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  border-radius: inherit;
  background: rgba(10, 61, 40, 0.72);
  color: #fff;
  text-align: center;
}

.game-overlay[hidden] {
  display: none;
}

.game-overlay p {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
}

@keyframes pop {
  from { transform: scale(0.6); opacity: 0.4; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes merge-pop {
  from { transform: scale(1.12); }
  to { transform: scale(1); }
}

.site-footer {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 2.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
}

.site-footer p {
  margin: 0;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .hero,
  .about,
  .tools-section,
  .hero-cta,
  .key,
  .tile,
  .pad-btn {
    animation: none;
    transition: none;
  }
}

@media (max-width: 820px) {
  .tools-grid {
    grid-template-columns: 1fr;
    gap: 2.5rem;
  }

  .calculator,
  .game-2468 {
    max-width: 100%;
  }
}

@media (max-width: 560px) {
  .site-header {
    padding-inline: 1.1rem;
  }

  .hero,
  .about,
  .tools-section,
  .site-footer {
    padding-inline: 1.1rem;
  }

  .key {
    min-height: 3.1rem;
  }
}
