/* ============================================================
   Antibiotic Memory — game-specific styles
   Brand tokens, reset, buttons and the .brand__mark live in the
   shared design system (../../css/theme.css); the topbar, HUD,
   overlays, setup choices, score grid and toast live in the shared
   game shell (../../css/game-shell.css). This file layers on both. Card faces are tinted by target class, so
   colour is still part of what you memorise.

   Local token: --cols is set on #board by the layout code.
   ============================================================ */

:root {
  --cols: 4;
  /* Card-back emblem. Declared here (not in theme.css) so the relative url()
     resolves against this file's folder — games/memory/ → ../../assets/. */
  --emblem: url('../../assets/project-emblem.png');
}

/* This game fills the viewport; the board never scrolls on desktop. */
body { overflow: hidden; }

/* ------------------------------------------------------------ shell */

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  padding: clamp(10px, 1.6vw, 20px);
  gap: clamp(10px, 1.4vw, 18px);
}

/* ------------------------------------------------------------ stage */

.stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(250px, 22vw, 320px);
  gap: clamp(10px, 1.4vw, 18px);
  min-height: 0;
}

.board-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
  min-width: 0;
}

/* --card-w is measured in JS so the whole board fits without scrolling. */
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--card-w, minmax(0, 1fr)));
  gap: clamp(6px, 0.85vw, 13px);
  align-content: center;
  justify-content: center;
}

/* ------------------------------------------------------------ cards */

.card {
  position: relative;
  container-type: inline-size;
  aspect-ratio: 4 / 5;
  min-width: 0;
  padding: 0;
  border: none;
  background: none;
  border-radius: var(--radius);
  cursor: pointer;
  perspective: 1100px;
  -webkit-tap-highlight-color: transparent;
  animation: deal 460ms var(--ease) backwards;
  animation-delay: var(--deal-delay, 0ms);
}

@keyframes deal {
  from { opacity: 0; transform: translateY(22px) scale(0.9) rotate(-3deg); }
  to   { opacity: 1; transform: none; }
}

.card__inner {
  position: relative;
  display: block;              /* it's a <span>; preserve-3d needs a real box */
  width: 100%; height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--flip);
  border-radius: inherit;
}

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

.card:hover:not(.is-flipped):not(.is-matched) .card__inner { transform: translateY(-4px) rotateX(6deg); }

.card__face {
  position: absolute;
  inset: 0;
  display: grid;
  border-radius: inherit;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

/* --- back (face-down) --- */

.card__face--back {
  place-items: center;
  background:
    radial-gradient(circle at 30% 22%, rgb(63 138 214 / 0.16), transparent 55%),
    linear-gradient(150deg, #103063, #0a1a38 60%, #0b1730);
  border: 1px solid #23417a;
  box-shadow: inset 0 1px 0 rgb(120 170 240 / 0.12), var(--shadow);
}

/* Gold hairline frame — echoes the logo's blue-outline / gold-fill motif. */
.card__face--back::before {
  content: "";
  position: absolute;
  inset: 7%;
  border-radius: 10px;
  border: 1px solid hsl(43 90% 60% / 0.28);
  pointer-events: none;
}

/* The real project logo on a light medallion — a proper card-back emblem. */
.card__logo {
  width: 66%;
  max-width: 94px;
  aspect-ratio: 1;
  border-radius: 50%;
  background:
    var(--emblem) center / 76% no-repeat,
    radial-gradient(circle at 50% 38%, #ffffff, #e7eef6);
  box-shadow:
    0 7px 18px -6px rgb(0 0 0 / 0.6),
    0 0 0 1px hsl(43 90% 60% / 0.55),
    inset 0 0 0 3px rgb(255 255 255 / 0.55);
  transition: transform 240ms var(--ease), box-shadow 240ms var(--ease);
}
.card:hover:not(.is-flipped):not(.is-matched) .card__logo {
  transform: rotate(6deg) scale(1.06);
  box-shadow:
    0 11px 24px -6px rgb(0 0 0 / 0.7),
    0 0 0 1px hsl(43 90% 62% / 0.9),
    inset 0 0 0 3px rgb(255 255 255 / 0.55);
}

/* --- front (revealed) --- */

.card__face--front {
  transform: rotateY(180deg);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 2%;
  padding: 8% 7%;
  text-align: left;
  overflow: hidden;
  border: 1px solid hsl(var(--hue, 200) 45% 40% / 0.55);
  background:
    linear-gradient(165deg, hsl(var(--hue, 200) 55% 22%), hsl(var(--hue, 200) 45% 13%) 70%, #0d1421);
  box-shadow: inset 0 1px 0 hsl(var(--hue, 200) 60% 60% / 0.22), var(--shadow);
}

/* "Blind" mode: strip the class colour, keep the layout */
.board.no-hints .card__face--front {
  --hue: 218;
  border-color: hsl(218 25% 38% / 0.6);
  background: linear-gradient(165deg, #1b2436, #131a28 70%, #0d1421);
}
.board.no-hints .card__tag { opacity: 0; }

.card__kind {
  font-size: clamp(6px, 8.5cqi, 11px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: hsl(var(--hue, 200) 70% 72%);
}
.board.no-hints .card__kind { color: var(--ink-3); }

.card__body {
  display: grid;
  align-content: center;
  gap: 4%;
  min-height: 0;
  overflow: hidden;
}

.card__title {
  font-size: clamp(10px, 12cqi, 18px);
  font-weight: 650;
  line-height: 1.16;
  letter-spacing: -0.015em;
  color: #fff;
  text-wrap: balance;
  overflow-wrap: break-word;
  hyphens: auto;
  min-width: 0;   /* grid item: let long names like "Aminoglycosides" wrap */
}

/* Subtitles are supporting detail — clip rather than push the tag off-card. */
.card__sub {
  font-size: clamp(7px, 8cqi, 11px);
  line-height: 1.3;
  color: hsl(var(--hue, 200) 30% 76%);
  opacity: 0.86;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.board.no-hints .card__sub { color: var(--ink-2); }

.card__tag {
  justify-self: start;
  font-size: clamp(6px, 7.5cqi, 10px);
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0.35em 0.7em;
  border-radius: 999px;
  color: hsl(var(--hue, 200) 80% 80%);
  background: hsl(var(--hue, 200) 70% 50% / 0.18);
  border: 1px solid hsl(var(--hue, 200) 70% 60% / 0.3);
  transition: opacity 200ms;
}

/* Very small cards (18-pair board): drop the least important text. */
@container (max-width: 108px) {
  .card__sub { display: none; }
  .card__face--front { padding: 9% 8%; }
}

/* --- states --- */

.card.is-matched {
  cursor: default;
  animation: locked 620ms var(--ease);
}
.card.is-matched .card__face--front {
  border-color: hsl(var(--hue, 200) 70% 60% / 0.9);
  box-shadow:
    inset 0 1px 0 hsl(var(--hue, 200) 70% 70% / 0.3),
    0 0 0 1px hsl(var(--hue, 200) 70% 55% / 0.45),
    0 0 26px -4px hsl(var(--hue, 200) 80% 55% / 0.5);
}
.card.is-matched::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  animation: pulse-ring 700ms var(--ease) forwards;
}

@keyframes locked {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.06); }
}
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 hsl(var(--hue, 200) 85% 60% / 0.55); }
  100% { box-shadow: 0 0 0 18px hsl(var(--hue, 200) 85% 60% / 0); }
}

.card.is-settled { opacity: 0.55; transform: scale(0.97); transition: opacity 400ms, transform 400ms; }
.card.is-settled:hover { opacity: 1; }

.card.is-wrong { animation: wrong 460ms var(--ease); }
.card.is-wrong .card__face--front {
  border-color: hsl(350 80% 60% / 0.8);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.1), 0 0 20px -4px hsl(350 85% 60% / 0.6);
}
@keyframes wrong {
  0%, 100% { transform: translateX(0); }
  18% { transform: translateX(-7px) rotate(-1.2deg); }
  42% { transform: translateX(6px) rotate(1deg); }
  68% { transform: translateX(-3px); }
}

.board.is-locked .card { pointer-events: none; }
.board.is-locked .card.is-matched { pointer-events: auto; }

/* Preview: every card held face-up until the player presses Begin. The hover
   rules above would otherwise flip cards back on mouse-over, so override them. */
.board.is-preview .card { cursor: default; }
.board.is-preview .card__inner,
.board.is-preview .card:hover .card__inner { transform: rotateY(180deg); }

/* ------------------------------------------------------------ insight panel */

.insight {
  display: grid;
  align-content: start;
  padding: clamp(14px, 1.5vw, 20px);
  background: linear-gradient(180deg, rgb(255 255 255 / 0.05), rgb(255 255 255 / 0.015));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.insight__empty {
  display: grid;
  gap: 9px;
  align-content: center;
  min-height: 240px;
  color: var(--ink-3);
  font-size: 0.86rem;
  line-height: 1.55;
  text-align: center;
}
.insight__empty p { margin: 0; }
.insight__empty strong { color: var(--ink-2); }
.insight__glyph { justify-self: center; color: var(--ink-3); opacity: 0.5; }
.insight__glyph svg { width: 32px; height: 32px; }

.insight__preview {
  display: grid;
  gap: 11px;
  align-content: center;
  justify-items: center;
  min-height: 240px;
  text-align: center;
  animation: rise 380ms var(--ease);
}
.insight__preview p { margin: 0; max-width: 32ch; font-size: 0.86rem; line-height: 1.55; color: var(--ink-2); }
.insight__preview strong { display: block; margin-bottom: 2px; font-size: 1rem; color: var(--ink); }
.insight__preview .insight__glyph { opacity: 0.7; color: var(--gold); }
.insight__preview .btn { margin-top: 8px; animation: begin-pulse 2.2s var(--ease) 0.7s infinite; }

/* Gentle nudge so the primary action is unmistakable. */
@keyframes begin-pulse {
  0%, 100% { transform: none; box-shadow: 0 12px 28px -12px hsl(43 96% 48% / 0.75); }
  50% { transform: translateY(-2px); box-shadow: 0 16px 32px -10px hsl(43 96% 52% / 0.95); }
}

.insight__card { animation: rise 380ms var(--ease); }

.insight__tag {
  display: inline-block;
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
  color: hsl(var(--hue, 200) 80% 78%);
  background: hsl(var(--hue, 200) 70% 50% / 0.16);
  border: 1px solid hsl(var(--hue, 200) 70% 60% / 0.3);
}

.insight__drug {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.insight__arrow { color: hsl(var(--hue, 200) 70% 60%); margin: 9px 0 7px; }
.insight__arrow svg { width: 30px; height: 12px; }

.insight__target {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
  color: hsl(var(--hue, 200) 65% 82%);
}

.insight__effect {
  margin-top: 12px;
  font-size: 0.73rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.insight__fact {
  margin: 12px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-size: 0.83rem;
  line-height: 1.62;
  color: var(--ink-2);
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1000px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100dvh; }
  .stage { grid-template-columns: minmax(0, 1fr); }
  /* Keep the panel above the board, but don't let its empty state eat the fold. */
  .insight { order: -1; padding: 14px 16px; }
  .insight__empty { min-height: 0; gap: 4px; font-size: 0.8rem; }
  .insight__glyph { display: none; }
  .insight__empty p:last-child { display: none; }
  .insight__preview { min-height: 0; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .card__inner { transition: none; }
}
