/* =========================================================
   Memory Match — tool-specific styles.
   Layered on /tools/_shared/tool.css.
   ========================================================= */

/* Per-player colors (multiplayer): distinct, theme-aware hues used to
   tint a player's matched cards and their scoreboard chip. Picked to
   stay distinguishable for the common colorblindness types
   (teal / amber / violet / rose). */
:root {
  --mm-p1: #0D9488;
  --mm-p2: #D97706;
  --mm-p3: #7C3AED;
  --mm-p4: #DB2777;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --mm-p1: #2DD4BF;
    --mm-p2: #FBBF24;
    --mm-p3: #A78BFA;
    --mm-p4: #F472B6;
  }
}
:root[data-theme="dark"] {
  --mm-p1: #2DD4BF;
  --mm-p2: #FBBF24;
  --mm-p3: #A78BFA;
  --mm-p4: #F472B6;
}

/* Card sits at default 600px while setting up; expands wider when a
   game starts so the board has horizontal room for 6 columns of
   cards. Same pattern as the Word Search Generator but expands
   further (memory game needs more horizontal real estate than a
   typical puzzle). */
.widget-card {
  transition: max-width 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.widget-card.is-game-started {
  max-width: 1040px;
}

/* ---------- Setup form ---------- */
.mm-setup { display: flex; flex-direction: column; gap: var(--space-5); }

.mm-field { display: flex; flex-direction: column; gap: var(--space-2); }
.mm-field label,
.mm-field legend,
.mm-field-label-block {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
}
.mm-field-hint {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--text-subtle);
  margin-left: 6px;
}
.mm-field-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}
.mm-status {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.mm-status strong { color: var(--text); font-weight: 700; }

.mm-field input[type="text"],
.mm-field select,
.mm-field textarea {
  width: 100%;
  padding: 10px 14px;
  font: inherit;
  font-size: 15px;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  transition: var(--transition-colors);
}
.mm-field textarea {
  resize: vertical;
  min-height: 180px;
  line-height: 1.55;
  padding: var(--space-4);
  font-family: var(--font-mono);
  font-size: 14px;
}
.mm-field textarea::placeholder { color: var(--text-subtle); white-space: pre-line; }
.mm-field input:focus,
.mm-field select:focus,
.mm-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* ---------- Mode radios ---------- */
.mm-mode {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  background: var(--surface-inset);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
}
.mm-mode legend { padding: 0; margin-bottom: var(--space-3); }
.mm-radio {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.mm-radio input[type="radio"] {
  margin-top: 3px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.mm-radio-hint {
  display: inline-block;
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-muted);
}
.mm-radio code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.mm-hint {
  margin: var(--space-2) 0 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
.mm-hint.is-good { color: var(--success); }
.mm-hint.is-warn { color: var(--warning); }
.mm-hint.is-error { color: var(--danger); }

.mm-actions { margin-top: var(--space-2); }
.mm-actions .btn { font-size: 16px; min-height: 52px; }

/* Secondary actions sitting just under the items textarea — Load
   sample / Clear. Outline buttons, smaller than the primary Start CTA. */
.mm-textarea-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
  flex-wrap: wrap;
}
.mm-textarea-actions .btn {
  font-size: 13px;
  padding: 6px 12px;
  min-height: 0;
}

/* ---------- Game ---------- */
.mm-game-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-6);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.mm-game-title {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1.2;
}
.mm-game-actions {
  display: inline-flex;
  gap: var(--space-4);
}
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 0;
  cursor: pointer;
}
.btn-link:hover { color: var(--accent-hover); text-decoration: underline; }

.mm-stats {
  display: flex;
  gap: var(--space-2);
  justify-content: space-between;
  margin-bottom: var(--space-5);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}
.mm-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 1;
}
.mm-stat-num {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.1;
}
.mm-stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---------- Multiplayer scoreboard ----------
   Shown instead of .mm-stats when 2+ players. Per-player score
   chips with the active player highlighted. No timer. */
.mm-scoreboard {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}
@media (min-width: 560px) {
  .mm-scoreboard[data-players="3"] { grid-template-columns: repeat(3, 1fr); }
  .mm-scoreboard[data-players="4"] { grid-template-columns: repeat(4, 1fr); }
}
.mm-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1px;
  padding: var(--space-3) var(--space-2);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: var(--transition-colors);
}
.mm-player.is-active {
  border-color: var(--mm-owner);
  background: color-mix(in srgb, var(--mm-owner) 12%, var(--surface));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--mm-owner) 45%, transparent);
}
.mm-player-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--text-muted);
}
.mm-player-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--mm-owner);
  flex: none;
}
.mm-player.is-active .mm-player-name { color: var(--text); }
.mm-player-score {
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1.15;
}
.mm-player-turn {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-weight: 700;
  color: var(--mm-owner);
  min-height: 1.3em;
  visibility: hidden;
}
.mm-player.is-active .mm-player-turn { visibility: visible; }

/* ---------- Board ---------- */
.mm-board {
  display: grid;
  gap: 10px;
  margin: 0 auto var(--space-5);
  /* No max-width — let the board fill the widget-card so 6-column
     grids have decent card sizes. */
  perspective: 1200px;
}
.mm-board[data-cols="4"] { grid-template-columns: repeat(4, 1fr); }
.mm-board[data-cols="6"] { grid-template-columns: repeat(6, 1fr); }

/* Mobile collapse: 6-column grids get too tight on narrow screens.
   Drop to 4 columns under 640px — taller grid, but each card stays
   readable. */
@media (max-width: 640px) {
  .mm-board[data-cols="6"] { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Card ---------- */
.mm-card {
  position: relative;
  /* Square cards — more memory-game-traditional and gives text room
     to breathe horizontally in pairs mode. */
  aspect-ratio: 1 / 1;
  cursor: pointer;
  background: transparent;
  border: none;
  padding: 0;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}
.mm-card-inner {
  /* display: block is required — the JS uses <span> for this element,
     which is inline by default and would ignore the width/height,
     collapsing the parent for the absolutely-positioned faces. */
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}
.mm-card.is-flipped .mm-card-inner,
.mm-card.is-matched .mm-card-inner {
  transform: rotateY(180deg);
}
.mm-card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 8px;
  box-sizing: border-box;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  overflow: hidden;
}
.mm-card-back {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: var(--accent-fg);
  border: 1px solid var(--accent);
  box-shadow: var(--shadow-sm);
}
.mm-card-back::before {
  /* Subtle diagonal pattern so the card-backs feel finished */
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      45deg,
      transparent 0 6px,
      rgba(255, 255, 255, 0.10) 6px 7px
    );
  border-radius: inherit;
  pointer-events: none;
}
.mm-card-back-mark {
  position: relative;
  font-size: 24px;
  font-weight: 900;
  letter-spacing: -0.02em;
  opacity: 0.9;
}
.mm-card-front {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  transform: rotateY(180deg);
  font-size: clamp(12px, 1.6vw, 17px);
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
  padding: 10px;
}
.mm-card.is-matched .mm-card-front {
  background: var(--accent-soft-bg);
  border-color: var(--accent);
  color: var(--accent-soft-fg);
}
/* Multiplayer: a matched pair takes the color of the player who found
   it. --mm-owner is set inline per card from the player palette. The
   colored border conveys ownership even where color-mix is unsupported. */
.mm-card.is-matched.is-owned .mm-card-front {
  background: color-mix(in srgb, var(--mm-owner) 18%, var(--surface));
  border: 2px solid var(--mm-owner);
  color: var(--text);
}
.mm-card.is-matched {
  animation: mm-pop 0.4s ease;
}
@keyframes mm-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.mm-card.is-shake .mm-card-inner {
  animation: mm-shake 0.4s ease;
}
@keyframes mm-shake {
  0%, 100% { transform: rotateY(180deg) translateX(0); }
  25% { transform: rotateY(180deg) translateX(-4px); }
  75% { transform: rotateY(180deg) translateX(4px); }
}

/* ---------- Completion ---------- */
.mm-complete {
  text-align: center;
  background: var(--accent-soft-bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin: 0 auto;
  max-width: 480px;
}
.mm-complete h3 {
  margin: 0 0 8px;
  color: var(--accent-soft-fg);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.mm-complete p {
  margin: 0 0 var(--space-4);
  color: var(--accent-soft-fg);
  font-size: 14px;
}
