/* OLPW:css/memory.css | styles for memory */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --bg-deep: #0a1620;
    --bg-mid: #122838;
    --bg-light: #1c3a52;
    --gold: #e8b65a;
    --gold-bright: #f4d27a;
    --gold-pale: #fff5d6;
    --gold-deep: #a87a30;
    --jade: #3dd68c;
    --jade-bright: #6ff0b0;
    --coral: #ff6b6b;
    --coral-bright: #ff9a8b;
    --cream: #f5e6d3;
    --muted: #8ba3b8;
    --border: rgba(232, 182, 90, 0.22);
  }

  html, body { height: 100%; }
  body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg-deep);
    color: var(--cream);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
    line-height: 1.5;
  }

  /* ====== Cosmic background ====== */
  .cosmos-bg {
    position: fixed;
    inset: 0;
    z-index: -2;
    background:
      radial-gradient(ellipse at 15% 20%, rgba(61, 214, 140, 0.08), transparent 50%),
      radial-gradient(ellipse at 85% 80%, rgba(232, 182, 90, 0.1), transparent 50%),
      radial-gradient(ellipse at center, rgba(28, 58, 82, 0.55), transparent 70%),
      linear-gradient(180deg, #0a1620 0%, #050d15 100%);
  }
  .aurora {
    position: fixed;
    inset: -30%;
    z-index: -2;
    background:
      radial-gradient(circle at 25% 30%, rgba(61, 214, 140, 0.18), transparent 35%),
      radial-gradient(circle at 75% 70%, rgba(232, 182, 90, 0.16), transparent 35%),
      radial-gradient(circle at 50% 50%, rgba(255, 107, 107, 0.06), transparent 45%);
    filter: blur(70px);
    animation: auroraDrift 35s ease-in-out infinite;
  }
  @keyframes auroraDrift {
    0%, 100% { transform: translate(0,0) rotate(0deg); }
    33% { transform: translate(4%, -3%) rotate(120deg); }
    66% { transform: translate(-3%, 4%) rotate(240deg); }
  }
  #starfield {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
  }

  /* ====== Main layout ====== */
  main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 28px 32px 24px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    gap: 24px;
  }

  /* ====== Header ====== */
  .app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
    padding-bottom: 22px;
    border-bottom: 1px solid var(--border);
    position: relative;
  }
  .app-header::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: -1px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    opacity: 0.5;
  }

  .brand {
    display: flex;
    align-items: center;
    gap: 16px;
  }
  .brand-seal {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    animation: sealRotate 60s linear infinite;
  }
  @keyframes sealRotate {
    to { transform: rotate(360deg); }
  }
  .brand-text h1 {
    font-family: 'Cinzel', serif;
    font-size: 30px;
    font-weight: 900;
    letter-spacing: 0.18em;
    background: linear-gradient(135deg, var(--gold-pale), var(--gold) 50%, var(--gold-deep));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
  }
  .brand-text p {
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 0.35em;
    text-transform: uppercase;
    margin-top: 6px;
  }

  .stats-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
  }
  .stat {
    background: rgba(18, 40, 56, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    padding: 10px 18px;
    border-radius: 10px;
    min-width: 84px;
    text-align: center;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
  }
  .stat::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(232,182,90,0.08), transparent);
    pointer-events: none;
  }
  .stat-label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.22em;
    margin-bottom: 4px;
  }
  .stat-value {
    font-family: 'Cinzel', serif;
    font-size: 22px;
    font-weight: 700;
    color: var(--gold-bright);
    line-height: 1;
    transition: color 0.3s;
  }

  @keyframes streakPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 rgba(255,107,107,0); }
    50% { transform: scale(1.06); box-shadow: 0 0 30px rgba(255,107,107,0.4); }
  }
  .stat.streak-active {
    background: linear-gradient(135deg, rgba(255,107,107,0.18), rgba(232,182,90,0.18));
    border-color: var(--coral);
    animation: streakPulse 1.2s ease-in-out infinite;
  }
  .stat.streak-active .stat-value {
    color: var(--coral-bright);
    text-shadow: 0 0 18px rgba(255,154,139,0.7);
  }

  /* ====== Buttons ====== */
  .controls {
    display: flex;
    gap: 10px;
  }
  .btn {
    background: rgba(18, 40, 56, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    color: var(--cream);
    padding: 11px 18px;
    border-radius: 10px;
    cursor: pointer;
    font-family: 'Outfit', sans-serif;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    transition: all 0.25s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    position: relative;
    overflow: hidden;
  }
  .btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(232,182,90,0.15), transparent 60%);
    opacity: 0;
    transition: opacity 0.25s;
  }
  .btn:hover {
    border-color: var(--gold);
    transform: translateY(-2px);
    box-shadow: 0 10px 28px rgba(232, 182, 90, 0.18);
  }
  .btn:hover::before { opacity: 1; }
  .btn.active {
    background: linear-gradient(135deg, var(--gold-deep), var(--gold));
    color: var(--bg-deep);
    border-color: var(--gold-bright);
    box-shadow: 0 6px 20px rgba(232,182,90,0.3);
  }
  .btn svg { display: block; }
  .btn-primary {
    background: linear-gradient(135deg, var(--gold-deep), var(--gold));
    color: var(--bg-deep);
    border-color: var(--gold-bright);
    font-weight: 700;
    padding: 14px 28px;
    font-size: 13px;
  }
  .btn-primary:hover {
    background: linear-gradient(135deg, var(--gold), var(--gold-bright));
    box-shadow: 0 12px 35px rgba(232,182,90,0.4);
  }

  /* ====== Board ====== */
  .board-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px 0;
    min-height: 0;
  }
  .board {
    display: grid;
    gap: 14px;
    perspective: 1400px;
    width: 100%;
    max-width: 480px;
  }

  .card {
    aspect-ratio: 3 / 4;
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.3s;
  }
  .card:not(.flipped):not(.matched):hover {
    transform: translateY(-6px);
  }
  .card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.65s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
  }
  .card.flipped .card-inner {
    transform: rotateY(180deg);
  }

  .card-face {
    position: absolute;
    inset: 0;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }

  /* Card back — ornate alchemical seal */
  .card-back {
    background:
      radial-gradient(circle at center, rgba(232,182,90,0.18) 0%, transparent 55%),
      linear-gradient(135deg, #1a3447 0%, #0a1c28 100%);
    border: 1.5px solid rgba(232, 182, 90, 0.35);
    box-shadow:
      0 6px 22px rgba(0,0,0,0.5),
      inset 0 1px 0 rgba(255,255,255,0.04);
    transition: all 0.3s;
  }
  .card:not(.flipped):not(.matched):hover .card-back {
    border-color: var(--gold);
    box-shadow:
      0 12px 32px rgba(0,0,0,0.5),
      0 0 30px rgba(232,182,90,0.25),
      inset 0 1px 0 rgba(255,255,255,0.08);
  }
  .card-back::before {
    content: '';
    position: absolute;
    inset: 6px;
    border: 1px solid rgba(232,182,90,0.22);
    border-radius: 8px;
    pointer-events: none;
  }
  .card-back-seal {
    width: 70%;
    height: 70%;
    opacity: 0.85;
  }

  /* Card front — revealed sigil */
  .card-front {
    transform: rotateY(180deg);
    background:
      radial-gradient(circle at center, rgba(232,182,90,0.28) 0%, rgba(28,58,82,0.5) 70%),
      linear-gradient(135deg, #243f54, #122434);
    border: 1.5px solid var(--gold);
    box-shadow:
      0 6px 22px rgba(232, 182, 90, 0.25),
      inset 0 0 28px rgba(232, 182, 90, 0.12);
    transition: all 0.3s;
  }
  .card-front::before {
    content: '';
    position: absolute;
    inset: 6px;
    border: 1px solid rgba(232,182,90,0.4);
    border-radius: 8px;
    pointer-events: none;
  }
  .card-symbol {
    font-size: clamp(34px, 7vw, 64px);
    color: var(--gold-pale);
    text-shadow:
      0 0 18px rgba(244, 210, 122, 0.9),
      0 0 36px rgba(232, 182, 90, 0.5);
    position: relative;
    z-index: 1;
    line-height: 1;
  }

  /* Match — float and fade */
  @keyframes floatFade {
    0% {
      transform: translateY(0) scale(1) rotateY(180deg);
      opacity: 1;
      filter: brightness(1);
    }
    30% {
      transform: translateY(-12px) scale(1.12) rotateY(180deg);
      opacity: 1;
      filter: brightness(1.5);
    }
    100% {
      transform: translateY(-90px) scale(0.4) rotateY(180deg);
      opacity: 0;
      filter: brightness(2);
    }
  }
  .card.matched {
    pointer-events: none;
  }
  .card.matched .card-inner {
    animation: floatFade 0.95s cubic-bezier(0.4, 0, 0.2, 1) forwards;
  }

  /* Miss — shake and flip back */
  @keyframes shake {
    0%, 100% { transform: rotateY(180deg) translateX(0); }
    15% { transform: rotateY(180deg) translateX(-10px); }
    30% { transform: rotateY(180deg) translateX(10px); }
    45% { transform: rotateY(180deg) translateX(-9px); }
    60% { transform: rotateY(180deg) translateX(9px); }
    75% { transform: rotateY(180deg) translateX(-5px); }
    90% { transform: rotateY(180deg) translateX(5px); }
  }
  .card.miss .card-inner {
    animation: shake 0.55s ease-in-out;
  }
  .card.miss .card-front {
    border-color: var(--coral);
    box-shadow:
      0 6px 22px rgba(255, 107, 107, 0.4),
      inset 0 0 30px rgba(255, 107, 107, 0.2);
  }
  .card.miss .card-symbol {
    color: var(--coral-bright);
    text-shadow:
      0 0 18px rgba(255, 154, 139, 0.9),
      0 0 36px rgba(255, 107, 107, 0.5);
  }

  /* Card entrance */
  @keyframes cardDeal {
    0% {
      opacity: 0;
      transform: translateY(30px) rotateY(-180deg) scale(0.8);
    }
    100% {
      opacity: 1;
      transform: translateY(0) rotateY(0) scale(1);
    }
  }
  .card.dealing {
    animation: cardDeal 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
  }

  /* ====== Difficulty bar ====== */
  .difficulty-bar {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    padding: 18px 0 6px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
    position: relative;
  }
  .difficulty-bar::before {
    content: '';
    position: absolute;
    left: 0; right: 0; top: -1px;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    opacity: 0.4;
  }
  .difficulty-label {
    font-size: 10px;
    color: var(--muted);
    letter-spacing: 0.3em;
    text-transform: uppercase;
    margin-right: 6px;
  }

  /* ====== Modal ====== */
  .modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 13, 21, 0.88);
    backdrop-filter: blur(22px);
    -webkit-backdrop-filter: blur(22px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s;
    padding: 20px;
  }
  .modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
  }
  .modal {
    background:
      radial-gradient(circle at top, rgba(232,182,90,0.12), transparent 65%),
      linear-gradient(180deg, var(--bg-mid), var(--bg-deep));
    border: 1px solid var(--gold);
    border-radius: 24px;
    padding: 48px 48px 40px;
    text-align: center;
    max-width: 480px;
    width: 100%;
    box-shadow:
      0 30px 80px rgba(0, 0, 0, 0.6),
      0 0 100px rgba(232, 182, 90, 0.2);
    transform: scale(0.85) translateY(30px);
    transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
  }
  .modal::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(232,182,90,0.05), transparent 50%);
    pointer-events: none;
  }
  .modal-overlay.active .modal {
    transform: scale(1) translateY(0);
  }
  .modal-rune {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    opacity: 0.85;
  }
  .modal h2 {
    font-family: 'Cinzel', serif;
    font-size: 32px;
    font-weight: 900;
    letter-spacing: 0.12em;
    background: linear-gradient(135deg, var(--gold-pale), var(--gold) 60%, var(--gold-deep));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 6px;
    line-height: 1.1;
  }
  .modal-subtitle {
    color: var(--muted);
    margin-bottom: 28px;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    font-size: 11px;
  }

  .stars {
    display: flex;
    justify-content: center;
    gap: 18px;
    margin: 28px 0;
    min-height: 70px;
    align-items: center;
  }
  .star {
    width: 64px;
    height: 64px;
    opacity: 0.25;
    transform: scale(0.7) rotate(-15deg);
    transition: all 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 0 0 transparent);
  }
  .star.lit {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    filter: drop-shadow(0 0 18px rgba(244, 210, 122, 0.8));
    animation: starGlow 2s ease-in-out infinite;
  }
  @keyframes starGlow {
    0%, 100% { filter: drop-shadow(0 0 18px rgba(244, 210, 122, 0.8)); }
    50% { filter: drop-shadow(0 0 28px rgba(244, 210, 122, 1)); }
  }

  .modal-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 24px 0 28px;
    padding: 18px 12px;
    background: rgba(10, 22, 32, 0.6);
    border-radius: 12px;
    border: 1px solid var(--border);
  }
  .modal-stat-value {
    font-family: 'Cinzel', serif;
    font-size: 24px;
    font-weight: 700;
    color: var(--gold-bright);
    line-height: 1;
    margin-bottom: 6px;
  }
  .modal-stat-label {
    font-size: 10px;
    color: var(--muted);
    letter-spacing: 0.22em;
    text-transform: uppercase;
  }

  /* ====== Floating particles / streak text ====== */
  .particle {
    position: fixed;
    pointer-events: none;
    border-radius: 50%;
    z-index: 50;
  }
  .streak-text {
    position: fixed;
    top: 32%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-family: 'Cinzel', serif;
    font-size: clamp(36px, 6vw, 56px);
    font-weight: 900;
    letter-spacing: 0.18em;
    background: linear-gradient(135deg, var(--coral-bright), var(--gold-bright));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    pointer-events: none;
    z-index: 60;
    text-shadow: 0 0 40px rgba(255, 154, 139, 0.5);
    white-space: nowrap;
  }

  /* ====== Confetti ====== */
  #confetti {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 200;
  }

  /* ====== Music indicator pulse ====== */
  .music-wave {
    display: inline-flex;
    gap: 2px;
    align-items: flex-end;
    height: 12px;
  }
  .music-wave span {
    width: 2px;
    background: currentColor;
    border-radius: 1px;
    animation: wave 0.9s ease-in-out infinite;
  }
  .music-wave span:nth-child(1) { height: 60%; animation-delay: 0s; }
  .music-wave span:nth-child(2) { height: 100%; animation-delay: 0.15s; }
  .music-wave span:nth-child(3) { height: 70%; animation-delay: 0.3s; }
  .music-wave span:nth-child(4) { height: 90%; animation-delay: 0.45s; }
  @keyframes wave {
    0%, 100% { transform: scaleY(0.4); }
    50% { transform: scaleY(1); }
  }
  .btn:not(.active) .music-wave { display: none; }
  .btn.active .music-icon-static { display: none; }

  /* ====== Responsive ====== */
  @media (max-width: 820px) {
    main { padding: 20px 16px; gap: 16px; }
    .app-header { gap: 14px; }
    .brand-text h1 { font-size: 24px; letter-spacing: 0.14em; }
    .brand-text p { font-size: 10px; letter-spacing: 0.25em; }
    .brand-seal { width: 46px; height: 46px; }
    .stats-bar { gap: 6px; width: 100%; justify-content: space-between; }
    .stat { padding: 8px 10px; min-width: 0; flex: 1; }
    .stat-value { font-size: 17px; }
    .stat-label { font-size: 9px; letter-spacing: 0.15em; }
    .controls { width: 100%; }
    .controls .btn { flex: 1; justify-content: center; padding: 10px 12px; font-size: 11px; }
    .board { gap: 10px; }
    .difficulty-bar { gap: 6px; }
    .difficulty-label { display: none; }
    .difficulty-bar .btn { padding: 9px 12px; font-size: 11px; }
    .modal { padding: 36px 28px 30px; }
    .modal h2 { font-size: 26px; }
    .star { width: 52px; height: 52px; }
  }
  @media (max-width: 480px) {
    .stats-bar { gap: 4px; }
    .stat { padding: 6px 8px; }
    .stat-value { font-size: 15px; }
  }

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