:root {
  --bg-1: #3a4a5c;
  --bg-2: #212d3a;
  --ink: #16241c;
  --cream: #f2f5f8;
  --accent: #ffb300;
  --accent-dark: #c98600;
  --red: #c62828;
  --panel: rgba(24, 34, 46, 0.92);

  --font-display: "Baloo 2", "Segoe UI", sans-serif;
  --font-body: "Poppins", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

@media(min-width: 1340px) {
	body .card-grid {
		max-width: 1260px;
		grid-template-columns: repeat(auto-fill, minmax(122px, 1fr));
	}
}
html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg-2);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.game-frame {
  position: relative;
  width: 100vw;
  height: calc(100vh - 48px);
  height: calc(100dvh - 48px);
  overflow: hidden;
}

html.ksz-fullscreen .game-frame {
  height: 100vh;
  height: 100dvh;
}

.play-area {
  position: relative;
  width: 100%;
  height: 100%;
  background: radial-gradient(ellipse at 50% 0%, var(--bg-1), var(--bg-2) 75%);
}

.hidden { display: none !important; }

/* ---------------- Screens ---------------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.start-content {
  max-width: 560px;
  text-align: center;
  color: var(--cream);
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.2rem, 8vw, 3.6rem);
  letter-spacing: 2px;
  color: var(--accent);
  text-shadow: 0 3px 0 rgba(0,0,0,0.35);
  margin: 0 0 18px;
}

.hint {
  font-size: 0.96rem;
  line-height: 1.6;
  color: rgba(242,245,248,0.88);
  margin: 0 0 26px;
}

.btnrow {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn-primary, .btn-secondary {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  padding: 14px 28px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn-primary {
  background: var(--accent);
  color: #2b1a00;
  box-shadow: 0 4px 0 var(--accent-dark);
}

.btn-secondary {
  background: transparent;
  color: var(--cream);
  border: 2px solid rgba(242,245,248,0.6);
}

.btn-primary:active, .btn-secondary:active {
  transform: translateY(2px);
}

.btn-primary:hover, .btn-secondary:hover {
  filter: brightness(1.08);
}

/* ---------------- Panels (leaderboard / win) ---------------- */
.panel {
  background: var(--panel);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 28px 32px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  color: var(--cream);
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
}

.panel-title {
  font-family: var(--font-display);
  color: var(--accent);
  font-size: 1.7rem;
  margin: 0 0 18px;
}

.win-time {
  font-size: 1.05rem;
  margin: 0 0 20px;
}

.leaderboard-list {
  list-style: none;
  margin: 0 0 22px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 40vh;
  overflow-y: auto;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 2em 1fr auto auto;
  gap: 10px;
  align-items: center;
  background: rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.92rem;
}

.leaderboard-list li.is-me {
  background: rgba(255,179,0,0.16);
}

.lb-rank { color: var(--accent); font-weight: 700; text-align: left; }
.lb-name { text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-moves { font-weight: 600; }
.lb-time { color: rgba(242,245,248,0.7); }

.lb-empty {
  font-size: 0.9rem;
  color: rgba(242,245,248,0.7);
  margin: 0 0 20px;
}

.highscore-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0 0 20px;
}

.highscore-form label {
  font-size: 0.9rem;
  text-align: left;
}

.highscore-form input {
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 10px 14px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: var(--cream);
}

.highscore-form input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---------------- Fullscreen button ---------------- */
.fullscreen-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 50;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.35);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.fullscreen-btn svg { width: 20px; height: 20px; }
.fullscreen-icon--exit { display: none; }
.fullscreen-btn.is-fullscreen .fullscreen-icon--enter { display: none; }
.fullscreen-btn.is-fullscreen .fullscreen-icon--exit { display: block; }

/* ---------------- HUD ---------------- */
.hud {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 40;
}

.hud-pill {
  background: rgba(0,0,0,0.3);
  border-radius: 999px;
  padding: 6px 16px;
  display: flex;
  gap: 8px;
  align-items: baseline;
  color: var(--cream);
}

.hud-label { font-size: 0.72rem; opacity: 0.75; }
.hud-value { font-family: var(--font-display); font-weight: 700; font-size: 1rem; }

.hud-controls { margin-left: auto; display: flex; gap: 8px; }

.hud-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.3);
  color: var(--cream);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hud-icon-btn:active { transform: translateY(1px); }

/* ---------------- Board / card grid ---------------- */
#screen-game { align-items: stretch; padding: 0; }

.board-viewport {
  position: absolute;
  inset: 0;
  padding: 64px 16px 16px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
}

.card-grid {
  margin: auto;
  width: 100%;
  max-width: 760px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
}

.card {
  aspect-ratio: 3 / 4;
  perspective: 800px;
  cursor: pointer;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.45s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
}

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

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card-front {
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,0.16), transparent 55%),
    linear-gradient(155deg, var(--accent) 0%, var(--accent-dark) 100%);
  border: 2px solid rgba(255,255,255,0.25);
  font-size: 1.6rem;
}

.card-back {
  transform: rotateY(180deg);
  background: var(--cream);
  border: 2px solid rgba(255,255,255,0.5);
  padding: 4px;
}

.card-back img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.card.is-matched {
  cursor: default;
}

.card.is-matched .card-face {
  filter: saturate(0.85) brightness(0.97);
}

.card:not(.is-flipped):not(.is-matched):hover .card-inner {
  transform: translateY(-3px) rotateY(0deg);
}

@media (max-width: 640px) {
  .hint { font-size: 0.88rem; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 8px; }
}
