  /* ── memory view (card match game) ──────────────────────── */
  body.view-memory { overflow: hidden; }
  #view-memory {
    position: fixed;
    inset: 0;
    overflow: hidden;
    background-color: var(--bg);
    background-image: radial-gradient(circle, rgba(201, 195, 183, .45) 1px, transparent 1.2px);
    background-size: 26px 26px;
    background-position: 13px 13px;
  }
  #view-memory:not(.active) { display: none; }

  .memory-board {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 110px 24px 110px;
    box-sizing: border-box;
  }
  .memory-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 14px;
    perspective: 1200px;
    width: 100%;
    height: 100%;
    max-width: 560px;
    max-height: 780px;
    aspect-ratio: 20 / 28;
  }

  .memory-card {
    position: relative;
    border-radius: 12px;
    transform-style: preserve-3d;
    transition: transform .55s cubic-bezier(.2,.8,.2,1);
    cursor: pointer;
    background: transparent;
    border: none;
    padding: 0;
    will-change: transform;
  }
  .memory-card.flipped,
  .memory-card.matched { transform: rotateY(180deg); }
  .memory-card.matched { cursor: pointer; }
  .memory-card.matched.pop {
    animation: memory-match .55s cubic-bezier(.2,.8,.2,1) both;
  }
  @keyframes memory-match {
    0%   { transform: rotateY(180deg) scale(1); }
    45%  { transform: rotateY(180deg) scale(1.08); }
    100% { transform: rotateY(180deg) scale(1); }
  }
  /* Halo behind a matched card on hover */
  .memory-card.matched::before {
    content: "";
    position: absolute;
    inset: -14px;
    border-radius: 18px;
    background: radial-gradient(closest-side, rgba(217,119,87,.18), rgba(217,119,87,0) 70%);
    opacity: 0;
    transition: opacity .25s;
    pointer-events: none;
    z-index: -1;
    transform: rotateY(180deg);
  }
  .memory-card.matched.color-mint::before {
    background: radial-gradient(closest-side, rgba(120,180,90,.22), rgba(120,180,90,0) 70%);
  }
  .memory-card.matched:hover::before { opacity: 1; }
  .memory-card.matched:hover { transform: rotateY(180deg) translateY(-4px) scale(1.03); }

  .memory-face {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    overflow: hidden;
  }
  /* iOS Safari sometimes leaks the back face (star + dashed border) through the
     flipped front, even with backface-visibility. Force-hide the back face once
     the card is past the edge-on midpoint of the .55s flip. */
  .memory-card .memory-face-back {
    visibility: visible;
    transition: visibility 0s .27s;
  }
  .memory-card.flipped .memory-face-back,
  .memory-card.matched .memory-face-back {
    visibility: hidden;
  }
  /* Backs alternate mint/orange */
  .memory-face-back.mint {
    background: linear-gradient(180deg, #e7f6d6 0%, #c6efb1 55%, #95d278 100%);
    box-shadow:
      inset 0 0 0 1.5px #6fb049,
      inset 0 0 0 3px #defaca,
      inset 0 -7px 12px -8px rgba(60,100,40,.45),
      0 10px 18px -6px rgba(120,180,90,.45);
    color: #2f5d1f;
  }
  .memory-face-back.orange {
    background: linear-gradient(180deg, #fbdccc 0%, #e9b5a0 45%, #d97757 100%);
    box-shadow:
      inset 0 0 0 1.5px #a85339,
      inset 0 0 0 3px #f6cdbb,
      inset 0 -7px 12px -8px rgba(120,40,20,.45),
      0 10px 18px -6px rgba(217,119,87,.45);
    color: #5c2812;
  }
  .memory-face-back::before {
    content: "";
    position: absolute;
    inset: 9px;
    border-radius: 8px;
    border: 1px dashed currentColor;
    opacity: .35;
    pointer-events: none;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
  }
  .memory-face-back .ornament {
    width: 46%;
    height: 46%;
    fill: currentColor;
    opacity: .55;
    position: relative;
    z-index: 1;
    transition: transform .55s cubic-bezier(.2,.8,.2,1), opacity .25s;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
  }
  .memory-card:hover .memory-face-back .ornament {
    transform: rotate(45deg) scale(1.1);
    opacity: .75;
  }

  .memory-face-front {
    transform: rotateY(180deg);
    background: var(--card);
    box-shadow:
      0 0 0 1px var(--line) inset,
      0 8px 18px -10px rgba(0,0,0,.18);
    color: var(--ink);
    padding: 10px;
  }
  .memory-card-body {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
  }
  .memory-card-illu { width: 52%; height: 52%; }
  .memory-card-illu svg {
    width: 100%;
    height: 100%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .55s cubic-bezier(.2,.8,.2,1);
    transform-origin: 50% 50%;
  }
  .memory-card:hover .memory-card-illu svg {
    transform: rotate(-12deg) scale(1.1);
  }
  .memory-corner {
    position: absolute;
    font-family: var(--mono);
    font-size: 9px;
    letter-spacing: .1em;
    text-transform: uppercase;
    line-height: 1.15;
    max-width: 60%;
    font-weight: 600;
    pointer-events: none;
  }
  .memory-corner-tl { top: 8px; left: 10px; text-align: left; }
  .memory-corner-br {
    bottom: 8px;
    right: 10px;
    text-align: right;
    transform: rotate(180deg);
    transform-origin: center;
  }
  .memory-card.color-mint .memory-corner,
  .memory-card.color-mint .memory-card-illu { color: #2f5d1f; }
  .memory-card.color-orange .memory-corner,
  .memory-card.color-orange .memory-card-illu { color: #8d3b1d; }

  /* Floating toolbar — canvas-style pill */
  .memory-toolbar {
    position: absolute;
    top: 92px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 8;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 8px;
    box-shadow:
      0 2px 6px rgba(26,26,26,.08),
      0 12px 28px -10px rgba(26,26,26,.25),
      0 30px 60px -20px rgba(26,26,26,.35);
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .18em;
    text-transform: uppercase;
    color: var(--ink-mute);
  }
  .memory-toolbar .mt-stat {
    padding: 6px 12px;
    white-space: nowrap;
  }
  .memory-toolbar .mt-stat em {
    font-style: normal;
    font-weight: 600;
    color: var(--ink);
  }
  .memory-toolbar .mt-sep {
    width: 1px;
    height: 18px;
    background: var(--line);
    flex-shrink: 0;
  }
  .memory-toolbar .mt-restart {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .22em;
    text-transform: uppercase;
    color: var(--ink-soft);
    background: transparent;
    border: 0;
    border-radius: 999px;
    padding: 6px 14px;
    cursor: pointer;
    transition: background .2s, color .2s;
  }
  .memory-toolbar .mt-restart:hover { background: var(--ink); color: var(--bg); }

  /* Intro dialog overlay — appears centered until "Start" clicked */
  .memory-scrim {
    position: absolute;
    inset: 0;
    background: rgba(245, 243, 238, .82);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
    opacity: 1;
    transition: opacity .45s ease, visibility .45s ease;
  }
  .memory-scrim.hide {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }
  .memory-dialog {
    text-align: center;
    max-width: 460px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }
  /* "Top visual with the cards" — a small fan of 3 cards above the dialog */
  .memory-fan {
    position: relative;
    width: 200px;
    height: 132px;
    margin-bottom: 22px;
  }
  .memory-fan-card {
    position: absolute;
    top: 0;
    left: 50%;
    width: 80px;
    height: 112px;
    border-radius: 10px;
    transform-origin: 50% 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    will-change: transform;
  }
  .memory-fan-card::before {
    content: "";
    position: absolute;
    inset: 6px;
    border-radius: 6px;
    border: 1px dashed currentColor;
    opacity: .35;
  }
  .memory-fan-card svg {
    width: 44%;
    height: 44%;
    fill: currentColor;
    opacity: .55;
    z-index: 1;
  }
  .memory-fan-card.f1 {
    background: linear-gradient(180deg, #e7f6d6 0%, #c6efb1 55%, #95d278 100%);
    box-shadow:
      inset 0 0 0 1.5px #6fb049,
      inset 0 0 0 3px #defaca,
      0 10px 18px -6px rgba(120,180,90,.45);
    color: #2f5d1f;
    transform: translateX(-50%) rotate(-14deg) translateY(6px);
    animation: memory-fan-pop-1 .8s cubic-bezier(.2,1.3,.35,1) both;
  }
  .memory-fan-card.f2 {
    background: linear-gradient(180deg, #fbdccc 0%, #e9b5a0 45%, #d97757 100%);
    box-shadow:
      inset 0 0 0 1.5px #a85339,
      inset 0 0 0 3px #f6cdbb,
      0 10px 18px -6px rgba(217,119,87,.45);
    color: #5c2812;
    transform: translateX(-50%) rotate(0deg) translateY(-6px);
    z-index: 2;
    animation: memory-fan-pop-2 .85s cubic-bezier(.2,1.3,.35,1) both .08s;
  }
  .memory-fan-card.f3 {
    background: linear-gradient(180deg, #e7f6d6 0%, #c6efb1 55%, #95d278 100%);
    box-shadow:
      inset 0 0 0 1.5px #6fb049,
      inset 0 0 0 3px #defaca,
      0 10px 18px -6px rgba(120,180,90,.45);
    color: #2f5d1f;
    transform: translateX(-50%) rotate(14deg) translateY(6px);
    animation: memory-fan-pop-3 .8s cubic-bezier(.2,1.3,.35,1) both .16s;
  }
  @keyframes memory-fan-pop-1 {
    0%   { transform: translateX(-50%) rotate(0) translateY(20px) scale(.6); opacity: 0; }
    100% { transform: translateX(-50%) rotate(-14deg) translateY(6px) scale(1); opacity: 1; }
  }
  @keyframes memory-fan-pop-2 {
    0%   { transform: translateX(-50%) rotate(0) translateY(20px) scale(.6); opacity: 0; }
    100% { transform: translateX(-50%) rotate(0) translateY(-6px) scale(1); opacity: 1; }
  }
  @keyframes memory-fan-pop-3 {
    0%   { transform: translateX(-50%) rotate(0) translateY(20px) scale(.6); opacity: 0; }
    100% { transform: translateX(-50%) rotate(14deg) translateY(6px) scale(1); opacity: 1; }
  }
  .memory-dialog .memory-eyebrow {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .24em;
    text-transform: uppercase;
    color: var(--ink-mute);
  }
  .memory-dialog .memory-title {
    font-family: var(--serif);
    font-size: 44px;
    font-weight: 500;
    line-height: 1.05;
    letter-spacing: -.01em;
    margin: 6px 0 10px;
    color: var(--ink);
  }
  .memory-dialog .memory-title em { font-style: italic; }
  .memory-dialog .memory-sub {
    font-family: var(--serif);
    font-size: 17px;
    line-height: 1.5;
    color: var(--ink-soft);
    margin: 0 0 22px;
    text-wrap: pretty;
  }
  .memory-btn {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .22em;
    text-transform: uppercase;
    border-radius: 999px;
    padding: 12px 22px;
    cursor: pointer;
    transition: transform .15s cubic-bezier(.2,.8,.2,1), box-shadow .2s, color .2s, background .2s, border-color .2s;
  }
  .memory-btn.primary {
    color: var(--bg);
    background: var(--ink);
    border: 0;
    box-shadow: 0 10px 22px -10px rgba(26,26,26,.45);
  }
  .memory-btn.primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 26px -10px rgba(26,26,26,.55);
  }
  .memory-btn.secondary {
    color: var(--ink-soft);
    background: transparent;
    border: 1px solid var(--line);
  }
  .memory-btn.secondary:hover { color: var(--ink); border-color: var(--ink); }

  /* Backward-compat: legacy class still used on the Start button */
  .memory-dialog .memory-start {
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: .22em;
    text-transform: uppercase;
    color: var(--bg);
    background: var(--ink);
    border: 0;
    border-radius: 999px;
    padding: 12px 22px;
    cursor: pointer;
    transition: transform .15s cubic-bezier(.2,.8,.2,1), box-shadow .2s;
    box-shadow: 0 10px 22px -10px rgba(26,26,26,.45);
  }
  .memory-dialog .memory-start:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 26px -10px rgba(26,26,26,.55);
  }

  /* Action row for match dialog */
  .memory-actions {
    display: flex;
    gap: 10px;
    margin-top: 6px;
    flex-wrap: wrap;
    justify-content: center;
  }

  /* Single "matched card" visual shown above the match-dialog headline */
  .memory-match-visual {
    position: relative;
    width: 110px;
    height: 154px;
    margin-bottom: 22px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    box-sizing: border-box;
    will-change: transform;
    animation: memory-match-visual-pop .55s cubic-bezier(.2,1.3,.35,1) both;
  }
  .memory-match-visual.color-mint {
    background: linear-gradient(180deg, #e7f6d6 0%, #c6efb1 55%, #95d278 100%);
    box-shadow:
      inset 0 0 0 1.5px #6fb049,
      inset 0 0 0 3px #defaca,
      0 14px 26px -8px rgba(120,180,90,.55);
    color: #2f5d1f;
  }
  .memory-match-visual.color-orange {
    background: linear-gradient(180deg, #fbdccc 0%, #e9b5a0 45%, #d97757 100%);
    box-shadow:
      inset 0 0 0 1.5px #a85339,
      inset 0 0 0 3px #f6cdbb,
      0 14px 26px -8px rgba(217,119,87,.55);
    color: #5c2812;
  }
  .memory-match-visual::before {
    content: "";
    position: absolute;
    inset: 8px;
    border-radius: 8px;
    border: 1px dashed currentColor;
    opacity: .35;
    pointer-events: none;
  }
  .memory-match-visual svg {
    width: 56%;
    height: 56%;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    position: relative;
    z-index: 1;
  }
  @keyframes memory-match-visual-pop {
    0%   { transform: scale(.5) rotate(-10deg); opacity: 0; }
    55%  { transform: scale(1.08) rotate(4deg); opacity: 1; }
    100% { transform: scale(1) rotate(0); opacity: 1; }
  }

  .memory-match-meta {
    font-family: var(--mono);
    font-size: 10px;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: var(--ink-mute);
    margin: 0 0 16px;
  }

  @media (max-width: 820px) {
    .memory-toolbar { top: 76px; font-size: 9px; }
    .memory-toolbar .mt-stat { padding: 6px 10px; }
    .memory-toolbar .mt-restart { padding: 6px 12px; }
    .memory-dialog .memory-title { font-size: 32px; }
    .memory-dialog .memory-sub { font-size: 15px; }
    .memory-fan { width: 170px; height: 116px; }
    .memory-fan-card { width: 68px; height: 96px; }
    .memory-hovercard {
      right: 12px;
      left: 12px;
      width: auto;
      max-width: none;
      top: auto;
      bottom: 100px;
      transform: translateY(16px);
    }
    .memory-hovercard.show { transform: translateY(0); }
    .memory-hovercard .mhc-cover { display: none; }
    .memory-hovercard .mhc-title { font-size: 22px; }
  }
  @media (max-width: 700px) {
    .memory-corner { font-size: 7px; letter-spacing: .08em; }
    .memory-corner-tl { top: 6px; left: 7px; }
    .memory-corner-br { bottom: 6px; right: 7px; }
    .memory-board { padding: 100px 14px 100px; }
    /* Squatter cards on phones so the grid doesn't dominate vertical space. */
    .memory-grid {
      gap: 10px;
      height: auto;
      aspect-ratio: 20 / 23;
      max-height: 560px;
    }
  }

