/*
 * Flip Match — memory game styling for sourcestrongai.com/games/flip-match/
 *
 * Look: warm cream ground, ink outlines, and card backs painted with the
 * brand slash motif. Cards flip in true 3D (CSS perspective + backface
 * visibility), matches pop, wins confetti. Mobile-first.
 */

:root {
  --cream: #fff7ec;
  --card-face: #ffffff;
  --ink: #1a1a1a;
  --ink2: #6b6156;
  --orange: #ff5e00;
  --orange-text: #c2410c; /* AA-safe orange for text on cream */
  --orange-ring: #d94f00; /* 3:1+ non-text focus ring on cream */
  --gold: #ffc432;
  --teal: #0e9f8c;
  --shadow: 4px 4px 0 rgba(26, 26, 26, 0.9);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(700px 420px at 110% -5%, rgba(255, 196, 50, 0.25), transparent 60%),
    radial-gradient(600px 400px at -10% 20%, rgba(255, 94, 0, 0.12), transparent 55%), var(--cream);
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-font-smoothing: antialiased;
}

#fx-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 40;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  z-index: 50;
}
.skip-link:focus {
  left: 0;
}

.noscript-card {
  max-width: 420px;
  margin: 18vh auto 0;
  padding: 22px;
  background: #fff;
  border: 2px solid var(--ink);
  box-shadow: var(--shadow);
  line-height: 1.55;
}
.noscript-card a {
  color: var(--orange);
}
.noscript-title {
  margin-top: 0;
}

.mini-header {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-wrap: wrap; /* 320px: brand + links cannot share one row */
  justify-content: space-between;
  align-items: center;
  gap: 4px 10px;
  padding: 14px 16px 6px;
}
.brand-link {
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
}
.brand-link .accent {
  color: var(--orange-text);
}
.mini-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.more-games {
  color: var(--ink2);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}
.more-games:hover {
  color: var(--orange-text);
}

.chip-btn {
  min-height: 44px;
  padding: 0 13px;
  border: 2px solid var(--ink);
  border-radius: 99px;
  background: #fff;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.game-title {
  margin: 8px 0 0;
  font-size: clamp(1.7rem, 7vw, 2.4rem);
  font-weight: 900;
  letter-spacing: 0.02em;
}
.game-title .accent {
  color: var(--orange-text);
}

.topbar {
  width: 100%;
  max-width: 720px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 0 16px;
}
.seg {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 rgba(26, 26, 26, 0.9);
}
.seg button {
  min-height: 44px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  opacity: 0.6;
  font-size: 0.85rem;
  font-weight: 800;
  padding: 0 14px;
  cursor: pointer;
  transition:
    background 0.15s ease-out,
    opacity 0.15s ease-out;
  touch-action: manipulation;
}
.seg button[aria-checked='true'] {
  background: var(--orange);
  color: #1a1a1a; /* ink on orange passes AA at this size */
  opacity: 1;
}

/* ---------- HUD ---------- */

.hud {
  width: 100%;
  max-width: 560px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 16px 4px;
}
@media (max-width: 430px) {
  .hud {
    grid-template-columns: repeat(2, 1fr);
  }
}
.hud-item {
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: 3px 3px 0 rgba(26, 26, 26, 0.9);
  padding: 7px 10px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.hud-item span {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink2);
}
.hud-item b {
  font-size: 0.98rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

/* ---------- board & cards ---------- */

.board {
  width: min(94vw, 640px);
  margin: 10px auto 0;
  display: grid;
  gap: clamp(6px, 1.6vw, 11px);
  perspective: 1100px;
}

.card {
  position: relative;
  aspect-ratio: 3 / 4;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  outline-offset: 3px;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.card:focus-visible {
  outline: 3px solid var(--orange-ring);
}
.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.42s cubic-bezier(0.3, 1.4, 0.45, 1);
}
.card.flipped .card-inner,
.card.matched .card-inner {
  transform: rotateY(180deg);
}

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 2.5px solid var(--ink);
  border-radius: clamp(9px, 2vw, 14px);
  box-shadow: 3px 3px 0 rgba(26, 26, 26, 0.85);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.face-back {
  /* the brand slash motif on a warm gradient — unmistakably ours */
  background: linear-gradient(135deg, #ffd9a8 0%, #ffb066 100%);
}
.face-back::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top right,
    transparent calc(50% - 14%),
    rgba(255, 255, 255, 0.85) calc(50% - 14%),
    rgba(255, 255, 255, 0.85) calc(50% + 6%),
    transparent calc(50% + 6%)
  );
  opacity: 0.9;
}
.face-back::before {
  content: '?';
  position: relative;
  z-index: 1;
  font-weight: 900;
  font-size: clamp(1rem, 4vw, 1.5rem);
  color: var(--ink);
  opacity: 0.35;
}

.face-front {
  background: var(--card-face);
  transform: rotateY(180deg);
  font-size: clamp(1.5rem, 6vw, 2.4rem);
  line-height: 1;
}

.card.matched {
  pointer-events: none;
}
.card.matched .face-front {
  background: #ecfdf3;
  border-color: var(--teal);
  box-shadow: 3px 3px 0 var(--teal);
  animation: matchPop 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
}
@keyframes matchPop {
  0% {
    transform: rotateY(180deg) scale(1);
  }
  50% {
    transform: rotateY(180deg) scale(1.12);
  }
  100% {
    transform: rotateY(180deg) scale(1);
  }
}
.card.shake {
  animation: cardShake 0.4s ease-out;
}
@keyframes cardShake {
  20%,
  60% {
    translate: -5px 0;
  }
  40%,
  80% {
    translate: 5px 0;
  }
}

/* ---------- actions / footer ---------- */

.actions {
  margin-top: 16px;
}
.btn-primary {
  border: none;
  background: var(--orange);
  color: #fff;
  font-size: 1.2rem; /* ≥18.66px bold = large text: 3:1 floor applies */
  font-weight: 900;
  letter-spacing: 0.03em;
  padding: 14px 34px;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 4px 4px 0 rgba(26, 26, 26, 0.9);
  transition:
    transform 0.08s ease-out,
    box-shadow 0.08s ease-out;
  touch-action: manipulation;
}
.btn-primary:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 rgba(26, 26, 26, 0.9);
}

.hint-line {
  color: var(--ink2);
  font-size: 0.82rem;
  text-align: center;
  padding: 0 16px;
}

.mini-footer {
  margin-top: auto;
  padding: 18px 0 16px;
  display: flex;
  gap: 10px;
  color: var(--ink2);
  font-size: 0.85rem;
}
.mini-footer a {
  color: var(--ink2);
  text-decoration: none;
}
.mini-footer a:hover {
  color: var(--orange-text);
}

/* landscape tablets (e.g. 1024×768): cap the board so the default 4×3
   fits the viewport without scrolling */
@media (orientation: landscape) and (min-height: 501px) and (max-height: 940px) {
  .board {
    /* 336px floor keeps 6-col cells ≥46px wide on short landscape tablets */
    width: min(94vw, 640px, max(336px, calc(100dvh - 293px)));
  }
}

/* landscape phones: re-proportion the board to the short viewport */
@media (orientation: landscape) and (max-height: 500px) {
  .card {
    aspect-ratio: 4 / 3;
  }
  .board {
    /* 224px floor keeps 4-col cells ≥56px wide — the dvh cap alone would
       collapse phones-in-landscape below touch minimum */
    width: min(94vw, 640px, max(224px, calc((100dvh - 150px) * 4 / 3)));
  }
  .win-banner .win-inner {
    padding: 10px 18px 12px;
    gap: 3px;
  }
  .win-banner .win-emoji {
    font-size: 1.4rem;
  }
  .win-banner .win-title {
    font-size: 1.05rem;
  }
  .win-banner .btn-primary {
    min-height: 44px;
    padding: 8px 22px;
    font-size: 1rem;
  }
}

/* ---------- win banner ---------- */

.win-banner {
  position: fixed;
  inset: auto 0 calc(env(safe-area-inset-bottom) + 14px);
  display: flex;
  justify-content: center;
  z-index: 30;
  pointer-events: none;
}
.hidden {
  display: none !important;
}
.win-banner.hidden {
  display: none;
}
.win-inner {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 6px 6px 0 rgba(26, 26, 26, 0.9);
  padding: 16px 26px 18px;
  animation: winIn 0.45s cubic-bezier(0.22, 1.4, 0.36, 1);
}
@keyframes winIn {
  from {
    transform: translateY(30px) scale(0.92);
    opacity: 0;
  }
}
.win-emoji {
  font-size: 2rem;
}
.win-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}
.win-line {
  margin: 0;
  color: var(--ink2);
  font-weight: 600;
  font-size: 0.95rem;
}
.win-best {
  margin: 0;
  font-weight: 900;
  letter-spacing: 0.12em;
  font-size: 0.85rem;
  background: linear-gradient(90deg, var(--gold), #ffe9a8, var(--gold));
  padding: 4px 14px;
  border-radius: 99px;
}
.win-banner .btn-primary {
  margin-top: 8px;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--orange-ring);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .card-inner {
    transition-duration: 0.01ms;
  }
  .card.matched .face-front,
  .card.shake,
  .win-inner {
    animation: none;
  }
}
