:root {
  --bg: #171516;
  --panel: #f8f1e9;
  --ink: #312722;
  --muted: #7d6f66;
  --grid: #d9c8bc;
  --grid-cell: rgba(255, 255, 255, 0.42);
  --her: #f48ba5;
  --you: #65a7df;
  --son: #f0c35a;
  --gap: clamp(5px, 1.5vw, 7px);
  --board-padding: clamp(7px, 2vw, 9px);
  --tile-size: calc((100% - var(--gap) * 3) / 4);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  align-items: center;
  background:
    linear-gradient(135deg, rgba(244, 139, 165, 0.2), transparent 32%),
    linear-gradient(225deg, rgba(101, 167, 223, 0.22), transparent 36%),
    var(--bg);
  color: var(--ink);
  display: flex;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  justify-content: center;
  min-height: 100vh;
  padding: max(18px, env(safe-area-inset-top)) 10px max(18px, env(safe-area-inset-bottom));
}

button {
  font: inherit;
}

.app {
  max-width: 430px;
  width: min(100%, 430px);
}

.topbar {
  align-items: flex-end;
  color: #fff8ef;
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
}

.eyebrow {
  color: rgba(255, 248, 239, 0.68);
  font-size: 0.72rem;
  letter-spacing: 0;
  margin: 0 0 4px;
}

h1 {
  font-size: clamp(2rem, 12vw, 3.2rem);
  line-height: 0.95;
  margin: 0;
}

.counter {
  align-items: baseline;
  background: rgba(255, 248, 239, 0.12);
  border: 1px solid rgba(255, 248, 239, 0.18);
  border-radius: 8px;
  color: #fff8ef;
  display: flex;
  gap: 4px;
  min-width: 78px;
  padding: 10px 12px;
  justify-content: center;
}

.counter span {
  font-size: 1.35rem;
  font-weight: 800;
}

.counter small {
  color: rgba(255, 248, 239, 0.66);
}

.game-shell {
  background: var(--panel);
  border-radius: 8px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.3);
  padding: 10px;
}

.legend {
  color: var(--muted);
  display: flex;
  font-size: 0.9rem;
  gap: 14px;
  margin: 0 0 12px;
}

.legend span {
  align-items: center;
  display: inline-flex;
  gap: 6px;
}

.swatch {
  border-radius: 50%;
  display: inline-block;
  height: 10px;
  width: 10px;
}

.swatch-her {
  background: var(--her);
}

.swatch-you {
  background: var(--you);
}

.swatch-son {
  background: var(--son);
}

.board {
  aspect-ratio: 1;
  background: var(--grid);
  border-radius: 8px;
  outline: none;
  padding: var(--board-padding);
  position: relative;
  touch-action: none;
  width: 100%;
}

.board:focus-visible {
  box-shadow: 0 0 0 3px rgba(240, 195, 90, 0.55);
}

.grid-cells {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(4, 1fr);
  height: 100%;
  width: 100%;
}

.grid-cells span {
  background: var(--grid-cell);
  border-radius: 7px;
}

.tile-layer {
  inset: var(--board-padding);
  pointer-events: none;
  position: absolute;
}

.tile {
  align-items: center;
  border-radius: 7px;
  box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.08), 0 6px 18px rgba(74, 55, 42, 0.16);
  color: #fff;
  display: flex;
  flex-direction: column;
  font-weight: 800;
  height: var(--tile-size);
  justify-content: center;
  left: 0;
  line-height: 1;
  position: absolute;
  top: 0;
  transform: translate(var(--x), var(--y));
  transition: transform 150ms ease;
  width: var(--tile-size);
}

.tile--photo {
  align-items: flex-start;
  background-position: center;
  background-size: cover;
  justify-content: space-between;
  overflow: hidden;
  padding: 5px;
}

.tile--photo::before {
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.28), transparent 46%, rgba(0, 0, 0, 0.34));
  content: "";
  inset: 0;
  position: absolute;
}

.tile strong {
  font-size: clamp(1.3rem, 8vw, 2.2rem);
  position: relative;
  z-index: 1;
}

.tile span {
  font-size: 0.78rem;
  margin-top: 4px;
  opacity: 0.8;
  position: relative;
  z-index: 1;
}

.tile--photo strong,
.tile--photo span {
  background: rgba(23, 21, 22, 0.56);
  border-radius: 999px;
  color: #fff8ef;
  line-height: 1;
  padding: 4px 6px;
}

.tile--photo strong {
  font-size: 0.72rem;
}

.tile--photo span {
  align-self: flex-end;
  font-size: 0.68rem;
  font-weight: 900;
  margin-top: 0;
  opacity: 1;
}

.tile--photo .tile-level {
  margin-top: auto;
}

.tile--her {
  background: linear-gradient(145deg, #ff9fb7, #df5d82);
}

.tile--you {
  background: linear-gradient(145deg, #79b9ef, #347bb7);
}

.tile--son {
  background: linear-gradient(145deg, #f9d878, #d89e24);
  color: #47320c;
}

.tile--her-1 {
  background-image: url("./assets/her/her-1.jpg");
  background-position: 62% 36%;
}

.tile--her-2 {
  background-image: url("./assets/her/her-2.jpg");
  background-position: 55% 42%;
}

.tile--her-3 {
  background-image: url("./assets/her/her-3.jpg");
  background-position: 53% 31%;
}

.tile--her-4 {
  background-image: url("./assets/her/her-4.jpg");
  background-position: 52% 45%;
}

.tile--her-5 {
  background-image: url("./assets/her/her-5.jpg");
  background-position: 47% 41%;
}

.tile--you-1 {
  background-image: url("./assets/you/you-1.jpg");
  background-position: 42% 36%;
}

.tile--you-2 {
  background-image: url("./assets/you/you-2.jpg");
  background-position: 50% 41%;
}

.tile--you-3 {
  background-image: url("./assets/you/you-3.jpg");
  background-position: 57% 46%;
}

.tile--you-4 {
  background-image: url("./assets/you/you-4.jpg");
  background-position: 50% 50%;
}

.tile--you-5 {
  background-image: url("./assets/you/you-5.jpg");
  background-position: 48% 38%;
}

.tile--son-photo {
  background-image: url("./assets/son.jpg");
  background-position: 52% 40%;
}

.tile--photo {
  background-repeat: no-repeat;
  background-size: cover;
}

.tile--new {
  animation: appear 180ms ease both;
}

.tile--merged {
  animation: pop 220ms ease both;
}

.status-text {
  color: rgba(255, 248, 239, 0.7);
  font-size: 0.92rem;
  line-height: 1.5;
  margin: 14px 2px 0;
  text-align: center;
}

.hidden {
  display: none !important;
}

.ending,
.retry {
  align-items: center;
  background:
    radial-gradient(circle at 50% 22%, rgba(240, 195, 90, 0.2), transparent 30%),
    linear-gradient(180deg, rgba(13, 10, 11, 0.92), rgba(13, 10, 11, 0.98));
  display: flex;
  inset: 0;
  justify-content: center;
  overflow: hidden;
  padding: 12px;
  position: fixed;
  z-index: 10;
}

.ending-card,
.retry-panel {
  align-items: center;
  color: #fff8ef;
  display: flex;
  flex-direction: column;
  max-width: 420px;
  text-align: center;
  width: 100%;
}

.ending-card {
  height: calc(100svh - 24px);
  justify-content: center;
  max-height: none;
  padding: 0;
}

.son-placeholder {
  align-items: center;
  animation: sonIn 620ms ease both;
  background: url("./assets/son.jpg") 52% 42% / cover;
  border-radius: 8px;
  box-shadow: 0 22px 80px rgba(216, 158, 36, 0.32);
  color: #fff8ef;
  display: flex;
  font-size: clamp(1.5rem, 6vw, 1.9rem);
  font-weight: 900;
  height: min(42vw, 180px);
  justify-content: center;
  margin-bottom: 12px;
  overflow: hidden;
  position: relative;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  width: min(42vw, 180px);
}

.son-placeholder::before {
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.36));
  content: "";
  inset: 0;
  position: absolute;
}

.ending-lines {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  min-height: 0;
  overflow: visible;
  padding: 0 2px;
}

.ending-lines p {
  animation: lineIn 420ms ease both;
  font-size: clamp(0.84rem, 3.45vw, 0.98rem);
  line-height: 1.42;
  margin: 0;
}

.retry-panel {
  background: #fff8ef;
  border-radius: 8px;
  color: var(--ink);
  padding: 28px 22px;
}

.retry-panel p {
  font-size: 1.4rem;
  font-weight: 800;
  margin: 0 0 18px;
}

.primary-button {
  background: #fff8ef;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  min-height: 46px;
  padding: 0 22px;
}

.ending .primary-button {
  flex: 0 0 auto;
  min-height: 42px;
  padding: 0 20px;
  position: static;
}

.retry-panel .primary-button {
  background: var(--ink);
  color: #fff8ef;
}

@keyframes appear {
  from {
    opacity: 0;
    transform: translate(var(--x), var(--y)) scale(0.72);
  }
  to {
    opacity: 1;
    transform: translate(var(--x), var(--y)) scale(1);
  }
}

@keyframes pop {
  0%,
  100% {
    transform: translate(var(--x), var(--y)) scale(1);
  }
  55% {
    transform: translate(var(--x), var(--y)) scale(1.1);
  }
}

@keyframes sonIn {
  from {
    opacity: 0;
    transform: scale(0.86);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

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