/* ==========================================================================
   Memoria Visual — Therapeutic Memory Pairs Web App
   Clean, warm, high-contrast daylight design for Occupational Therapy
   ========================================================================== */

:root {
  --bg-page: #f5f3ee;
  --bg-surface: #ffffff;
  --bg-surface-soft: #faf9f5;
  --bg-elevated: #ffffff;

  --text-primary: #1c2833;
  --text-secondary: #4e5d6c;
  --text-muted: #768594;

  --accent-primary: #1e7a6d;
  --accent-primary-hover: #176258;
  --accent-primary-soft: #e6f4f1;
  --accent-primary-border: #a7d9d0;

  --accent-warm: #d97736;
  --accent-warm-hover: #be6226;
  --accent-warm-soft: #fdf0e6;
  --accent-warm-border: #f3c4a2;

  --success: #15803d;
  --success-bright: #22c55e;
  --success-soft: #ecfdf3;
  --success-border: #86efac;

  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-border: #fca5a5;

  --border-subtle: #e4e1d8;
  --border-medium: #d2cec2;

  --shadow-sm: 0 2px 8px rgba(28, 40, 51, 0.05);
  --shadow-md: 0 8px 24px rgba(28, 40, 51, 0.08);
  --shadow-lg: 0 18px 46px rgba(28, 40, 51, 0.14);
  --shadow-card: 0 4px 12px rgba(28, 40, 51, 0.08), 0 1px 3px rgba(28, 40, 51, 0.05);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --font-display: "Plus Jakarta Sans", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-body: "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(circle at 12% 8%, #eef6f4 0%, var(--bg-page) 45%, #f3efe6 100%);
  color: var(--text-primary);
  font-family: var(--font-body);
  line-height: 1.45;
  overscroll-behavior-y: contain;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   App Shell & Header
   ========================================================================== */

.app-shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 20px 36px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--accent-primary-soft);
  border-radius: 12px;
}

.brand-icon svg {
  width: 30px;
  height: 30px;
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.15;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.12s ease;
}

.icon-pill.install-pill {
  background: var(--accent-primary-soft);
  border-color: var(--accent-primary-border);
  color: var(--accent-primary-hover);
}

.icon-pill.install-pill:hover {
  background: #d7eeea;
}

.icon-pill:hover {
  background: var(--bg-surface-soft);
  border-color: var(--border-medium);
}

.icon-pill:active {
  transform: scale(0.97);
}

.icon-pill[aria-pressed="false"] {
  color: var(--text-muted);
  background: #f3f2ee;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-family: var(--font-display);
  font-size: 0.94rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.16s ease, transform 0.12s ease, box-shadow 0.16s ease, border-color 0.16s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px) scale(0.99);
}

.btn:focus-visible,
.icon-pill:focus-visible,
.select-input:focus-visible,
.memory-card:focus-visible,
.text-link-btn:focus-visible {
  outline: 3px solid rgba(30, 122, 109, 0.35);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(30, 122, 109, 0.28);
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  box-shadow: 0 6px 18px rgba(30, 122, 109, 0.34);
}

.btn-accent {
  background: var(--accent-warm);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(217, 119, 54, 0.28);
}

.btn-accent:hover {
  background: var(--accent-warm-hover);
}

.btn-ghost {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
}

.btn-ghost:hover {
  background: var(--bg-surface-soft);
  border-color: var(--border-medium);
}

.btn-lg {
  padding: 15px 28px;
  font-size: 1.05rem;
  border-radius: 14px;
  width: 100%;
}

.text-link-btn {
  background: none;
  border: none;
  padding: 2px 4px;
  color: var(--accent-primary);
  font-family: var(--font-body);
  font-size: 0.83rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.text-link-btn:hover {
  color: var(--accent-primary-hover);
}

/* ==========================================================================
   Setup View
   ========================================================================== */

.view-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding-top: 4px;
}

.setup-card {
  width: 100%;
  max-width: 680px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 28px 30px 26px;
  box-shadow: var(--shadow-md);
}

.setup-header {
  margin-bottom: 22px;
}

.eyebrow {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent-primary);
  background: var(--accent-primary-soft);
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  margin-bottom: 8px;
}

.setup-header h2 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.setup-desc {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.96rem;
}

.setup-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.label-title {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.label-hint {
  font-size: 0.83rem;
  color: var(--text-muted);
}

.select-wrapper {
  position: relative;
}

.select-input {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-surface-soft);
  border: 1.5px solid var(--border-subtle);
  border-radius: 12px;
  padding: 13px 42px 13px 15px;
  font-family: var(--font-body);
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.select-input:hover {
  border-color: var(--accent-primary-border);
  background: #ffffff;
}

.select-input:focus {
  border-color: var(--accent-primary);
  background: #ffffff;
}

.select-chevron {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-secondary);
  font-size: 1.05rem;
}

/* Segmented Control (2 / 3 / 4 min) */
.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.segment-option {
  position: relative;
  cursor: pointer;
}

.segment-option input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.segment-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 13px 10px;
  border-radius: 13px;
  border: 1.5px solid var(--border-subtle);
  background: var(--bg-surface-soft);
  transition: all 0.16s ease;
}

.segment-box strong {
  font-family: var(--font-display);
  font-size: 1.06rem;
  font-weight: 800;
  color: var(--text-primary);
}

.segment-box small {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.segment-option:hover .segment-box {
  border-color: var(--accent-primary-border);
  background: #ffffff;
}

.segment-option input:checked + .segment-box {
  background: var(--accent-primary-soft);
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 1px var(--accent-primary);
}

.segment-option input:checked + .segment-box strong {
  color: var(--accent-primary);
}

.segment-option input:checked + .segment-box small {
  color: var(--accent-primary-hover);
}

.segment-option input:focus-visible + .segment-box {
  outline: 3px solid rgba(30, 122, 109, 0.35);
  outline-offset: 2px;
}

.pool-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.pool-status {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Optional Toggle Checkbox */
.toggle-row {
  padding-top: 2px;
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  padding: 10px 13px;
  border-radius: 12px;
  background: var(--bg-surface-soft);
  border: 1px solid var(--border-subtle);
}

.checkbox-label input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.checkbox-custom {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 2px solid var(--border-medium);
  background: #ffffff;
  flex-shrink: 0;
  margin-top: 2px;
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}

.checkbox-label input:checked + .checkbox-custom {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.checkbox-label input:checked + .checkbox-custom::after {
  content: "✓";
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 800;
}

.checkbox-label strong {
  display: block;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.checkbox-label small {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.setup-cta {
  margin-top: 4px;
}

/* Scoring Rules Strip */
.rules-strip {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px dashed var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
}

.rule-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.rule-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 800;
  flex-shrink: 0;
}

.rule-badge.neutral {
  background: #edf1f5;
  color: var(--text-primary);
}

.rule-badge.positive {
  background: var(--success-soft);
  color: var(--success);
}

.rule-badge.negative {
  background: var(--danger-soft);
  color: var(--danger);
}

.rule-badge.bonus {
  background: var(--accent-warm-soft);
  color: var(--accent-warm-hover);
}

/* History Panel */
.history-card {
  width: 100%;
  max-width: 680px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.history-header h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
}

.history-table-wrap {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.87rem;
}

.history-table th,
.history-table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.history-table th {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 800;
}

.history-table tbody tr:last-child td {
  border-bottom: none;
}

.history-score {
  font-weight: 800;
  color: var(--accent-primary);
}

/* ==========================================================================
   Game View & HUD
   ========================================================================== */

.view-game {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.game-hud {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 15px 18px 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hud-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.phase-indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  background: var(--accent-warm-soft);
  border: 1px solid var(--accent-warm-border);
  color: #9a4715;
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 800;
}

.phase-indicator.phase-playing {
  background: var(--accent-primary-soft);
  border-color: var(--accent-primary-border);
  color: var(--accent-primary-hover);
}

.phase-indicator.phase-completed {
  background: var(--success-soft);
  border-color: var(--success-border);
  color: var(--success);
}

.phase-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
  animation: pulseDot 1.6s ease-in-out infinite;
}

.phase-indicator.phase-completed .phase-dot {
  animation: none;
}

@keyframes pulseDot {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.75);
  }
}

.hud-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

/* Memorization Progress Bar */
.memo-progress-wrap {
  width: 100%;
}

.memo-progress-track {
  width: 100%;
  height: 8px;
  border-radius: var(--radius-pill);
  background: #ece9e0;
  overflow: hidden;
}

.memo-progress-bar {
  height: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--accent-primary) 0%, #37a697 100%);
  transition: width 0.25s linear, background 0.3s ease;
}

.memo-progress-bar.warning {
  background: linear-gradient(90deg, #dc2626 0%, var(--accent-warm) 100%);
}

/* Metrics Cards */
.hud-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  background: var(--bg-surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: 13px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.metric-label {
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.metric-value-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}

.metric-value {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.1;
}

.metric-timer.warning {
  background: #fff7ed;
  border-color: var(--accent-warm-border);
}

.metric-timer.warning .metric-value {
  color: var(--danger);
}

.metric-timer.stopped {
  background: var(--success-soft);
  border-color: var(--success-border);
}

.metric-timer.stopped .metric-value {
  color: var(--success);
}

.mini-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 800;
  background: var(--success);
  color: #ffffff;
}

.mini-badge.streak {
  background: var(--accent-warm-soft);
  color: var(--accent-warm-hover);
  border: 1px solid var(--accent-warm-border);
}

.score-delta {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 800;
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
}

.score-delta.show-positive {
  color: var(--success);
  animation: deltaPop 0.95s ease forwards;
}

.score-delta.show-negative {
  color: var(--danger);
  animation: deltaPop 0.95s ease forwards;
}

@keyframes deltaPop {
  0% {
    opacity: 0;
    transform: translateY(6px) scale(0.9);
  }
  20% {
    opacity: 1;
    transform: translateY(0) scale(1.06);
  }
  75% {
    opacity: 1;
    transform: translateY(-2px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
  }
}

/* Subbar */
.game-subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 4px;
}

.status-message {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.source-pill {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--border-subtle);
  padding: 4px 11px;
  border-radius: var(--radius-pill);
}

/* ==========================================================================
   Board Stage & 3D Memory Cards
   ========================================================================== */

.board-stage {
  position: relative;
  flex: 1;
  min-height: 360px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6px 0 12px;
}

.card-grid {
  --grid-cols: 4;
  --grid-gap: 14px;
  --card-max-w: 165px;
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), minmax(0, var(--card-max-w)));
  gap: var(--grid-gap);
  width: 100%;
  justify-content: center;
  align-content: start;
}

.memory-card {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1.08;
  perspective: 1000px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  border-radius: var(--radius-md);
}

.memory-card[data-interactive="false"] {
  cursor: default;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.52s cubic-bezier(0.22, 1, 0.36, 1);
  border-radius: var(--radius-md);
}

.memory-card.is-face-up .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-md);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.2s ease, border-color 0.22s ease, background 0.22s ease;
}

/* Card Back (Face Down) */
.card-back {
  background:
    radial-gradient(circle at 25% 22%, rgba(255, 255, 255, 0.14) 0%, transparent 45%),
    repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.045) 0px,
      rgba(255, 255, 255, 0.045) 8px,
      transparent 8px,
      transparent 16px
    ),
    linear-gradient(145deg, #218577 0%, #165e55 100%);
  border: 2.5px solid #ffffff;
  color: rgba(255, 255, 255, 0.85);
}

.card-back-emblem {
  width: 44%;
  height: 44%;
  max-width: 52px;
  max-height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
}

.memory-card:not(.is-face-up):not(.is-matched):hover .card-back {
  box-shadow: 0 10px 22px rgba(22, 94, 85, 0.22);
  filter: brightness(1.05);
}

.memory-card:not(.is-face-up):not(.is-matched):hover .card-inner {
  transform: translateY(-3px);
}

/* Card Front (Face Up — High-Contrast Simple Image) */
.card-front {
  transform: rotateY(180deg);
  background: #ffffff;
  border: 2.5px solid var(--border-subtle);
  padding: 12%;
  gap: 4px;
}

.card-image {
  width: 84%;
  height: 84%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(28, 40, 51, 0.08));
}

.card-grid.show-labels .card-front {
  padding: 8% 8% 7%;
}

.card-grid.show-labels .card-image {
  width: 72%;
  height: 70%;
}

.card-caption {
  display: none;
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.15;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-grid.show-labels .card-caption {
  display: block;
}

/* Matched State — stays face-up cleanly */
.memory-card.is-matched .card-front {
  background: var(--success-soft);
  border-color: var(--success-bright);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.18), var(--shadow-sm);
}

.memory-card.is-matched.just-matched {
  animation: matchBounce 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.match-check {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--success);
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.22s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 2px 6px rgba(21, 128, 61, 0.28);
}

.memory-card.is-matched .match-check {
  opacity: 1;
  transform: scale(1);
}

@keyframes matchBounce {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.06);
  }
  100% {
    transform: scale(1);
  }
}

/* Mismatch State */
.memory-card.is-mismatch .card-front {
  background: var(--danger-soft);
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.16);
}

.memory-card.is-mismatch {
  animation: cardShake 0.42s ease;
}

@keyframes cardShake {
  0%, 100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(4px);
  }
}

/* Overlays (Loading & Pause) */
.board-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  border-radius: var(--radius-lg);
  background: rgba(245, 243, 238, 0.88);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}

.loader-spinner {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 4px solid var(--accent-primary-soft);
  border-top-color: var(--accent-primary);
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.pause-box {
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 28px 26px;
  box-shadow: var(--shadow-lg);
}

.pause-icon {
  font-size: 2rem;
  margin-bottom: 6px;
}

.pause-box h3 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.28rem;
}

.pause-box p {
  margin: 0 0 18px;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

/* ==========================================================================
   Modals (Results & Confirm)
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(28, 40, 51, 0.48);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-card {
  width: 100%;
  max-width: 500px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 26px 26px 24px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-sm {
  max-width: 400px;
  text-align: center;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.results-header {
  text-align: center;
  margin-bottom: 18px;
}

.results-stars {
  font-size: 2rem;
  letter-spacing: 5px;
  color: #f59e0b;
  line-height: 1.1;
  margin-bottom: 6px;
}

.results-header h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 800;
}

.results-subtitle {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-secondary);
}

.results-highlights {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.highlight-box {
  background: var(--bg-surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 12px 10px;
  text-align: center;
}

.highlight-primary {
  background: var(--accent-primary-soft);
  border-color: var(--accent-primary-border);
}

.highlight-label {
  display: block;
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.highlight-primary .highlight-label {
  color: var(--accent-primary-hover);
}

.highlight-value {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text-primary);
}

.highlight-primary .highlight-value {
  color: var(--accent-primary);
}

.results-details {
  background: var(--bg-surface-soft);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 12px 15px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.detail-row strong {
  color: var(--text-primary);
}

.score-breakdown {
  border: 1px dashed var(--border-medium);
  border-radius: 14px;
  padding: 12px 15px;
  margin-bottom: 18px;
}

.score-breakdown h4 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.86rem;
}

.breakdown-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-secondary);
}

.breakdown-item strong.pos {
  color: var(--success);
}

.breakdown-item strong.neg {
  color: var(--danger);
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-secondary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.confirm-text {
  margin: 8px 0 20px;
  color: var(--text-secondary);
  font-size: 0.94rem;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Confetti Canvas */
.confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 70;
}

/* ==========================================================================
   Responsive Design
   ========================================================================== */

@media (max-width: 760px) {
  .app-shell {
    padding: 12px 12px 24px;
    gap: 12px;
  }

  .app-header {
    padding: 10px 12px;
  }

  .brand-subtitle {
    display: none;
  }

  .setup-card {
    padding: 20px 18px;
  }

  .rules-strip {
    grid-template-columns: 1fr;
  }

  .hud-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-value {
    font-size: 1.25rem;
  }

  .card-grid {
    --grid-gap: 9px;
  }

  .match-check {
    width: 20px;
    height: 20px;
    font-size: 0.68rem;
    top: 5px;
    right: 5px;
  }

  .results-highlights {
    grid-template-columns: 1fr;
  }

  .modal-secondary-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner,
  .memory-card,
  .phase-dot,
  .modal-card,
  .score-delta {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}
