/* Portfolio — Play button aligned to main .container right (not viewport corner) */
.portfolio-game-anchor {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  pointer-events: none;
  padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.portfolio-game-anchor__inner {
  position: relative;
  pointer-events: none;
}

.portfolio-game-widget {
  position: absolute;
  right: 0;
  bottom: 0;
  left: auto;
  pointer-events: auto;
  font-family: var(--font-body);
}

html.portfolio-game-open {
  overflow: hidden;
  height: 100%;
  overscroll-behavior: none;
}

body.portfolio-game-open {
  overflow: hidden;
  overscroll-behavior: none;
}

.portfolio-game-window {
  position: absolute;
  bottom: calc(100% + 0.75rem);
  right: 0;
  left: auto;
  width: 380px;
  max-width: calc(
    100vw - 2rem - env(safe-area-inset-left, 0px) -
      env(safe-area-inset-right, 0px)
  );
  height: min(
    480px,
    calc(
      100vh - 7.5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    )
  );
  max-height: calc(
    100vh - 7.5rem - env(safe-area-inset-top, 0px) -
      env(safe-area-inset-bottom, 0px)
  );
  height: min(
    480px,
    calc(
      100dvh - 7.5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    )
  );
  max-height: calc(
    100dvh - 7.5rem - env(safe-area-inset-top, 0px) -
      env(safe-area-inset-bottom, 0px)
  );
  background: rgba(10, 10, 12, 0.98);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(212, 168, 59, 0.08);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.97);
  transition:
    opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    visibility 0.3s,
    transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(12px);
}

.portfolio-game-window.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.portfolio-game-window.active ~ .portfolio-game-toggle {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.portfolio-game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(
    180deg,
    rgba(212, 168, 59, 0.08) 0%,
    transparent 100%
  );
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  flex-shrink: 0;
}

.portfolio-game-header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.portfolio-game-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
  flex-shrink: 0;
}

.portfolio-game-header-text h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--text);
}

.portfolio-game-status {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: var(--text-subtle);
}

.portfolio-game-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    color var(--transition),
    background var(--transition),
    transform 0.18s ease,
    filter 0.18s ease;
  flex-shrink: 0;
  touch-action: manipulation;
}

.portfolio-game-close:hover {
  background: var(--border);
  color: var(--text);
  transform: scale(1.08);
  filter: brightness(1.15);
}

.portfolio-game-close:active {
  transform: scale(0.94);
}

.portfolio-game-body {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  padding: 0.65rem 0.75rem 0.7rem;
  display: flex;
  flex-direction: column;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.02) 0%,
    transparent 35%
  );
}

.portfolio-game-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.65rem 1.15rem 0.65rem 0.85rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--bg);
  background: var(--gradient-accent);
  box-shadow: 0 4px 22px var(--accent-glow);
  transition:
    transform 0.22s cubic-bezier(0.34, 1.45, 0.64, 1),
    box-shadow 0.22s ease,
    filter 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.portfolio-game-toggle:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 10px 32px var(--accent-glow-strong);
  filter: brightness(1.07);
}

.portfolio-game-toggle:active {
  transform: translateY(-1px) scale(0.97);
  box-shadow: 0 3px 14px var(--accent-glow);
  filter: brightness(1.02);
}

.portfolio-game-toggle svg {
  flex-shrink: 0;
}

.portfolio-game-toggle-text {
  letter-spacing: 0.02em;
}

/* Phones: near-full-width panel, dynamic viewport, comfortable touch */
@media (max-width: 480px) {
  .portfolio-game-anchor {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
  }

  .portfolio-game-window {
    width: calc(
      100vw - 1.25rem - env(safe-area-inset-left, 0px) -
        env(safe-area-inset-right, 0px)
    );
    max-width: none;
    height: min(
      560px,
      calc(
        100vh - 5.5rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100vh - 5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
    height: min(
      560px,
      calc(
        100dvh - 5.5rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100dvh - 5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
    border-radius: var(--radius-xl);
  }

  .portfolio-game-header {
    padding: 0.7rem 0.75rem;
    padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
  }

  .portfolio-game-body {
    padding: 0.55rem 0.65rem max(0.65rem, env(safe-area-inset-bottom, 0px));
  }

  .portfolio-game-toggle {
    min-height: 48px;
    padding: 0.6rem 1rem 0.6rem 0.8rem;
    font-size: 0.8125rem;
  }

  /* One row: mode pair + compact New game (avoid full-width flex-grow eating space) */
  .portfolio-game-body .portfolio-ttt-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    grid-template-rows: auto;
    align-items: stretch;
    gap: 0.4rem;
    flex-wrap: unset;
  }

  .portfolio-game-body .portfolio-ttt-mode-group {
    grid-column: 1 / 3;
    grid-row: 1;
    flex: unset;
    width: 100%;
    min-height: 44px;
  }

  .portfolio-game-body .portfolio-ttt-btn--mode {
    min-height: 44px;
    font-size: 0.72rem;
    padding: 0.45rem 0.35rem;
  }

  .portfolio-game-body .portfolio-ttt-btn--new {
    grid-column: 3;
    grid-row: 1;
    flex: none;
    width: auto;
    min-width: 0;
    max-width: none;
    min-height: 44px;
    max-height: 48px;
    align-self: stretch;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.45rem 0.65rem;
    white-space: nowrap;
  }

  .portfolio-game-body .portfolio-ttt-status-panel {
    padding: 0.6rem 0.55rem;
  }

  .portfolio-game-body .portfolio-ttt-status {
    font-size: 0.95rem;
  }

  .portfolio-game-body .portfolio-ttt-board-wrap {
    min-height: 8rem;
  }

  .portfolio-game-body .portfolio-ttt-board-frame {
    padding: 0.5rem;
    border-radius: var(--radius-xl);
  }

  .portfolio-game-body .portfolio-ttt-board {
    gap: 0.42rem;
  }

  .portfolio-game-body .portfolio-ttt-hint {
    font-size: 0.7rem;
    padding: 0.45rem 0.5rem;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay__card {
    padding: 0.75rem 0.85rem 0.9rem;
    max-width: 14rem;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay__title {
    font-size: 0.88rem;
  }

  .portfolio-game-body .portfolio-ttt-result-preview {
    width: 5rem;
    gap: 0.16rem;
    margin-bottom: 0.5rem;
  }

  .portfolio-game-body .portfolio-ttt-result-preview__cell {
    font-size: 0.64rem;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay__sub {
    font-size: 0.68rem;
    margin-bottom: 0.65rem;
  }

  .portfolio-game-body .portfolio-ttt-btn--try-again {
    min-height: 44px;
    font-size: 0.72rem;
  }
}

/* Phone landscape: shorter chrome so the grid still fits */
@media (max-width: 896px) and (orientation: landscape) and (max-height: 500px) {
  .portfolio-game-window {
    height: min(
      420px,
      calc(
        100vh - 1.25rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100vh - 1rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
    height: min(
      420px,
      calc(
        100dvh - 1.25rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100dvh - 1rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
  }

  .portfolio-game-header {
    padding: 0.45rem 0.65rem;
  }

  .portfolio-game-avatar {
    width: 32px;
    height: 32px;
  }

  .portfolio-game-header-text h4 {
    font-size: 0.9rem;
  }

  .portfolio-game-body .portfolio-ttt-hud {
    gap: 0.35rem;
  }

  .portfolio-game-body .portfolio-ttt-status-panel {
    padding: 0.4rem 0.5rem;
  }

  .portfolio-game-body .portfolio-ttt-status {
    font-size: 0.85rem;
    min-height: 1.2em;
  }

  .portfolio-game-body .portfolio-ttt-btn--mode,
  .portfolio-game-body .portfolio-ttt-btn--new {
    min-height: 40px;
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
  }

  .portfolio-game-body .portfolio-ttt-footer {
    gap: 0.25rem;
  }

  .portfolio-game-body .portfolio-ttt-hint {
    font-size: 0.62rem;
    padding: 0.3rem 0.4rem;
  }
}

/* iPad / tablets: wider panel, taller play area, still touch-friendly */
@media (min-width: 481px) and (max-width: 1024px) {
  .portfolio-game-anchor {
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
  }

  .portfolio-game-window {
    width: min(
      420px,
      calc(
        100vw - 2.5rem - env(safe-area-inset-left, 0px) -
          env(safe-area-inset-right, 0px)
      )
    );
    height: min(
      520px,
      calc(
        100vh - 8rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100vh - 7.5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
    height: min(
      520px,
      calc(
        100dvh - 8rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100dvh - 7.5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
    border-radius: var(--radius-xl);
  }

  .portfolio-game-header {
    padding: 0.75rem 1rem;
  }

  .portfolio-game-avatar {
    width: 40px;
    height: 40px;
  }

  .portfolio-game-body {
    padding: 0.75rem 0.85rem 0.85rem;
  }

  .portfolio-game-body .portfolio-ttt-btn--mode {
    min-height: 44px;
    font-size: 0.78rem;
    padding: 0.5rem 0.65rem;
  }

  .portfolio-game-body .portfolio-ttt-btn--new {
    min-height: 44px;
    font-size: 0.78rem;
    padding: 0.5rem 1rem;
  }

  .portfolio-game-body .portfolio-ttt-status {
    font-size: 1.02rem;
  }

  .portfolio-game-body .portfolio-ttt-board-wrap {
    min-height: 9rem;
  }

  .portfolio-game-body .portfolio-ttt-board-frame {
    padding: 0.55rem;
  }

  .portfolio-game-body .portfolio-ttt-board {
    gap: 0.4rem;
  }

  .portfolio-game-body .portfolio-ttt-hint {
    font-size: 0.72rem;
    padding: 0.45rem 0.55rem;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay__title {
    font-size: 0.9rem;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay__sub {
    font-size: 0.7rem;
  }
}

/* Large desktop only: slightly denser control strip (not on touch tablets) */
@media (min-width: 1025px) {
  .portfolio-game-body .portfolio-ttt-btn--mode {
    font-size: 0.72rem;
    padding: 0.48rem 0.55rem;
    min-height: 0;
  }

  .portfolio-game-body .portfolio-ttt-btn--new {
    font-size: 0.72rem;
    padding: 0.48rem 0.85rem;
    min-height: 0;
  }

  .portfolio-game-body .portfolio-ttt-status {
    font-size: 1rem;
  }
}

/* Mobile / tablet (≤1024px): under nav sidebar; Play right; modal centered on full container width */
@media (max-width: 1024px) {
  .portfolio-game-anchor {
    z-index: 99;
  }

  /*
   * Widget must span the .container — otherwise position:absolute .portfolio-game-window
   * uses the narrow toggle-only box as containing block and left:50% looks off-center.
   */
  .portfolio-game-widget {
    width: 100%;
    max-width: 100%;
    left: 0;
    right: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }

  .portfolio-game-window {
    right: auto;
    left: 50%;
    transform: translateX(-50%) translateY(12px) scale(0.97);
  }

  .portfolio-game-window.active {
    transform: translateX(-50%) translateY(0) scale(1);
  }

  body:has(.nav-sidebar.open) .portfolio-game-toggle {
    display: none !important;
  }
}

@media (max-width: 1024px) and (prefers-reduced-motion: reduce) {
  .portfolio-game-window,
  .portfolio-game-window.active {
    transform: translateX(-50%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .portfolio-game-window {
    transition: none;
  }

  .portfolio-game-toggle {
    transition: none;
  }

  .portfolio-game-toggle:hover {
    transform: none;
  }
}

/* ----- Back button ----- */
.pgame-back {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
  touch-action: manipulation;
}

.pgame-back:hover {
  background: var(--border);
  color: var(--text);
  border-color: var(--border-strong);
}

/* ----- Game Menu ----- */
.pgame-menu {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.1rem 0.05rem 0.1rem;
}

.pgame-menu-grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: 1fr;
  gap: 0.6rem;
}

.pgame-menu-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 1.15rem 0.6rem;
  border-radius: 14px;
  border: 1px solid rgba(212, 168, 59, 0.18);
  background:
    radial-gradient(circle at 50% 0%, rgba(212, 168, 59, 0.08) 0%, transparent 60%),
    linear-gradient(165deg, rgba(26, 26, 32, 0.95) 0%, rgba(12, 12, 16, 0.95) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 3px 10px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  font-family: var(--font-body);
  color: var(--text-muted);
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s cubic-bezier(0.34, 1.45, 0.64, 1), box-shadow 0.2s ease, color 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.pgame-menu-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(110deg, transparent 25%, rgba(212, 168, 59, 0.15) 50%, transparent 75%);
  transition: left 0.6s ease;
  pointer-events: none;
}

.pgame-menu-card:hover {
  border-color: rgba(212, 168, 59, 0.55);
  background:
    radial-gradient(circle at 50% 0%, rgba(212, 168, 59, 0.18) 0%, transparent 60%),
    linear-gradient(165deg, rgba(36, 30, 22, 0.95) 0%, rgba(20, 16, 10, 0.95) 100%);
  transform: translateY(-3px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 8px 24px rgba(0, 0, 0, 0.4),
    0 0 24px rgba(212, 168, 59, 0.12);
  color: var(--text);
}

.pgame-menu-card:hover::before {
  left: 100%;
}

.pgame-menu-card:active {
  transform: translateY(-1px) scale(0.97);
}

.pgame-menu-card__icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(232, 192, 74, 0.22) 0%, rgba(140, 100, 30, 0.08) 100%);
  border: 1px solid rgba(212, 168, 59, 0.35);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 12px rgba(212, 168, 59, 0.15);
  color: var(--accent-light);
  transition: transform 0.3s cubic-bezier(0.34, 1.45, 0.64, 1), box-shadow 0.25s ease;
}

.pgame-menu-card:hover .pgame-menu-card__icon {
  transform: scale(1.08) rotate(-4deg);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.15),
    0 6px 18px rgba(212, 168, 59, 0.3);
}

.pgame-menu-card__name {
  position: relative;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* ----- Shared game view ----- */
.pgame-view {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.pgame-shell {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: hidden;
  position: relative;
}

.pgame-hud {
  display: flex;
  align-items: stretch;
  gap: 0.45rem;
  flex-shrink: 0;
}

.pgame-hud-stat {
  flex: 1 1 0;
  text-align: center;
  padding: 0.5rem 0.45rem;
  border-radius: 10px;
  background:
    radial-gradient(circle at 50% 0%, rgba(212, 168, 59, 0.08) 0%, transparent 70%),
    linear-gradient(145deg, rgba(24, 24, 30, 0.95) 0%, rgba(14, 14, 18, 0.95) 100%);
  border: 1px solid rgba(212, 168, 59, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 2px 8px rgba(0, 0, 0, 0.25);
}

.pgame-hud-label {
  display: block;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: 0.2rem;
}

.pgame-hud-val {
  display: block;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--accent-light);
  text-shadow: 0 0 8px rgba(212, 168, 59, 0.25);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.pgame-result-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0.65rem;
  background: rgba(6, 6, 8, 0.82);
  backdrop-filter: blur(6px);
  border-radius: inherit;
}

.pgame-result-overlay[aria-hidden="false"] {
  display: flex;
}

.pgame-result-card {
  width: 100%;
  max-width: 16rem;
  padding: 1.15rem 1rem 1.1rem;
  text-align: center;
  border-radius: 14px;
  background:
    radial-gradient(circle at 50% 0%, rgba(212, 168, 59, 0.15) 0%, transparent 60%),
    linear-gradient(165deg, rgba(26, 26, 32, 0.98) 0%, rgba(12, 12, 16, 0.99) 100%);
  border: 1px solid rgba(212, 168, 59, 0.4);
  box-shadow:
    0 16px 48px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 0 30px rgba(212, 168, 59, 0.1);
  animation: pgame-result-in 0.35s cubic-bezier(0.34, 1.45, 0.64, 1);
}

@keyframes pgame-result-in {
  0%   { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.pgame-result-title {
  display: block;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
  margin: 0 0 0.4rem;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 12px rgba(212, 168, 59, 0.3);
}

.pgame-result-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 0 0 0.85rem;
  line-height: 1.5;
}

.pgame-btn-retry {
  width: 100%;
  padding: 0.6rem 0.85rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.pgame-btn-start {
  flex-shrink: 0;
  width: 100%;
  padding: 0.7rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-top: auto;
}

/* ============================================================
   MEMORY MATCH — Polished card design with smooth flip + glow
   ============================================================ */
.pgame-memory-board {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 0.45rem;
  padding: 0.15rem;
}

.pgame-mem-cell {
  position: relative;
  border-radius: 12px;
  border: 1px solid rgba(212, 168, 59, 0.28);
  background:
    repeating-linear-gradient(45deg, rgba(212, 168, 59, 0.07) 0 2px, transparent 2px 8px),
    linear-gradient(135deg, #1c1c24 0%, #0c0c12 100%);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 3px 10px rgba(0, 0, 0, 0.3);
  transition: transform 0.18s cubic-bezier(0.34, 1.45, 0.64, 1), border-color 0.2s ease, box-shadow 0.2s ease, background 0.25s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  outline: none;
  overflow: hidden;
}

.pgame-mem-cell::after {
  content: '?';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1rem, 5.5vw, 1.5rem);
  color: rgba(212, 168, 59, 0.45);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.pgame-mem-cell .pgame-mem-face {
  font-size: clamp(1.4rem, 7.5vw, 2rem);
  opacity: 0;
  transform: scale(0.5) rotate(-15deg);
  transition: opacity 0.25s ease 0.05s, transform 0.35s cubic-bezier(0.34, 1.65, 0.64, 1) 0.05s;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}

.pgame-mem-cell:hover:not(.is-flipped):not(.is-matched) {
  border-color: rgba(232, 192, 74, 0.55);
  transform: translateY(-3px) scale(1.03);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 8px 22px rgba(0, 0, 0, 0.4),
    0 0 18px rgba(212, 168, 59, 0.18);
}

.pgame-mem-cell:hover:not(.is-flipped):not(.is-matched)::after {
  color: rgba(232, 192, 74, 0.8);
}

.pgame-mem-cell:active:not(.is-flipped):not(.is-matched) {
  transform: scale(0.96);
}

.pgame-mem-cell.is-flipped,
.pgame-mem-cell.is-matched {
  background: linear-gradient(145deg, rgba(212, 168, 59, 0.12) 0%, rgba(20, 20, 26, 0.95) 100%);
  border-color: rgba(212, 168, 59, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 4px 18px rgba(212, 168, 59, 0.18);
}

.pgame-mem-cell.is-flipped::after,
.pgame-mem-cell.is-matched::after {
  opacity: 0;
}

.pgame-mem-cell.is-flipped .pgame-mem-face,
.pgame-mem-cell.is-matched .pgame-mem-face {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.pgame-mem-cell.is-matched {
  border-color: rgba(34, 197, 94, 0.65);
  background: linear-gradient(145deg, rgba(34, 197, 94, 0.18) 0%, rgba(15, 22, 18, 0.95) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 0 22px rgba(34, 197, 94, 0.3);
  pointer-events: none;
  animation: pgame-mem-pulse 0.55s ease;
}

@keyframes pgame-mem-pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ============================================================
   SNAKE — Bigger d-pad, polished controls, retro vibe
   ============================================================ */
.pgame-snake-wrap {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(212, 168, 59, 0.22);
  background:
    radial-gradient(circle at 30% 20%, rgba(212, 168, 59, 0.08) 0%, transparent 50%),
    linear-gradient(160deg, rgba(15, 15, 20, 0.95) 0%, rgba(8, 8, 12, 0.98) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 4px 20px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

#snakeCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.pgame-snake-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 8, 0.85);
  backdrop-filter: blur(8px);
  z-index: 5;
  padding: 0.75rem;
}

.pgame-snake-overlay.is-hidden {
  display: none;
}

.pgame-snake-dpad {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 0.4rem;
  width: 100%;
  max-width: 220px;
  aspect-ratio: 3 / 2.4;
  margin: 0 auto;
}

.pgame-dpad-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  width: 100%;
  height: 100%;
  border-radius: 12px;
  border: 1px solid rgba(212, 168, 59, 0.25);
  background: linear-gradient(145deg, rgba(34, 34, 42, 0.95) 0%, rgba(18, 18, 24, 0.98) 100%);
  color: var(--accent-light);
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    inset 0 -2px 0 rgba(0, 0, 0, 0.3),
    0 3px 10px rgba(0, 0, 0, 0.35);
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.pgame-dpad-btn svg {
  width: 22px;
  height: 22px;
}

.pgame-dpad-btn:hover {
  border-color: rgba(212, 168, 59, 0.5);
  color: #f0d078;
  background: linear-gradient(145deg, rgba(44, 38, 24, 0.95) 0%, rgba(28, 24, 16, 0.98) 100%);
}

.pgame-dpad-btn:active {
  transform: translateY(2px) scale(0.94);
  background: linear-gradient(145deg, rgba(212, 168, 59, 0.25) 0%, rgba(140, 110, 40, 0.2) 100%);
  color: #fff;
  box-shadow:
    inset 0 2px 6px rgba(0, 0, 0, 0.4),
    0 1px 4px rgba(0, 0, 0, 0.2);
}

.pgame-dpad-up    { grid-column: 2; grid-row: 1; }
.pgame-dpad-left  { grid-column: 1; grid-row: 2; }
.pgame-dpad-right { grid-column: 3; grid-row: 2; }
.pgame-dpad-down  { grid-column: 2; grid-row: 3; }

/* ============================================================
   WHACK-A-MOLE — Real holes with pop-up moles + dirt rim
   ============================================================ */
.pgame-whack-board {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 0.5rem;
  padding: 0.4rem;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 50% 50%, rgba(86, 60, 30, 0.18) 0%, transparent 70%),
    linear-gradient(160deg, rgba(40, 28, 18, 0.4) 0%, rgba(15, 12, 8, 0.6) 100%);
  border: 1px solid rgba(120, 90, 50, 0.2);
}

.pgame-whack-hole {
  position: relative;
  border-radius: 50%;
  background: transparent;
  border: none;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  padding: 0;
}

.pgame-whack-pit {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 50% 35%, #000 0%, #0a0608 50%, #1a1410 100%);
  box-shadow:
    inset 0 6px 14px rgba(0, 0, 0, 0.85),
    inset 0 -2px 4px rgba(80, 60, 40, 0.15),
    0 2px 0 rgba(120, 88, 50, 0.25),
    0 4px 12px rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(80, 58, 30, 0.4);
  z-index: 1;
}

.pgame-whack-mole {
  position: relative;
  z-index: 2;
  width: 78%;
  height: 78%;
  border: none;
  border-radius: 50%;
  background: linear-gradient(165deg, #c79a6a 0%, #8b6240 50%, #5d3f24 100%);
  box-shadow:
    inset 0 4px 8px rgba(255, 220, 180, 0.2),
    inset 0 -6px 12px rgba(0, 0, 0, 0.35),
    0 4px 10px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.2rem, 7vw, 1.9rem);
  transform: translateY(115%) scale(0.85);
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

.pgame-whack-mole-emoji {
  display: block;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.4));
  transform: scaleX(1) translateY(-2px);
  font-style: normal;
}

.pgame-whack-hole.is-active .pgame-whack-mole {
  transform: translateY(8%) scale(1);
}

.pgame-whack-hole.is-hit .pgame-whack-mole {
  transform: translateY(8%) scale(0.78);
  background: linear-gradient(165deg, #d4a574 0%, #a07045 50%, #6d4a2c 100%);
  box-shadow:
    inset 0 4px 8px rgba(255, 220, 180, 0.3),
    inset 0 -6px 12px rgba(0, 0, 0, 0.35),
    0 0 24px rgba(34, 197, 94, 0.5);
  animation: pgame-whack-bonk 0.25s ease;
}

@keyframes pgame-whack-bonk {
  0%   { transform: translateY(8%) scale(1); }
  50%  { transform: translateY(40%) scale(0.7); }
  100% { transform: translateY(115%) scale(0.85); }
}

/* ============================================================
   MATH SPRINT — Display + answer pad
   ============================================================ */
.pgame-math-question {
  flex: 1 1 0;
  min-height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(212, 168, 59, 0.25);
  background:
    radial-gradient(circle at 30% 30%, rgba(212, 168, 59, 0.1) 0%, transparent 60%),
    linear-gradient(160deg, rgba(20, 20, 26, 0.95) 0%, rgba(10, 10, 14, 0.98) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 4px 16px rgba(0, 0, 0, 0.3);
  position: relative;
  padding: 1rem;
  overflow: hidden;
}

.pgame-math-question::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, rgba(212, 168, 59, 0.03) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(90deg, rgba(212, 168, 59, 0.03) 0 1px, transparent 1px 24px);
  pointer-events: none;
  opacity: 0.5;
}

.pgame-math-expr {
  position: relative;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 8vw, 2.1rem);
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.04em;
  text-shadow: 0 2px 16px rgba(212, 168, 59, 0.25);
}

.pgame-math-answers {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.pgame-math-btn {
  padding: 0.85rem 0.5rem;
  min-height: 52px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: linear-gradient(165deg, rgba(28, 28, 36, 0.95) 0%, rgba(14, 14, 18, 0.98) 100%);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 2px 8px rgba(0, 0, 0, 0.25);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease, color 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.pgame-math-btn:hover:not(:disabled) {
  border-color: rgba(212, 168, 59, 0.55);
  background: linear-gradient(165deg, rgba(212, 168, 59, 0.12) 0%, rgba(22, 22, 28, 0.95) 100%);
  color: #f0d078;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.07),
    0 4px 14px rgba(212, 168, 59, 0.18);
}

.pgame-math-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.pgame-math-btn.is-correct {
  border-color: rgba(34, 197, 94, 0.7);
  background: linear-gradient(165deg, rgba(34, 197, 94, 0.22) 0%, rgba(22, 22, 26, 0.95) 100%);
  color: #4ade80;
  box-shadow: 0 0 16px rgba(34, 197, 94, 0.3);
  animation: pgame-math-correct 0.4s ease;
}

@keyframes pgame-math-correct {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.pgame-math-btn.is-wrong {
  border-color: rgba(239, 68, 68, 0.7);
  background: linear-gradient(165deg, rgba(239, 68, 68, 0.18) 0%, rgba(22, 22, 26, 0.95) 100%);
  color: #f87171;
  animation: pgame-math-shake 0.35s ease;
}

@keyframes pgame-math-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ============================================================
   REACTION TIME — Big bold display
   ============================================================ */
.pgame-rxn-zone {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  border: 2px solid var(--border-strong);
  background: linear-gradient(160deg, rgba(20, 20, 26, 0.95) 0%, rgba(10, 10, 14, 0.98) 100%);
  cursor: pointer;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  text-align: center;
  padding: 1.25rem 1rem;
  outline: none;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 4px 20px rgba(0, 0, 0, 0.3);
}

.pgame-rxn-zone:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -2px;
}

.pgame-rxn-zone.is-waiting {
  background:
    radial-gradient(circle at 50% 50%, rgba(239, 68, 68, 0.25) 0%, rgba(150, 30, 30, 0.18) 60%, rgba(60, 12, 12, 0.4) 100%);
  border-color: rgba(239, 68, 68, 0.6);
  box-shadow:
    inset 0 0 50px rgba(239, 68, 68, 0.15),
    0 0 30px rgba(239, 68, 68, 0.2);
  animation: pgame-rxn-pulse-red 1.4s ease-in-out infinite;
}

@keyframes pgame-rxn-pulse-red {
  0%, 100% { box-shadow: inset 0 0 50px rgba(239, 68, 68, 0.15), 0 0 30px rgba(239, 68, 68, 0.2); }
  50% { box-shadow: inset 0 0 60px rgba(239, 68, 68, 0.25), 0 0 40px rgba(239, 68, 68, 0.35); }
}

.pgame-rxn-zone.is-go {
  background:
    radial-gradient(circle at 50% 50%, rgba(34, 197, 94, 0.35) 0%, rgba(22, 163, 74, 0.22) 60%, rgba(10, 60, 30, 0.4) 100%);
  border-color: rgba(34, 197, 94, 0.8);
  box-shadow:
    inset 0 0 60px rgba(34, 197, 94, 0.2),
    0 0 40px rgba(34, 197, 94, 0.4);
  animation: pgame-rxn-go 0.4s cubic-bezier(0.34, 1.45, 0.64, 1);
}

@keyframes pgame-rxn-go {
  0% { transform: scale(0.98); }
  50% { transform: scale(1.015); }
  100% { transform: scale(1); }
}

.pgame-rxn-zone.is-result {
  border-color: rgba(212, 168, 59, 0.55);
  background:
    radial-gradient(circle at 50% 50%, rgba(212, 168, 59, 0.15) 0%, transparent 60%),
    linear-gradient(160deg, rgba(20, 20, 26, 0.95) 0%, rgba(10, 10, 14, 0.98) 100%);
  box-shadow:
    inset 0 0 40px rgba(212, 168, 59, 0.08),
    0 4px 24px rgba(212, 168, 59, 0.15);
}

.pgame-rxn-content {
  pointer-events: none;
  max-width: 100%;
}

.pgame-rxn-title {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 7vw, 1.85rem);
  font-weight: 800;
  color: var(--text);
  margin: 0 0 0.6rem;
  letter-spacing: 0.02em;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
}

.pgame-rxn-zone.is-go .pgame-rxn-title {
  color: #fff;
  font-size: clamp(1.6rem, 9vw, 2.4rem);
  text-shadow: 0 0 24px rgba(34, 197, 94, 0.7);
  letter-spacing: 0.08em;
}

.pgame-rxn-zone.is-result .pgame-rxn-title {
  color: var(--accent-light);
  font-size: clamp(1.6rem, 9vw, 2.2rem);
  text-shadow: 0 0 20px rgba(212, 168, 59, 0.4);
}

.pgame-rxn-sub {
  font-size: clamp(0.75rem, 3.2vw, 0.9rem);
  color: var(--text-muted);
  margin: 0;
  line-height: 1.55;
  font-weight: 500;
}

.pgame-rxn-sub strong {
  color: #4ade80;
  font-weight: 700;
}

.pgame-rxn-zone.is-waiting .pgame-rxn-sub strong {
  color: #4ade80;
}

/* ----- Tic tac toe main content (modal) ----- */
.portfolio-game-body .portfolio-ttt-shell {
  max-width: none;
  margin: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 0.5rem;
}

.portfolio-game-body .portfolio-ttt-hud {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0;
}

.portfolio-game-body .portfolio-ttt-status-panel {
  text-align: center;
  padding: 0.55rem 0.65rem 0.6rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(
    145deg,
    rgba(22, 22, 26, 0.95) 0%,
    rgba(15, 15, 18, 0.88) 100%
  );
  border: 1px solid var(--border-strong);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 4px 20px rgba(0, 0, 0, 0.2);
}

.portfolio-game-body .portfolio-ttt-status-eyebrow {
  display: block;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: 0.35rem;
}

.portfolio-game-body .portfolio-ttt-status {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  min-height: 1.35em;
  line-height: 1.3;
}

.portfolio-ttt-hud {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.portfolio-ttt-status {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  min-height: 1.4em;
}

.portfolio-ttt-status span {
  color: var(--accent-light);
}

.portfolio-game-body .portfolio-ttt-actions {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.45rem;
  flex-wrap: nowrap;
}

.portfolio-game-body .portfolio-ttt-mode-group {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  overflow: hidden;
  background: var(--bg-elevated);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.portfolio-game-body .portfolio-ttt-btn--mode {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  border-radius: 0;
  border: none;
  border-right: 1px solid var(--border);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.45rem 0.4rem;
  background: transparent;
  color: var(--text-muted);
  transition:
    background 0.2s ease,
    color 0.2s ease,
    transform 0.18s cubic-bezier(0.34, 1.45, 0.64, 1),
    filter 0.18s ease;
}

.portfolio-game-body .portfolio-ttt-btn--mode:last-child {
  border-right: none;
}

.portfolio-game-body .portfolio-ttt-btn--mode:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  filter: brightness(1.12);
}

.portfolio-game-body .portfolio-ttt-btn--mode:active:not(:disabled) {
  transform: scale(0.96);
  filter: brightness(0.95);
}

.portfolio-game-body .portfolio-ttt-btn--mode.is-active {
  background: linear-gradient(
    180deg,
    rgba(232, 192, 74, 0.22) 0%,
    rgba(212, 168, 59, 0.14) 100%
  );
  color: #f0d078;
  text-shadow: 0 0 14px rgba(232, 192, 74, 0.35);
  border-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 0 0 1px rgba(212, 168, 59, 0.22);
}

.portfolio-game-body .portfolio-ttt-btn--mode.is-active:hover:not(:disabled) {
  background: linear-gradient(
    180deg,
    rgba(232, 192, 74, 0.3) 0%,
    rgba(212, 168, 59, 0.2) 100%
  );
  color: #f5dc98;
  text-shadow: 0 0 18px rgba(240, 208, 120, 0.45);
  filter: brightness(1.04);
}

.portfolio-game-body .portfolio-ttt-btn--mode.is-active:active:not(:disabled) {
  filter: brightness(0.98);
}

.portfolio-game-body .portfolio-ttt-btn--new {
  flex: 0 0 auto;
  padding: 0.45rem 0.75rem;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 12px var(--accent-glow);
  transition:
    transform 0.2s cubic-bezier(0.34, 1.45, 0.64, 1),
    box-shadow 0.2s ease,
    filter 0.2s ease,
    background 0.2s ease,
    color 0.2s ease;
}

.portfolio-ttt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.portfolio-ttt-btn {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color var(--transition),
    border-color var(--transition),
    background var(--transition),
    transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.portfolio-ttt-btn:hover:not(:disabled):not(.portfolio-ttt-btn--primary) {
  color: var(--text);
  border-color: var(--border-focus);
  background: var(--bg-elevated);
}

.portfolio-ttt-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.portfolio-ttt-btn.is-active {
  border-color: var(--accent);
  color: var(--accent-light);
  background: var(--accent-dim);
}

.portfolio-ttt-btn--primary {
  background: var(--gradient-accent);
  color: var(--bg);
  border-color: transparent;
  box-shadow: 0 4px 18px var(--accent-glow);
  transition:
    color var(--transition),
    background var(--transition),
    border-color var(--transition),
    transform 0.22s cubic-bezier(0.34, 1.45, 0.64, 1),
    box-shadow 0.22s ease,
    filter 0.2s ease;
}

.portfolio-ttt-btn--primary:hover:not(:disabled),
.portfolio-ttt-btn--primary:focus-visible:not(:disabled) {
  color: var(--bg);
  background: var(--gradient-accent);
  border-color: transparent;
  transform: translateY(-2px);
  box-shadow: 0 8px 26px var(--accent-glow-strong);
  filter: brightness(1.08);
}

.portfolio-ttt-btn--primary:active:not(:disabled) {
  color: var(--bg);
  background: var(--gradient-accent);
  border-color: transparent;
  transform: translateY(0) scale(0.96);
  box-shadow: 0 2px 12px var(--accent-glow);
  filter: brightness(1.03);
}

.portfolio-ttt-btn--primary.is-active {
  color: var(--bg);
  background: var(--gradient-accent);
  border-color: transparent;
}

/* Board: fill remaining column height (avoid align-items:center collapse + broken cqh) */
.portfolio-game-body .portfolio-ttt-board-wrap {
  flex: 1 1 0;
  min-height: 7.5rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.portfolio-game-body .portfolio-ttt-board-frame {
  position: relative;
  overflow: hidden;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(
    160deg,
    rgba(212, 168, 59, 0.06) 0%,
    rgba(10, 10, 12, 0.5) 45%,
    rgba(15, 15, 18, 0.85) 100%
  );
  border: 1px solid rgba(212, 168, 59, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 8px 28px rgba(0, 0, 0, 0.25);
}

/* End-game overlay: centered on board */
.portfolio-game-body .portfolio-ttt-result-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0.65rem;
  background: rgba(6, 6, 8, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: inherit;
}

.portfolio-game-body .portfolio-ttt-result-overlay.is-visible {
  display: flex;
}

.portfolio-game-body .portfolio-ttt-result-overlay__card {
  width: 100%;
  max-width: 15.5rem;
  margin: 0 auto;
  padding: 0.85rem 1rem 1rem;
  text-align: center;
  border-radius: var(--radius-lg);
  background: linear-gradient(
    165deg,
    rgba(22, 22, 28, 0.98) 0%,
    rgba(12, 12, 16, 0.99) 100%
  );
  border: 1px solid rgba(212, 168, 59, 0.28);
  box-shadow:
    0 12px 36px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.portfolio-game-body .portfolio-ttt-result-overlay__title {
  display: block;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
  margin: 0 0 0.4rem;
}

/* Mini board: final positions + winning line (decorative; aria-hidden) */
.portfolio-game-body .portfolio-ttt-result-preview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 0.18rem;
  width: 5.25rem;
  max-width: 100%;
  aspect-ratio: 1;
  margin: 0 auto 0.55rem;
  user-select: none;
}

.portfolio-game-body .portfolio-ttt-result-preview__cell {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  min-width: 0;
  min-height: 0;
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(
    165deg,
    rgba(22, 22, 26, 0.95) 0%,
    rgba(10, 10, 14, 0.98) 100%
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
}

.portfolio-game-body .portfolio-ttt-result-preview__cell.is-x {
  color: var(--accent-light);
}

.portfolio-game-body .portfolio-ttt-result-preview__cell.is-o {
  color: var(--accent-secondary);
}

.portfolio-game-body .portfolio-ttt-result-preview__cell.is-winning {
  border-color: rgba(14, 165, 233, 0.45);
  background: var(--accent-secondary-dim);
  box-shadow: inset 0 0 0 1px rgba(14, 165, 233, 0.2);
}

.portfolio-game-body .portfolio-ttt-result-overlay__sub {
  margin: 0 0 0.75rem;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.portfolio-game-body .portfolio-ttt-btn--try-again {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0.5rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 700;
}

/* Square board; equal cells (minmax prevents content from shrinking tracks) */
.portfolio-game-body .portfolio-ttt-board {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  aspect-ratio: 1;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  height: auto;
  margin: 0;
  gap: 0.3rem;
  align-self: center;
}

/* Fixed box model: same border width in every state — no layout shift on tap / hover / win */
.portfolio-game-body .portfolio-ttt-cell {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  font-family: var(--font-display);
  font-size: clamp(1rem, 6vw, 1.75rem);
  touch-action: manipulation;
  border-radius: var(--radius);
  border-width: 1px;
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.07);
  background: linear-gradient(
    165deg,
    rgba(22, 22, 26, 0.9) 0%,
    rgba(12, 12, 15, 0.95) 100%
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition:
    border-color var(--transition),
    background var(--transition),
    box-shadow var(--transition),
    transform 0.2s cubic-bezier(0.34, 1.45, 0.64, 1),
    filter 0.2s ease;
}

.portfolio-game-body .portfolio-ttt-cell:hover:not(:disabled):not(.is-taken) {
  border-color: rgba(212, 168, 59, 0.45);
  background: linear-gradient(
    165deg,
    rgba(212, 168, 59, 0.08) 0%,
    rgba(22, 22, 26, 0.9) 100%
  );
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 0 0 1px rgba(212, 168, 59, 0.18);
  transform: scale(1.03);
  filter: brightness(1.08);
}

.portfolio-game-body .portfolio-ttt-cell:active:not(:disabled):not(.is-taken) {
  transform: scale(0.94);
  filter: brightness(0.92);
}

.portfolio-game-body .portfolio-ttt-cell.is-x {
  text-shadow: 0 0 20px var(--accent-glow);
}

.portfolio-game-body .portfolio-ttt-cell.is-o {
  text-shadow: 0 0 18px rgba(14, 165, 233, 0.35);
}

.portfolio-game-body .portfolio-ttt-cell.is-winning {
  border-color: rgba(212, 168, 59, 0.55);
  background: linear-gradient(
    145deg,
    rgba(212, 168, 59, 0.2) 0%,
    rgba(14, 165, 233, 0.12) 100%
  );
  box-shadow:
    inset 0 0 0 1px rgba(212, 168, 59, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 4px 16px rgba(14, 165, 233, 0.12);
}

.portfolio-game-body .portfolio-ttt-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* vmin tracks the smaller modal dimension so marks scale with the board */
@supports (aspect-ratio: 1) {
  .portfolio-game-body .portfolio-ttt-cell {
    font-size: clamp(1.05rem, 10vmin, 1.85rem);
  }
}

.portfolio-ttt-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  aspect-ratio: 1;
  margin: 0 auto;
}

.portfolio-ttt-cell {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius-lg);
  border-width: 1px;
  border-style: solid;
  border-color: var(--border);
  background: var(--surface);
  cursor: pointer;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 10vw, 2.35rem);
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  transition:
    border-color var(--transition),
    background var(--transition),
    box-shadow var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.portfolio-ttt-cell:hover:not(:disabled):not(.is-taken) {
  border-color: var(--border-focus);
  background: var(--bg-elevated);
}

.portfolio-ttt-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.portfolio-ttt-cell.is-taken {
  cursor: default;
}

.portfolio-ttt-cell.is-x {
  color: var(--accent-light);
}

.portfolio-ttt-cell.is-o {
  color: var(--accent-secondary);
}

.portfolio-ttt-cell.is-winning {
  border-color: rgba(14, 165, 233, 0.55);
  background: var(--accent-secondary-dim);
  box-shadow: inset 0 0 0 1px rgba(14, 165, 233, 0.25);
}

.portfolio-ttt-cell:disabled {
  opacity: 1;
}

.portfolio-game-body .portfolio-ttt-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.1rem;
}

.portfolio-game-body .portfolio-ttt-hint {
  margin: 0;
  padding: 0.4rem 0.45rem;
  font-size: 0.65rem;
  line-height: 1.4;
  text-align: center;
  color: var(--text-subtle);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
}

.portfolio-game-body .portfolio-ttt-hint strong {
  color: var(--text-muted);
  font-weight: 600;
}

.portfolio-ttt-hint {
  margin: 1.1rem 0 0;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-subtle);
  line-height: 1.5;
}

.portfolio-ttt-live {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .portfolio-ttt-cell,
  .portfolio-ttt-btn,
  .portfolio-ttt-btn--primary,
  .portfolio-game-toggle,
  .portfolio-game-close,
  .portfolio-game-body .portfolio-ttt-btn--mode,
  .portfolio-game-body .portfolio-ttt-btn--new {
    transition: none;
  }

  .portfolio-ttt-btn--primary:hover,
  .portfolio-ttt-btn--primary:focus-visible,
  .portfolio-ttt-btn--primary:active,
  .portfolio-game-toggle:hover,
  .portfolio-game-toggle:active,
  .portfolio-game-close:hover,
  .portfolio-game-close:active,
  .portfolio-game-body .portfolio-ttt-btn--mode:hover,
  .portfolio-game-body .portfolio-ttt-btn--mode:active,
  .portfolio-game-body .portfolio-ttt-cell:hover,
  .portfolio-game-body .portfolio-ttt-cell:active {
    transform: none;
    filter: none;
  }

  .portfolio-game-body .portfolio-ttt-btn--mode.is-active,
  .portfolio-game-body .portfolio-ttt-btn--mode.is-active:hover,
  .portfolio-game-body .portfolio-ttt-btn--mode.is-active:active {
    text-shadow: none;
    filter: none;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }

  .pgame-menu-card,
  .pgame-mem-cell,
  .pgame-whack-mole,
  .pgame-math-btn,
  .pgame-rxn-zone,
  .pgame-dpad-btn {
    transition: none;
    animation: none;
  }

  .pgame-mem-cell.is-matched,
  .pgame-math-btn.is-correct,
  .pgame-math-btn.is-wrong,
  .pgame-result-card,
  .pgame-rxn-zone.is-waiting,
  .pgame-rxn-zone.is-go,
  .pgame-whack-hole.is-hit .pgame-whack-mole {
    animation: none;
  }
}

/* ============================================================
   Phone-specific tweaks for new games
   ============================================================ */
@media (max-width: 480px) {
  .pgame-menu-grid {
    gap: 0.5rem;
  }

  .pgame-menu-card {
    padding: 1rem 0.5rem;
    gap: 0.55rem;
  }

  .pgame-menu-card__icon {
    width: 44px;
    height: 44px;
  }

  .pgame-menu-card__name {
    font-size: 0.75rem;
  }

  .pgame-snake-dpad {
    max-width: 100%;
    gap: 0.5rem;
    aspect-ratio: 3 / 2.4;
  }

  .pgame-dpad-btn svg {
    width: 24px;
    height: 24px;
  }

  .pgame-math-expr {
    font-size: clamp(1.4rem, 9vw, 1.8rem);
  }

  .pgame-math-btn {
    min-height: 48px;
    font-size: 1rem;
  }

  .pgame-hud-val {
    font-size: 0.95rem;
  }

  .pgame-hud-label {
    font-size: 0.55rem;
  }

  .pgame-rxn-title {
    font-size: clamp(1.1rem, 7vw, 1.6rem);
  }

  .pgame-rxn-zone.is-go .pgame-rxn-title {
    font-size: clamp(1.5rem, 10vw, 2.2rem);
  }
}

/* ============================================================
   Tablet d-pad: allow more horizontal room
   ============================================================ */
@media (min-width: 481px) and (max-width: 1024px) {
  .pgame-snake-dpad {
    max-width: 240px;
  }

  .pgame-dpad-btn svg {
    width: 26px;
    height: 26px;
  }
}
