/* ToolyLab — 2048
   Kutular transform ile kayar (--r/--c × (--cell + --gap)); --cell/--gap JS ResizeObserver ile px olarak yazılır. */
.tz-tool {
  max-width: min(500px, max(340px, calc(100svh - 170px)));
  margin: 0 auto;
}
.tz-card { gap: var(--spacing-md); }

/* Skor kutuları (.calc-stats/.stat-box ortak) */
.tz-stats .stat-box { position: relative; padding: 10px 8px; }
.tz-stats .stat-val { font-size: clamp(1.2rem, 5vw, 1.5rem); font-weight: 800; line-height: 1.15; }
.tz-gain {
  position: absolute;
  left: 50%;
  top: 40%;
  font-weight: 800;
  font-size: 1rem;
  color: #c4b5fd;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%);
}
.tz-gain.go { animation: tzGain .7s ease-out forwards; }
@keyframes tzGain {
  0%   { opacity: 0; transform: translate(-50%, 6px); }
  15%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -26px); }
}

/* Tahta */
.tz-board {
  --n: 4;
  --gap: 12px;
  --cell: calc((100% - var(--gap) * 5) / 4);
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: rgba(10, 8, 26, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: clamp(10px, 3.5%, 18px);
  touch-action: none;
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  cursor: grab;
}
.tz-board:active { cursor: grabbing; }
.tz-board:focus-visible { box-shadow: 0 0 0 2px rgba(167, 139, 250, 0.75); }
.tz-bg {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-auto-rows: 1fr;
  gap: var(--gap);
  padding: var(--gap);
}
.tz-cell {
  background: rgba(255, 255, 255, 0.06);
  border-radius: clamp(4px, calc(var(--cell) * 0.1), 10px);
}
.tz-tiles { position: absolute; inset: 0; }

/* Kutular */
.tz-tile {
  --r: 0;
  --c: 0;
  --fs: 0.5;
  position: absolute;
  left: var(--gap);
  top: var(--gap);
  width: var(--cell);
  height: var(--cell);
  z-index: 2;
  transform: translate(calc(var(--c) * (var(--cell) + var(--gap))), calc(var(--r) * (var(--cell) + var(--gap))));
  transition: transform 110ms ease-in-out;
  will-change: transform;
}
.tz-tile.is-dying { z-index: 1; }
.tz-tile.is-merged { z-index: 3; }
.tz-board.no-anim .tz-tile { transition: none; }
.tz-inner {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: clamp(4px, calc(var(--cell) * 0.1), 10px);
  font-size: calc(var(--cell) * var(--fs));
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  white-space: nowrap;
  background: #eee4da;
  color: #574b40;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
}
/* Basamak sayısına göre yazı boyutu — 4–7 basamak da kutuya sığar */
.tz-tile.d3 { --fs: 0.42; }
.tz-tile.d4 { --fs: 0.33; }
.tz-tile.d5 { --fs: 0.27; }
.tz-tile.d6 { --fs: 0.23; }
.tz-tile.d7 { --fs: 0.2; }

.tz-tile.is-new .tz-inner { animation: tzAppear 180ms ease 110ms backwards; }
.tz-tile.is-merged .tz-inner { animation: tzPop 200ms ease 110ms backwards; }
@keyframes tzAppear {
  from { opacity: 0; transform: scale(0); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes tzPop {
  0%   { opacity: 0; }
  1%   { opacity: 1; transform: scale(1); }
  50%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* Geçersiz hamle: hafif sekme geri bildirimi */
.tz-board.bump-left  .tz-tiles { animation: tzBumpL 180ms ease; }
.tz-board.bump-right .tz-tiles { animation: tzBumpR 180ms ease; }
.tz-board.bump-up    .tz-tiles { animation: tzBumpU 180ms ease; }
.tz-board.bump-down  .tz-tiles { animation: tzBumpD 180ms ease; }
@keyframes tzBumpL { 50% { transform: translateX(-4px); } }
@keyframes tzBumpR { 50% { transform: translateX(4px); } }
@keyframes tzBumpU { 50% { transform: translateY(-4px); } }
@keyframes tzBumpD { 50% { transform: translateY(4px); } }

/* Renk skalası — her kutuda yazı/zemin kontrastı ≥ 4.4:1 (büyük kalın yazı için WCAG AA) */
.t2    .tz-inner { background: #eee4da; color: #574b40; }
.t4    .tz-inner { background: #ede0c8; color: #574b40; }
.t8    .tz-inner { background: #f2b179; color: #3a2412; }
.t16   .tz-inner { background: #f59563; color: #3a2412; }
.t32   .tz-inner { background: #f67c5f; color: #2e1a10; }
.t64   .tz-inner { background: #d9411f; color: #fff; }
.t128  .tz-inner { background: #f2d77a; color: #3a2a08; box-shadow: 0 0 10px rgba(242, 215, 122, 0.25); }
.t256  .tz-inner { background: #eecb55; color: #3a2a08; box-shadow: 0 0 12px rgba(238, 203, 85, 0.3); }
.t512  .tz-inner { background: #e9b935; color: #33240a; box-shadow: 0 0 14px rgba(233, 185, 53, 0.35); }
.t1024 .tz-inner { background: #e2a41c; color: #2a1d05; box-shadow: 0 0 16px rgba(226, 164, 28, 0.4); }
.t2048 .tz-inner { background: #ffcf33; color: #2a1d05; box-shadow: 0 0 22px rgba(255, 207, 51, 0.6); }
.t4096 .tz-inner { background: #8b5cf6; color: #fff; box-shadow: 0 0 18px rgba(139, 92, 246, 0.55); }
.t8192 .tz-inner { background: #7c3aed; color: #fff; box-shadow: 0 0 18px rgba(124, 58, 237, 0.6); }
.t16384 .tz-inner { background: #a21caf; color: #fff; box-shadow: 0 0 18px rgba(162, 28, 175, 0.6); }
.tsuper .tz-inner { background: #1e1838; color: #ffd76a; box-shadow: inset 0 0 0 2px #ffd76a, 0 0 18px rgba(255, 215, 106, 0.4); }

/* Kazandın / oyun bitti katmanı */
.tz-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: var(--spacing-sm);
  text-align: center;
  border-radius: inherit;
  background: rgba(14, 12, 30, 0.8);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: tzFade 0.35s ease backwards;
  cursor: default;
}
.tz-overlay[hidden] { display: none; }
@keyframes tzFade { from { opacity: 0; } to { opacity: 1; } }
.tz-ov-title { font-size: clamp(1.6rem, 7vw, 2.2rem); font-weight: 800; line-height: 1.15; color: var(--text-primary); }
.tz-overlay.is-win .tz-ov-title { color: #ffcf33; }
.tz-overlay.is-over .tz-ov-title { color: #fca5a5; }
.tz-ov-sub { max-width: 30ch; font-size: 0.95rem; line-height: 1.45; color: var(--text-secondary); font-weight: 600; }
.tz-ov-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  width: 100%;
  max-width: 340px;
  margin-top: 6px;
}
.tz-ov-main { flex: 1 1 100px; width: auto; max-width: none; padding: 12px 14px; font-size: 1rem; color: #fff; }
.tz-ov-alt { flex: 1 1 100px; height: auto; min-height: 48px; font-weight: 600; font-size: 0.95rem; }

/* Alt düğmeler: Yeni oyun (birincil) + Geri al (ikincil) */
.tz-actions { display: flex; gap: var(--spacing-xs); }
.tz-new { flex: 1 1 auto; max-width: none; color: #fff; }
.tz-new svg, .tz-undo svg { width: 18px; height: 18px; flex: none; }
.tz-undo {
  flex: 0 0 auto;
  height: auto;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 18px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--border-radius-sm);
}
.tz-undo:disabled { opacity: 0.4; cursor: not-allowed; }
.tz-undo:disabled:hover { background: rgba(255, 255, 255, 0.06); }

.tz-hint { text-align: center; color: var(--text-muted); font-size: 0.86rem; line-height: 1.5; margin: 0; }
.tz-live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

/* Ayarlar: tahta boyutu */
.tz-size { width: 100%; }
.tz-size-hint { margin: 8px 0 0; }

/* Mobil: kenar boşlukları azalır → tahta büyür */
@media (max-width: 640px) {
  .tz-tool .calc-card { padding: var(--spacing-sm) 12px; gap: var(--spacing-sm); }
}
@media (max-width: 360px) {
  .tz-undo { padding: 0 12px; }
  .tz-new { padding-left: 12px; padding-right: 12px; }
}

/* Tam ekran: tahta ekran yüksekliğine sığar (gövde kaydırılamaz) */
body.fullscreen .tz-tool { max-width: min(620px, max(260px, calc(100dvh - 330px))); }
body.fullscreen .tz-tool .calc-card { padding: var(--spacing-sm); gap: var(--spacing-sm); }

@media (prefers-reduced-motion: reduce) {
  .tz-tile { transition: none; }
  .tz-inner, .tz-tiles, .tz-overlay, .tz-gain { animation: none !important; }
}
