:root {
  --bg-top: #10243d;
  --bg-bottom: #275a6a;
  --panel: rgba(8, 21, 36, 0.78);
  --panel-border: rgba(255, 255, 255, 0.16);
  --text: #f5f7fb;
  --muted: #c7d3e3;
  --accent: #ffb703;
  --accent-deep: #ef8f00;
  --card-shadow: 0 20px 40px rgba(0, 0, 0, 0.28);
  --match-glow: rgba(101, 214, 145, 0.92);
  --error: #ffd3d3;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background-color: var(--bg-bottom);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.18), transparent 30%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  background-attachment: fixed, fixed;
  background-repeat: no-repeat, no-repeat;
  background-size: 100% 100%, 100% 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

button,
input {
  font: inherit;
}

.page-shell {
  width: min(1100px, 100%);
  margin: 0 auto;
  min-height: 100%;
  padding: 14px 12px 16px;
}

.hero {
  text-align: center;
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.admin-link-wrap {
  margin: 0;
}

.admin-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
}

.admin-link:hover {
  color: var(--text);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.3rem);
  line-height: 1;
}

.status-bar {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.status-pill {
  min-width: 130px;
  padding: 12px 16px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}

.status-pill span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-pill strong {
  font-size: 1.2rem;
}

.game-board-wrap {
  height: calc(100vh - 16px);
  height: calc(100dvh - 16px);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  background: var(--panel);
  box-shadow: var(--card-shadow);
  padding: 10px;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.game-board {
  display: grid;
  --board-columns: 4;
  --board-rows: 5;
  grid-template-columns: repeat(var(--board-columns), minmax(0, 1fr));
  grid-template-rows: repeat(var(--board-rows), minmax(0, 1fr));
  gap: 8px;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
}

.desktop-wide-board .memory-card.desktop-last-row:nth-child(17) {
  grid-column: 3;
}

.desktop-wide-board .memory-card.desktop-last-row:nth-child(18) {
  grid-column: 4;
}

.desktop-wide-board .memory-card.desktop-last-row:nth-child(19) {
  grid-column: 5;
}

.desktop-wide-board .memory-card.desktop-last-row:nth-child(20) {
  grid-column: 6;
}

.memory-card {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  perspective: 1200px;
}

.memory-card[disabled] {
  cursor: default;
}

.memory-card-inner {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.65s ease;
}

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

.memory-card-face {
  display: block;
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: var(--card-shadow);
}

.memory-card-front,
.memory-card-back {
  border: 3px solid transparent;
}

.memory-card-back img,
.memory-card-front img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.memory-card-back {
  background: #13283f;
}

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

.memory-card-title {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 6px 4px;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.8));
  color: #fff;
  font-size: clamp(0.5rem, 1.55vw, 0.82rem);
  font-weight: 700;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.memory-card.just-matched .memory-card-front {
  animation: matchBlink 0.65s ease 1;
}

@keyframes matchBlink {
  0%,
  100% {
    border-color: transparent;
    box-shadow: var(--card-shadow);
  }

  50% {
    border-color: var(--match-glow);
    box-shadow: 0 0 0 4px rgba(101, 214, 145, 0.22), var(--card-shadow);
  }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(4, 12, 24, 0.72);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.hidden {
  display: none;
}

.modal-card {
  width: min(460px, 100%);
  max-height: min(92vh, 92dvh);
  overflow: auto;
  padding: 28px 22px;
  border-radius: 26px;
  background: rgba(7, 18, 32, 0.95);
  border: 1px solid var(--panel-border);
  box-shadow: var(--card-shadow);
  text-align: center;
}

.modal-copy {
  color: var(--muted);
  margin-bottom: 18px;
}

.primary-button,
.secondary-button {
  width: 100%;
  border: 0;
  border-radius: 999px;
  padding: 14px 18px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  color: #17263a;
  background: linear-gradient(180deg, #ffd166, var(--accent));
}

.secondary-button {
  margin-top: 14px;
  background: rgba(255, 255, 255, 0.14);
  color: var(--text);
}

.leaderboard {
  margin-top: 22px;
  text-align: left;
}

.leaderboard h3 {
  margin-bottom: 10px;
}

.score-list {
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
}

.score-list li {
  margin-bottom: 8px;
}

.score-form {
  margin-top: 18px;
  text-align: left;
}

.score-form label {
  display: block;
  margin-bottom: 8px;
  font-weight: 700;
}

.score-form input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 14px;
  padding: 12px 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
}

.error-text {
  min-height: 1.2rem;
  margin: 8px 0 14px;
  color: var(--error);
}

@media (max-width: 720px) {
  .page-shell {
    padding: 10px 8px 10px;
  }

  .game-board-wrap {
    height: calc(100vh - 12px);
    height: calc(100dvh - 12px);
    padding: 8px;
    border-radius: 18px;
  }

  .game-board {
    gap: 6px;
  }

  h1 {
    font-size: clamp(1.4rem, 7vw, 2rem);
  }

  .eyebrow {
    margin-bottom: 0;
    font-size: 0.72rem;
  }

  .status-bar {
    gap: 8px;
  }

  .status-pill {
    min-width: 108px;
    padding: 8px 12px;
  }

  .status-pill span {
    font-size: 0.72rem;
  }

  .status-pill strong {
    font-size: 1rem;
  }

  .memory-card-face {
    border-radius: 10px;
  }

  .memory-card-front,
  .memory-card-back {
    border-width: 2px;
  }

  .memory-card-title {
    padding: 4px 3px;
    font-size: clamp(0.42rem, 2.2vw, 0.6rem);
  }

  .modal-card {
    padding: 20px 16px;
  }
}
