/* ===========================================================
   Go Kitten — styles
   =========================================================== */

:root {
  --board-bg: #c9b4a6;
  --score-bg: #6d564b;   /* darker than the board so white score text passes contrast */
  --cell-bg: rgba(255, 252, 250, 0.45);
  --ink: #6d4c41;
  --ink-soft: #9c8579;
  --accent: #ff6f87;
  --accent-deep: #ec2f4d;
  --paper: #fffaf6;
  --radius: 14px;
  --gap: 3.2%;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

/* Visually hidden but available to screen readers (live region). */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  font-family: "Baloo 2", "Quicksand", "Segoe UI", system-ui, -apple-system,
    "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% -10%, #fff 0%, rgba(255,255,255,0) 60%),
    linear-gradient(160deg, #fff5f7 0%, #ffe8ec 45%, #ffeede 100%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ---------- Masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.title-block { min-width: 0; }

h1 {
  margin: 0;
  font-size: clamp(34px, 9vw, 52px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  background: linear-gradient(120deg, #ff6f87, #ff9d5c, #9a63ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.6);
}

.tagline {
  margin: 6px 0 0;
  font-size: clamp(13px, 3.4vw, 16px);
  color: var(--ink-soft);
  font-weight: 600;
}
.tagline b { color: #ff9d00; }

.scores {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.score-box {
  position: relative;
  background: var(--score-bg);
  color: #fff;
  border-radius: 12px;
  padding: 8px 16px;
  min-width: 78px;
  text-align: center;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
  overflow: visible;
}

.score-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.9);
}

.score-value {
  display: block;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.1;
}

.score-add {
  position: absolute;
  left: 0;
  right: 0;
  top: 6px;
  font-size: 18px;
  font-weight: 800;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.25);
  pointer-events: none;
  animation: score-float 700ms ease-out forwards;
}

@keyframes score-float {
  0%   { opacity: 0; transform: translateY(6px) scale(0.8); }
  20%  { opacity: 1; }
  100% { opacity: 0; transform: translateY(-26px) scale(1.1); }
}

/* ---------- Controls ---------- */

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 0 14px;
  flex-wrap: wrap;
}

.how {
  margin: 0;
  font-size: 13.5px;
  color: var(--ink-soft);
  font-weight: 600;
  flex: 1 1 220px;
  line-height: 1.4;
}

kbd {
  display: inline-block;
  background: #fff;
  border: 1px solid #e7d6cb;
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 0 5px;
  font-size: 12px;
  color: var(--ink);
  font-family: inherit;
  margin: 0 1px;
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 15px;
  color: #fff;
  background: linear-gradient(135deg, #ff8aa0, #ff6f87 60%, #ec2f4d);
  border-radius: 12px;
  padding: 11px 18px;
  box-shadow: 0 6px 14px rgba(236, 47, 77, 0.28), inset 0 -3px 0 rgba(0,0,0,0.12);
  transition: transform 80ms ease, box-shadow 120ms ease, filter 120ms ease;
  flex-shrink: 0;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(2px); box-shadow: 0 3px 8px rgba(236, 47, 77, 0.28), inset 0 -1px 0 rgba(0,0,0,0.12); }
.btn:focus-visible { outline: 3px solid #ffd2dd; outline-offset: 2px; }

.btn-secondary {
  background: linear-gradient(135deg, #c39bff, #9a63ff 60%, #6f54f0);
  box-shadow: 0 6px 14px rgba(111, 84, 240, 0.28), inset 0 -3px 0 rgba(0,0,0,0.12);
}

.btn-ghost {
  background: #fff;
  color: var(--accent-deep);
  box-shadow: 0 4px 10px rgba(236, 47, 77, 0.14), inset 0 0 0 2px #ffd2dd;
}
.btn-ghost:active { box-shadow: 0 2px 6px rgba(236, 47, 77, 0.14), inset 0 0 0 2px #ffd2dd; }

.btn:disabled,
.btn[disabled] {
  opacity: 0.4;
  cursor: default;
  filter: none;
  box-shadow: inset 0 0 0 2px #ece0da;
  background: #f7f0eb;
  color: var(--ink-soft);
}
.btn:disabled:active { transform: none; }

.control-buttons {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

/* ---------- Board ---------- */

.grid-container {
  position: relative;
  width: 100%;
  /* Cap by viewport height so the square board never overflows on short
     (landscape phone) screens. */
  max-width: min(520px, 66vh);
  margin-left: auto;
  margin-right: auto;
  aspect-ratio: 1 / 1;
  background: var(--board-bg);
  border-radius: 18px;
  padding: var(--gap);
  box-shadow:
    0 18px 40px rgba(146, 109, 95, 0.28),
    inset 0 2px 0 rgba(255, 255, 255, 0.25);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Fallback for browsers without aspect-ratio support. */
@supports not (aspect-ratio: 1 / 1) {
  .grid-container::before {
    content: "";
    display: block;
    padding-top: 100%;
  }
}

.grid-background,
.tile-layer {
  position: absolute;
  inset: var(--gap);
}

.grid-background {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
  z-index: 1;
}

.grid-cell {
  background: var(--cell-bg);
  border-radius: var(--radius);
}

.tile-layer {
  z-index: 2;
  pointer-events: none;
}

/* ---------- Tiles ---------- */

.tile {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -4px 0 rgba(0, 0, 0, 0.08),
    0 6px 12px rgba(0, 0, 0, 0.12);
  transition: transform 110ms ease-in-out;
  will-change: transform;
  overflow: hidden;
}

.tile-emoji {
  font-size: clamp(26px, 11vw, 52px);
  line-height: 1;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.12));
}

.tile-name {
  margin-top: 3px;
  font-size: clamp(8px, 2.6vw, 12px);
  font-weight: 800;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  opacity: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.22);
  white-space: nowrap;
  max-width: 96%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tile-glow {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.4),
    inset 0 -4px 0 rgba(0, 0, 0, 0.12),
    0 0 0 2px var(--ring),
    0 0 22px 3px var(--ring);
}

/* The Lion King (the win tile) gets a regal, breathing glow all its own. */
.tile-king {
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.5),
    inset 0 -4px 0 rgba(0, 0, 0, 0.12),
    0 0 0 3px var(--ring),
    0 0 30px 7px var(--ring);
  animation: king-pulse 1.7s ease-in-out infinite;
}
@keyframes king-pulse {
  0%, 100% { filter: brightness(1) saturate(1); }
  50%      { filter: brightness(1.13) saturate(1.18); }
}

/* Scale pops are done on the emoji so the tile's translate transform is untouched
   (the tile element's `transform` is reserved for its grid-position translate). */
.tile-new .tile-emoji { animation: emoji-pop-in 240ms cubic-bezier(0.34, 1.56, 0.64, 1) both; }
.tile-merged .tile-emoji { animation: emoji-pop-merge 260ms cubic-bezier(0.34, 1.56, 0.64, 1) both; }

@keyframes emoji-pop-in {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes emoji-pop-merge {
  0%   { transform: scale(0.6); }
  45%  { transform: scale(1.4); }
  100% { transform: scale(1); }
}

.tile-merged { z-index: 3; }
.tile-merged .tile-name { animation: name-fade 240ms ease both; }
@keyframes name-fade { from { opacity: 0; } to { opacity: 0.92; } }

/* ---------- Overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  padding: 18px;
  background: rgba(255, 250, 246, 0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: overlay-in 280ms ease both;
}
.overlay[hidden] { display: none; }

@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.overlay-win { background: rgba(255, 247, 224, 0.86); }
.overlay-lose { background: rgba(247, 240, 255, 0.85); }

.overlay-card {
  text-align: center;
  max-width: 320px;
}

.overlay-emoji {
  font-size: 72px;
  line-height: 1;
  animation: bounce 1.2s ease-in-out infinite;
}
@keyframes bounce {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-10px) rotate(3deg); }
}

.overlay-title {
  margin: 8px 0 6px;
  font-size: 26px;
  font-weight: 800;
  color: var(--ink);
}

.overlay-text {
  margin: 0 0 18px;
  font-size: 15px;
  color: var(--ink-soft);
  font-weight: 600;
  line-height: 1.45;
}

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

/* ---------- Ladder ---------- */

.ladder {
  margin-top: 26px;
}
.ladder h3 {
  margin: 0 0 10px;
  font-size: 14px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 800;
}

.ladder-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.ladder-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 3px 7px rgba(0, 0, 0, 0.1), inset 0 -2px 0 rgba(0,0,0,0.08);
}
.ladder-emoji { font-size: 17px; line-height: 1; }
.ladder-name { white-space: nowrap; }
.ladder-arrow {
  color: var(--ink-soft);
  font-weight: 800;
  font-size: 13px;
  opacity: 0.6;
}

/* ---------- Footer ---------- */

.footer {
  margin-top: 26px;
  text-align: center;
}
.footer p {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 600;
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
  .tile-new,
  .tile-merged,
  .tile-king,
  .tile-new .tile-emoji,
  .tile-merged .tile-emoji,
  .overlay,
  .overlay-emoji,
  .score-add {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ---------- Small screens ---------- */

@media (max-width: 380px) {
  .app { padding: 14px 10px 30px; }
  .score-box { min-width: 66px; padding: 6px 10px; }
  .score-value { font-size: 20px; }
  .how { flex-basis: 100%; }
}

/* ---------- Short / landscape screens ---------- */

@media (orientation: landscape) and (max-height: 560px) {
  .app { padding: 10px 16px 16px; }
  .controls { margin: 10px 0 8px; }
  .ladder, .footer { display: none; }
}
