:root {
  color-scheme: light;
  --ink: #463249;
  --muted: #806f85;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #fff9fb;
  --pink: #ff8fb7;
  --pink-deep: #df5f94;
  --mint: #9fe8d2;
  --lemon: #ffe180;
  --sky: #9bdcff;
  --lavender: #c8a8ff;
  --rose-shadow: rgba(214, 84, 137, 0.26);
  --shadow: 0 22px 55px rgba(120, 80, 130, 0.18);
  font-family:
    Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system,
    BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255, 143, 183, 0.16), transparent 34%),
    linear-gradient(220deg, rgba(159, 232, 210, 0.26), transparent 38%),
    linear-gradient(0deg, #fff7c9, #fff8fc 48%, #effbff);
}

button,
label {
  font: inherit;
}

.game-shell {
  width: min(1180px, calc(100% - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 26px 0;
  display: grid;
  place-items: center;
}

.game-panel {
  width: 100%;
  padding: clamp(16px, 3vw, 30px);
  border: 2px solid rgba(255, 143, 183, 0.38);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark,
.dialog-art {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  border: 3px solid #fff;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--lavender) 55%, var(--sky));
  box-shadow: 0 10px 22px var(--rose-shadow);
  font-weight: 900;
  font-size: 1.25rem;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.55rem, 4vw, 2.55rem);
  line-height: 1;
  letter-spacing: 0;
}

.subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-weight: 650;
}

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

.upload-button {
  display: none !important;
}

#photoUpload {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.icon-button,
.primary-button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--pink-deep);
  box-shadow: 0 10px 20px rgba(223, 95, 148, 0.24);
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    filter 160ms ease;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  font-weight: 800;
}

.icon-button span:first-child {
  font-size: 1.35rem;
  line-height: 1;
}

.icon-button:hover,
.primary-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 24px rgba(223, 95, 148, 0.32);
  filter: saturate(1.05);
}

.icon-button:focus-visible,
.primary-button:focus-visible,
.card:focus-visible {
  outline: 4px solid rgba(155, 220, 255, 0.72);
  outline-offset: 3px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stats > div {
  min-width: 0;
  padding: 12px;
  border: 2px solid rgba(255, 143, 183, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stats strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.15rem, 3vw, 1.55rem);
  line-height: 1.05;
}

.board-wrap {
  width: 100%;
  display: grid;
  place-items: center;
}

.board {
  width: min(100%, 900px);
  display: grid;
  grid-template-columns: repeat(var(--columns, 4), minmax(74px, 1fr));
  gap: clamp(9px, 2vw, 16px);
  perspective: 1200px;
}

.card {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  border-radius: 8px;
  background: var(--panel-solid);
  cursor: pointer;
  isolation: isolate;
  transform-style: preserve-3d;
}

.card[disabled] {
  cursor: default;
}

.card-inner {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  transform-style: preserve-3d;
  transition: transform 420ms cubic-bezier(0.2, 0.82, 0.28, 1);
  will-change: transform;
}

.card.is-flipped .card-inner,
.card.is-matched .card-inner {
  transform: rotateY(180deg);
}

.card-front,
.card-back {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: inherit;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-style: preserve-3d;
}

.card-front {
  transform: translateZ(1px);
  border: 2px solid rgba(223, 95, 148, 0.35);
  background:
    radial-gradient(circle at 24% 20%, rgba(255, 255, 255, 0.9) 0 9%, transparent 10%),
    radial-gradient(circle at 76% 74%, rgba(255, 255, 255, 0.82) 0 8%, transparent 9%),
    repeating-linear-gradient(
      45deg,
      rgba(255, 143, 183, 0.22) 0 12px,
      rgba(155, 220, 255, 0.2) 12px 24px
    ),
    #fff0f7;
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.68);
}

.card-front::before {
  content: "JL";
  display: grid;
  place-items: center;
  width: 48%;
  aspect-ratio: 1;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--mint));
  box-shadow: 0 12px 28px rgba(70, 50, 73, 0.14);
  font-size: clamp(1.1rem, 4vw, 2rem);
  font-weight: 950;
}

.card-back {
  transform: rotateY(180deg) translateZ(1px);
  border: 2px solid rgba(255, 255, 255, 0.9);
  background: var(--panel-solid);
  box-shadow: 0 12px 26px rgba(70, 50, 73, 0.16);
}

.tile-art,
.custom-art {
  width: 100%;
  height: 100%;
}

.tile-art {
  background-image: url("../../assets/jl-sprites.png");
  background-size: 300% 200%;
  background-position: var(--sprite-x) var(--sprite-y);
}

.custom-art {
  object-fit: cover;
  display: block;
}

.card.is-matched .card-back {
  border-color: rgba(159, 232, 210, 0.95);
  box-shadow:
    0 12px 26px rgba(70, 50, 73, 0.12),
    0 0 0 5px rgba(159, 232, 210, 0.26);
}

.card.just-matched::after {
  content: "";
  position: absolute;
  inset: -6px;
  z-index: 2;
  border: 3px solid rgba(159, 232, 210, 0.9);
  border-radius: 10px;
  box-shadow:
    0 0 0 0 rgba(255, 143, 183, 0.32),
    0 0 24px rgba(159, 232, 210, 0.5);
  opacity: 0;
  pointer-events: none;
  animation: match-glow 720ms ease both;
}

.match-burst {
  position: fixed;
  z-index: 20;
  width: 0;
  height: 0;
  pointer-events: none;
}

.match-particle {
  position: absolute;
  left: 0;
  top: 0;
  width: 10px;
  height: 10px;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 999px;
  background: var(--particle-color);
  box-shadow: 0 6px 12px rgba(70, 50, 73, 0.16);
  animation: sparkle-burst 760ms cubic-bezier(0.18, 0.84, 0.28, 1) forwards;
}

@keyframes match-glow {
  0% {
    opacity: 0;
    box-shadow:
      0 0 0 0 rgba(255, 143, 183, 0.28),
      0 0 18px rgba(159, 232, 210, 0.3);
  }

  38% {
    opacity: 1;
    box-shadow:
      0 0 0 9px rgba(255, 143, 183, 0),
      0 0 30px rgba(159, 232, 210, 0.72);
  }

  100% {
    opacity: 0;
    box-shadow:
      0 0 0 15px rgba(255, 143, 183, 0),
      0 0 22px rgba(159, 232, 210, 0);
  }
}

@keyframes sparkle-burst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.3);
  }

  18% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(calc(var(--x) - 50%), calc(var(--y) - 50%)) scale(1.1);
  }
}

.win-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 28px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: #fff9fb;
  box-shadow: var(--shadow);
  text-align: center;
}

.win-dialog::backdrop {
  background: rgba(70, 50, 73, 0.22);
  backdrop-filter: blur(4px);
}

.dialog-art {
  width: 76px;
  height: 76px;
  margin: 0 auto 14px;
  font-size: 1.5rem;
}

.dialog-picture {
  width: min(210px, 70vw);
  height: auto;
  aspect-ratio: 3 / 4;
  padding: 0;
  overflow: hidden;
  background: #fff;
}

.dialog-picture .tile-art,
.dialog-picture .custom-art {
  border-radius: 5px;
}

.win-dialog h2 {
  font-size: 1.8rem;
  letter-spacing: 0;
}

.win-dialog p {
  margin: 9px 0 20px;
  color: var(--muted);
  font-weight: 700;
}

.primary-button {
  width: 100%;
  padding: 13px 18px;
  font-weight: 900;
}

@media (max-width: 760px) {
  .game-shell {
    width: min(100% - 18px, 620px);
    padding: 10px 0;
    align-items: start;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    width: 100%;
    justify-content: stretch;
  }

  .icon-button,
  .upload-button {
    flex: 1 1 0;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board {
    grid-template-columns: repeat(3, minmax(70px, 1fr));
  }
}

@media (max-width: 390px) {
  .game-panel {
    padding: 12px;
  }

  .brand-mark {
    width: 50px;
    height: 50px;
  }

  .button-text {
    display: none;
  }

  .stats > div {
    padding: 10px;
  }

  .board {
    gap: 8px;
  }
}

.utility-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.utility-link {
  min-height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  text-decoration: none;
  color: var(--pink-deep);
  background: rgba(255, 255, 255, 0.82);
  border: 2px solid rgba(255, 143, 183, 0.24);
  font-size: 0.82rem;
  font-weight: 800;
}

.utility-link-secondary {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.66);
}

.utility-link:hover,
.utility-link:focus-visible {
  transform: translateY(-1px);
  outline: 4px solid rgba(155, 220, 255, 0.72);
  outline-offset: 3px;
}
