:root {
  --bg: #060d16;
  --card: #0d1826;
  --card-2: #101f31;
  --cell: #132235;
  --stroke: #223752;
  --text: #eef5fc;
  --muted: #a6bbd0;
  --accent: #38bdf8;
  --accent-deep: #0ea5e9;
  --amber: #fbbf24;
  --danger: #f87171;
  --radius: 20px;
  --tile-radius: 11px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(900px 600px at 12% -10%, rgba(56, 189, 248, .16), transparent 60%),
    radial-gradient(700px 520px at 110% 5%, rgba(251, 191, 36, .10), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  padding: 0 18px 56px;
}

a { color: #7dd3fc; }

.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 {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--amber);
  color: #14100a;
  padding: 10px 16px;
  border-radius: 0 0 12px 0;
  font-weight: 700;
  z-index: 10;
}
.skip:focus { left: 0; }

.topbar {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 0 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
  letter-spacing: .2px;
}

.brand-arrow { color: var(--accent); }
.brand-tld { color: var(--muted); font-weight: 500; }

.badge {
  color: var(--muted);
  border: 1px solid var(--stroke);
  background: rgba(13, 24, 38, .8);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: .78rem;
  white-space: nowrap;
}

main {
  max-width: 760px;
  margin: 0 auto;
}

.hero { padding: 12px 0 4px; }

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 7vw, 3.6rem);
  line-height: 1.04;
  letter-spacing: -.02em;
  color: #fde68a;
}

.lead {
  margin: 10px 0 0;
  color: var(--muted);
  max-width: 60ch;
}

.game-card {
  margin-top: 16px;
  background: linear-gradient(180deg, rgba(16, 31, 49, .96), rgba(13, 24, 38, .96));
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .35);
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.stat {
  background: rgba(6, 13, 22, .65);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.stat-label {
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.stat-value {
  font-size: 1.35rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  transition: transform .12s ease, color .12s ease;
}
.stat-value.bump { transform: scale(1.14); color: var(--amber); }

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

.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  gap: 9px;
  padding: 10px;
  background: #0a1421;
  border: 1px solid var(--stroke);
  border-radius: 16px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  outline: none;
}
.board:focus-visible { box-shadow: 0 0 0 3px rgba(251, 191, 36, .75); }

.board-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
  min-height: 0;
}

.cell {
  position: relative;
  background: var(--cell);
  border: 1px solid rgba(40, 64, 94, .75);
  border-radius: var(--tile-radius);
  min-width: 0;
  min-height: 0;
  cursor: pointer;
}

.tile {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--tile-radius);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.03em;
  font-size: clamp(1.15rem, 5.2vw, 1.95rem);
  line-height: 1;
  background: #1e3047;
  color: var(--text);
  will-change: transform;
}
.tile.tile-new { animation: tile-in .15s ease-out; }
.tile.tile-merged { animation: tile-pop .18s ease-out; }
.tile.digits-4 { font-size: clamp(.95rem, 4.1vw, 1.5rem); }
.tile.digits-5 { font-size: clamp(.78rem, 3.4vw, 1.2rem); }

.tile.v2 { background: #dbe7f3; color: #0b1520; }
.tile.v4 { background: #c7d9ea; color: #0b1520; }
.tile.v8 { background: #7dd3fc; color: #07202c; }
.tile.v16 { background: #38bdf8; color: #04131d; }
.tile.v32 { background: #0ea5e9; color: #04121a; }
.tile.v64 { background: #0369a1; color: #ffffff; }
.tile.v128 { background: #fbbf24; color: #1c1100; }
.tile.v256 { background: #f59e0b; color: #1c1100; }
.tile.v512 { background: #f97316; color: #1a0a00; }
.tile.v1024 { background: #fb7185; color: #1f0409; }
.tile.v2048 {
  background: linear-gradient(135deg, #be123c, #e11d48);
  color: #ffffff;
  box-shadow: 0 0 24px rgba(244, 63, 94, .55), inset 0 0 0 1px rgba(255, 255, 255, .25);
}
.tile.v4096, .tile.v8192, .tile.v16384, .tile.v32768, .tile.v65536 {
  background: linear-gradient(135deg, #7c3aed, #5b21b6);
  color: #ffffff;
  box-shadow: 0 0 22px rgba(167, 139, 250, .45);
}

@keyframes tile-in {
  from { transform: scale(.78); opacity: .6; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes tile-pop {
  0% { transform: scale(.9); }
  55% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 10, 18, .82);
  backdrop-filter: blur(3px);
  border-radius: 16px;
  z-index: 5;
}
.overlay[hidden] { display: none; }

.overlay-card {
  width: min(100%, 320px);
  background: var(--card-2);
  border: 1px solid var(--stroke);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45);
}

.overlay-title { margin: 0 0 8px; font-size: 1.55rem; }
.overlay-text { margin: 0 0 16px; color: var(--muted); }

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.status {
  margin: 12px auto 0;
  min-height: 2.8em;
  max-width: 58ch;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(6, 13, 22, .5);
  border: 1px solid rgba(34, 55, 82, .7);
  text-align: center;
  color: var(--text);
  font-size: .95rem;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 62px);
  grid-template-rows: repeat(3, 52px);
  gap: 8px;
  justify-content: center;
  margin: 12px auto 0;
}
.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-center { grid-column: 2; grid-row: 2; font-size: .88rem !important; }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }

.dpad-btn {
  border: 1px solid var(--stroke);
  background: var(--card-2);
  color: var(--text);
  border-radius: 14px;
  font-size: 1.35rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s ease, border-color .12s ease;
}
.dpad-btn:hover { border-color: var(--accent); }
.dpad-btn:active { background: #16324a; transform: scale(.95); }
.dpad-center {
  background: #142840;
  border-color: #2f557d;
  color: #bae6fd;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}

.btn {
  appearance: none;
  border: 1px solid var(--stroke);
  background: var(--card-2);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 16px;
  min-height: 46px;
  font: inherit;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color .12s ease, transform .08s ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .48; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, #fcd34d, #f59e0b);
  border-color: #f59e0b;
  color: #1a1203;
}
.btn-primary:hover:not(:disabled) { border-color: #fbbf24; background: linear-gradient(180deg, #fde68a, #fbbf24); }

.toggles {
  margin: 16px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  background: rgba(6, 13, 22, .45);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
}

.toggles-legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: .95rem;
  color: var(--text);
  min-height: 36px;
}

.toggle-featured {
  font-weight: 700;
  color: #fde68a;
}

.toggle input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--amber);
  cursor: pointer;
}

.help {
  margin-top: 14px;
  border-top: 1px solid var(--stroke);
  padding-top: 12px;
}
.help summary {
  cursor: pointer;
  color: #7dd3fc;
  font-weight: 700;
  padding: 4px 0;
}
.help-body { color: var(--muted); font-size: .95rem; }
.help-body ul { padding-left: 20px; }
.help-body li { margin: 6px 0; }

kbd {
  font: inherit;
  font-size: .82em;
  border: 1px solid var(--stroke);
  border-bottom-width: 2px;
  background: #0a1421;
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--text);
}

.note {
  margin: 16px auto 0;
  color: var(--muted);
  font-size: .92rem;
  text-align: center;
  max-width: 58ch;
}

.foot {
  max-width: 760px;
  margin: 26px auto 0;
  color: var(--muted);
  font-size: .9rem;
  text-align: center;
}

:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

/* Режим для незрячих: заметная строка статуса и ещё более крупные кнопки */
body.blind-mode .status {
  border-color: var(--amber);
  background: #0d1d30;
  font-size: 1.05rem;
  font-weight: 600;
}
body.blind-mode .dpad-btn {
  border-width: 2px;
}
body.blind-mode .btn {
  min-height: 52px;
  font-size: 1rem;
}

/* Режим высокого контраста для слабовидящих (WCAG AAA) */
body.high-contrast {
  background: #000000;
  color: #ffffff;
  --bg: #000000;
  --card: #000000;
  --card-2: #0a0a0a;
  --cell: #000000;
  --stroke: #ffffff;
  --text: #ffffff;
  --muted: #f5f5f5;
  --accent: #ffe600;
  --amber: #ffe600;
}
body.high-contrast h1 { color: #ffe600; }
body.high-contrast a,
body.high-contrast .help summary,
body.high-contrast .brand-arrow { color: #ffe600; }
body.high-contrast .game-card,
body.high-contrast .stat,
body.high-contrast .board,
body.high-contrast .status,
body.high-contrast .toggles,
body.high-contrast .overlay-card,
body.high-contrast .badge {
  background: #000000;
  border: 2px solid #ffffff;
  box-shadow: none;
}
body.high-contrast .cell {
  border: 2px solid #999999;
}
body.high-contrast .tile {
  background: #ffffff;
  color: #000000;
  border: 3px solid #ffe600;
  box-shadow: none;
}
body.high-contrast .tile.v128,
body.high-contrast .tile.v256,
body.high-contrast .tile.v512,
body.high-contrast .tile.v1024,
body.high-contrast .tile.v2048,
body.high-contrast .tile.v4096,
body.high-contrast .tile.v8192 {
  background: #ffe600;
  color: #000000;
  border: 3px solid #ffffff;
}
body.high-contrast .btn-primary {
  background: #ffe600;
  color: #000000;
  border: 2px solid #ffffff;
}
body.high-contrast .dpad-btn,
body.high-contrast .btn {
  background: #000000;
  color: #ffffff;
  border: 2px solid #ffffff;
}
body.high-contrast .dpad-center {
  background: #ffe600;
  color: #000000;
  border-color: #ffffff;
}
body.high-contrast .toggle-featured { color: #ffe600; }

@media (max-width: 700px) {
  body { padding: 0 10px 36px; }
  .topbar { padding: 10px 0 4px; }
  .badge { font-size: .72rem; padding: 4px 10px; }
  .hero { padding: 4px 0 0; }
  h1 { font-size: 1.8rem; }
  .lead { display: none; }
  .game-card {
    margin-top: 8px;
    padding: 12px;
    border-radius: 16px;
  }
  .hud { gap: 8px; margin-bottom: 10px; }
  .stat { padding: 6px 10px; }
  .stat-value { font-size: 1.15rem; }
  .board-wrap { width: min(100%, 312px); }
  .board { gap: 6px; padding: 7px; }
  .board-row { gap: 6px; }
  .status {
    margin-top: 8px;
    min-height: 2.3em;
    padding: 6px 10px;
    font-size: .86rem;
  }
  .dpad {
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 46px);
    gap: 6px;
    margin-top: 10px;
  }
  .actions { gap: 8px; margin-top: 12px; }
  .actions .btn { flex: 1 1 44%; padding: 10px 10px; font-size: .9rem; }
}

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