:root {
  --ink: #27303f;
  --muted: #697286;
  --paper: #fffaf2;
  --rose: #ff8fa3;
  --coral: #ff715b;
  --mint: #72d6bd;
  --aqua: #7bdff2;
  --lemon: #ffd166;
  --lilac: #b8a4ff;
  --leaf: #8fd14f;
  --shadow: 0 18px 40px rgba(39, 48, 63, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Jua", "Nunito", system-ui, sans-serif;
  background:
    radial-gradient(circle at 8% 10%, rgba(255, 209, 102, 0.42), transparent 24rem),
    radial-gradient(circle at 92% 14%, rgba(123, 223, 242, 0.34), transparent 23rem),
    linear-gradient(135deg, #fff7df 0%, #f1fff8 48%, #fff0f4 100%);
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.game-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 32px;
}

.top-panel,
.control-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.top-panel {
  padding: 16px 0 14px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--coral);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.05rem, 6vw, 4.4rem);
  line-height: 0.94;
}

.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(74px, 1fr));
  gap: 8px;
  min-width: min(100%, 420px);
}

.stat {
  min-height: 70px;
  padding: 10px 12px;
  border: 2px solid rgba(39, 48, 63, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  box-shadow: 0 8px 20px rgba(39, 48, 63, 0.08);
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.95rem;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 1.32rem;
  font-weight: 900;
}

.stat.is-warning {
  border-color: rgba(255, 113, 91, 0.62);
  background: rgba(255, 240, 244, 0.9);
}

.stat.is-warning strong {
  color: var(--coral);
}

.control-panel {
  align-items: stretch;
  margin: 10px 0 16px;
}

.level-tabs {
  display: grid;
  grid-template-columns: repeat(10, minmax(36px, 1fr));
  gap: 7px;
  flex: 1;
}

.level-tab,
.icon-button,
.primary-button,
.secondary-button {
  min-height: 44px;
  border: 2px solid rgba(39, 48, 63, 0.12);
  border-radius: 8px;
  color: var(--ink);
  box-shadow: 0 8px 16px rgba(39, 48, 63, 0.1);
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease;
}

.level-tab {
  background: rgba(255, 255, 255, 0.72);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 900;
}

.level-tab.is-active {
  background: var(--lemon);
  border-color: rgba(39, 48, 63, 0.2);
}

.level-tab.is-cleared::after {
  content: "✓";
  display: block;
  margin-top: -4px;
  color: var(--leaf);
  font-size: 0.74rem;
}

.control-actions {
  display: flex;
  gap: 8px;
}

.icon-button,
.primary-button,
.secondary-button {
  padding: 0 18px;
  background: #fff;
  font-size: 1.05rem;
}

.icon-button {
  width: 48px;
  padding: 0;
  background: var(--aqua);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 1.45rem;
  font-weight: 900;
}

.primary-button {
  background: var(--rose);
  color: #fff;
  text-shadow: 0 1px 0 rgba(39, 48, 63, 0.1);
}

.secondary-button {
  background: #fff;
}

.level-tab:hover,
.icon-button:hover,
.primary-button:hover,
.secondary-button:hover,
.card:not(.is-matched):hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 22px rgba(39, 48, 63, 0.14);
}

.board-wrap {
  min-height: 54vh;
  padding: clamp(12px, 2.8vw, 28px);
  border: 3px solid rgba(39, 48, 63, 0.08);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.76), rgba(255, 255, 255, 0.54)),
    repeating-linear-gradient(45deg, rgba(255, 143, 163, 0.1) 0 16px, rgba(114, 214, 189, 0.1) 16px 32px);
  box-shadow: var(--shadow);
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
  gap: clamp(8px, 1.4vw, 14px);
  width: 100%;
  max-width: var(--board-width);
  margin: 0 auto;
}

.card {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.08;
  border-radius: 8px;
  perspective: 900px;
  background: transparent;
  padding: 0;
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 380ms cubic-bezier(0.2, 0.7, 0.25, 1.18);
}

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

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 3px solid rgba(39, 48, 63, 0.14);
  border-radius: 8px;
  backface-visibility: hidden;
  box-shadow: 0 10px 18px rgba(39, 48, 63, 0.12);
}

.card-back {
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.24), transparent),
    var(--card-color);
}

.card-back::before {
  content: "?";
  display: grid;
  place-items: center;
  width: 52%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  color: rgba(39, 48, 63, 0.68);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: clamp(1.55rem, 5vw, 2.75rem);
  font-weight: 900;
}

.card-front {
  transform: rotateY(180deg);
  background: #fff;
}

.card-emoji {
  font-size: clamp(2rem, 7vw, 4.6rem);
  line-height: 1;
}

.card-name {
  position: absolute;
  right: 8px;
  bottom: 6px;
  left: 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: clamp(0.78rem, 1.8vw, 1rem);
  line-height: 1.1;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card.is-matched .card-front {
  border-color: rgba(143, 209, 79, 0.8);
  background: #f6ffe8;
}

.board.is-time-up .card:not(.is-matched) {
  filter: grayscale(0.2) saturate(0.85);
  opacity: 0.72;
  cursor: not-allowed;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(39, 48, 63, 0.46);
  z-index: 10;
}

.modal-backdrop.is-open {
  display: grid;
}

.modal-card {
  width: min(420px, 100%);
  padding: 26px;
  border: 4px solid rgba(39, 48, 63, 0.12);
  border-radius: 8px;
  background: var(--paper);
  text-align: center;
  box-shadow: var(--shadow);
}

.modal-badge {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: var(--lemon);
  color: #fff;
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 2.4rem;
  text-shadow: 0 2px 0 rgba(39, 48, 63, 0.16);
}

.modal-card h2 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.modal-card p {
  margin: 0;
  color: var(--muted);
  font-size: 1.12rem;
  line-height: 1.45;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

@media (max-width: 820px) {
  .top-panel,
  .control-panel {
    flex-direction: column;
  }

  .title-block,
  .stats-bar,
  .level-tabs,
  .control-actions {
    width: 100%;
  }

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

@media (max-width: 560px) {
  .game-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 12px;
  }

  .level-tabs {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .board-wrap {
    padding: 10px;
  }

  .modal-actions,
  .control-actions {
    flex-direction: column;
  }

  .icon-button,
  .primary-button,
  .secondary-button {
    width: 100%;
  }
}
