@font-face {
  font-family: "IHH Sans";
  font-weight: 300;
  font-style: normal;
  font-display: swap;
  src:
    url("./fonts/IHHSans-Light.woff2") format("woff2"),
    url("./fonts/IHHSans-Light.woff") format("woff");
}

@font-face {
  font-family: "IHH Sans";
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src:
    url("./fonts/IHHSans-Regular.woff2") format("woff2"),
    url("./fonts/IHHSans-Regular.woff") format("woff");
}

@font-face {
  font-family: "IHH Sans";
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  src:
    url("./fonts/IHHSans-Bold.woff2") format("woff2"),
    url("./fonts/IHHSans-Bold.woff") format("woff");
}

:root {
  --indigo: #2f3078;
  --indigo-deep: #25265f;
  --purple: #98559e;
  --teal: #78ccc7;
  --white: #ffffff;
  --accent: #78ccc7;
  --bg: #191a45;
  --bg-deep: #13142f;
  --panel: rgba(47, 48, 120, 0.92);
  --panel-strong: rgba(37, 38, 95, 0.96);
  --line: rgba(255, 255, 255, 0.16);
  --shadow: 0 26px 70px rgba(20, 20, 60, 0.34);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 18px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IHH Sans", sans-serif;
  color: var(--white);
  background: linear-gradient(180deg, var(--bg), var(--bg-deep));
}

/* Decorative background glows removed for a clean, even brand blue. */

.app-shell {
  width: 100vw;
  height: 100dvh;
}

.game-card {
  position: relative;
  overflow: hidden;
  width: 100vw;
  height: 100dvh;
  background: var(--panel);
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.primary-button,
.ghost-button {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 14px 16px;
  font: inherit;
}

.primary-button {
  background: var(--accent);
  color: var(--indigo);
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 14px 26px rgba(120, 204, 199, 0.24);
}

.game-card {
  --stage-pad: 28px;
  --hud-height: 64px;
  --board-gap: 14px;
  --leaderboard-height: clamp(150px, 23dvh, 300px);
  --board-height-fit: calc((100dvh - var(--leaderboard-height) - (var(--stage-pad) * 2) - var(--hud-height) - 22px - (var(--board-gap) * 2)) / 3);
  --board-width-fit: calc(((100vw - (var(--stage-pad) * 2)) - (var(--board-gap) * 3)) * 7 / 20);
  --card-height: min(var(--board-height-fit), var(--board-width-fit), 31dvh);
  --card-width: calc(var(--card-height) * 5 / 7);
  background: linear-gradient(180deg, var(--bg), var(--bg-deep));
  display: flex;
  flex-direction: column;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--stage-pad);
}

.game-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(37, 38, 95, 0.5);
  backdrop-filter: blur(3px);
  transition: opacity 220ms ease, visibility 220ms ease;
}

.game-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-panel {
  width: min(100%, 560px);
  position: relative;
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 28px 36px 40px;
  background: rgba(47, 48, 120, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 28px;
  box-shadow: 0 14px 32px rgba(20, 20, 60, 0.2);
  backdrop-filter: blur(18px);
}

/* Result / form views carry a leaderboard or inputs — tighten so the
   action button always fits, while the intro keeps its generous headroom. */
.overlay-panel.is-compact {
  gap: 13px;
  padding: 24px 30px 28px;
}

.overlay-panel.is-compact .overlay-logo {
  width: min(80%, 240px);
  margin: 0 auto;
}

.overlay-panel.is-compact .overlay-message {
  font-size: clamp(1.3rem, 3.4vw, 2rem);
  line-height: 1.24;
}

.overlay-logo {
  width: min(88%, 332px);
  height: auto;
  display: block;
  object-fit: contain;
  margin: 0 auto;
}

.overlay-message {
  margin: 0;
  color: var(--white);
  text-align: center;
  font-size: clamp(1.6rem, 3.2vw, 2.7rem);
  line-height: 1.2;
  font-weight: 600;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.overlay-instructions {
  width: min(100%, 620px);
  margin: 0;
  color: rgba(255, 255, 255, 0.9);
  text-align: center;
  font-size: clamp(1.15rem, 2vw, 1.45rem);
  line-height: 1.55;
  font-weight: 500;
  letter-spacing: 0.005em;
  text-wrap: balance;
}

.game-overlay .primary-button {
  min-width: min(100%, 420px);
  min-height: 96px;
  padding: 24px 40px;
  font-size: clamp(1.6rem, 2.8vw, 2.25rem);
  font-weight: 700;
  border-radius: 999px;
}

.game-overlay:not(.hidden) .overlay-panel {
  animation: overlay-panel-in 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.game-overlay:not(.hidden) .overlay-logo {
  animation: overlay-item-in 520ms 80ms both;
}

.game-overlay:not(.hidden) .overlay-instructions {
  animation: overlay-item-in 520ms 160ms both;
}

.game-overlay:not(.hidden) .overlay-message:not([hidden]) {
  animation: overlay-item-in 520ms 120ms both;
}

.game-overlay:not(.hidden) .primary-button {
  animation:
    overlay-item-in 520ms 240ms both,
    overlay-button-breathe 2.6s ease-in-out 900ms infinite;
}

@keyframes overlay-panel-in {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.97);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes overlay-item-in {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes overlay-button-breathe {
  0%,
  100% {
    transform: translateY(0);
    box-shadow:
      0 14px 26px rgba(120, 204, 199, 0.28),
      0 0 20px rgba(120, 204, 199, 0.26);
  }

  50% {
    transform: translateY(0);
    box-shadow:
      0 18px 34px rgba(120, 204, 199, 0.36),
      0 0 48px rgba(120, 204, 199, 0.52),
      0 0 76px rgba(120, 204, 199, 0.24);
  }
}

.hud {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.playfield {
  width: calc((var(--card-width) * 4) + (var(--board-gap) * 3));
  max-width: 100%;
  display: grid;
  gap: 22px;
  align-content: center;
}

.timer-bar {
  --timer-progress: 100%;
  position: relative;
  width: 100%;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.5);
  box-shadow: inset 0 1px 3px rgba(20, 20, 60, 0.18);
}

.timer-bar::before {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--timer-progress);
  background: var(--accent);
  transition: none;
}

.timer-bar strong {
  position: relative;
  z-index: 1;
  font-size: 1.9rem;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--indigo);
}

.game-board {
  display: grid;
  grid-template-columns: repeat(4, var(--card-width));
  grid-template-rows: repeat(3, var(--card-height));
  gap: var(--board-gap);
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  perspective: 1200px;
  -webkit-perspective: 1200px;
}

.memory-card {
  position: relative;
  width: var(--card-width);
  height: var(--card-height);
  border-radius: 20px;
  border: none;
  padding: 0;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  transition: transform 220ms ease;
  background: transparent;
  overflow: hidden;
  will-change: transform;
}

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

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transition: transform 320ms ease, filter 220ms ease;
  box-shadow: 0 8px 18px rgba(20, 20, 60, 0.18);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  overflow: hidden;
  background-color: rgba(8, 22, 48, 0.01);
}

.card-front {
  transform: rotateY(0deg);
  -webkit-transform: rotateY(0deg);
  border: none;
}

.card-back {
  transform: rotateY(-180deg);
  -webkit-transform: rotateY(-180deg);
  border: none;
}

.memory-card.flipped .card-front {
  transform: rotateY(180deg);
  -webkit-transform: rotateY(180deg);
}

.memory-card.flipped .card-back {
  transform: rotateY(0deg);
  -webkit-transform: rotateY(0deg);
}

.memory-card.matched .card-back {
  box-shadow:
    inset 0 0 0 3px rgba(120, 204, 199, 0.95),
    0 8px 18px rgba(20, 20, 60, 0.18);
}

.memory-card.celebrate {
  animation: matched-card-celebrate 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes matched-card-celebrate {
  0% {
    transform: scale(1);
  }

  45% {
    transform: scale(1.07);
  }

  100% {
    transform: scale(1);
  }
}

.leaderboard {
  width: 100%;
  display: grid;
  gap: 12px;
}

.leaderboard-title {
  margin: 0 0 2px;
  text-align: center;
  font-size: clamp(1.1rem, 2.4vw, 1.55rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  width: 100%;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 1.6em 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 11px 18px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.09);
  font-size: clamp(1rem, 2vw, 1.35rem);
  line-height: 1.2;
}

.leaderboard-row.is-you {
  background: var(--teal);
  color: var(--indigo);
  font-weight: 700;
}

.lb-rank {
  font-weight: 700;
  opacity: 0.85;
  text-align: center;
}

.lb-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.005em;
}

.lb-time {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.leaderboard-empty {
  list-style: none;
  text-align: center;
  opacity: 0.8;
  padding: 14px 8px;
}

.lead-form {
  width: 100%;
  display: grid;
  gap: 12px;
}

.lead-input {
  width: 100%;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.96);
  color: var(--indigo);
  font: inherit;
  font-size: clamp(1.05rem, 2.2vw, 1.4rem);
}

.lead-input::placeholder {
  color: rgba(47, 48, 120, 0.5);
}

.form-hint {
  margin: -4px 4px 0;
  text-align: left;
  font-size: clamp(0.85rem, 1.8vw, 1rem);
  line-height: 1.4;
  letter-spacing: 0.01em;
  color: rgba(255, 255, 255, 0.62);
}

.form-error {
  margin: 0;
  text-align: center;
  font-weight: 600;
  color: #ffd2d2;
}

/* Persistent bottom leaderboard (medal columns) */
.board-leaderboard {
  flex: 0 0 var(--leaderboard-height);
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px clamp(12px, 2vw, 22px) clamp(14px, 2vw, 20px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(20, 20, 60, 0.32);
}

.bl-title {
  margin: 0;
  font-size: clamp(0.68rem, 1.5vw, 0.82rem);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--teal);
}

.bl-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: clamp(8px, 1.4vw, 14px);
}

.bl-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.4vh, 14px);
  padding: 12px 8px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.015));
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.bl-col.rank-1 {
  background: linear-gradient(180deg, rgba(244, 198, 74, 0.16), rgba(244, 198, 74, 0.03));
  border-color: rgba(244, 198, 74, 0.32);
}

.bl-col.is-you {
  outline: 2px solid var(--teal);
  outline-offset: -2px;
}

.bl-col.bl-empty {
  opacity: 0.55;
}

.bl-medal {
  width: clamp(40px, 8vw, 58px);
  height: clamp(40px, 8vw, 58px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: clamp(1rem, 2.4vw, 1.35rem);
  color: #1b1b32;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28);
}

.medal-1 { background: linear-gradient(145deg, #f8d976, #e0a836); }
.medal-2 { background: linear-gradient(145deg, #e6ecf2, #aab4c0); }
.medal-3 { background: linear-gradient(145deg, #e0a06a, #c1743f); }
.medal-4 { background: linear-gradient(145deg, #62b2ea, #3a82c6); color: #fff; }
.medal-5 { background: linear-gradient(145deg, #70d182, #44a958); color: #fff; }

.bl-empty .bl-medal {
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.5);
  box-shadow: none;
}

.bl-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: clamp(0.85rem, 1.9vw, 1.15rem);
  letter-spacing: 0.005em;
  color: var(--white);
}

.bl-time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  color: rgba(255, 255, 255, 0.92);
}

.bl-col.rank-1 .bl-time {
  color: #f4c64a;
}

.bl-empty .bl-name,
.bl-empty .bl-time {
  color: rgba(255, 255, 255, 0.45);
}

@media (max-width: 900px) {
  .app-shell {
    width: 100%;
    height: 100dvh;
  }

  .game-card {
    --stage-pad: 18px;
    --hud-height: 54px;
    --board-gap: 10px;
    --leaderboard-height: clamp(128px, 20dvh, 230px);
    --card-height: min(var(--board-height-fit), var(--board-width-fit), 24dvh);
    width: 100%;
    height: 100dvh;
    aspect-ratio: auto;
  }

  .playfield {
    gap: 16px;
  }

  .hud {
    gap: 10px;
  }

  .overlay-panel {
    width: 100%;
    padding: 44px 24px 28px;
  }
}

@media (max-width: 420px) {
  .game-card {
    padding: 16px;
  }

  .overlay-panel {
    padding: 36px 18px 24px;
  }

  .timer-bar {
    height: 40px;
  }

  .timer-bar strong {
    font-size: 1.6rem;
  }
}

@media (orientation: portrait) {
  .game-card {
    --stage-pad: 20px;
    --board-gap: 14px;
  }

  .playfield {
    gap: 28px;
  }

  .hud {
    flex-direction: row;
    gap: 16px;
  }

  .timer-bar {
    height: 56px;
  }

  .timer-bar strong {
    font-size: 2.2rem;
  }

  .overlay-panel {
    width: min(100%, 720px);
    gap: 28px;
    padding: 64px 44px 48px;
  }

  .overlay-logo {
    width: min(86%, 458px);
  }

  .overlay-message {
    font-size: clamp(2rem, 5.5vw, 4rem);
  }

  .overlay-instructions {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
  }

  .game-overlay .primary-button {
    min-height: 110px;
    font-size: clamp(2rem, 5vw, 3rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
